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 */ /* init */
sigar->ks.lcpu = ncpu; sigar->ks.lcpu = ncpu;
sigar->ks.cpu = malloc(sizeof(*(sigar->ks.cpu)) * 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); sigar->ks.cpuid = malloc(sizeof(*(sigar->ks.cpuid)) * ncpu);
} }
else { else {
@ -63,6 +64,8 @@ int sigar_get_kstats(sigar_t *sigar)
/* one or more cpus have been added */ /* one or more cpus have been added */
sigar->ks.cpu = realloc(sigar->ks.cpu, sigar->ks.cpu = realloc(sigar->ks.cpu,
sizeof(*(sigar->ks.cpu)) * ncpu); 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, sigar->ks.cpuid = realloc(sigar->ks.cpuid,
sizeof(*(sigar->ks.cpuid)) * ncpu); sizeof(*(sigar->ks.cpuid)) * ncpu);
sigar->ks.lcpu = 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) { for (i=0, ksp=kc->kc_chain; i<ncpu; ksp=ksp->ks_next) {
char *id; char *id;
kstat_t *cpu_info;
if (!ksp) { if (!ksp) {
break; break;
@ -97,6 +101,9 @@ int sigar_get_kstats(sigar_t *sigar)
sigar->ks.cpu[i] = ksp; sigar->ks.cpu[i] = ksp;
sigar->ks.cpuid[i] = atoi(id); 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) { if (is_debug) {
sigar_log_printf(sigar, SIGAR_LOG_DEBUG, sigar_log_printf(sigar, SIGAR_LOG_DEBUG,
"cpu %d id=%d", i, sigar->ks.cpuid[i]); "cpu %d id=%d", i, sigar->ks.cpuid[i]);

View File

@ -190,6 +190,7 @@ struct sigar_t {
/* kstat_lookup() as needed */ /* kstat_lookup() as needed */
struct { struct {
kstat_t **cpu; kstat_t **cpu;
kstat_t **cpu_info;
processorid_t *cpuid; processorid_t *cpuid;
unsigned int lcpu; /* number malloced slots in the cpu array above */ unsigned int lcpu; /* number malloced slots in the cpu array above */
kstat_t *system; kstat_t *system;

View File

@ -64,6 +64,7 @@ int sigar_os_open(sigar_t **sig)
sigar->cpulist.size = 0; sigar->cpulist.size = 0;
sigar->ncpu = 0; sigar->ncpu = 0;
sigar->ks.cpu = NULL; sigar->ks.cpu = NULL;
sigar->ks.cpu_info = NULL;
sigar->ks.cpuid = NULL; sigar->ks.cpuid = NULL;
sigar->ks.lcpu = 0; sigar->ks.lcpu = 0;
@ -129,6 +130,7 @@ int sigar_os_close(sigar_t *sigar)
} }
if (sigar->ks.lcpu) { if (sigar->ks.lcpu) {
free(sigar->ks.cpu); free(sigar->ks.cpu);
free(sigar->ks.cpu_info);
free(sigar->ks.cpuid); free(sigar->ks.cpuid);
} }
if (sigar->pinfo) { if (sigar->pinfo) {
@ -226,6 +228,34 @@ int sigar_swap_get(sigar_t *sigar, sigar_swap_t *swap)
return SIGAR_OK; 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 sigar_cpu_get(sigar_t *sigar, sigar_cpu_t *cpu)
{ {
int status, i; int status, i;
@ -322,16 +352,22 @@ int sigar_cpu_list_get(sigar_t *sigar, sigar_cpu_list_t *cpulist)
buf += sizeof(kmutex_t); buf += sizeof(kmutex_t);
memcpy(&cpuinfo[0], buf, sizeof(cpuinfo)); 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); SIGAR_CPU_LIST_GROW(cpulist);
cpu = &cpulist->data[cpulist->number++]; cpu = &cpulist->data[cpulist->number++];
SIGAR_ZERO(cpu);
}
cpu->user = SIGAR_TICK2SEC(cpuinfo[CPU_USER]); cpu->user += SIGAR_TICK2SEC(cpuinfo[CPU_USER]);
cpu->sys = SIGAR_TICK2SEC(cpuinfo[CPU_KERNEL]); cpu->sys += SIGAR_TICK2SEC(cpuinfo[CPU_KERNEL]);
cpu->idle = SIGAR_TICK2SEC(cpuinfo[CPU_IDLE]); cpu->idle += SIGAR_TICK2SEC(cpuinfo[CPU_IDLE]);
cpu->wait = SIGAR_TICK2SEC(cpuinfo[CPU_WAIT]); cpu->wait += SIGAR_TICK2SEC(cpuinfo[CPU_WAIT]);
cpu->nice = 0; /* no cpu->nice */ cpu->nice += 0; /* no cpu->nice */
cpu->total = cpu->user + cpu->sys + cpu->idle + cpu->wait; cpu->total += cpu->user + cpu->sys + cpu->idle + cpu->wait;
} }
return SIGAR_OK; return SIGAR_OK;
@ -1529,11 +1565,14 @@ int sigar_cpu_info_list_get(sigar_t *sigar,
for (i=0; i<sigar->ncpu; i++) { for (i=0; i<sigar->ncpu; i++) {
sigar_cpu_info_t *info; sigar_cpu_info_t *info;
if (is_same_chip(sigar, i, cpu_infos->number)) {
continue;
}
SIGAR_CPU_INFO_LIST_GROW(cpu_infos); SIGAR_CPU_INFO_LIST_GROW(cpu_infos);
info = &cpu_infos->data[cpu_infos->number++]; info = &cpu_infos->data[cpu_infos->number++];
SIGAR_SSTRCPY(info->model, stats.pi_processor_type); SIGAR_SSTRCPY(info->model, stats.pi_processor_type);
if (strEQ(info->model, "i386")) { if (strEQ(info->model, "i386")) {