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]);