Problems with kstat, -m64, load average

Problems with kstat, -m64, load average

Post by djber.. » Fri, 05 May 2006 05:29:21



Hi all,

Solaris 10
gcc 3.4.5 (blastwave package)

The following code works fine when compiled with -m32.  However, when
compiled with -m64 the load average values are totally wonky (as in
huge, wrong numbers).  I tinkered with changing the cast, but that
didn't seem to matter.  Any ideas?

/* loadavgtest.c
 *
 * Built with gcc -Wall -lkstat -m64 loadavgtest.c -o loadavgtest
 */
#include <stdio.h>
#include <kstat.h>

int main(){
   kstat_ctl_t* kc;
   kstat_t* ksp;
   kstat_named_t* kn1;
   kstat_named_t* kn5;
   kstat_named_t* kn15;

   kc = kstat_open();

   if(kc == 0){
      printf("kstat_open() error\n");
      return -1;
   }

   ksp = kstat_lookup(kc, "unix", 0, "system_misc");

   if(ksp == 0){
      printf("kstat_lookup() error\n");
      return -1;
   }

   if(kstat_read(kc,ksp,0) == -1){
      printf("kstat_read() error\n");
      return -1;
   }

   kn1  = kstat_data_lookup(ksp, "avenrun_1min");
   kn5  = kstat_data_lookup(ksp, "avenrun_5min");
   kn15 = kstat_data_lookup(ksp, "avenrun_15min");

   if( (kn1 == 0) || (kn5 == 0) || (kn15 == 0) ){
      printf("kstat_lookup() error\n");
      return -1;
   }

   printf("1 val: %f\n", (double)kn1->value.ul/256);
   printf("5 val: %f\n", (double)kn1->value.ul/256);
   printf("15 val: %f\n", (double)kn1->value.ul/256);

   return 0;

Quote:}

Thanks,

Dan

 
 
 

Problems with kstat, -m64, load average

Post by Peter Tribb » Fri, 05 May 2006 05:58:37




Quote:

> The following code works fine when compiled with -m32.  However, when
> compiled with -m64 the load average values are totally wonky (as in
> huge, wrong numbers).  I tinkered with changing the cast, but that
> didn't seem to matter.  Any ideas?

...
>    kn1  = kstat_data_lookup(ksp, "avenrun_1min");
>    kn5  = kstat_data_lookup(ksp, "avenrun_5min");
>    kn15 = kstat_data_lookup(ksp, "avenrun_15min");
...
>    printf("1 val: %f\n", (double)kn1->value.ul/256);
>    printf("5 val: %f\n", (double)kn1->value.ul/256);
>    printf("15 val: %f\n", (double)kn1->value.ul/256);

Well, presumably you meant kn1, kn5, kn15 - not all kn1?

And they're all uint32_t, so get them as

value.ui32

instead of the variable length ul.

Alternatively, why not just call getloadavg(), if all you want are the
load averages?

--
-Peter Tribble
L.I.S., University of Hertfordshire - http://www.herts.ac.uk/
http://www.petertribble.co.uk/ - http://ptribble.blogspot.com/

 
 
 

Problems with kstat, -m64, load average

Post by djber.. » Fri, 05 May 2006 06:18:17





> > The following code works fine when compiled with -m32.  However, when
> > compiled with -m64 the load average values are totally wonky (as in
> > huge, wrong numbers).  I tinkered with changing the cast, but that
> > didn't seem to matter.  Any ideas?

> ...
> >    kn1  = kstat_data_lookup(ksp, "avenrun_1min");
> >    kn5  = kstat_data_lookup(ksp, "avenrun_5min");
> >    kn15 = kstat_data_lookup(ksp, "avenrun_15min");
> ...
> >    printf("1 val: %f\n", (double)kn1->value.ul/256);
> >    printf("5 val: %f\n", (double)kn1->value.ul/256);
> >    printf("15 val: %f\n", (double)kn1->value.ul/256);

> Well, presumably you meant kn1, kn5, kn15 - not all kn1?

Whoops, yes.

Quote:> And they're all uint32_t, so get them as

> value.ui32

> instead of the variable length ul.

Ah, thanks!

Quote:> Alternatively, why not just call getloadavg(), if all you want are the
> load averages?

Not supported on older kernels. :)

Thanks again.

Dan

 
 
 

1. /dev/kstat and load average on Solaris 2?

I'm trying to write some code to determine the load average under
Solaris 2.  While trying to get this working--and it's harder than it
looks--I discovered that uptime opens /dev/kstat and (I think) gets the
load average from some ioctls to that device.  I don't have any
documentation that even mentions /dev/kstat.  There is a
/usr/include/kstat.h file that has some interesting things in it, but I
can't tell how to use them.

I'm not sure why uptime would use /dev/kstat (if it does) for the load
average.  There is an avenrun in the kernel anyway, although I have to
admit I haven't managed to figure out how to get to it from a C
program.  I have code that works under SunOS 4.1.3.

I guess I could always do a popen() uptime, but I'd rather not...

2. Please help....Compaq Mouse.....

3. System Load average: How much load average is good for?

4. Performance improvement with Akira Tsukamoto's Athlon copy_user patch

5. average load average?

6. Clusters and SCSI disks?

7. percpu load avererages / *real* load averages

8. mod_php pb

9. Load average problem...

10. Problem: lpsched drives load average up to 1.0

11. Proftpd - High Load averages and strange performance problems.

12. Extremely High Load Average problem

13. unresonable load average problem