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 ...
- 02-16-2006 #1Just 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.
- 02-16-2006 #2Just 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
- 02-17-2006 #3Have a look at loadavg_read_proc() in fs/proc/proc_misc.c
Originally Posted by Cormac_Redmond
There you can see, how the values for /proc/loadavg are calculated.
regards
JAN
- 02-17-2006 #4Just Joined!
- Join Date
- Feb 2006
- Location
- Ireland
- Posts
- 9
Thanks guys...


Reply With Quote
