From 06539b83ad5ec7b07e63c05aab62760324d463b7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Manuel=20Luis=20Sanmart=C3=ADn=20Rozada?= Date: Tue, 20 Jul 2010 18:25:24 +0200 Subject: [PATCH] AIX: Detect offline cpus Signed-off-by: Florian Forster --- src/cpu.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/cpu.c b/src/cpu.c index cfdea588..7a6bba3c 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -143,6 +143,8 @@ static int maxcpu; static perfstat_cpu_t *perfcpu; static int numcpu; static int pnumcpu; +static u_longlong_t *cpu_total; +static u_longlong_t *pcpu_total; #endif /* HAVE_PERFSTAT */ static int init (void) @@ -562,6 +564,7 @@ static int cpu_read (void) #elif defined(HAVE_PERFSTAT) perfstat_id_t id; perfstat_cpu_t *pcpu; + u_longlong_t *cpu_swap; int i, cpus; numcpu = perfstat_cpu(NULL, NULL, sizeof(perfstat_cpu_t), 0); @@ -578,6 +581,14 @@ static int cpu_read (void) if (perfcpu != NULL) free(perfcpu); perfcpu = malloc(numcpu * sizeof(perfstat_cpu_t)); + + if (cpu_total != NULL) + free(cpu_total); + cpu_total = (u_longlong_t *)calloc(numcpu, sizeof(u_longlong_t)); + + if (pcpu_total != NULL) + free(pcpu_total); + pcpu_total = (u_longlong_t *)calloc(numcpu, sizeof(u_longlong_t)); } pnumcpu = numcpu; @@ -592,11 +603,19 @@ static int cpu_read (void) for (i = 0, pcpu = perfcpu; i < cpus; i++, pcpu++) { + cpu_total[i] = pcpu->idle + pcpu->sys + pcpu->user + pcpu->wait; + if (cpu_total[i] == pcpu_total[i]) + continue; + submit (i, "idle", (counter_t) pcpu->idle); submit (i, "system", (counter_t) pcpu->sys); submit (i, "user", (counter_t) pcpu->user); submit (i, "wait", (counter_t) pcpu->wait); } + + cpu_swap = pcpu_total; + pcpu_total = cpu_total; + cpu_total = cpu_swap; #endif /* HAVE_PERFSTAT */ return (0); -- 2.11.0