From bd6415618b1f427108012b9fe045c2e5c8530260 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Wed, 3 May 2006 07:02:35 +0000 Subject: [PATCH] fold UltraSPARC-T1 virtual cpus into the physical cpus --- src/os/solaris/kstats.c | 7 ++++ src/os/solaris/sigar_os.h | 1 + src/os/solaris/solaris_sigar.c | 59 ++++++++++++++++++++++++++++------ 3 files changed, 57 insertions(+), 10 deletions(-) diff --git a/src/os/solaris/kstats.c b/src/os/solaris/kstats.c index 5958455c..f3300220 100644 --- a/src/os/solaris/kstats.c +++ b/src/os/solaris/kstats.c @@ -53,6 +53,7 @@ int sigar_get_kstats(sigar_t *sigar) /* init */ sigar->ks.lcpu = ncpu; sigar->ks.cpu = malloc(sizeof(*(sigar->ks.cpu)) * ncpu); + sigar->ks.cpu_info = malloc(sizeof(*(sigar->ks.cpu_info)) * ncpu); sigar->ks.cpuid = malloc(sizeof(*(sigar->ks.cpuid)) * ncpu); } else { @@ -63,6 +64,8 @@ int sigar_get_kstats(sigar_t *sigar) /* one or more cpus have been added */ sigar->ks.cpu = realloc(sigar->ks.cpu, sizeof(*(sigar->ks.cpu)) * ncpu); + sigar->ks.cpu_info = realloc(sigar->ks.cpu_info, + sizeof(*(sigar->ks.cpu_info)) * ncpu); sigar->ks.cpuid = realloc(sigar->ks.cpuid, sizeof(*(sigar->ks.cpuid)) * ncpu); sigar->ks.lcpu = ncpu; @@ -74,6 +77,7 @@ int sigar_get_kstats(sigar_t *sigar) for (i=0, ksp=kc->kc_chain; iks_next) { char *id; + kstat_t *cpu_info; if (!ksp) { break; @@ -97,6 +101,9 @@ int sigar_get_kstats(sigar_t *sigar) 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_info[i] = cpu_info; + } if (is_debug) { sigar_log_printf(sigar, SIGAR_LOG_DEBUG, "cpu %d id=%d", i, sigar->ks.cpuid[i]); diff --git a/src/os/solaris/sigar_os.h b/src/os/solaris/sigar_os.h index 0980c032..480a0fe4 100644 --- a/src/os/solaris/sigar_os.h +++ b/src/os/solaris/sigar_os.h @@ -190,6 +190,7 @@ struct sigar_t { /* kstat_lookup() as needed */ struct { kstat_t **cpu; + kstat_t **cpu_info; processorid_t *cpuid; unsigned int lcpu; /* number malloced slots in the cpu array above */ kstat_t *system; diff --git a/src/os/solaris/solaris_sigar.c b/src/os/solaris/solaris_sigar.c index ec8c398b..1e3cb8ac 100644 --- a/src/os/solaris/solaris_sigar.c +++ b/src/os/solaris/solaris_sigar.c @@ -64,6 +64,7 @@ int sigar_os_open(sigar_t **sig) sigar->cpulist.size = 0; sigar->ncpu = 0; sigar->ks.cpu = NULL; + sigar->ks.cpu_info = NULL; sigar->ks.cpuid = NULL; sigar->ks.lcpu = 0; @@ -129,6 +130,7 @@ int sigar_os_close(sigar_t *sigar) } if (sigar->ks.lcpu) { free(sigar->ks.cpu); + free(sigar->ks.cpu_info); free(sigar->ks.cpuid); } if (sigar->pinfo) { @@ -226,6 +228,34 @@ int sigar_swap_get(sigar_t *sigar, sigar_swap_t *swap) return SIGAR_OK; } +static int get_chip_id(sigar_t *sigar, int processor) +{ + kstat_t *ksp = sigar->ks.cpu_info[processor]; + kstat_named_t *chipid; + + if (ksp && + (kstat_read(sigar->kc, ksp, NULL) != -1) && + (chipid = (kstat_named_t *)kstat_data_lookup(ksp, "chip_id"))) + { + return chipid->value.i32; + } + else { + return -1; + } +} + +static int is_same_chip(sigar_t *sigar, int processor, int num) +{ + int chip_id = get_chip_id(sigar, processor); + + if ((chip_id == -1) || (chip_id != (num-1))) { + return 0; + } + else { + return 1; + } +} + int sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu) { int status, i; @@ -322,16 +352,22 @@ int sigar_cpu_list_get(sigar_t *sigar, sigar_cpu_list_t *cpulist) buf += sizeof(kmutex_t); memcpy(&cpuinfo[0], buf, sizeof(cpuinfo)); - SIGAR_CPU_LIST_GROW(cpulist); + if (is_same_chip(sigar, i, cpulist->number)) { + /* merge times of logical processors */ + cpu = &cpulist->data[cpulist->number-1]; + } + else { + SIGAR_CPU_LIST_GROW(cpulist); + cpu = &cpulist->data[cpulist->number++]; + SIGAR_ZERO(cpu); + } - cpu = &cpulist->data[cpulist->number++]; - - cpu->user = SIGAR_TICK2SEC(cpuinfo[CPU_USER]); - cpu->sys = SIGAR_TICK2SEC(cpuinfo[CPU_KERNEL]); - cpu->idle = SIGAR_TICK2SEC(cpuinfo[CPU_IDLE]); - cpu->wait = SIGAR_TICK2SEC(cpuinfo[CPU_WAIT]); - cpu->nice = 0; /* no cpu->nice */ - cpu->total = cpu->user + cpu->sys + cpu->idle + cpu->wait; + cpu->user += SIGAR_TICK2SEC(cpuinfo[CPU_USER]); + cpu->sys += SIGAR_TICK2SEC(cpuinfo[CPU_KERNEL]); + cpu->idle += SIGAR_TICK2SEC(cpuinfo[CPU_IDLE]); + cpu->wait += SIGAR_TICK2SEC(cpuinfo[CPU_WAIT]); + cpu->nice += 0; /* no cpu->nice */ + cpu->total += cpu->user + cpu->sys + cpu->idle + cpu->wait; } return SIGAR_OK; @@ -1529,11 +1565,14 @@ int sigar_cpu_info_list_get(sigar_t *sigar, for (i=0; incpu; i++) { sigar_cpu_info_t *info; + if (is_same_chip(sigar, i, cpu_infos->number)) { + continue; + } + SIGAR_CPU_INFO_LIST_GROW(cpu_infos); info = &cpu_infos->data[cpu_infos->number++]; - SIGAR_SSTRCPY(info->model, stats.pi_processor_type); if (strEQ(info->model, "i386")) {