Skip to contentSkip to conversation

tools/power turbostat: make the '-n' command line argument work in all cases

PATCH In review David Arcari 1 participant 2 messages May 20, 2024 – Jun 4, 2024 Turbostat utility

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/power turbostat: make the '-n' command line argument work in all cases

In some cases specifying the '-n' command line argument will cause turbostat to fail. For instance 'turbostat -n 1' works fine; however, 'turbostat -n 1 -d' will fail. This is the result of the first call to getopt_long_only() where "MP" is specified as the optstring. This can be easily fixed by changing the optstring from "MP" to "MPn:" to remove ambiguity between the arguments.

---
 tools/power/x86/turbostat/turbostat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/power/x86/turbostat/turbostat.c +1 -1
index 98256468e248..8071a3ef2a2e 100644
@@ -7851,7 +7851,7 @@ void cmdline(int argc, char **argv)
 	 * Parse some options early, because they may make other options invalid,
 	 * like adding the MSR counter with --add and at the same time using --no-msr.
 	 */
-	while ((opt = getopt_long_only(argc, argv, "MP", long_options, &option_index)) != -1) {
+	while ((opt = getopt_long_only(argc, argv, "MPn:", long_options, &option_index)) != -1) {
 		switch (opt) {
 		case 'M':
 			no_msr = 1;
Signature · 1 line
2.44.0
#1 lore raw

Hi,

Quoted 10 lines · David Arcari

In some cases specifying the '-n' command line argument will cause turbostat to fail. For instance 'turbostat -n 1' works fine; however, 'turbostat -n 1 -d' will fail. This is the result of the first call to getopt_long_only() where "MP" is specified as the optstring. This can be easily fixed by changing the optstring from "MP" to "MPn:" to remove ambiguity between the arguments.

Is there a problem with this commit? I don't believe it has been merged or otherwise replied to.

Thanks,
-DA

Quoted 17 lines
---
  tools/power/x86/turbostat/turbostat.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
tools/power/x86/turbostat/turbostat.c +1 -1
index 98256468e248..8071a3ef2a2e 100644
@@ -7851,7 +7851,7 @@ void cmdline(int argc, char **argv)
  	 * Parse some options early, because they may make other options invalid,
  	 * like adding the MSR counter with --add and at the same time using --no-msr.
  	 */
-	while ((opt = getopt_long_only(argc, argv, "MP", long_options, &option_index)) != -1) {
+	while ((opt = getopt_long_only(argc, argv, "MPn:", long_options, &option_index)) != -1) {
  		switch (opt) {
  		case 'M':
  			no_msr = 1;