home *** CD-ROM | disk | FTP | other *** search
- /*
- * Utility Routines
- *
- * Return the machine load average as a long int. This needs a lot of work
- * since it is very Unix
- * oriented. This is a rip-off of /usr/src/cmd/w.c with the
- * provision that we do not do an nlist or open a file on every
- * call, just the first one. It returns the one-minute load
- * average, multiplied by 100 and then TRUNCATED.
- *
- * WARNING: avenrun is an array of floating points on the VAXen
- * but an array of fixed point (ints) on the SUNs, which have
- * no hardware floating point.
- *
- * This is a rip-off from Eden.
- */
-
- #include <nlist.h>
- #include "Kernel/h/system.h"
- #include "Kernel/h/kmdTypes.h"
- #ifdef sun
- #include <sys/param.h>
- #endif
-
- static struct nlist nl[] = {
- { "_avenrun" },
- #define X_AVENRUN 0
- { 0 }
- };
-
- static int kmem = -1;
- static int opened = 0;
-
- #if defined(vax)
- static double avenrun[3];
- #endif
- #if defined(sun)
- static long avenrun[3];
- #endif
-
- #ifndef NODISK
- extern char nodisk;
- #endif
-
- int MachineLoad()
- {
- #ifndef NODISK
- if(nodisk){
- #endif
- return 1;
- #ifndef NODISK
- } else {
- if ( ! opened ) {
- opened = 1;
- kmem = open("/dev/kmem",0);
- if ( kmem < 0 ) return( 1000000 );
- nlist("/vmunix", nl);
- if ( nl[0].n_type == 0 ) return( 10000000 );
- }
- if ( kmem < 0 ) return( 1000000 );
- if ( nl[0].n_type == 0 ) return( 10000000 );
- (void) lseek(kmem, (long)nl[X_AVENRUN].n_value, 0 );
- (void) read(kmem, (char *) avenrun, sizeof(avenrun));
- #if defined(vax)
- return( (int) (avenrun[1] * 100.0) );
- #endif
- #if defined(sun)
- /* FSCALE is defined in /usr/include/sys/param.h on SUNs */
- return( avenrun[1]*100/FSCALE );
- #endif
- }
- #endif
- }
-
- float MachineLoadAvg()
- /* same but return a float */
- {
- #ifndef NODISK
- if(nodisk){
- #endif
- return 1.0;
- #ifndef NODISK
- } else {
- if ( ! opened ) {
- opened = 1;
- KMDTrace("FixMe", 6, "Might have to fix this for 4.3\n");
- kmem = open("/dev/kmem",0);
- if ( kmem < 0 ) return( 1000000 );
- nlist("/vmunix", nl);
- if ( nl[0].n_type == 0 ) return( 10000000 );
- }
- if ( kmem < 0 ) return( 10000000 );
- if ( nl[0].n_type == 0 ) return( 10000000 );
- (void) lseek(kmem, (long)nl[X_AVENRUN].n_value, 0 );
- (void) read(kmem, (char *) avenrun, sizeof(avenrun));
- #if defined(vax)
- return( (float) (avenrun[1]) );
- #endif
- #if defined(sun)
- /* FSCALE is defined in /usr/include/sys/param.h on SUNs */
- return( (double) avenrun[1] / (double) FSCALE );
- #endif
- }
- #endif
- }
-