diff options
author | Ian Munsie <imunsie@au.ibm.com> | 2010-04-13 04:37:33 -0400 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2010-04-14 05:26:44 -0400 |
commit | c05556421742eb47f80301767653a4bcb19de9de (patch) | |
tree | 1e9c441a457acee41d2585e05692cc90c1d88be2 /tools/perf/util | |
parent | 53e5b5c215ce8372250e227f2c9acf9892de8434 (diff) |
perf: Fix endianness argument compatibility with OPT_BOOLEAN() and introduce OPT_INCR()
Parsing an option from the command line with OPT_BOOLEAN on a
bool data type would not work on a big-endian machine due to the
manner in which the boolean was being cast into an int and
incremented. For example, running 'perf probe --list' on a
PowerPC machine would fail to properly set the list_events bool
and would therefore print out the usage information and
terminate.
This patch makes OPT_BOOLEAN work as expected with a bool
datatype. For cases where the original OPT_BOOLEAN was
intentionally being used to increment an int each time it was
passed in on the command line, this patch introduces OPT_INCR
with the old behaviour of OPT_BOOLEAN (the verbose variable is
currently the only such example of this).
I have reviewed every use of OPT_BOOLEAN to verify that a true
C99 bool was passed. Where integers were used, I verified that
they were only being used for boolean logic and changed them to
bools to ensure that they would not be mistakenly used as ints.
The major exception was the verbose variable which now uses
OPT_INCR instead of OPT_BOOLEAN.
Signed-off-by: Ian Munsie <imunsie@au.ibm.com>
Acked-by: David S. Miller <davem@davemloft.net>
Cc: <stable@kernel.org> # NOTE: wont apply to .3[34].x cleanly, please backport
Cc: Git development list <git@vger.kernel.org>
Cc: Ian Munsie <imunsie@au1.ibm.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
Cc: Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Eric B Munson <ebmunson@us.ibm.com>
Cc: Valdis.Kletnieks@vt.edu
Cc: WANG Cong <amwang@redhat.com>
Cc: Thiago Farina <tfransosi@gmail.com>
Cc: Masami Hiramatsu <mhiramat@redhat.com>
Cc: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Cc: Jaswinder Singh Rajput <jaswinderrajput@gmail.com>
Cc: Arjan van de Ven <arjan@linux.intel.com>
Cc: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Tom Zanussi <tzanussi@gmail.com>
Cc: Anton Blanchard <anton@samba.org>
Cc: John Kacur <jkacur@redhat.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <1271147857-11604-1-git-send-email-imunsie@au.ibm.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'tools/perf/util')
-rw-r--r-- | tools/perf/util/debug.c | 2 | ||||
-rw-r--r-- | tools/perf/util/debug.h | 3 | ||||
-rw-r--r-- | tools/perf/util/parse-options.c | 6 | ||||
-rw-r--r-- | tools/perf/util/parse-options.h | 4 | ||||
-rw-r--r-- | tools/perf/util/trace-event-parse.c | 2 | ||||
-rw-r--r-- | tools/perf/util/trace-event.h | 3 |
6 files changed, 15 insertions, 5 deletions
diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c index 033d66db863a..dd824cf3b628 100644 --- a/tools/perf/util/debug.c +++ b/tools/perf/util/debug.c | |||
@@ -13,7 +13,7 @@ | |||
13 | #include "util.h" | 13 | #include "util.h" |
14 | 14 | ||
15 | int verbose = 0; | 15 | int verbose = 0; |
16 | int dump_trace = 0; | 16 | bool dump_trace = false; |
17 | 17 | ||
18 | int eprintf(int level, const char *fmt, ...) | 18 | int eprintf(int level, const char *fmt, ...) |
19 | { | 19 | { |
diff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h index 5cb0a1b1401a..047ac3324ebe 100644 --- a/tools/perf/util/debug.h +++ b/tools/perf/util/debug.h | |||
@@ -2,10 +2,11 @@ | |||
2 | #ifndef __PERF_DEBUG_H | 2 | #ifndef __PERF_DEBUG_H |
3 | #define __PERF_DEBUG_H | 3 | #define __PERF_DEBUG_H |
4 | 4 | ||
5 | #include <stdbool.h> | ||
5 | #include "event.h" | 6 | #include "event.h" |
6 | 7 | ||
7 | extern int verbose; | 8 | extern int verbose; |
8 | extern int dump_trace; | 9 | extern bool dump_trace; |
9 | 10 | ||
10 | int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2))); | 11 | int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2))); |
11 | void trace_event(event_t *event); | 12 | void trace_event(event_t *event); |
diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c index 79dfa0c34b3c..ed887642460c 100644 --- a/tools/perf/util/parse-options.c +++ b/tools/perf/util/parse-options.c | |||
@@ -49,6 +49,7 @@ static int get_value(struct parse_opt_ctx_t *p, | |||
49 | break; | 49 | break; |
50 | /* FALLTHROUGH */ | 50 | /* FALLTHROUGH */ |
51 | case OPTION_BOOLEAN: | 51 | case OPTION_BOOLEAN: |
52 | case OPTION_INCR: | ||
52 | case OPTION_BIT: | 53 | case OPTION_BIT: |
53 | case OPTION_SET_INT: | 54 | case OPTION_SET_INT: |
54 | case OPTION_SET_PTR: | 55 | case OPTION_SET_PTR: |
@@ -73,6 +74,10 @@ static int get_value(struct parse_opt_ctx_t *p, | |||
73 | return 0; | 74 | return 0; |
74 | 75 | ||
75 | case OPTION_BOOLEAN: | 76 | case OPTION_BOOLEAN: |
77 | *(bool *)opt->value = unset ? false : true; | ||
78 | return 0; | ||
79 | |||
80 | case OPTION_INCR: | ||
76 | *(int *)opt->value = unset ? 0 : *(int *)opt->value + 1; | 81 | *(int *)opt->value = unset ? 0 : *(int *)opt->value + 1; |
77 | return 0; | 82 | return 0; |
78 | 83 | ||
@@ -478,6 +483,7 @@ int usage_with_options_internal(const char * const *usagestr, | |||
478 | case OPTION_GROUP: | 483 | case OPTION_GROUP: |
479 | case OPTION_BIT: | 484 | case OPTION_BIT: |
480 | case OPTION_BOOLEAN: | 485 | case OPTION_BOOLEAN: |
486 | case OPTION_INCR: | ||
481 | case OPTION_SET_INT: | 487 | case OPTION_SET_INT: |
482 | case OPTION_SET_PTR: | 488 | case OPTION_SET_PTR: |
483 | case OPTION_LONG: | 489 | case OPTION_LONG: |
diff --git a/tools/perf/util/parse-options.h b/tools/perf/util/parse-options.h index 948805af43c2..b2da725f102a 100644 --- a/tools/perf/util/parse-options.h +++ b/tools/perf/util/parse-options.h | |||
@@ -8,7 +8,8 @@ enum parse_opt_type { | |||
8 | OPTION_GROUP, | 8 | OPTION_GROUP, |
9 | /* options with no arguments */ | 9 | /* options with no arguments */ |
10 | OPTION_BIT, | 10 | OPTION_BIT, |
11 | OPTION_BOOLEAN, /* _INCR would have been a better name */ | 11 | OPTION_BOOLEAN, |
12 | OPTION_INCR, | ||
12 | OPTION_SET_INT, | 13 | OPTION_SET_INT, |
13 | OPTION_SET_PTR, | 14 | OPTION_SET_PTR, |
14 | /* options with arguments (usually) */ | 15 | /* options with arguments (usually) */ |
@@ -95,6 +96,7 @@ struct option { | |||
95 | #define OPT_GROUP(h) { .type = OPTION_GROUP, .help = (h) } | 96 | #define OPT_GROUP(h) { .type = OPTION_GROUP, .help = (h) } |
96 | #define OPT_BIT(s, l, v, h, b) { .type = OPTION_BIT, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (b) } | 97 | #define OPT_BIT(s, l, v, h, b) { .type = OPTION_BIT, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (b) } |
97 | #define OPT_BOOLEAN(s, l, v, h) { .type = OPTION_BOOLEAN, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } | 98 | #define OPT_BOOLEAN(s, l, v, h) { .type = OPTION_BOOLEAN, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } |
99 | #define OPT_INCR(s, l, v, h) { .type = OPTION_INCR, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } | ||
98 | #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) } | 100 | #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) } |
99 | #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) } | 101 | #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) } |
100 | #define OPT_INTEGER(s, l, v, h) { .type = OPTION_INTEGER, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } | 102 | #define OPT_INTEGER(s, l, v, h) { .type = OPTION_INTEGER, .short_name = (s), .long_name = (l), .value = (v), .help = (h) } |
diff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c index 3b81250ffedb..17d6d66ed766 100644 --- a/tools/perf/util/trace-event-parse.c +++ b/tools/perf/util/trace-event-parse.c | |||
@@ -42,7 +42,7 @@ int header_page_overwrite_size; | |||
42 | int header_page_data_offset; | 42 | int header_page_data_offset; |
43 | int header_page_data_size; | 43 | int header_page_data_size; |
44 | 44 | ||
45 | int latency_format; | 45 | bool latency_format; |
46 | 46 | ||
47 | static char *input_buf; | 47 | static char *input_buf; |
48 | static unsigned long long input_buf_ptr; | 48 | static unsigned long long input_buf_ptr; |
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h index c3269b937db4..81f2fd20a0ea 100644 --- a/tools/perf/util/trace-event.h +++ b/tools/perf/util/trace-event.h | |||
@@ -1,6 +1,7 @@ | |||
1 | #ifndef __PERF_TRACE_EVENTS_H | 1 | #ifndef __PERF_TRACE_EVENTS_H |
2 | #define __PERF_TRACE_EVENTS_H | 2 | #define __PERF_TRACE_EVENTS_H |
3 | 3 | ||
4 | #include <stdbool.h> | ||
4 | #include "parse-events.h" | 5 | #include "parse-events.h" |
5 | 6 | ||
6 | #define __unused __attribute__((unused)) | 7 | #define __unused __attribute__((unused)) |
@@ -241,7 +242,7 @@ extern int header_page_size_size; | |||
241 | extern int header_page_data_offset; | 242 | extern int header_page_data_offset; |
242 | extern int header_page_data_size; | 243 | extern int header_page_data_size; |
243 | 244 | ||
244 | extern int latency_format; | 245 | extern bool latency_format; |
245 | 246 | ||
246 | int parse_header_page(char *buf, unsigned long size); | 247 | int parse_header_page(char *buf, unsigned long size); |
247 | int trace_parse_common_type(void *data); | 248 | int trace_parse_common_type(void *data); |