fold UltraSPARC-T1 virtual cpus into the physical cpus

This commit is contained in:
Doug MacEachern 2006-05-03 07:02:35 +00:00
parent 3bc1ba5ea8
commit bd6415618b
3 changed files with 57 additions and 10 deletions

View File

@ -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; i<ncpu; ksp=ksp->ks_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]);

View File

@ -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;

View File

@ -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));
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->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; i<sigar->ncpu; 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")) {