Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf options: Check v type in OPT_U?INTEGER

To avoid problems like the one fixed by Stephane Eranian in 3de29ca, now
we'll got this instead:

bench/sched-messaging.c:259: error: negative width in bit-field ‘<anonymous>’
bench/sched-messaging.c:261: error: negative width in bit-field ‘<anonymous>’

Which is rather cryptic, but is how BUILD_BUG_ON_ZERO works, so kernel
hackers should be already used to this.

With it in place found some problems, fixed by changing the affected
variables to sensible types or changed some OPT_INTEGER to OPT_UINTEGER.

Next csets will go thru converting each of the remaining OPT_ so that
review can be made easier by grouping changes per type per patch.

Cc: Frédéric Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

+18 -17
+2 -4
tools/perf/bench/sched-messaging.c
··· 256 256 "Use pipe() instead of socketpair()"), 257 257 OPT_BOOLEAN('t', "thread", &thread_mode, 258 258 "Be multi thread instead of multi process"), 259 - OPT_INTEGER('g', "group", &num_groups, 260 - "Specify number of groups"), 261 - OPT_INTEGER('l', "loop", &loops, 262 - "Specify number of loops"), 259 + OPT_UINTEGER('g', "group", &num_groups, "Specify number of groups"), 260 + OPT_UINTEGER('l', "loop", &loops, "Specify number of loops"), 263 261 OPT_END() 264 262 }; 265 263
+3 -5
tools/perf/builtin-record.c
··· 45 45 static int pipe_output = 0; 46 46 static const char *output_name = "perf.data"; 47 47 static int group = 0; 48 - static unsigned int realtime_prio = 0; 48 + static int realtime_prio = 0; 49 49 static bool raw_samples = false; 50 50 static bool system_wide = false; 51 51 static int profile_cpu = -1; ··· 822 822 "output file name"), 823 823 OPT_BOOLEAN('i', "no-inherit", &no_inherit, 824 824 "child tasks do not inherit counters"), 825 - OPT_INTEGER('F', "freq", &user_freq, 826 - "profile at this frequency"), 827 - OPT_INTEGER('m', "mmap-pages", &mmap_pages, 828 - "number of mmap data pages"), 825 + OPT_UINTEGER('F', "freq", &user_freq, "profile at this frequency"), 826 + OPT_UINTEGER('m', "mmap-pages", &mmap_pages, "number of mmap data pages"), 829 827 OPT_BOOLEAN('g', "call-graph", &call_graph, 830 828 "do call-graph (stack chain/backtrace) recording"), 831 829 OPT_INCR('v', "verbose", &verbose,
+3 -3
tools/perf/builtin-sched.c
··· 105 105 static u64 sum_fluct; 106 106 static u64 run_avg; 107 107 108 - static unsigned long replay_repeat = 10; 108 + static unsigned int replay_repeat = 10; 109 109 static unsigned long nr_timestamps; 110 110 static unsigned long nr_unordered_timestamps; 111 111 static unsigned long nr_state_machine_bugs; ··· 1816 1816 }; 1817 1817 1818 1818 static const struct option replay_options[] = { 1819 - OPT_INTEGER('r', "repeat", &replay_repeat, 1820 - "repeat the workload replay N times (-1: infinite)"), 1819 + OPT_UINTEGER('r', "repeat", &replay_repeat, 1820 + "repeat the workload replay N times (-1: infinite)"), 1821 1821 OPT_INCR('v', "verbose", &verbose, 1822 1822 "be more verbose (show symbol address, etc)"), 1823 1823 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
+2 -3
tools/perf/builtin-top.c
··· 71 71 static bool inherit = false; 72 72 static int profile_cpu = -1; 73 73 static int nr_cpus = 0; 74 - static unsigned int realtime_prio = 0; 74 + static int realtime_prio = 0; 75 75 static bool group = false; 76 76 static unsigned int page_size; 77 77 static unsigned int mmap_pages = 16; ··· 1357 1357 "file", "vmlinux pathname"), 1358 1358 OPT_BOOLEAN('K', "hide_kernel_symbols", &hide_kernel_symbols, 1359 1359 "hide kernel symbols"), 1360 - OPT_INTEGER('m', "mmap-pages", &mmap_pages, 1361 - "number of mmap data pages"), 1360 + OPT_UINTEGER('m', "mmap-pages", &mmap_pages, "number of mmap data pages"), 1362 1361 OPT_INTEGER('r', "realtime", &realtime_prio, 1363 1362 "collect data with this RT SCHED_FIFO priority"), 1364 1363 OPT_INTEGER('d', "delay", &delay_secs,
+2
tools/perf/util/include/linux/kernel.h
··· 28 28 (type *)((char *)__mptr - offsetof(type, member)); }) 29 29 #endif 30 30 31 + #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); })) 32 + 31 33 #ifndef max 32 34 #define max(x, y) ({ \ 33 35 typeof(x) _max1 = (x); \
+6 -2
tools/perf/util/parse-options.h
··· 1 1 #ifndef __PERF_PARSE_OPTIONS_H 2 2 #define __PERF_PARSE_OPTIONS_H 3 3 4 + #include <linux/kernel.h> 5 + 4 6 enum parse_opt_type { 5 7 /* special types */ 6 8 OPTION_END, ··· 95 93 intptr_t defval; 96 94 }; 97 95 96 + #define check_vtype(v, type) ( BUILD_BUG_ON_ZERO(!__builtin_types_compatible_p(typeof(v), type)) + v ) 97 + 98 98 #define OPT_END() { .type = OPTION_END } 99 99 #define OPT_ARGUMENT(l, h) { .type = OPTION_ARGUMENT, .long_name = (l), .help = (h) } 100 100 #define OPT_GROUP(h) { .type = OPTION_GROUP, .help = (h) } ··· 105 101 #define OPT_INCR(s, l, v, h) { .type = OPTION_INCR, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } 106 102 #define OPT_SET_INT(s, l, v, h, i) { .type = OPTION_SET_INT, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (i) } 107 103 #define OPT_SET_PTR(s, l, v, h, p) { .type = OPTION_SET_PTR, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (p) } 108 - #define OPT_INTEGER(s, l, v, h) { .type = OPTION_INTEGER, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } 109 - #define OPT_UINTEGER(s, l, v, h) { .type = OPTION_UINTEGER, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } 104 + #define OPT_INTEGER(s, l, v, h) { .type = OPTION_INTEGER, .short_name = (s), .long_name = (l), .value = check_vtype(v, int *), .help = (h) } 105 + #define OPT_UINTEGER(s, l, v, h) { .type = OPTION_UINTEGER, .short_name = (s), .long_name = (l), .value = check_vtype(v, unsigned int *), .help = (h) } 110 106 #define OPT_LONG(s, l, v, h) { .type = OPTION_LONG, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } 111 107 #define OPT_U64(s, l, v, h) { .type = OPTION_U64, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } 112 108 #define OPT_STRING(s, l, v, a, h) { .type = OPTION_STRING, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h) }