Mercurial > hg > xemacs-beta
comparison src/getloadavg.c @ 209:41ff10fd062f r20-4b3
Import from CVS: tag r20-4b3
author | cvs |
---|---|
date | Mon, 13 Aug 2007 10:04:58 +0200 |
parents | 850242ba4a81 |
children | 557eaa0339bf |
comparison
equal
deleted
inserted
replaced
208:f427b8ec4379 | 209:41ff10fd062f |
---|---|
42 | 42 |
43 apollo | 43 apollo |
44 BSD Real BSD, not just BSD-like. | 44 BSD Real BSD, not just BSD-like. |
45 convex | 45 convex |
46 DGUX | 46 DGUX |
47 eunice UNIX emulator under VMS. | |
48 hpux | 47 hpux |
49 MSDOS No-op for MSDOS. | 48 MSDOS No-op for MSDOS. |
50 NeXT | 49 NeXT |
51 sgi | 50 sgi |
52 sequent Sequent Dynix 3.x.x (BSD) | 51 sequent Sequent Dynix 3.x.x (BSD) |
53 _SEQUENT_ Sequent DYNIX/ptx 1.x.x (SYSV) | 52 _SEQUENT_ Sequent DYNIX/ptx 1.x.x (SYSV) |
54 sony_news NEWS-OS (works at least for 4.1C) | 53 sony_news NEWS-OS (works at least for 4.1C) |
55 UMAX | 54 UMAX |
56 UMAX4_3 | 55 UMAX4_3 |
57 VMS | |
58 WIN32 No-op for Windows95/NT. | 56 WIN32 No-op for Windows95/NT. |
59 __linux__ Linux: assumes /proc filesystem mounted. | 57 __linux__ Linux: assumes /proc filesystem mounted. |
60 Support from Michael K. Johnson. | 58 Support from Michael K. Johnson. |
61 __NetBSD__ NetBSD: assumes /kern filesystem mounted. | 59 __NetBSD__ NetBSD: assumes /kern filesystem mounted. |
62 | 60 |
393 #define LOAD_AVE_TYPE double | 391 #define LOAD_AVE_TYPE double |
394 #endif | 392 #endif |
395 | 393 |
396 #ifdef LOAD_AVE_TYPE | 394 #ifdef LOAD_AVE_TYPE |
397 | 395 |
398 #ifndef VMS | |
399 #ifndef NLIST_STRUCT | 396 #ifndef NLIST_STRUCT |
400 #include <a.out.h> | 397 #include <a.out.h> |
401 #else /* NLIST_STRUCT */ | 398 #else /* NLIST_STRUCT */ |
402 #include <nlist.h> | 399 #include <nlist.h> |
403 #endif /* NLIST_STRUCT */ | 400 #endif /* NLIST_STRUCT */ |
412 #endif /* KERNEL_FILE */ | 409 #endif /* KERNEL_FILE */ |
413 | 410 |
414 #ifndef LDAV_SYMBOL | 411 #ifndef LDAV_SYMBOL |
415 #define LDAV_SYMBOL "_avenrun" | 412 #define LDAV_SYMBOL "_avenrun" |
416 #endif /* LDAV_SYMBOL */ | 413 #endif /* LDAV_SYMBOL */ |
417 | |
418 #else /* VMS */ | |
419 | |
420 #ifndef eunice | |
421 #include <iodef.h> | |
422 #include <descrip.h> | |
423 #else /* eunice */ | |
424 #include <vms/iodef.h> | |
425 #endif /* eunice */ | |
426 #endif /* VMS */ | |
427 | 414 |
428 #ifndef LDAV_CVT | 415 #ifndef LDAV_CVT |
429 #define LDAV_CVT(n) ((double) (n)) | 416 #define LDAV_CVT(n) ((double) (n)) |
430 #endif /* !LDAV_CVT */ | 417 #endif /* !LDAV_CVT */ |
431 | 418 |
497 #ifdef DGUX | 484 #ifdef DGUX |
498 static struct dg_sys_info_load_info load_info; /* what-a-mouthful! */ | 485 static struct dg_sys_info_load_info load_info; /* what-a-mouthful! */ |
499 #endif /* DGUX */ | 486 #endif /* DGUX */ |
500 | 487 |
501 #ifdef LOAD_AVE_TYPE | 488 #ifdef LOAD_AVE_TYPE |
502 /* File descriptor open to /dev/kmem or VMS load ave driver. */ | 489 /* File descriptor open to /dev/kmem */ |
503 static int channel; | 490 static int channel; |
504 /* Nonzero iff channel is valid. */ | 491 /* Nonzero iff channel is valid. */ |
505 static int getloadavg_initialized; | 492 static int getloadavg_initialized; |
506 /* Offset in kmem to seek to read load average, or 0 means invalid. */ | 493 /* Offset in kmem to seek to read load average, or 0 means invalid. */ |
507 static long offset; | 494 static long offset; |
508 | 495 |
509 #if !defined(VMS) && !defined(sgi) | 496 #ifndef sgi |
510 static struct nlist nl[2]; | 497 static struct nlist nl[2]; |
511 #endif /* Not VMS or sgi */ | 498 #endif /* not sgi */ |
512 | 499 |
513 #ifdef SUNOS_5 | 500 #ifdef SUNOS_5 |
514 static kvm_t *kd; | 501 static kvm_t *kd; |
515 #endif /* SUNOS_5 */ | 502 #endif /* SUNOS_5 */ |
516 | 503 |
831 = (load_ave.tl_lscale == 0 | 818 = (load_ave.tl_lscale == 0 |
832 ? load_ave.tl_avenrun.d[elem] | 819 ? load_ave.tl_avenrun.d[elem] |
833 : (load_ave.tl_avenrun.l[elem] / (double) load_ave.tl_lscale)); | 820 : (load_ave.tl_avenrun.l[elem] / (double) load_ave.tl_lscale)); |
834 #endif /* OSF_ALPHA */ | 821 #endif /* OSF_ALPHA */ |
835 | 822 |
836 #if !defined (LDAV_DONE) && defined (VMS) | 823 #if !defined (LDAV_DONE) && defined(LOAD_AVE_TYPE) |
837 /* VMS specific code -- read from the Load Ave driver. */ | |
838 | |
839 LOAD_AVE_TYPE load_ave[3]; | |
840 static int getloadavg_initialized = 0; | |
841 #ifdef eunice | |
842 struct | |
843 { | |
844 int dsc$w_length; | |
845 char *dsc$a_pointer; | |
846 } descriptor; | |
847 #endif | |
848 | |
849 /* Ensure that there is a channel open to the load ave device. */ | |
850 if (!getloadavg_initialized) | |
851 { | |
852 /* Attempt to open the channel. */ | |
853 #ifdef eunice | |
854 descriptor.dsc$w_length = 18; | |
855 descriptor.dsc$a_pointer = "$$VMS_LOAD_AVERAGE"; | |
856 #else | |
857 $DESCRIPTOR (descriptor, "LAV0:"); | |
858 #endif | |
859 if (sys$assign (&descriptor, &channel, 0, 0) & 1) | |
860 getloadavg_initialized = 1; | |
861 } | |
862 | |
863 /* Read the load average vector. */ | |
864 if (getloadavg_initialized | |
865 && !(sys$qiow (0, channel, IO$_READVBLK, 0, 0, 0, | |
866 load_ave, 12, 0, 0, 0, 0) & 1)) | |
867 { | |
868 sys$dassgn (channel); | |
869 getloadavg_initialized = 0; | |
870 } | |
871 | |
872 if (!getloadavg_initialized) | |
873 return -1; | |
874 #endif /* VMS */ | |
875 | |
876 #if !defined (LDAV_DONE) && defined(LOAD_AVE_TYPE) && !defined(VMS) | |
877 | 824 |
878 /* UNIX-specific code -- read the average from /dev/kmem. */ | 825 /* UNIX-specific code -- read the average from /dev/kmem. */ |
879 | 826 |
880 #define LDAV_PRIVILEGED /* This code requires special installation. */ | 827 #define LDAV_PRIVILEGED /* This code requires special installation. */ |
881 | 828 |
976 #endif /* SUNOS_5 */ | 923 #endif /* SUNOS_5 */ |
977 } | 924 } |
978 | 925 |
979 if (offset == 0 || !getloadavg_initialized) | 926 if (offset == 0 || !getloadavg_initialized) |
980 return -1; | 927 return -1; |
981 #endif /* LOAD_AVE_TYPE and not VMS */ | 928 |
982 | |
983 #if !defined (LDAV_DONE) && defined (LOAD_AVE_TYPE) /* Including VMS. */ | |
984 if (nelem > 0) | 929 if (nelem > 0) |
985 loadavg[elem++] = LDAV_CVT (load_ave[0]); | 930 loadavg[elem++] = LDAV_CVT (load_ave[0]); |
986 if (nelem > 1) | 931 if (nelem > 1) |
987 loadavg[elem++] = LDAV_CVT (load_ave[1]); | 932 loadavg[elem++] = LDAV_CVT (load_ave[1]); |
988 if (nelem > 2) | 933 if (nelem > 2) |