Skip to contentSkip to conversation

tools/power turbostat: Improve handling for unsupported platforms

PATCH In review Zhang Rui 2 participants 6 messages Dec 3, 2024 Turbostat utility

lore
Share & tools
lore

Zhang Rui

author
#0 lore raw

cover tools/power turbostat: Improve handling for unsupported platforms

Hi, all,

Turbostat requires per-platform enabling for different platforms due to platform-specific features. When running on unsupported platforms, turbostat currently operates with limited default features, which can lead to users unknowingly using an outdated version of the tool.

Enhance turbostat to
1. exit by default when run on unsupported X86 Vendors/Intel models.
2. give a clear message to users, informing them that their CPU model is not supported and advising them to update to the latest version of turbostat for full functionality.
3. allow force loading with minimum support on unsupported platforms by introducing a new '--force' parameter.

With above patches, when turbostat runs
1. on supported platforms, no functional change.
2. on unsupported X86 Vendors or unsupported Intel Models without '--force' parameter, turbostat exits with below message:

"Unsupported platform detected.
Use "--force" parameter to launch turbostat with minimum default support. To get latest turbostat support, please contact
[email protected]
or pull from
https://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux.git turbostat"

3. on unsupported X86 Vendors or unsupported Intel Models with '--force' parameter, turbostat continues but with below message

"Unsupported platform detected. Force running with minimum default support."

Any comments are welcome.

thanks,
rui

Zhang Rui (4):
tools/power turbostat: Exit on unsupported Intel models tools/power turbostat: Exit on unsupported Vendors tools/power turbostat: Improve --help output tools/power turbostat: Introduce --force parameter

 tools/power/x86/turbostat/turbostat.c | 72 ++++++++++++++++++++-------
 1 file changed, 54 insertions(+), 18 deletions(-)
Signature · 1 line
2.43.0
author
#1 lore raw

PATCH 1/4 tools/power turbostat: Exit on unsupported Intel models

Turbostat requires per-platform enabling for Intel CPU models due to platform-specific features. When running on unsupported Intel CPU models, turbostat currently operates with limited default features, which can lead to users unknowingly using an outdated version of the tool.

Enhance turbostat to exit by default when run on unsupported Intel CPU models, with a clear message to users, informing them that their CPU model is not supported and advising them to update to the latest version of turbostat for full functionality.

---
 tools/power/x86/turbostat/turbostat.c | 7 +++++++
 1 file changed, 7 insertions(+)
tools/power/x86/turbostat/turbostat.c +7 -0
index e203f109dd2e..bb65c5e1273c 100644
@@ -1079,6 +1079,13 @@ void probe_platform_features(unsigned int family, unsigned int model)
 			return;
 		}
 	}
+
+	fprintf(stderr, "Unsupported platform detected.\n"
+		"\tTo get latest turbostat support, please contact\n"
+		"\t   [email protected]\n"
+		"\tor pull from\n"
+		"\t   https://git.kernel.org/pub/scm/linux/kernel/git/lenb/linux.git turbostat\n");
+	exit(1);
 }
 
 /* Model specific support End */
Signature · 1 line
2.43.0
maintainer
#2 lore raw

Re: [PATCH 1/4] tools/power turbostat: Exit on unsupported Intel models

Quoted 1 line · Zhang Rui

+ "\tTo get latest turbostat support, please contact\n" ...

"\t Please refer to turbostat(8) to find the latest version of turbostat.\n"

I'll create a patch to turbostat.8 to with clear instructions.

thanks!
-Len

author
#3 lore raw

PATCH 2/4 tools/power turbostat: Exit on unsupported Vendors

In reply to Zhang Rui

Turbostat currently supports x86 processors from Intel, AMD, and Hygon. The behavior of turbostat on CPUs from other vendors has not been evaluated and may lead to incorrect or undefined behavior.

Enhance turbostat to exit by default when running on an unsupported CPU vendor. This ensures that users are aware that their CPU is not currently supported by turbostat, guiding them to seek support for their specific hardware through future patches.

---
 tools/power/x86/turbostat/turbostat.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
tools/power/x86/turbostat/turbostat.c +6 -2
index bb65c5e1273c..508d65e60981 100644
@@ -1056,9 +1056,9 @@ void probe_platform_features(unsigned int family, unsigned int model)
 {
 	int i;
 
-	platform = &default_features;
 
 	if (authentic_amd || hygon_genuine) {
+		platform = &default_features;
 		if (max_extended_level >= 0x80000007) {
 			unsigned int eax, ebx, ecx, edx;
 
@@ -1071,7 +1071,7 @@ void probe_platform_features(unsigned int family, unsigned int model)
 	}
 
 	if (!genuine_intel)
-		return;
+		goto end;
 
 	for (i = 0; turbostat_pdata[i].features; i++) {
 		if (VFM_FAMILY(turbostat_pdata[i].vfm) == family && VFM_MODEL(turbostat_pdata[i].vfm) == model) {
@@ -1080,6 +1080,10 @@ void probe_platform_features(unsigned int family, unsigned int model)
 		}
 	}
 
+end:
+	if (platform)
+		return;
+
 	fprintf(stderr, "Unsupported platform detected.\n"
 		"\tTo get latest turbostat support, please contact\n"
 		"\t   [email protected]\n"
Signature · 1 line
2.43.0
author
#4 lore raw

PATCH 3/4 tools/power turbostat: Improve --help output

In reply to Zhang Rui

Improve the --help output of turbostat by standardizing the format and enhancing readability. The following changes are made to ensure consistency and clarity in the help message:
1. Use a consistent pattern for each parameter's help message:
- Display the parameter and its input (if any) on the same line, separated by a space.
- Provide the detailed description on a separate line.
2. Ensure that the first character of each description is in lower-case.

These changes make the help output more uniform and easier to read, helping users quickly understand the available options and their usage.

No functional change.

---
 tools/power/x86/turbostat/turbostat.c | 41 +++++++++++++++++----------
 1 file changed, 26 insertions(+), 15 deletions(-)
tools/power/x86/turbostat/turbostat.c +26 -15
index 508d65e60981..442a993c5114 100644
@@ -2148,41 +2148,52 @@ void help(void)
 		"when COMMAND completes.\n"
 		"If no COMMAND is specified, turbostat wakes every 5-seconds\n"
 		"to print statistics, until interrupted.\n"
-		"  -a, --add	add a counter\n"
+		"  -a, --add counter\n"
+		"		add a counter\n"
 		"		  eg. --add msr0x10,u64,cpu,delta,MY_TSC\n"
 		"		  eg. --add perf/cstate_pkg/c2-residency,package,delta,percent,perfPC2\n"
 		"		  eg. --add pmt,name=XTAL,type=raw,domain=package0,offset=0,lsb=0,msb=63,guid=0x1a067102\n"
-		"  -c, --cpu	cpu-set	limit output to summary plus cpu-set:\n"
+		"  -c, --cpu cpu-set\n"
+		"		limit output to summary plus cpu-set:\n"
 		"		  {core | package | j,k,l..m,n-p }\n"
-		"  -d, --debug	displays usec, Time_Of_Day_Seconds and more debugging\n"
+		"  -d, --debug\n"
+		"		displays usec, Time_Of_Day_Seconds and more debugging\n"
 		"		debug messages are printed to stderr\n"
-		"  -D, --Dump	displays the raw counter values\n"
-		"  -e, --enable	[all | column]\n"
+		"  -D, --Dump\n"
+		"		displays the raw counter values\n"
+		"  -e, --enable [all | column]\n"
 		"		shows all or the specified disabled column\n"
-		"  -H, --hide [column|column,column,...]\n"
+		"  -H, --hide [column | column,column,...]\n"
 		"		hide the specified column(s)\n"
 		"  -i, --interval sec.subsec\n"
-		"		Override default 5-second measurement interval\n"
-		"  -J, --Joules	displays energy in Joules instead of Watts\n"
-		"  -l, --list	list column headers only\n"
-		"  -M, --no-msr Disable all uses of the MSR driver\n"
-		"  -P, --no-perf Disable all uses of the perf API\n"
+		"		override default 5-second measurement interval\n"
+		"  -J, --Joules\n"
+		"		displays energy in Joules instead of Watts\n"
+		"  -l, --list\n"
+		"		list column headers only\n"
+		"  -M, --no-msr\n"
+		"		disable all uses of the MSR driver\n"
+		"  -P, --no-perf\n"
+		"		disable all uses of the perf API\n"
 		"  -n, --num_iterations num\n"
 		"		number of the measurement iterations\n"
 		"  -N, --header_iterations num\n"
 		"		print header every num iterations\n"
 		"  -o, --out file\n"
 		"		create or truncate \"file\" for all output\n"
-		"  -q, --quiet	skip decoding system configuration header\n"
-		"  -s, --show [column|column,column,...]\n"
+		"  -q, --quiet\n"
+		"		skip decoding system configuration header\n"
+		"  -s, --show [column | column,column,...]\n"
 		"		show only the specified column(s)\n"
 		"  -S, --Summary\n"
 		"		limits output to 1-line system summary per interval\n"
 		"  -T, --TCC temperature\n"
 		"		sets the Thermal Control Circuit temperature in\n"
 		"		  degrees Celsius\n"
-		"  -h, --help	print this help message\n"
-		"  -v, --version	print version information\n" "\n" "For more help, run \"man turbostat\"\n");
+		"  -h, --help\n"
+		"		print this help message\n"
+		"  -v, --version\n"
+		"		print version information\n" "\n" "For more help, run \"man turbostat\"\n");
 }
 
 /*
Signature · 1 line
2.43.0
author
#5 lore raw

PATCH 4/4 tools/power turbostat: Introduce --force parameter

In reply to Zhang Rui

Turbostat currently exits under the following conditions:
1. When running on non-Intel/AMD/Hygon x86 vendors.
2. When running on Intel models that lack specific platform features.

Introduce a new --force parameter that allows turbostat to run on these unsupported platforms with minimal default feature support. This provides users with the flexibility to gather basic information even on unsupported systems.

---
 tools/power/x86/turbostat/turbostat.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
tools/power/x86/turbostat/turbostat.c +16 -2
index 442a993c5114..123eb9ead7df 100644
@@ -326,6 +326,7 @@ unsigned int rapl_joules;
 unsigned int summary_only;
 unsigned int list_header_only;
 unsigned int dump_only;
+unsigned int force_load;
 unsigned int has_aperf;
 unsigned int has_aperf_access;
 unsigned int has_epb;
@@ -1058,7 +1059,8 @@ void probe_platform_features(unsigned int family, unsigned int model)
 
 
 	if (authentic_amd || hygon_genuine) {
-		platform = &default_features;
+		/* fallback to default features on unsupported models */
+		force_load++;
 		if (max_extended_level >= 0x80000007) {
 			unsigned int eax, ebx, ecx, edx;
 
@@ -1067,7 +1069,7 @@ void probe_platform_features(unsigned int family, unsigned int model)
 			if ((edx & (1 << 14)) && family >= 0x17)
 				platform = &amd_features_with_rapl;
 		}
-		return;
+		goto end;
 	}
 
 	if (!genuine_intel)
@@ -1081,10 +1083,16 @@ void probe_platform_features(unsigned int family, unsigned int model)
 	}
 
 end:
+	if (force_load && !platform) {
+		fprintf(outf, "Unsupported platform detected. Force running with minimum default support.\n");
+		platform = &default_features;
+	}
+
 	if (platform)
 		return;
 
 	fprintf(stderr, "Unsupported platform detected.\n"
+		"\tUse \"--force\" parameter to launch turbostat with minimum default support.\n"
 		"\tTo get latest turbostat support, please contact\n"
 		"\t   [email protected]\n"
 		"\tor pull from\n"
@@ -2163,6 +2171,8 @@ void help(void)
 		"		displays the raw counter values\n"
 		"  -e, --enable [all | column]\n"
 		"		shows all or the specified disabled column\n"
+		"  -f, --force\n"
+		"		force load turbostat with minimum default features on unsupported platforms.\n"
 		"  -H, --hide [column | column,column,...]\n"
 		"		hide the specified column(s)\n"
 		"  -i, --interval sec.subsec\n"
@@ -9945,6 +9955,7 @@ void cmdline(int argc, char **argv)
 		{ "Dump", no_argument, 0, 'D' },
 		{ "debug", no_argument, 0, 'd' },	/* internal, not documented */
 		{ "enable", required_argument, 0, 'e' },
+		{ "force", no_argument, 0, 'f' },
 		{ "interval", required_argument, 0, 'i' },
 		{ "IPC", no_argument, 0, 'I' },
 		{ "num_iterations", required_argument, 0, 'n' },
@@ -10005,6 +10016,9 @@ void cmdline(int argc, char **argv)
 			/* --enable specified counter */
 			bic_enabled = bic_enabled | bic_lookup(optarg, SHOW_LIST);
 			break;
+		case 'f':
+			force_load++;
+			break;
 		case 'd':
 			debug++;
 			ENABLE_BIC(BIC_DISABLED_BY_DEFAULT);
Signature · 1 line
2.43.0