From 48b807b0ff892d41387f6cedfb3668e2bcc246ac Mon Sep 17 00:00:00 2001 From: Ian Sutton Date: Tue, 17 Jul 2018 08:43:50 -0500 Subject: [PATCH 1/3] Fix CPU meters Introduction of CP_SPIN sched state broke hard-coded state indexes resulting in the meters incorrectly reporting bogus intr data instead of CPU usage. Change hardcoded values to sched.h macros. --- openbsd/Platform.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 01b6c478..cda424b6 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -46,7 +46,7 @@ extern ProcessFieldData Process_fields[]; #define MAXCPU 256 // XXX: probably should be a struct member -static int64_t old_v[MAXCPU][5]; +static int64_t old_v[MAXCPU][CPUSTATES]; /* * Copyright (c) 1984, 1989, William LeFebvre, Rice University @@ -225,7 +225,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { v[i] = diff_v[i] / 10.; } - Meter_setItems(this, 4); + Meter_setItems(this, CP_IDLE); perc = v[0] + v[1] + v[2] + v[3]; From c005ffc3d70c14189952fa1041bab04462417308 Mon Sep 17 00:00:00 2001 From: Ian Sutton Date: Tue, 17 Jul 2018 08:50:22 -0500 Subject: [PATCH 2/3] Fix zero-index array bounds issue --- openbsd/Platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbsd/Platform.c b/openbsd/Platform.c index cda424b6..a3648f4e 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -220,7 +220,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { percentages(CPUSTATES, diff_v, new_v, (int64_t *)old_v[cpu-1], scratch_v); - for (i = 0; i < CPUSTATES; i++) { + for (i = 0; i < CPUSTATES - 1; i++) { old_v[cpu-1][i] = new_v[i]; v[i] = diff_v[i] / 10.; } From 060aa2b20f88a7dbc1a8b77724df612d3b6fd9ea Mon Sep 17 00:00:00 2001 From: kremlin Date: Thu, 26 Jul 2018 04:17:06 -0500 Subject: [PATCH 3/3] remove wrongfix --- openbsd/Platform.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openbsd/Platform.c b/openbsd/Platform.c index a3648f4e..cda424b6 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -220,7 +220,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { percentages(CPUSTATES, diff_v, new_v, (int64_t *)old_v[cpu-1], scratch_v); - for (i = 0; i < CPUSTATES - 1; i++) { + for (i = 0; i < CPUSTATES; i++) { old_v[cpu-1][i] = new_v[i]; v[i] = diff_v[i] / 10.; }