Message ID | 20230501193034.88575-13-jandryuk@gmail.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Intel Hardware P-States (HWP) support | expand |
On 01.05.2023 21:30, Jason Andryuk wrote: > Allow cpuid_parse to be re-used without terminating xenpm. HWP will > re-use it to optionally parse a cpuid. Unlike other uses of > cpuid_parse, parse_hwp_opts will take a variable number of arguments and > cannot just check argc. > > Signed-off-by: Jason Andryuk <jandryuk@gmail.com> > --- > v2: > Retained because cpuid_parse handles numeric cpu numbers and "all". Assuming you can convince me of retaining this patch: > --- a/tools/misc/xenpm.c > +++ b/tools/misc/xenpm.c > @@ -79,17 +79,26 @@ void help_func(int argc, char *argv[]) > show_help(); > } > > -static void parse_cpuid(const char *arg, int *cpuid) > +static int parse_cpuid_non_fatal(const char *arg, int *cpuid) > { > if ( sscanf(arg, "%d", cpuid) != 1 || *cpuid < 0 ) > { > if ( strcasecmp(arg, "all") ) > - { > - fprintf(stderr, "Invalid CPU identifier: '%s'\n", arg); > - exit(EINVAL); > - } > + return -1; > + > *cpuid = -1; > } > + > + return 0; > +} Looks like this function wants to return bool? Jan
diff --git a/tools/misc/xenpm.c b/tools/misc/xenpm.c index b2defde0d4..6e74606970 100644 --- a/tools/misc/xenpm.c +++ b/tools/misc/xenpm.c @@ -79,17 +79,26 @@ void help_func(int argc, char *argv[]) show_help(); } -static void parse_cpuid(const char *arg, int *cpuid) +static int parse_cpuid_non_fatal(const char *arg, int *cpuid) { if ( sscanf(arg, "%d", cpuid) != 1 || *cpuid < 0 ) { if ( strcasecmp(arg, "all") ) - { - fprintf(stderr, "Invalid CPU identifier: '%s'\n", arg); - exit(EINVAL); - } + return -1; + *cpuid = -1; } + + return 0; +} + +static void parse_cpuid(const char *arg, int *cpuid) +{ + if ( parse_cpuid_non_fatal(arg, cpuid) ) + { + fprintf(stderr, "Invalid CPU identifier: '%s'\n", arg); + exit(EINVAL); + } } static void parse_cpuid_and_int(int argc, char *argv[],
Allow cpuid_parse to be re-used without terminating xenpm. HWP will re-use it to optionally parse a cpuid. Unlike other uses of cpuid_parse, parse_hwp_opts will take a variable number of arguments and cannot just check argc. Signed-off-by: Jason Andryuk <jandryuk@gmail.com> --- v2: Retained because cpuid_parse handles numeric cpu numbers and "all". --- tools/misc/xenpm.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)