[Powertop] [PATCH POWERTOP V3] resolve the bug that powertop doesn't show correct frequency stats

Shaojie Sun <shaojie.sun at linaro.org>
Newsgroups dev.linux.lists.powertop
Message-ID <[email protected]>
From: Jon Medhurst <tixy(a)linaro.org>

For cpu_frequency events, perf_power_bundle::handle_trace_point()
is always being called with the same cpunr. so the parameter of
cpunr is not equal to the cpu which cpu_frequency events happened.
Lucky the trace event themselves have a cpu_id field to say to which
CPU event it relates, we should use this cpu_id field.

Signed-off-by:  Jon Medhurst <tixy(a)linaro.org>
		Shaojie Sun <shaojie.sun(a)linaro.com>
---
 src/cpu/cpu.cpp |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/cpu/cpu.cpp b/src/cpu/cpu.cpp
index 7f3af69..e304bbe 100644
--- a/src/cpu/cpu.cpp
+++ b/src/cpu/cpu.cpp
@@ -781,10 +781,15 @@ void perf_power_bundle::handle_trace_point(void *trace, int cpunr, uint64_t time
 
 	if (strcmp(event->name, "power_frequency") == 0
 	|| strcmp(event->name, "cpu_frequency") == 0){
-
+		ret = pevent_get_field_val(NULL, event, "cpu_id", &rec, &val, 0);
+		if (ret < 0) {
+			fprintf(stderr, _("power or cpu_frequency event returned no cpu?\n"));
+			exit(-1);
+		}
+		cpu = all_cpus[val];
 		ret = pevent_get_field_val(NULL, event, "state", &rec, &val, 0);
 		if (ret < 0) {
-			fprintf(stderr, _("power or cpu_frequecny event returned no state?\n"));
+			fprintf(stderr, _("power or cpu_frequency event returned no state?\n"));
 			exit(-1);
 		}
 
-- 
1.7.9.5
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.