Find the answer to your Linux question:
Results 1 to 4 of 4
Hi.. Basically we're making a load balancer, and we need a way of finding CPU load, somehow from inside the kernel. Using a user-space program isn't an option(too slow)... How ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2006
    Location
    Ireland
    Posts
    9

    Calculating CPU load from kernel module...


    Hi..

    Basically we're making a load balancer, and we need a way of finding CPU load, somehow from inside the kernel. Using a user-space program isn't an option(too slow)...

    How can I access /proc/loadavg or /proc/stat from within the kernel??
    Or is there some systems calls I can use?

    Any help greatly appreciated.

    Cormac Redmond.

  2. #2
    Just Joined!
    Join Date
    Apr 2005
    Location
    Romania
    Posts
    42
    Hi,

    #include <stdlib.h>
    #include <stdio.h>
    double loadavg[3];
    main ()
    {
    int i;
    getloadavg(loadavg, sizeof(loadavg) / sizeof(loadavg[0]));
    for (i = 0; i < (sizeof(loadavg)/sizeof(loadavg[0])); i++)
    printf(" %.2f\n", loadavg[i]);
    }


    Compare the results with this shell command:

    awk '{print "1 min:\t" $1 "\n5 min:\t" $2 "\n15 min:\t" $3 }' /proc/loadavg

  3. #3
    Just Joined! tb10alj's Avatar
    Join Date
    Feb 2006
    Location
    Germany
    Posts
    31
    Quote Originally Posted by Cormac_Redmond
    Hi..
    Basically we're making a load balancer, and we need a way of finding CPU load, somehow from inside the kernel. Using a user-space program isn't an option(too slow)...
    Have a look at loadavg_read_proc() in fs/proc/proc_misc.c
    There you can see, how the values for /proc/loadavg are calculated.


    regards
    JAN

  4. $spacer_open
    $spacer_close
  5. #4
    Just Joined!
    Join Date
    Feb 2006
    Location
    Ireland
    Posts
    9
    Thanks guys...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •