improve logical processor folding

This commit is contained in:
Doug MacEachern 2007-06-28 00:01:51 +00:00
parent 3dea5eb761
commit 407144e707
1 changed files with 59 additions and 28 deletions

View File

@ -300,6 +300,11 @@ static int get_chip_brand(sigar_t *sigar, int processor,
} }
} }
static void free_chip_id(void *ptr)
{
/*noop*/
}
static int get_chip_id(sigar_t *sigar, int processor) static int get_chip_id(sigar_t *sigar, int processor)
{ {
kstat_t *ksp = sigar->ks.cpu_info[processor]; kstat_t *ksp = sigar->ks.cpu_info[processor];
@ -316,18 +321,6 @@ static int get_chip_id(sigar_t *sigar, int processor)
} }
} }
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;
@ -361,7 +354,7 @@ int sigar_cpu_list_get(sigar_t *sigar, sigar_cpu_list_t *cpulist)
uint_t cpuinfo[CPU_STATES]; uint_t cpuinfo[CPU_STATES];
unsigned int i; unsigned int i;
int is_debug = SIGAR_LOG_IS_DEBUG(sigar); int is_debug = SIGAR_LOG_IS_DEBUG(sigar);
int reported_virtual = 0; sigar_cache_t *chips;
if (sigar_kstat_update(sigar) == -1) { if (sigar_kstat_update(sigar) == -1) {
return errno; return errno;
@ -387,9 +380,14 @@ int sigar_cpu_list_get(sigar_t *sigar, sigar_cpu_list_t *cpulist)
sigar->ncpu); sigar->ncpu);
} }
chips = sigar_cache_new(16);
chips->free_value = free_chip_id;
for (i=0; i<sigar->ncpu; i++) { for (i=0; i<sigar->ncpu; i++) {
sigar_cpu_t *cpu; sigar_cpu_t *cpu;
char *buf; char *buf;
int chip_id;
sigar_cache_entry_t *ent;
if (!CPU_ONLINE(sigar->ks.cpuid[i])) { if (!CPU_ONLINE(sigar->ks.cpuid[i])) {
sigar_log_printf(sigar, SIGAR_LOG_INFO, sigar_log_printf(sigar, SIGAR_LOG_INFO,
@ -431,21 +429,31 @@ int sigar_cpu_list_get(sigar_t *sigar, sigar_cpu_list_t *cpulist)
buf = ksp->ks_data; buf = ksp->ks_data;
buf += sizeof(kmutex_t); buf += sizeof(kmutex_t);
memcpy(&cpuinfo[0], buf, sizeof(cpuinfo)); memcpy(&cpuinfo[0], buf, sizeof(cpuinfo));
chip_id = get_chip_id(sigar, i);
if (is_same_chip(sigar, i, cpulist->number)) { if (chip_id == -1) {
/* merge times of logical processors */ SIGAR_CPU_LIST_GROW(cpulist);
cpu = &cpulist->data[cpulist->number-1]; cpu = &cpulist->data[cpulist->number++];
SIGAR_ZERO(cpu);
if (is_debug && !reported_virtual++) {
sigar_log_printf(sigar, SIGAR_LOG_DEBUG,
"[cpu_list] Merging times of"
" logical processors");
} }
else {
/* merge times of logical processors */
ent = sigar_cache_get(chips, chip_id);
if (ent->value) {
cpu = (sigar_cpu_t *)ent->value;
} }
else { else {
SIGAR_CPU_LIST_GROW(cpulist); SIGAR_CPU_LIST_GROW(cpulist);
cpu = &cpulist->data[cpulist->number++]; cpu = &cpulist->data[cpulist->number++];
SIGAR_ZERO(cpu); SIGAR_ZERO(cpu);
ent->value = cpu;
if (is_debug) {
sigar_log_printf(sigar, SIGAR_LOG_DEBUG,
"[cpu_list] Merging times of"
" logical processors for chip_id=%d",
chip_id);
}
}
} }
cpu->user += SIGAR_TICK2MSEC(cpuinfo[CPU_USER]); cpu->user += SIGAR_TICK2MSEC(cpuinfo[CPU_USER]);
@ -456,6 +464,8 @@ int sigar_cpu_list_get(sigar_t *sigar, sigar_cpu_list_t *cpulist)
cpu->total = cpu->user + cpu->sys + cpu->idle + cpu->wait; cpu->total = cpu->user + cpu->sys + cpu->idle + cpu->wait;
} }
sigar_cache_destroy(chips);
return SIGAR_OK; return SIGAR_OK;
} }
@ -1627,6 +1637,8 @@ int sigar_cpu_info_list_get(sigar_t *sigar,
unsigned int i; unsigned int i;
int status = SIGAR_OK; int status = SIGAR_OK;
int brand = -1; int brand = -1;
sigar_cache_t *chips;
int is_debug = SIGAR_LOG_IS_DEBUG(sigar);
if (sigar_kstat_update(sigar) == -1) { /* for sigar->ncpu */ if (sigar_kstat_update(sigar) == -1) { /* for sigar->ncpu */
return errno; return errno;
@ -1654,13 +1666,30 @@ int sigar_cpu_info_list_get(sigar_t *sigar,
} }
sigar_cpu_info_list_create(cpu_infos); sigar_cpu_info_list_create(cpu_infos);
chips = sigar_cache_new(16);
chips->free_value = free_chip_id;
for (i=0; i<sigar->ncpu; i++) { for (i=0; i<sigar->ncpu; i++) {
sigar_cpu_info_t *info; sigar_cpu_info_t *info;
int chip_id = get_chip_id(sigar, i);
if (is_same_chip(sigar, i, cpu_infos->number)) { if (chip_id != -1) {
sigar_cache_entry_t *ent =
sigar_cache_get(chips, chip_id);
if (ent->value) {
continue; continue;
} }
else {
ent->value = chips; /*anything non-NULL*/
if (is_debug) {
sigar_log_printf(sigar, SIGAR_LOG_DEBUG,
"[cpu_list] Merging info of"
" logical processors for chip_id=%d",
chip_id);
}
}
}
SIGAR_CPU_INFO_LIST_GROW(cpu_infos); SIGAR_CPU_INFO_LIST_GROW(cpu_infos);
@ -1696,6 +1725,8 @@ int sigar_cpu_info_list_get(sigar_t *sigar,
info->cache_size = SIGAR_FIELD_NOTIMPL; /*XXX*/ info->cache_size = SIGAR_FIELD_NOTIMPL; /*XXX*/
} }
sigar_cache_destroy(chips);
return SIGAR_OK; return SIGAR_OK;
} }