Author: Dharanendiran <dharanendiran@timesys.com>
Date: Mon, 22 Dec 2025 10:03:09 +0530

Based on:
https://github.com/torvalds/linux/commit/1a202afeaa370970413846c2cb09b383875e753c

Error log:

turbostat.c: In function 'format_counters':
turbostat.c:2812:4: error: a label can only be part of a statement and a declaration is not a statement
 2812 |    const unsigned long value_raw = t->pmt_counter[i];
      |    ^~~~~
turbostat.c:2813:4: error: expected expression before 'const'
 2813 |    const double value_converted = 100.0 * value_raw / crystal_hz / interval_float;
      |    ^~~~~
turbostat.c:2815:62: error: 'value_converted' undeclared (first use in this function)
 2815 |    outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), value_converted);
      |                                                              ^~~~~~~~~~~~~~~
turbostat.c:2815:62: note: each undeclared identifier is reported only once for each function it appears in
turbostat.c:2893:4: error: a label can only be part of a statement and a declaration is not a statement
 2893 |    const unsigned long value_raw = c->pmt_counter[i];
      |    ^~~~~
turbostat.c:2894:4: error: expected expression before 'const'
 2894 |    const double value_converted = 100.0 * value_raw / crystal_hz / interval_float;
      |    ^~~~~
turbostat.c:3092:4: error: a label can only be part of a statement and a declaration is not a statement
 3092 |    const unsigned long value_raw = p->pmt_counter[i];
      |    ^~~~~
turbostat.c:3093:4: error: expected expression before 'const'
 3093 |    const double value_converted = 100.0 * value_raw / crystal_hz / interval_float;
      |    ^~~~~
make[1]: *** [Makefile:23: turbostat] Error 1

---
 tools/power/x86/turbostat/turbostat.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index b663a76d3..66f8581da 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -2798,6 +2798,8 @@ int format_counters(struct thread_data *t, struct core_data *c, struct pkg_data
 	}
 
 	for (i = 0, ppmt = sys.pmt_tp; ppmt; i++, ppmt = ppmt->next) {
+		const unsigned long value_raw = t->pmt_counter[i];
+		double value_converted;
 		switch (ppmt->type) {
 		case PMT_TYPE_RAW:
 			if (pmt_counter_get_width(ppmt) <= 32)
@@ -2809,9 +2811,7 @@ int format_counters(struct thread_data *t, struct core_data *c, struct pkg_data
 			break;
 
 		case PMT_TYPE_XTAL_TIME:
-			const unsigned long value_raw = t->pmt_counter[i];
-			const double value_converted = 100.0 * value_raw / crystal_hz / interval_float;
-
+			value_converted = 100.0 * value_raw / crystal_hz / interval_float;
 			outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), value_converted);
 			break;
 		}
@@ -2879,6 +2879,8 @@ int format_counters(struct thread_data *t, struct core_data *c, struct pkg_data
 	}
 
 	for (i = 0, ppmt = sys.pmt_cp; ppmt; i++, ppmt = ppmt->next) {
+		const unsigned long value_raw = c->pmt_counter[i];
+		double value_converted;
 		switch (ppmt->type) {
 		case PMT_TYPE_RAW:
 			if (pmt_counter_get_width(ppmt) <= 32)
@@ -2890,9 +2892,7 @@ int format_counters(struct thread_data *t, struct core_data *c, struct pkg_data
 			break;
 
 		case PMT_TYPE_XTAL_TIME:
-			const unsigned long value_raw = c->pmt_counter[i];
-			const double value_converted = 100.0 * value_raw / crystal_hz / interval_float;
-
+			value_converted = 100.0 * value_raw / crystal_hz / interval_float;
 			outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), value_converted);
 			break;
 		}
@@ -3078,6 +3078,8 @@ int format_counters(struct thread_data *t, struct core_data *c, struct pkg_data
 	}
 
 	for (i = 0, ppmt = sys.pmt_pp; ppmt; i++, ppmt = ppmt->next) {
+		const unsigned long value_raw = p->pmt_counter[i];
+		double value_converted;
 		switch (ppmt->type) {
 		case PMT_TYPE_RAW:
 			if (pmt_counter_get_width(ppmt) <= 32)
@@ -3089,9 +3091,7 @@ int format_counters(struct thread_data *t, struct core_data *c, struct pkg_data
 			break;
 
 		case PMT_TYPE_XTAL_TIME:
-			const unsigned long value_raw = p->pmt_counter[i];
-			const double value_converted = 100.0 * value_raw / crystal_hz / interval_float;
-
+			value_converted = 100.0 * value_raw / crystal_hz / interval_float;
 			outp += sprintf(outp, "%s%.2f", (printed++ ? delim : ""), value_converted);
 			break;
 		}
-- 
2.34.1

