comparison src/getloadavg.c @ 412:697ef44129c6 r21-2-14

Import from CVS: tag r21-2-14
author cvs
date Mon, 13 Aug 2007 11:20:41 +0200
parents de805c49cfc1
children 11054d720c21
comparison
equal deleted inserted replaced
411:12e008d41344 412:697ef44129c6
42 apollo 42 apollo
43 BSD Real BSD, not just BSD-like. 43 BSD Real BSD, not just BSD-like.
44 convex 44 convex
45 DGUX 45 DGUX
46 hpux 46 hpux
47 MSDOS No-op for MSDOS.
47 NeXT 48 NeXT
48 sgi 49 sgi
49 sequent Sequent Dynix 3.x.x (BSD) 50 sequent Sequent Dynix 3.x.x (BSD)
50 _SEQUENT_ Sequent DYNIX/ptx 1.x.x (SYSV) 51 _SEQUENT_ Sequent DYNIX/ptx 1.x.x (SYSV)
51 sony_news NEWS-OS (works at least for 4.1C) 52 sony_news NEWS-OS (works at least for 4.1C)
52 UMAX 53 UMAX
53 UMAX4_3 54 UMAX4_3
54 WIN32_NATIVE No-op for Windows95/NT. 55 WIN32 No-op for Windows95/NT.
55 __linux__ Linux: assumes /proc filesystem mounted. 56 __linux__ Linux: assumes /proc filesystem mounted.
56 Support from Michael K. Johnson. 57 Support from Michael K. Johnson.
57 __NetBSD__ NetBSD: assumes /kern filesystem mounted. 58 __NetBSD__ NetBSD: assumes /kern filesystem mounted.
58 __OpenBSD__ OpenBSD: ditto. 59 __OpenBSD__ OpenBSD: ditto.
59 60
66 /* This should always be first. */ 67 /* This should always be first. */
67 #ifdef HAVE_CONFIG_H 68 #ifdef HAVE_CONFIG_H
68 #include <config.h> 69 #include <config.h>
69 #endif 70 #endif
70 71
71 #include "lisp.h" 72 #ifndef WINDOWSNT
72 #include "sysfile.h" /* for encapsulated open, close, read, write */ 73 #ifndef __CYGWIN32__
73
74 #ifndef WIN32_NATIVE
75 #ifndef CYGWIN
76 74
77 #include <sys/types.h> 75 #include <sys/types.h>
78 76
79 /* Both the Emacs and non-Emacs sections want this. Some 77 /* Both the Emacs and non-Emacs sections want this. Some
80 configuration files' definitions for the LOAD_AVE_CVT macro (like 78 configuration files' definitions for the LOAD_AVE_CVT macro (like
81 sparc.h's) use macros like FSCALE, defined here. */ 79 sparc.h's) use macros like FSCALE, defined here. */
82 #ifdef unix 80 #ifdef unix
83 #include <sys/param.h> 81 #include <sys/param.h>
84 #endif 82 #endif
85 83
84 #ifdef XEMACS
85 #include "lisp.h"
86 #include "sysfile.h" /* for encapsulated open, close, read, write */
87 #endif /* XEMACS */
86 88
87 /* Exclude all the code except the test program at the end 89 /* Exclude all the code except the test program at the end
88 if the system has its own `getloadavg' function. 90 if the system has its own `getloadavg' function.
89 91
90 The declaration of `errno' is needed by the test program 92 The declaration of `errno' is needed by the test program
91 as well as the function itself, so it comes first. */ 93 as well as the function itself, so it comes first. */
92 94
93 #include <errno.h> 95 #include <errno.h>
96
97 #ifndef errno
98 extern int errno;
99 #endif
94 100
95 #ifndef HAVE_GETLOADAVG 101 #ifndef HAVE_GETLOADAVG
96 102
97 /* The existing Emacs configuration files define a macro called 103 /* The existing Emacs configuration files define a macro called
98 LOAD_AVE_CVT, which accepts a value of type LOAD_AVE_TYPE, and 104 LOAD_AVE_CVT, which accepts a value of type LOAD_AVE_TYPE, and
106 112
107 #if !defined(LDAV_CVT) && defined(LOAD_AVE_CVT) 113 #if !defined(LDAV_CVT) && defined(LOAD_AVE_CVT)
108 #define LDAV_CVT(n) (LOAD_AVE_CVT (n) / 100.0) 114 #define LDAV_CVT(n) (LOAD_AVE_CVT (n) / 100.0)
109 #endif 115 #endif
110 116
117 #ifdef XEMACS
111 #if defined (HAVE_KSTAT_H) 118 #if defined (HAVE_KSTAT_H)
112 #include <kstat.h> 119 #include <kstat.h>
113 #endif /* HAVE_KSTAT_H */ 120 #endif /* HAVE_KSTAT_H */
121 #endif /* XEMACS */
114 122
115 #if !defined (BSD) && defined (ultrix) 123 #if !defined (BSD) && defined (ultrix)
116 /* Ultrix behaves like BSD on Vaxen. */ 124 /* Ultrix behaves like BSD on Vaxen. */
117 #define BSD 125 #define BSD
118 #endif 126 #endif
451 459
452 #ifdef DGUX 460 #ifdef DGUX
453 #include <sys/dg_sys_info.h> 461 #include <sys/dg_sys_info.h>
454 #endif 462 #endif
455 463
464 #ifdef XEMACS
456 #if defined (HAVE_SYS_PSTAT_H) 465 #if defined (HAVE_SYS_PSTAT_H)
457 #include <sys/pstat.h> 466 #include <sys/pstat.h>
458 #endif /* HAVE_SYS_PSTAT_H (on HPUX) */ 467 #endif /* HAVE_SYS_PSTAT_H (on HPUX) */
468 #endif /* XEMACS */
459 469
460 #if defined(HAVE_FCNTL_H) || defined(_POSIX_VERSION) 470 #if defined(HAVE_FCNTL_H) || defined(_POSIX_VERSION)
461 #include <fcntl.h> 471 #include <fcntl.h>
462 #else 472 #else
463 #include <sys/file.h> 473 #include <sys/file.h>
524 /* getloadavg is best implemented using kstat (kernel stats), on 534 /* getloadavg is best implemented using kstat (kernel stats), on
525 systems (like SunOS5) that support it, since you don't need special 535 systems (like SunOS5) that support it, since you don't need special
526 privileges to use it. 536 privileges to use it.
527 537
528 Initial implementation courtesy Zlatko Calusic <zcalusic@carnet.hr>. 538 Initial implementation courtesy Zlatko Calusic <zcalusic@carnet.hr>.
529 Integrated to XEmacs by Hrvoje Niksic <hniksic@xemacs.org>. 539 Integrated to XEmacs by Hrvoje Niksic <hniksic@srce.hr>.
530 Additional cleanup by Hrvoje Niksic, based on code published by 540 Additional cleanup by Hrvoje Niksic, based on code published by
531 Casper Dik <Casper.Dik@Holland.Sun.Com>. */ 541 Casper Dik <Casper.Dik@Holland.Sun.Com>. */
532 kstat_ctl_t *kc; 542 kstat_ctl_t *kc;
533 kstat_t *ksp; 543 kstat_t *ksp;
534 static char *avestrings[] = { "avenrun_1min", 544 static char *avestrings[] = { "avenrun_1min",
760 loadavg[elem++] = load_info.five_minute; 770 loadavg[elem++] = load_info.five_minute;
761 if (nelem > 2) 771 if (nelem > 2)
762 loadavg[elem++] = load_info.fifteen_minute; 772 loadavg[elem++] = load_info.fifteen_minute;
763 #endif /* DGUX */ 773 #endif /* DGUX */
764 774
775 #if !defined (LDAV_DONE) && defined (apollo)
776 #define LDAV_DONE
777 /* Apollo code from lisch@mentorg.com (Ray Lischner).
778
779 This system call is not documented. The load average is obtained as
780 three long integers, for the load average over the past minute,
781 five minutes, and fifteen minutes. Each value is a scaled integer,
782 with 16 bits of integer part and 16 bits of fraction part.
783
784 I'm not sure which operating system first supported this system call,
785 but I know that SR10.2 supports it. */
786
787 extern void proc1_$get_loadav ();
788 unsigned long load_ave[3];
789
790 proc1_$get_loadav (load_ave);
791
792 if (nelem > 0)
793 loadavg[elem++] = load_ave[0] / 65536.0;
794 if (nelem > 1)
795 loadavg[elem++] = load_ave[1] / 65536.0;
796 if (nelem > 2)
797 loadavg[elem++] = load_ave[2] / 65536.0;
798 #endif /* apollo */
799
765 #if !defined (LDAV_DONE) && defined (OSF_MIPS) 800 #if !defined (LDAV_DONE) && defined (OSF_MIPS)
766 #define LDAV_DONE 801 #define LDAV_DONE
767 802
768 struct tbl_loadavg load_ave; 803 struct tbl_loadavg load_ave;
769 table (TBL_LOADAVG, 0, &load_ave, 1, sizeof (load_ave)); 804 table (TBL_LOADAVG, 0, &load_ave, 1, sizeof (load_ave));
771 = (load_ave.tl_lscale == 0 806 = (load_ave.tl_lscale == 0
772 ? load_ave.tl_avenrun.d[0] 807 ? load_ave.tl_avenrun.d[0]
773 : (load_ave.tl_avenrun.l[0] / (double) load_ave.tl_lscale)); 808 : (load_ave.tl_avenrun.l[0] / (double) load_ave.tl_lscale));
774 #endif /* OSF_MIPS */ 809 #endif /* OSF_MIPS */
775 810
776 #if !defined (LDAV_DONE) && defined (WIN32_NATIVE) 811 #if !defined (LDAV_DONE) && (defined (MSDOS) || defined (WIN32))
777 #define LDAV_DONE 812 #define LDAV_DONE
778 813
779 /* A faithful emulation is going to have to be saved for a rainy day. */ 814 /* A faithful emulation is going to have to be saved for a rainy day. */
780 for ( ; elem < nelem; elem++) 815 for ( ; elem < nelem; elem++)
781 { 816 {
782 loadavg[elem] = 0.0; 817 loadavg[elem] = 0.0;
783 } 818 }
784 #endif /* WIN32_NATIVE */ 819 #endif /* MSDOS */
785 820
786 #if !defined (LDAV_DONE) && defined (OSF_ALPHA) 821 #if !defined (LDAV_DONE) && defined (OSF_ALPHA)
787 #define LDAV_DONE 822 #define LDAV_DONE
788 823
789 struct tbl_loadavg load_ave; 824 struct tbl_loadavg load_ave;
970 } 1005 }
971 return i; 1006 return i;
972 } 1007 }
973 1008
974 #endif /*__GNUWIN32__*/ 1009 #endif /*__GNUWIN32__*/
975 #endif /* WIN32_NATIVE */ 1010 #endif /* WINDOWSNT */