From 39d8d0930bc222aacfbe1d12444156e161759230 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Tue, 13 Feb 2007 00:21:11 +0000 Subject: [PATCH] [SIGAR-17] Fix possible bad cpu list number on Solaris --- ChangeLog | 4 ++++ src/os/solaris/kstats.c | 43 +++++++++++++++++------------------------ 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/ChangeLog b/ChangeLog index 810a4c34..05553037 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2007-02-12 Doug MacEachern + + * [SIGAR-17] Fix possible bad cpu list number on Solaris + 2007-02-07 Doug MacEachern * Make sure solaris has _POSIX_PTHREAD_SEMANTICS defined diff --git a/src/os/solaris/kstats.c b/src/os/solaris/kstats.c index 3096b219..6ca95ca2 100644 --- a/src/os/solaris/kstats.c +++ b/src/os/solaris/kstats.c @@ -62,8 +62,7 @@ int sigar_get_multi_kstats(sigar_t *sigar, int sigar_get_kstats(sigar_t *sigar) { kstat_ctl_t *kc = sigar->kc; - kstat_t *ksp; - unsigned int i, ncpu = sysconf(_SC_NPROCESSORS_CONF); + unsigned int i, id, ncpu = sysconf(_SC_NPROCESSORS_CONF); int is_debug = SIGAR_LOG_IS_DEBUG(sigar); if (ncpu != sigar->ncpu) { @@ -93,35 +92,29 @@ int sigar_get_kstats(sigar_t *sigar) sigar->ncpu = ncpu; - for (i=0, ksp=kc->kc_chain; iks_next) { - char *id; - kstat_t *cpu_info; + /* from man p_online: + * ``Processor numbers are integers, + * greater than or equal to 0, + * and are defined by the hardware platform. + * Processor numbers are not necessarily contiguous, + * but "not too sparse."`` + * so we maintain our own mapping in ks.cpuid[] + */ - if (!ksp) { - break; - } - if (strncmp(ksp->ks_name, "cpu_stat", 8)) { + /* lookup in order, which kstat chain may not be in */ + for (i=0, id=0; iks_name; - while (!sigar_isdigit(*id)) { - id++; - } - - sigar->ks.cpu[i] = ksp; - sigar->ks.cpuid[i] = atoi(id); - if ((cpu_info = kstat_lookup(kc, "cpu_info", sigar->ks.cpuid[i], NULL))) { + sigar->ks.cpu[i] = cpu_stat; + sigar->ks.cpuid[i] = id; + if ((cpu_info = kstat_lookup(kc, "cpu_info", id, NULL))) { sigar->ks.cpu_info[i] = cpu_info; } + if (is_debug) { sigar_log_printf(sigar, SIGAR_LOG_DEBUG, "cpu %d id=%d", i, sigar->ks.cpuid[i]);