diff options
Diffstat (limited to 'gl/getloadavg.c')
| -rw-r--r-- | gl/getloadavg.c | 268 |
1 files changed, 111 insertions, 157 deletions
diff --git a/gl/getloadavg.c b/gl/getloadavg.c index c940e4c7..73b2ee28 100644 --- a/gl/getloadavg.c +++ b/gl/getloadavg.c | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | /* Get the system load averages. | 1 | /* Get the system load averages. |
| 2 | 2 | ||
| 3 | Copyright (C) 1985-1989, 1991-1995, 1997, 1999-2000, 2003-2024 Free Software | 3 | Copyright (C) 1985-1989, 1991-1995, 1997, 1999-2000, 2003-2026 Free Software |
| 4 | Foundation, Inc. | 4 | Foundation, Inc. |
| 5 | 5 | ||
| 6 | NOTE: The canonical source of this file is maintained with gnulib. | 6 | NOTE: The canonical source of this file is maintained with gnulib. |
| @@ -47,8 +47,6 @@ | |||
| 47 | N_NAME_POINTER The nlist n_name element is a pointer, | 47 | N_NAME_POINTER The nlist n_name element is a pointer, |
| 48 | not an array. | 48 | not an array. |
| 49 | HAVE_STRUCT_NLIST_N_UN_N_NAME 'n_un.n_name' is member of 'struct nlist'. | 49 | HAVE_STRUCT_NLIST_N_UN_N_NAME 'n_un.n_name' is member of 'struct nlist'. |
| 50 | LINUX_LDAV_FILE [__linux__, __ANDROID__, __CYGWIN__]: File | ||
| 51 | containing load averages. | ||
| 52 | 50 | ||
| 53 | Specific system predefines this file uses, aside from setting | 51 | Specific system predefines this file uses, aside from setting |
| 54 | default values if not emacs: | 52 | default values if not emacs: |
| @@ -65,8 +63,7 @@ | |||
| 65 | UMAX4_3 | 63 | UMAX4_3 |
| 66 | VMS | 64 | VMS |
| 67 | _WIN32 Native Windows (possibly also defined on Cygwin) | 65 | _WIN32 Native Windows (possibly also defined on Cygwin) |
| 68 | __linux__, __ANDROID__ Linux: assumes /proc file system mounted. | 66 | __linux__, __ANDROID__ Linux: assumes sysinfo() call. |
| 69 | Support from Michael K. Johnson. | ||
| 70 | __CYGWIN__ Cygwin emulates linux /proc/loadavg. | 67 | __CYGWIN__ Cygwin emulates linux /proc/loadavg. |
| 71 | __NetBSD__ NetBSD: assumes /kern file system mounted. | 68 | __NetBSD__ NetBSD: assumes /kern file system mounted. |
| 72 | 69 | ||
| @@ -108,10 +105,10 @@ | |||
| 108 | # endif | 105 | # endif |
| 109 | 106 | ||
| 110 | /* Same issues as for NeXT apply to the HURD-based GNU system. */ | 107 | /* Same issues as for NeXT apply to the HURD-based GNU system. */ |
| 111 | # ifdef __GNU__ | 108 | # if defined __gnu_hurd__ || defined NeXT |
| 112 | # undef BSD | 109 | # undef BSD |
| 113 | # undef FSCALE | 110 | # undef FSCALE |
| 114 | # endif /* __GNU__ */ | 111 | # endif /* __gnu_hurd__ || NeXT */ |
| 115 | 112 | ||
| 116 | /* Set values that are different from the defaults, which are | 113 | /* Set values that are different from the defaults, which are |
| 117 | set a little farther down with #ifndef. */ | 114 | set a little farther down with #ifndef. */ |
| @@ -143,21 +140,6 @@ | |||
| 143 | # define SUNOS_5 | 140 | # define SUNOS_5 |
| 144 | # endif | 141 | # endif |
| 145 | 142 | ||
| 146 | # if defined (__osf__) && (defined (__alpha) || defined (__alpha__)) | ||
| 147 | # define OSF_ALPHA | ||
| 148 | # include <sys/mbuf.h> | ||
| 149 | # include <sys/socket.h> | ||
| 150 | # include <net/route.h> | ||
| 151 | # include <sys/table.h> | ||
| 152 | /* Tru64 4.0D's table.h redefines sys */ | ||
| 153 | # undef sys | ||
| 154 | # endif | ||
| 155 | |||
| 156 | # if defined (__osf__) && (defined (mips) || defined (__mips__)) | ||
| 157 | # define OSF_MIPS | ||
| 158 | # include <sys/table.h> | ||
| 159 | # endif | ||
| 160 | |||
| 161 | 143 | ||
| 162 | /* VAX C can't handle multi-line #ifs, or lines longer than 256 chars. */ | 144 | /* VAX C can't handle multi-line #ifs, or lines longer than 256 chars. */ |
| 163 | # ifndef LOAD_AVE_TYPE | 145 | # ifndef LOAD_AVE_TYPE |
| @@ -170,31 +152,16 @@ | |||
| 170 | # define LOAD_AVE_TYPE long | 152 | # define LOAD_AVE_TYPE long |
| 171 | # endif | 153 | # endif |
| 172 | 154 | ||
| 173 | # ifdef sgi | ||
| 174 | # define LOAD_AVE_TYPE long | ||
| 175 | # endif | ||
| 176 | |||
| 177 | # ifdef SVR4 | 155 | # ifdef SVR4 |
| 178 | # define LOAD_AVE_TYPE long | 156 | # define LOAD_AVE_TYPE long |
| 179 | # endif | 157 | # endif |
| 180 | 158 | ||
| 181 | # ifdef OSF_ALPHA | ||
| 182 | # define LOAD_AVE_TYPE long | ||
| 183 | # endif | ||
| 184 | |||
| 185 | # if defined _AIX && ! defined HAVE_LIBPERFSTAT | 159 | # if defined _AIX && ! defined HAVE_LIBPERFSTAT |
| 186 | # define LOAD_AVE_TYPE long | 160 | # define LOAD_AVE_TYPE long |
| 187 | # endif | 161 | # endif |
| 188 | 162 | ||
| 189 | # endif /* No LOAD_AVE_TYPE. */ | 163 | # endif /* No LOAD_AVE_TYPE. */ |
| 190 | 164 | ||
| 191 | # ifdef OSF_ALPHA | ||
| 192 | /* <sys/param.h> defines an incorrect value for FSCALE on Alpha OSF/1, | ||
| 193 | according to ghazi@noc.rutgers.edu. */ | ||
| 194 | # undef FSCALE | ||
| 195 | # define FSCALE 1024.0 | ||
| 196 | # endif | ||
| 197 | |||
| 198 | 165 | ||
| 199 | # ifndef FSCALE | 166 | # ifndef FSCALE |
| 200 | 167 | ||
| @@ -312,8 +279,7 @@ | |||
| 312 | # endif | 279 | # endif |
| 313 | # endif | 280 | # endif |
| 314 | 281 | ||
| 315 | # if defined (__GNU__) && !defined (NeXT) | 282 | # if defined __gnu_hurd__ && !defined NeXT |
| 316 | /* Note that NeXT Openstep defines __GNU__ even though it should not. */ | ||
| 317 | /* GNU system acts much like NeXT, for load average purposes, | 283 | /* GNU system acts much like NeXT, for load average purposes, |
| 318 | but not exactly. */ | 284 | but not exactly. */ |
| 319 | # define NeXT | 285 | # define NeXT |
| @@ -328,10 +294,6 @@ | |||
| 328 | # endif | 294 | # endif |
| 329 | # endif /* NeXT */ | 295 | # endif /* NeXT */ |
| 330 | 296 | ||
| 331 | # ifdef sgi | ||
| 332 | # include <sys/sysmp.h> | ||
| 333 | # endif /* sgi */ | ||
| 334 | |||
| 335 | # ifdef UMAX | 297 | # ifdef UMAX |
| 336 | # include <signal.h> | 298 | # include <signal.h> |
| 337 | # include <sys/time.h> | 299 | # include <sys/time.h> |
| @@ -358,6 +320,11 @@ | |||
| 358 | # include <sys/dg_sys_info.h> | 320 | # include <sys/dg_sys_info.h> |
| 359 | # endif | 321 | # endif |
| 360 | 322 | ||
| 323 | # if defined __linux__ || defined __ANDROID__ | ||
| 324 | # include <sys/param.h> | ||
| 325 | # include <sys/sysinfo.h> | ||
| 326 | # endif | ||
| 327 | |||
| 361 | # if (defined __linux__ || defined __ANDROID__ \ | 328 | # if (defined __linux__ || defined __ANDROID__ \ |
| 362 | || defined __CYGWIN__ || defined SUNOS_5 \ | 329 | || defined __CYGWIN__ || defined SUNOS_5 \ |
| 363 | || (defined LOAD_AVE_TYPE && ! defined __VMS)) | 330 | || (defined LOAD_AVE_TYPE && ! defined __VMS)) |
| @@ -388,7 +355,7 @@ static bool getloadavg_initialized; | |||
| 388 | /* Offset in kmem to seek to read load average, or 0 means invalid. */ | 355 | /* Offset in kmem to seek to read load average, or 0 means invalid. */ |
| 389 | static long offset; | 356 | static long offset; |
| 390 | 357 | ||
| 391 | # if ! defined __VMS && ! defined sgi && ! (defined __linux__ || defined __ANDROID__) | 358 | # if ! defined __VMS && ! (defined __linux__ || defined __ANDROID__) |
| 392 | static struct nlist name_list[2]; | 359 | static struct nlist name_list[2]; |
| 393 | # endif | 360 | # endif |
| 394 | 361 | ||
| @@ -417,51 +384,47 @@ getloadavg (double loadavg[], int nelem) | |||
| 417 | # if !defined (LDAV_DONE) && defined (HAVE_LIBKSTAT) /* Solaris <= 2.6 */ | 384 | # if !defined (LDAV_DONE) && defined (HAVE_LIBKSTAT) /* Solaris <= 2.6 */ |
| 418 | /* Use libkstat because we don't have to be root. */ | 385 | /* Use libkstat because we don't have to be root. */ |
| 419 | # define LDAV_DONE | 386 | # define LDAV_DONE |
| 420 | kstat_ctl_t *kc; | 387 | { |
| 421 | kstat_t *ksp; | 388 | kstat_ctl_t *kc = kstat_open (); |
| 422 | kstat_named_t *kn; | 389 | if (kc == NULL) |
| 423 | int saved_errno; | 390 | return -1; |
| 424 | 391 | kstat_t *ksp = kstat_lookup (kc, "unix", 0, "system_misc"); | |
| 425 | kc = kstat_open (); | 392 | if (ksp == NULL) |
| 426 | if (kc == NULL) | 393 | return -1; |
| 427 | return -1; | 394 | if (kstat_read (kc, ksp, 0) == -1) |
| 428 | ksp = kstat_lookup (kc, "unix", 0, "system_misc"); | 395 | return -1; |
| 429 | if (ksp == NULL) | ||
| 430 | return -1; | ||
| 431 | if (kstat_read (kc, ksp, 0) == -1) | ||
| 432 | return -1; | ||
| 433 | |||
| 434 | |||
| 435 | kn = kstat_data_lookup (ksp, "avenrun_1min"); | ||
| 436 | if (kn == NULL) | ||
| 437 | { | ||
| 438 | /* Return -1 if no load average information is available. */ | ||
| 439 | nelem = 0; | ||
| 440 | elem = -1; | ||
| 441 | } | ||
| 442 | |||
| 443 | if (nelem >= 1) | ||
| 444 | loadavg[elem++] = (double) kn->value.ul / FSCALE; | ||
| 445 | |||
| 446 | if (nelem >= 2) | ||
| 447 | { | ||
| 448 | kn = kstat_data_lookup (ksp, "avenrun_5min"); | ||
| 449 | if (kn != NULL) | ||
| 450 | { | ||
| 451 | loadavg[elem++] = (double) kn->value.ul / FSCALE; | ||
| 452 | 396 | ||
| 453 | if (nelem >= 3) | 397 | kstat_named_t *kn = kstat_data_lookup (ksp, "avenrun_1min"); |
| 454 | { | 398 | if (kn == NULL) |
| 455 | kn = kstat_data_lookup (ksp, "avenrun_15min"); | 399 | { |
| 456 | if (kn != NULL) | 400 | /* Return -1 if no load average information is available. */ |
| 457 | loadavg[elem++] = (double) kn->value.ul / FSCALE; | 401 | nelem = 0; |
| 458 | } | 402 | elem = -1; |
| 459 | } | 403 | } |
| 460 | } | 404 | |
| 405 | if (nelem >= 1) | ||
| 406 | loadavg[elem++] = (double) kn->value.ul / FSCALE; | ||
| 407 | |||
| 408 | if (nelem >= 2) | ||
| 409 | { | ||
| 410 | kn = kstat_data_lookup (ksp, "avenrun_5min"); | ||
| 411 | if (kn != NULL) | ||
| 412 | { | ||
| 413 | loadavg[elem++] = (double) kn->value.ul / FSCALE; | ||
| 414 | |||
| 415 | if (nelem >= 3) | ||
| 416 | { | ||
| 417 | kn = kstat_data_lookup (ksp, "avenrun_15min"); | ||
| 418 | if (kn != NULL) | ||
| 419 | loadavg[elem++] = (double) kn->value.ul / FSCALE; | ||
| 420 | } | ||
| 421 | } | ||
| 422 | } | ||
| 461 | 423 | ||
| 462 | saved_errno = errno; | 424 | int saved_errno = errno; |
| 463 | kstat_close (kc); | 425 | kstat_close (kc); |
| 464 | errno = saved_errno; | 426 | errno = saved_errno; |
| 427 | } | ||
| 465 | # endif /* HAVE_LIBKSTAT */ | 428 | # endif /* HAVE_LIBKSTAT */ |
| 466 | 429 | ||
| 467 | # if !defined (LDAV_DONE) && defined (hpux) && defined (HAVE_PSTAT_GETDYNAMIC) | 430 | # if !defined (LDAV_DONE) && defined (hpux) && defined (HAVE_PSTAT_GETDYNAMIC) |
| @@ -498,24 +461,36 @@ getloadavg (double loadavg[], int nelem) | |||
| 498 | } | 461 | } |
| 499 | # endif | 462 | # endif |
| 500 | 463 | ||
| 501 | # if !defined (LDAV_DONE) && (defined __linux__ || defined __ANDROID__ || defined __CYGWIN__) | 464 | # if (!defined LDAV_DONE \ |
| 502 | /* Linux without glibc, Android, Cygwin */ | 465 | && (defined __ANDROID__ ? 13 <= __ANDROID_API__ : defined __linux__)) |
| 466 | /* non-Android Linux without glibc, Android 3.2+, Cygwin */ | ||
| 503 | # define LDAV_DONE | 467 | # define LDAV_DONE |
| 504 | # undef LOAD_AVE_TYPE | 468 | # undef LOAD_AVE_TYPE |
| 505 | 469 | ||
| 506 | # ifndef LINUX_LDAV_FILE | 470 | { |
| 507 | # define LINUX_LDAV_FILE "/proc/loadavg" | 471 | struct sysinfo info; |
| 508 | # endif | 472 | if (sysinfo (&info) < 0) |
| 473 | return -1; | ||
| 474 | loadavg[0] = info.loads[0] / (double)(1U << SI_LOAD_SHIFT); | ||
| 475 | loadavg[1] = info.loads[1] / (double)(1U << SI_LOAD_SHIFT); | ||
| 476 | loadavg[2] = info.loads[2] / (double)(1U << SI_LOAD_SHIFT); | ||
| 477 | elem = 3; | ||
| 478 | } | ||
| 479 | # endif /* __ANDROID__ ? 13 <= __ANDROID_API__ : __linux__ */ | ||
| 480 | |||
| 481 | # if !defined (LDAV_DONE) && defined __CYGWIN__ | ||
| 482 | /* Cygwin */ | ||
| 483 | # define LDAV_DONE | ||
| 484 | # undef LOAD_AVE_TYPE | ||
| 509 | 485 | ||
| 510 | char ldavgbuf[3 * (INT_STRLEN_BOUND (int) + sizeof ".00 ")]; | 486 | char ldavgbuf[3 * (INT_STRLEN_BOUND (int) + sizeof ".00 ")]; |
| 511 | char const *ptr = ldavgbuf; | 487 | char const *ptr = ldavgbuf; |
| 512 | int fd, count, saved_errno; | ||
| 513 | 488 | ||
| 514 | fd = open (LINUX_LDAV_FILE, O_RDONLY | O_CLOEXEC); | 489 | int fd = open ("/proc/loadavg", O_RDONLY | O_CLOEXEC); |
| 515 | if (fd == -1) | 490 | if (fd == -1) |
| 516 | return -1; | 491 | return -1; |
| 517 | count = read (fd, ldavgbuf, sizeof ldavgbuf - 1); | 492 | int count = read (fd, ldavgbuf, sizeof ldavgbuf - 1); |
| 518 | saved_errno = errno; | 493 | int saved_errno = errno; |
| 519 | (void) close (fd); | 494 | (void) close (fd); |
| 520 | errno = saved_errno; | 495 | errno = saved_errno; |
| 521 | if (count <= 0) | 496 | if (count <= 0) |
| @@ -524,9 +499,6 @@ getloadavg (double loadavg[], int nelem) | |||
| 524 | 499 | ||
| 525 | for (elem = 0; elem < nelem; elem++) | 500 | for (elem = 0; elem < nelem; elem++) |
| 526 | { | 501 | { |
| 527 | double numerator = 0; | ||
| 528 | double denominator = 1; | ||
| 529 | |||
| 530 | while (*ptr == ' ') | 502 | while (*ptr == ' ') |
| 531 | ptr++; | 503 | ptr++; |
| 532 | 504 | ||
| @@ -542,6 +514,9 @@ getloadavg (double loadavg[], int nelem) | |||
| 542 | break; | 514 | break; |
| 543 | } | 515 | } |
| 544 | 516 | ||
| 517 | double numerator = 0; | ||
| 518 | double denominator = 1; | ||
| 519 | |||
| 545 | while ('0' <= *ptr && *ptr <= '9') | 520 | while ('0' <= *ptr && *ptr <= '9') |
| 546 | numerator = 10 * numerator + (*ptr++ - '0'); | 521 | numerator = 10 * numerator + (*ptr++ - '0'); |
| 547 | 522 | ||
| @@ -554,7 +529,7 @@ getloadavg (double loadavg[], int nelem) | |||
| 554 | 529 | ||
| 555 | return elem; | 530 | return elem; |
| 556 | 531 | ||
| 557 | # endif /* __linux__ || __ANDROID__ || __CYGWIN__ */ | 532 | # endif /* __CYGWIN__ */ |
| 558 | 533 | ||
| 559 | # if !defined (LDAV_DONE) && defined (__NetBSD__) /* NetBSD < 0.9 */ | 534 | # if !defined (LDAV_DONE) && defined (__NetBSD__) /* NetBSD < 0.9 */ |
| 560 | # define LDAV_DONE | 535 | # define LDAV_DONE |
| @@ -564,24 +539,25 @@ getloadavg (double loadavg[], int nelem) | |||
| 564 | # define NETBSD_LDAV_FILE "/kern/loadavg" | 539 | # define NETBSD_LDAV_FILE "/kern/loadavg" |
| 565 | # endif | 540 | # endif |
| 566 | 541 | ||
| 567 | unsigned long int load_ave[3], scale; | ||
| 568 | int count; | ||
| 569 | char readbuf[4 * INT_BUFSIZE_BOUND (unsigned long int) + 1]; | ||
| 570 | int fd = open (NETBSD_LDAV_FILE, O_RDONLY | O_CLOEXEC); | 542 | int fd = open (NETBSD_LDAV_FILE, O_RDONLY | O_CLOEXEC); |
| 571 | if (fd < 0) | 543 | if (fd < 0) |
| 572 | return fd; | 544 | return fd; |
| 545 | |||
| 546 | char readbuf[4 * INT_BUFSIZE_BOUND (unsigned long int) + 1]; | ||
| 573 | int nread = read (fd, readbuf, sizeof readbuf - 1); | 547 | int nread = read (fd, readbuf, sizeof readbuf - 1); |
| 574 | int err = errno; | 548 | int saved_errno = errno; |
| 575 | close (fd); | 549 | close (fd); |
| 576 | if (nread < 0) | 550 | if (nread < 0) |
| 577 | { | 551 | { |
| 578 | errno = err; | 552 | errno = saved_errno; |
| 579 | return -1; | 553 | return -1; |
| 580 | } | 554 | } |
| 581 | readbuf[nread] = '\0'; | 555 | readbuf[nread] = '\0'; |
| 582 | count = sscanf (readbuf, "%lu %lu %lu %lu\n", | 556 | |
| 583 | &load_ave[0], &load_ave[1], &load_ave[2], | 557 | unsigned long int load_ave[3], scale; |
| 584 | &scale); | 558 | int count = sscanf (readbuf, "%lu %lu %lu %lu\n", |
| 559 | &load_ave[0], &load_ave[1], &load_ave[2], | ||
| 560 | &scale); | ||
| 585 | if (count != 4) | 561 | if (count != 4) |
| 586 | { | 562 | { |
| 587 | errno = ENOTSUP; | 563 | errno = ENOTSUP; |
| @@ -599,10 +575,6 @@ getloadavg (double loadavg[], int nelem) | |||
| 599 | # define LDAV_DONE | 575 | # define LDAV_DONE |
| 600 | /* The NeXT code was adapted from iscreen 3.2. */ | 576 | /* The NeXT code was adapted from iscreen 3.2. */ |
| 601 | 577 | ||
| 602 | host_t host; | ||
| 603 | struct processor_set_basic_info info; | ||
| 604 | unsigned int info_count; | ||
| 605 | |||
| 606 | /* We only know how to get the 1-minute average for this system, | 578 | /* We only know how to get the 1-minute average for this system, |
| 607 | so even if the caller asks for more than 1, we only return 1. */ | 579 | so even if the caller asks for more than 1, we only return 1. */ |
| 608 | 580 | ||
| @@ -614,7 +586,9 @@ getloadavg (double loadavg[], int nelem) | |||
| 614 | 586 | ||
| 615 | if (getloadavg_initialized) | 587 | if (getloadavg_initialized) |
| 616 | { | 588 | { |
| 617 | info_count = PROCESSOR_SET_BASIC_INFO_COUNT; | 589 | host_t host; |
| 590 | struct processor_set_basic_info info; | ||
| 591 | unsigned int info_count = PROCESSOR_SET_BASIC_INFO_COUNT; | ||
| 618 | if (processor_set_info (default_set, PROCESSOR_SET_BASIC_INFO, &host, | 592 | if (processor_set_info (default_set, PROCESSOR_SET_BASIC_INFO, &host, |
| 619 | (processor_set_info_t) &info, &info_count) | 593 | (processor_set_info_t) &info, &info_count) |
| 620 | != KERN_SUCCESS) | 594 | != KERN_SUCCESS) |
| @@ -640,14 +614,9 @@ getloadavg (double loadavg[], int nelem) | |||
| 640 | can be gathered with inq_stats system calls. | 614 | can be gathered with inq_stats system calls. |
| 641 | We only know how to get the 1-minute average for this system. */ | 615 | We only know how to get the 1-minute average for this system. */ |
| 642 | 616 | ||
| 643 | struct proc_summary proc_sum_data; | ||
| 644 | struct stat_descr proc_info; | ||
| 645 | double load; | ||
| 646 | register unsigned int i, j; | ||
| 647 | |||
| 648 | if (cpus == 0) | 617 | if (cpus == 0) |
| 649 | { | 618 | { |
| 650 | register unsigned int c, i; | 619 | register unsigned int c; |
| 651 | struct cpu_config conf; | 620 | struct cpu_config conf; |
| 652 | struct stat_descr desc; | 621 | struct stat_descr desc; |
| 653 | 622 | ||
| @@ -661,7 +630,7 @@ getloadavg (double loadavg[], int nelem) | |||
| 661 | return -1; | 630 | return -1; |
| 662 | 631 | ||
| 663 | c = 0; | 632 | c = 0; |
| 664 | for (i = 0; i < conf.config_maxclass; ++i) | 633 | for (unsigned int i = 0; i < conf.config_maxclass; ++i) |
| 665 | { | 634 | { |
| 666 | struct class_stats stats; | 635 | struct class_stats stats; |
| 667 | memset (&stats, 0, sizeof stats); | 636 | memset (&stats, 0, sizeof stats); |
| @@ -680,6 +649,9 @@ getloadavg (double loadavg[], int nelem) | |||
| 680 | samples = cpus < 2 ? 3 : (2 * cpus / 3); | 649 | samples = cpus < 2 ? 3 : (2 * cpus / 3); |
| 681 | } | 650 | } |
| 682 | 651 | ||
| 652 | struct proc_summary proc_sum_data; | ||
| 653 | |||
| 654 | struct stat_descr proc_info; | ||
| 683 | proc_info.sd_next = 0; | 655 | proc_info.sd_next = 0; |
| 684 | proc_info.sd_subsys = SUBSYS_PROC; | 656 | proc_info.sd_subsys = SUBSYS_PROC; |
| 685 | proc_info.sd_type = PROCTYPE_SUMMARY; | 657 | proc_info.sd_type = PROCTYPE_SUMMARY; |
| @@ -690,9 +662,9 @@ getloadavg (double loadavg[], int nelem) | |||
| 690 | if (inq_stats (1, &proc_info) != 0) | 662 | if (inq_stats (1, &proc_info) != 0) |
| 691 | return -1; | 663 | return -1; |
| 692 | 664 | ||
| 693 | load = proc_sum_data.ps_nrunnable; | 665 | double load = proc_sum_data.ps_nrunnable; |
| 694 | j = 0; | 666 | register unsigned int j = 0; |
| 695 | for (i = samples - 1; i > 0; --i) | 667 | for (unsigned int i = samples - 1; i > 0; --i) |
| 696 | { | 668 | { |
| 697 | load += proc_sum_data.ps_nrun[j]; | 669 | load += proc_sum_data.ps_nrun[j]; |
| 698 | if (j++ == PS_NRUNSIZE) | 670 | if (j++ == PS_NRUNSIZE) |
| @@ -767,18 +739,6 @@ getloadavg (double loadavg[], int nelem) | |||
| 767 | } | 739 | } |
| 768 | # endif /* __MSDOS__ || WINDOWS32 */ | 740 | # endif /* __MSDOS__ || WINDOWS32 */ |
| 769 | 741 | ||
| 770 | # if !defined (LDAV_DONE) && defined (OSF_ALPHA) /* OSF/1 */ | ||
| 771 | # define LDAV_DONE | ||
| 772 | |||
| 773 | struct tbl_loadavg load_ave; | ||
| 774 | table (TBL_LOADAVG, 0, &load_ave, 1, sizeof (load_ave)); | ||
| 775 | for (elem = 0; elem < nelem; elem++) | ||
| 776 | loadavg[elem] | ||
| 777 | = (load_ave.tl_lscale == 0 | ||
| 778 | ? load_ave.tl_avenrun.d[elem] | ||
| 779 | : (load_ave.tl_avenrun.l[elem] / (double) load_ave.tl_lscale)); | ||
| 780 | # endif /* OSF_ALPHA */ | ||
| 781 | |||
| 782 | # if ! defined LDAV_DONE && defined __VMS /* VMS */ | 742 | # if ! defined LDAV_DONE && defined __VMS /* VMS */ |
| 783 | /* VMS specific code -- read from the Load Ave driver. */ | 743 | /* VMS specific code -- read from the Load Ave driver. */ |
| 784 | 744 | ||
| @@ -823,52 +783,44 @@ getloadavg (double loadavg[], int nelem) | |||
| 823 | # endif /* ! defined LDAV_DONE && defined __VMS */ | 783 | # endif /* ! defined LDAV_DONE && defined __VMS */ |
| 824 | 784 | ||
| 825 | # if ! defined LDAV_DONE && defined LOAD_AVE_TYPE && ! defined __VMS | 785 | # if ! defined LDAV_DONE && defined LOAD_AVE_TYPE && ! defined __VMS |
| 826 | /* IRIX, other old systems */ | 786 | /* other old systems */ |
| 827 | 787 | ||
| 828 | /* UNIX-specific code -- read the average from /dev/kmem. */ | 788 | /* UNIX-specific code -- read the average from /dev/kmem. */ |
| 829 | 789 | ||
| 830 | # define LDAV_PRIVILEGED /* This code requires special installation. */ | 790 | # define LDAV_PRIVILEGED /* This code requires special installation. */ |
| 831 | 791 | ||
| 832 | LOAD_AVE_TYPE load_ave[3]; | ||
| 833 | |||
| 834 | /* Get the address of LDAV_SYMBOL. */ | 792 | /* Get the address of LDAV_SYMBOL. */ |
| 835 | if (offset == 0) | 793 | if (offset == 0) |
| 836 | { | 794 | { |
| 837 | # ifndef sgi | 795 | # if ! defined NLIST_STRUCT || ! defined N_NAME_POINTER |
| 838 | # if ! defined NLIST_STRUCT || ! defined N_NAME_POINTER | ||
| 839 | strcpy (name_list[0].n_name, LDAV_SYMBOL); | 796 | strcpy (name_list[0].n_name, LDAV_SYMBOL); |
| 840 | strcpy (name_list[1].n_name, ""); | 797 | strcpy (name_list[1].n_name, ""); |
| 841 | # else /* NLIST_STRUCT */ | 798 | # else /* NLIST_STRUCT */ |
| 842 | # ifdef HAVE_STRUCT_NLIST_N_UN_N_NAME | 799 | # ifdef HAVE_STRUCT_NLIST_N_UN_N_NAME |
| 843 | name_list[0].n_un.n_name = LDAV_SYMBOL; | 800 | name_list[0].n_un.n_name = LDAV_SYMBOL; |
| 844 | name_list[1].n_un.n_name = 0; | 801 | name_list[1].n_un.n_name = 0; |
| 845 | # else /* not HAVE_STRUCT_NLIST_N_UN_N_NAME */ | 802 | # else /* not HAVE_STRUCT_NLIST_N_UN_N_NAME */ |
| 846 | name_list[0].n_name = LDAV_SYMBOL; | 803 | name_list[0].n_name = LDAV_SYMBOL; |
| 847 | name_list[1].n_name = 0; | 804 | name_list[1].n_name = 0; |
| 848 | # endif /* not HAVE_STRUCT_NLIST_N_UN_N_NAME */ | 805 | # endif /* not HAVE_STRUCT_NLIST_N_UN_N_NAME */ |
| 849 | # endif /* NLIST_STRUCT */ | 806 | # endif /* NLIST_STRUCT */ |
| 850 | 807 | ||
| 851 | # ifndef SUNOS_5 | 808 | # ifndef SUNOS_5 |
| 852 | if ( | 809 | if ( |
| 853 | # if !defined (_AIX) | 810 | # if !defined (_AIX) |
| 854 | nlist (KERNEL_FILE, name_list) | 811 | nlist (KERNEL_FILE, name_list) |
| 855 | # else /* _AIX */ | 812 | # else /* _AIX */ |
| 856 | knlist (name_list, 1, sizeof (name_list[0])) | 813 | knlist (name_list, 1, sizeof (name_list[0])) |
| 857 | # endif | 814 | # endif |
| 858 | >= 0) | 815 | >= 0) |
| 859 | /* Omit "&& name_list[0].n_type != 0 " -- it breaks on Sun386i. */ | 816 | /* Omit "&& name_list[0].n_type != 0 " -- it breaks on Sun386i. */ |
| 860 | { | 817 | { |
| 861 | # ifdef FIXUP_KERNEL_SYMBOL_ADDR | 818 | # ifdef FIXUP_KERNEL_SYMBOL_ADDR |
| 862 | FIXUP_KERNEL_SYMBOL_ADDR (name_list); | 819 | FIXUP_KERNEL_SYMBOL_ADDR (name_list); |
| 863 | # endif | 820 | # endif |
| 864 | offset = name_list[0].n_value; | 821 | offset = name_list[0].n_value; |
| 865 | } | 822 | } |
| 866 | # endif /* !SUNOS_5 */ | 823 | # endif /* !SUNOS_5 */ |
| 867 | # else /* sgi */ | ||
| 868 | ptrdiff_t ldav_off = sysmp (MP_KERNADDR, MPKA_AVENRUN); | ||
| 869 | if (ldav_off != -1) | ||
| 870 | offset = (long int) ldav_off & 0x7fffffff; | ||
| 871 | # endif /* sgi */ | ||
| 872 | } | 824 | } |
| 873 | 825 | ||
| 874 | /* Make sure we have /dev/kmem open. */ | 826 | /* Make sure we have /dev/kmem open. */ |
| @@ -895,6 +847,8 @@ getloadavg (double loadavg[], int nelem) | |||
| 895 | # endif /* SUNOS_5 */ | 847 | # endif /* SUNOS_5 */ |
| 896 | } | 848 | } |
| 897 | 849 | ||
| 850 | LOAD_AVE_TYPE load_ave[3]; | ||
| 851 | |||
| 898 | /* If we can, get the load average values. */ | 852 | /* If we can, get the load average values. */ |
| 899 | if (offset && getloadavg_initialized) | 853 | if (offset && getloadavg_initialized) |
| 900 | { | 854 | { |
