Skip to contentSkip to conversation

tools:misc:xenpm: set max freq to all cpu with default cpuid

PATCH Superseded Luwei Kang 3 participants 4 messages Apr 12, 2017 – Apr 13, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Luwei Kang

author
#0 lore raw

PATCH 1/1 tools:misc:xenpm: set max freq to all cpu with default cpuid

User can set max freq to specific cpu by "xenpm set-scaling-maxfreq <cpuid> <max freq>" or set max freq to all cpu with default cpuid by "xenpm set-scaling-maxfreq <max freq>".

Set max freq with defaule cpuid will cause segmentation fault after commit id d4906b5d05. This patch will fix this issue and add ability to set max freq with default cpuid.

---
 tools/misc/xenpm.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/misc/xenpm.c +4 -2
index ded40b9..abe31b5 100644
@@ -99,8 +99,10 @@ static void parse_cpuid_and_int(int argc, char *argv[],
          exit(EINVAL);
     }
 
-    parse_cpuid(argv[0], cpuid);
-    if ( sscanf(argv[1], "%d", val) != 1 )
+    if ( argc > 1 )
+        parse_cpuid(argv[0], cpuid);
+
+    if ( argc == 0 || sscanf(argv[argc > 1], "%d", val) != 1 )
     {
         fprintf(stderr, "Invalid %s '%s'\n", what, argv[1]);
         exit(EINVAL);
Signature · 7 lines
1.8.3.1


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Luwei Kang

User can set max freq to specific cpu by "xenpm set-scaling-maxfreq <cpuid> <max freq>" or set max freq to all cpu with default cpuid by "xenpm set-scaling-maxfreq <max freq>".

Set max freq with defaule cpuid will cause

default

Quoted 5 lines

segmentation fault after commit id d4906b5d05. This patch will fix this issue and add ability to set max freq with default cpuid.

I think this patch basically restores the code to the correct logic before it was broken by d4906b5d05, so:

CC Julien

Quoted 24 lines
---
 tools/misc/xenpm.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/misc/xenpm.c +4 -2
index ded40b9..abe31b5 100644
@@ -99,8 +99,10 @@ static void parse_cpuid_and_int(int argc, char *argv[],
          exit(EINVAL);
     }
 
-    parse_cpuid(argv[0], cpuid);
-    if ( sscanf(argv[1], "%d", val) != 1 )
+    if ( argc > 1 )
+        parse_cpuid(argv[0], cpuid);
+
+    if ( argc == 0 || sscanf(argv[argc > 1], "%d", val) != 1 )
     {
         fprintf(stderr, "Invalid %s '%s'\n", what, argv[1]);
         exit(EINVAL);
Signature · 1 line
1.8.3.1

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#2 lore raw

Hi Wei,

Quoted 14 lines · Wei Liu
Quoted 6 lines · Luwei Kang

User can set max freq to specific cpu by "xenpm set-scaling-maxfreq <cpuid> <max freq>" or set max freq to all cpu with default cpuid by "xenpm set-scaling-maxfreq <max freq>".

Set max freq with defaule cpuid will cause

default

Quoted 4 lines

segmentation fault after commit id d4906b5d05. This patch will fix this issue and add ability to set max freq with default cpuid.

Quoted 6 lines
Quoted 1 line

I think this patch basically restores the code to the correct logic before it was broken by d4906b5d05, so:

If I am not mistaken, this patch will re-introduce an error with clang build. From the commit message the sscanf was problematic:

xenpm.c:102:23: error: data argument not used by format string
[-Werror,-Wformat-extra-args]

                    what, argv[argc > 1]);
                          ^

So we would break clang build but get a segfault fixed :). I have CCed Roger to confirm.

Cheers,

Quoted 27 lines

CC Julien

Quoted 24 lines
---
 tools/misc/xenpm.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/misc/xenpm.c +4 -3
index ded40b9..abe31b5 100644
@@ -99,8 +99,10 @@ static void parse_cpuid_and_int(int argc, char *argv[],
          exit(EINVAL);
     }
 
-    parse_cpuid(argv[0], cpuid);
-    if ( sscanf(argv[1], "%d", val) != 1 )
+    if ( argc > 1 )
+        parse_cpuid(argv[0], cpuid);
+
+    if ( argc == 0 || sscanf(argv[argc > 1], "%d", val) != 1 )
     {
         fprintf(stderr, "Invalid %s '%s'\n", what, argv[1]);
         exit(EINVAL);
--

1.8.3.1

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#3 lore raw
Quoted 24 lines · Julien Grall

Hi Wei,

Quoted 14 lines · Wei Liu
Quoted 6 lines · Luwei Kang

User can set max freq to specific cpu by "xenpm set-scaling-maxfreq <cpuid> <max freq>" or set max freq to all cpu with default cpuid by "xenpm set-scaling-maxfreq <max freq>".

Set max freq with defaule cpuid will cause

default

Quoted 4 lines

segmentation fault after commit id d4906b5d05. This patch will fix this issue and add ability to set max freq with default cpuid.

Quoted 6 lines
Quoted 1 line

I think this patch basically restores the code to the correct logic before it was broken by d4906b5d05, so:

Quoted 7 lines

If I am not mistaken, this patch will re-introduce an error with clang build. From the commit message the sscanf was problematic:

xenpm.c:102:23: error: data argument not used by format string
[-Werror,-Wformat-extra-args]

                    what, argv[argc > 1]);
                          ^

That a different thing. The error was due to

        fprintf(stderr, argc ? "Invalid %s '%s'\n" : "Missing %s\n",
                what, argv[argc > 1]);

When argc was 0 the format string only contained one %s but two data arguments were provided.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel