]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob
dd13d25c3696605767f9da09715254c8b2f212ea
[thirdparty/kernel/stable-queue.git] /
1 From c05556421742eb47f80301767653a4bcb19de9de Mon Sep 17 00:00:00 2001
2 From: Ian Munsie <imunsie@au.ibm.com>
3 Date: Tue, 13 Apr 2010 18:37:33 +1000
4 Subject: perf: Fix endianness argument compatibility with OPT_BOOLEAN() and introduce OPT_INCR()
5
6 From: Ian Munsie <imunsie@au.ibm.com>
7
8 commit c05556421742eb47f80301767653a4bcb19de9de upstream.
9
10 Parsing an option from the command line with OPT_BOOLEAN on a
11 bool data type would not work on a big-endian machine due to the
12 manner in which the boolean was being cast into an int and
13 incremented. For example, running 'perf probe --list' on a
14 PowerPC machine would fail to properly set the list_events bool
15 and would therefore print out the usage information and
16 terminate.
17
18 This patch makes OPT_BOOLEAN work as expected with a bool
19 datatype. For cases where the original OPT_BOOLEAN was
20 intentionally being used to increment an int each time it was
21 passed in on the command line, this patch introduces OPT_INCR
22 with the old behaviour of OPT_BOOLEAN (the verbose variable is
23 currently the only such example of this).
24
25 I have reviewed every use of OPT_BOOLEAN to verify that a true
26 C99 bool was passed. Where integers were used, I verified that
27 they were only being used for boolean logic and changed them to
28 bools to ensure that they would not be mistakenly used as ints.
29 The major exception was the verbose variable which now uses
30 OPT_INCR instead of OPT_BOOLEAN.
31
32 Signed-off-by: Ian Munsie <imunsie@au.ibm.com>
33 Acked-by: David S. Miller <davem@davemloft.net>
34 Cc: <stable@kernel.org> # NOTE: wont apply to .3[34].x cleanly, please backport
35 Cc: Git development list <git@vger.kernel.org>
36 Cc: Ian Munsie <imunsie@au1.ibm.com>
37 Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
38 Cc: Paul Mackerras <paulus@samba.org>
39 Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
40 Cc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
41 Cc: Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
42 Cc: Rusty Russell <rusty@rustcorp.com.au>
43 Cc: Frederic Weisbecker <fweisbec@gmail.com>
44 Cc: Eric B Munson <ebmunson@us.ibm.com>
45 Cc: Valdis.Kletnieks@vt.edu
46 Cc: WANG Cong <amwang@redhat.com>
47 Cc: Thiago Farina <tfransosi@gmail.com>
48 Cc: Masami Hiramatsu <mhiramat@redhat.com>
49 Cc: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
50 Cc: Jaswinder Singh Rajput <jaswinderrajput@gmail.com>
51 Cc: Arjan van de Ven <arjan@linux.intel.com>
52 Cc: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>
53 Cc: Mike Galbraith <efault@gmx.de>
54 Cc: Tom Zanussi <tzanussi@gmail.com>
55 Cc: Anton Blanchard <anton@samba.org>
56 Cc: John Kacur <jkacur@redhat.com>
57 Cc: Li Zefan <lizf@cn.fujitsu.com>
58 Cc: Steven Rostedt <rostedt@goodmis.org>
59 LKML-Reference: <1271147857-11604-1-git-send-email-imunsie@au.ibm.com>
60 Signed-off-by: Ingo Molnar <mingo@elte.hu>
61 Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
62
63 ---
64 tools/perf/bench/mem-memcpy.c | 2 +-
65 tools/perf/bench/sched-messaging.c | 4 ++--
66 tools/perf/builtin-annotate.c | 8 ++++----
67 tools/perf/builtin-buildid-cache.c | 2 +-
68 tools/perf/builtin-buildid-list.c | 4 ++--
69 tools/perf/builtin-diff.c | 4 ++--
70 tools/perf/builtin-help.c | 2 +-
71 tools/perf/builtin-lock.c | 2 +-
72 tools/perf/builtin-probe.c | 2 +-
73 tools/perf/builtin-record.c | 24 ++++++++++++------------
74 tools/perf/builtin-report.c | 6 +++---
75 tools/perf/builtin-sched.c | 6 +++---
76 tools/perf/builtin-stat.c | 10 +++++-----
77 tools/perf/builtin-timechart.c | 2 +-
78 tools/perf/builtin-top.c | 14 +++++++-------
79 tools/perf/builtin-trace.c | 2 +-
80 tools/perf/util/debug.c | 2 +-
81 tools/perf/util/debug.h | 3 ++-
82 tools/perf/util/parse-options.c | 6 ++++++
83 tools/perf/util/parse-options.h | 4 +++-
84 tools/perf/util/trace-event-parse.c | 2 +-
85 tools/perf/util/trace-event.h | 3 ++-
86 22 files changed, 62 insertions(+), 52 deletions(-)
87
88 --- a/tools/perf/bench/mem-memcpy.c
89 +++ b/tools/perf/bench/mem-memcpy.c
90 @@ -24,7 +24,7 @@
91
92 static const char *length_str = "1MB";
93 static const char *routine = "default";
94 -static int use_clock = 0;
95 +static bool use_clock = false;
96 static int clock_fd;
97
98 static const struct option options[] = {
99 --- a/tools/perf/bench/sched-messaging.c
100 +++ b/tools/perf/bench/sched-messaging.c
101 @@ -31,9 +31,9 @@
102
103 #define DATASIZE 100
104
105 -static int use_pipes = 0;
106 +static bool use_pipes = false;
107 static unsigned int loops = 100;
108 -static unsigned int thread_mode = 0;
109 +static bool thread_mode = false;
110 static unsigned int num_groups = 10;
111
112 struct sender_context {
113 --- a/tools/perf/builtin-annotate.c
114 +++ b/tools/perf/builtin-annotate.c
115 @@ -29,11 +29,11 @@
116
117 static char const *input_name = "perf.data";
118
119 -static int force;
120 +static bool force;
121
122 -static int full_paths;
123 +static bool full_paths;
124
125 -static int print_line;
126 +static bool print_line;
127
128 struct sym_hist {
129 u64 sum;
130 @@ -584,7 +584,7 @@ static const struct option options[] = {
131 OPT_STRING('s', "symbol", &sym_hist_filter, "symbol",
132 "symbol to annotate"),
133 OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
134 - OPT_BOOLEAN('v', "verbose", &verbose,
135 + OPT_INCR('v', "verbose", &verbose,
136 "be more verbose (show symbol address, etc)"),
137 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
138 "dump raw trace in ASCII"),
139 --- a/tools/perf/builtin-buildid-cache.c
140 +++ b/tools/perf/builtin-buildid-cache.c
141 @@ -27,7 +27,7 @@ static const struct option buildid_cache
142 "file list", "file(s) to add"),
143 OPT_STRING('r', "remove", &remove_name_list_str, "file list",
144 "file(s) to remove"),
145 - OPT_BOOLEAN('v', "verbose", &verbose, "be more verbose"),
146 + OPT_INCR('v', "verbose", &verbose, "be more verbose"),
147 OPT_END()
148 };
149
150 --- a/tools/perf/builtin-buildid-list.c
151 +++ b/tools/perf/builtin-buildid-list.c
152 @@ -16,7 +16,7 @@
153 #include "util/symbol.h"
154
155 static char const *input_name = "perf.data";
156 -static int force;
157 +static bool force;
158 static bool with_hits;
159
160 static const char * const buildid_list_usage[] = {
161 @@ -29,7 +29,7 @@ static const struct option options[] = {
162 OPT_STRING('i', "input", &input_name, "file",
163 "input file name"),
164 OPT_BOOLEAN('f', "force", &force, "don't complain, do it"),
165 - OPT_BOOLEAN('v', "verbose", &verbose,
166 + OPT_INCR('v', "verbose", &verbose,
167 "be more verbose"),
168 OPT_END()
169 };
170 --- a/tools/perf/builtin-diff.c
171 +++ b/tools/perf/builtin-diff.c
172 @@ -19,7 +19,7 @@
173 static char const *input_old = "perf.data.old",
174 *input_new = "perf.data";
175 static char diff__default_sort_order[] = "dso,symbol";
176 -static int force;
177 +static bool force;
178 static bool show_displacement;
179
180 static int perf_session__add_hist_entry(struct perf_session *self,
181 @@ -188,7 +188,7 @@ static const char * const diff_usage[] =
182 };
183
184 static const struct option options[] = {
185 - OPT_BOOLEAN('v', "verbose", &verbose,
186 + OPT_INCR('v', "verbose", &verbose,
187 "be more verbose (show symbol address, etc)"),
188 OPT_BOOLEAN('m', "displacement", &show_displacement,
189 "Show position displacement relative to baseline"),
190 --- a/tools/perf/builtin-help.c
191 +++ b/tools/perf/builtin-help.c
192 @@ -29,7 +29,7 @@ enum help_format {
193 HELP_FORMAT_WEB,
194 };
195
196 -static int show_all = 0;
197 +static bool show_all = false;
198 static enum help_format help_format = HELP_FORMAT_MAN;
199 static struct option builtin_help_options[] = {
200 OPT_BOOLEAN('a', "all", &show_all, "print all available commands"),
201 --- a/tools/perf/builtin-lock.c
202 +++ b/tools/perf/builtin-lock.c
203 @@ -744,7 +744,7 @@ static const char * const lock_usage[] =
204
205 static const struct option lock_options[] = {
206 OPT_STRING('i', "input", &input_name, "file", "input file name"),
207 - OPT_BOOLEAN('v', "verbose", &verbose, "be more verbose (show symbol address, etc)"),
208 + OPT_INCR('v', "verbose", &verbose, "be more verbose (show symbol address, etc)"),
209 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace, "dump raw trace in ASCII"),
210 OPT_END()
211 };
212 --- a/tools/perf/builtin-probe.c
213 +++ b/tools/perf/builtin-probe.c
214 @@ -162,7 +162,7 @@ static const char * const probe_usage[]
215 };
216
217 static const struct option options[] = {
218 - OPT_BOOLEAN('v', "verbose", &verbose,
219 + OPT_INCR('v', "verbose", &verbose,
220 "be more verbose (show parsed arguments, etc)"),
221 #ifndef NO_DWARF_SUPPORT
222 OPT_STRING('k', "vmlinux", &symbol_conf.vmlinux_name,
223 --- a/tools/perf/builtin-record.c
224 +++ b/tools/perf/builtin-record.c
225 @@ -39,19 +39,19 @@ static int output;
226 static const char *output_name = "perf.data";
227 static int group = 0;
228 static unsigned int realtime_prio = 0;
229 -static int raw_samples = 0;
230 -static int system_wide = 0;
231 +static bool raw_samples = false;
232 +static bool system_wide = false;
233 static int profile_cpu = -1;
234 static pid_t target_pid = -1;
235 static pid_t child_pid = -1;
236 -static int inherit = 1;
237 -static int force = 0;
238 -static int append_file = 0;
239 -static int call_graph = 0;
240 -static int inherit_stat = 0;
241 -static int no_samples = 0;
242 -static int sample_address = 0;
243 -static int multiplex = 0;
244 +static bool inherit = true;
245 +static bool force = false;
246 +static bool append_file = false;
247 +static bool call_graph = false;
248 +static bool inherit_stat = false;
249 +static bool no_samples = false;
250 +static bool sample_address = false;
251 +static bool multiplex = false;
252 static int multiplex_fd = -1;
253
254 static long samples = 0;
255 @@ -451,7 +451,7 @@ static int __cmd_record(int argc, const
256 rename(output_name, oldname);
257 }
258 } else {
259 - append_file = 0;
260 + append_file = false;
261 }
262
263 flags = O_CREAT|O_RDWR;
264 @@ -676,7 +676,7 @@ static const struct option options[] = {
265 "number of mmap data pages"),
266 OPT_BOOLEAN('g', "call-graph", &call_graph,
267 "do call-graph (stack chain/backtrace) recording"),
268 - OPT_BOOLEAN('v', "verbose", &verbose,
269 + OPT_INCR('v', "verbose", &verbose,
270 "be more verbose (show counter open errors, etc)"),
271 OPT_BOOLEAN('s', "stat", &inherit_stat,
272 "per thread counts"),
273 --- a/tools/perf/builtin-report.c
274 +++ b/tools/perf/builtin-report.c
275 @@ -33,11 +33,11 @@
276
277 static char const *input_name = "perf.data";
278
279 -static int force;
280 +static bool force;
281 static bool hide_unresolved;
282 static bool dont_use_callchains;
283
284 -static int show_threads;
285 +static bool show_threads;
286 static struct perf_read_values show_threads_values;
287
288 static char default_pretty_printing_style[] = "normal";
289 @@ -400,7 +400,7 @@ static const char * const report_usage[]
290 static const struct option options[] = {
291 OPT_STRING('i', "input", &input_name, "file",
292 "input file name"),
293 - OPT_BOOLEAN('v', "verbose", &verbose,
294 + OPT_INCR('v', "verbose", &verbose,
295 "be more verbose (show symbol address, etc)"),
296 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
297 "dump raw trace in ASCII"),
298 --- a/tools/perf/builtin-sched.c
299 +++ b/tools/perf/builtin-sched.c
300 @@ -1790,7 +1790,7 @@ static const char * const sched_usage[]
301 static const struct option sched_options[] = {
302 OPT_STRING('i', "input", &input_name, "file",
303 "input file name"),
304 - OPT_BOOLEAN('v', "verbose", &verbose,
305 + OPT_INCR('v', "verbose", &verbose,
306 "be more verbose (show symbol address, etc)"),
307 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
308 "dump raw trace in ASCII"),
309 @@ -1805,7 +1805,7 @@ static const char * const latency_usage[
310 static const struct option latency_options[] = {
311 OPT_STRING('s', "sort", &sort_order, "key[,key2...]",
312 "sort by key(s): runtime, switch, avg, max"),
313 - OPT_BOOLEAN('v', "verbose", &verbose,
314 + OPT_INCR('v', "verbose", &verbose,
315 "be more verbose (show symbol address, etc)"),
316 OPT_INTEGER('C', "CPU", &profile_cpu,
317 "CPU to profile on"),
318 @@ -1822,7 +1822,7 @@ static const char * const replay_usage[]
319 static const struct option replay_options[] = {
320 OPT_INTEGER('r', "repeat", &replay_repeat,
321 "repeat the workload replay N times (-1: infinite)"),
322 - OPT_BOOLEAN('v', "verbose", &verbose,
323 + OPT_INCR('v', "verbose", &verbose,
324 "be more verbose (show symbol address, etc)"),
325 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
326 "dump raw trace in ASCII"),
327 --- a/tools/perf/builtin-stat.c
328 +++ b/tools/perf/builtin-stat.c
329 @@ -66,16 +66,16 @@ static struct perf_event_attr default_at
330
331 };
332
333 -static int system_wide = 0;
334 +static bool system_wide = false;
335 static unsigned int nr_cpus = 0;
336 static int run_idx = 0;
337
338 static int run_count = 1;
339 -static int inherit = 1;
340 -static int scale = 1;
341 +static bool inherit = true;
342 +static bool scale = true;
343 static pid_t target_pid = -1;
344 static pid_t child_pid = -1;
345 -static int null_run = 0;
346 +static bool null_run = false;
347
348 static int fd[MAX_NR_CPUS][MAX_COUNTERS];
349
350 @@ -494,7 +494,7 @@ static const struct option options[] = {
351 "system-wide collection from all CPUs"),
352 OPT_BOOLEAN('c', "scale", &scale,
353 "scale/normalize counters"),
354 - OPT_BOOLEAN('v', "verbose", &verbose,
355 + OPT_INCR('v', "verbose", &verbose,
356 "be more verbose (show counter open errors, etc)"),
357 OPT_INTEGER('r', "repeat", &run_count,
358 "repeat command and print average + stddev (max: 100)"),
359 --- a/tools/perf/builtin-timechart.c
360 +++ b/tools/perf/builtin-timechart.c
361 @@ -43,7 +43,7 @@ static u64 turbo_frequency;
362
363 static u64 first_time, last_time;
364
365 -static int power_only;
366 +static bool power_only;
367
368
369 struct per_pid;
370 --- a/tools/perf/builtin-top.c
371 +++ b/tools/perf/builtin-top.c
372 @@ -57,7 +57,7 @@
373
374 static int fd[MAX_NR_CPUS][MAX_COUNTERS];
375
376 -static int system_wide = 0;
377 +static bool system_wide = false;
378
379 static int default_interval = 0;
380
381 @@ -65,18 +65,18 @@ static int count_filter = 5;
382 static int print_entries;
383
384 static int target_pid = -1;
385 -static int inherit = 0;
386 +static bool inherit = false;
387 static int profile_cpu = -1;
388 static int nr_cpus = 0;
389 static unsigned int realtime_prio = 0;
390 -static int group = 0;
391 +static bool group = false;
392 static unsigned int page_size;
393 static unsigned int mmap_pages = 16;
394 static int freq = 1000; /* 1 KHz */
395
396 static int delay_secs = 2;
397 -static int zero = 0;
398 -static int dump_symtab = 0;
399 +static bool zero = false;
400 +static bool dump_symtab = false;
401
402 static bool hide_kernel_symbols = false;
403 static bool hide_user_symbols = false;
404 @@ -839,7 +839,7 @@ static void handle_keypress(int c)
405 display_weighted = ~display_weighted;
406 break;
407 case 'z':
408 - zero = ~zero;
409 + zero = !zero;
410 break;
411 default:
412 break;
413 @@ -1296,7 +1296,7 @@ static const struct option options[] = {
414 "display this many functions"),
415 OPT_BOOLEAN('U', "hide_user_symbols", &hide_user_symbols,
416 "hide user symbols"),
417 - OPT_BOOLEAN('v', "verbose", &verbose,
418 + OPT_INCR('v', "verbose", &verbose,
419 "be more verbose (show counter open errors, etc)"),
420 OPT_END()
421 };
422 --- a/tools/perf/builtin-trace.c
423 +++ b/tools/perf/builtin-trace.c
424 @@ -505,7 +505,7 @@ static const char * const trace_usage[]
425 static const struct option options[] = {
426 OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
427 "dump raw trace in ASCII"),
428 - OPT_BOOLEAN('v', "verbose", &verbose,
429 + OPT_INCR('v', "verbose", &verbose,
430 "be more verbose (show symbol address, etc)"),
431 OPT_BOOLEAN('L', "Latency", &latency_format,
432 "show latency attributes (irqs/preemption disabled, etc)"),
433 --- a/tools/perf/util/debug.c
434 +++ b/tools/perf/util/debug.c
435 @@ -12,7 +12,7 @@
436 #include "util.h"
437
438 int verbose = 0;
439 -int dump_trace = 0;
440 +bool dump_trace = false;
441
442 int eprintf(int level, const char *fmt, ...)
443 {
444 --- a/tools/perf/util/debug.h
445 +++ b/tools/perf/util/debug.h
446 @@ -2,10 +2,11 @@
447 #ifndef __PERF_DEBUG_H
448 #define __PERF_DEBUG_H
449
450 +#include <stdbool.h>
451 #include "event.h"
452
453 extern int verbose;
454 -extern int dump_trace;
455 +extern bool dump_trace;
456
457 int eprintf(int level,
458 const char *fmt, ...) __attribute__((format(printf, 2, 3)));
459 --- a/tools/perf/util/parse-options.c
460 +++ b/tools/perf/util/parse-options.c
461 @@ -49,6 +49,7 @@ static int get_value(struct parse_opt_ct
462 break;
463 /* FALLTHROUGH */
464 case OPTION_BOOLEAN:
465 + case OPTION_INCR:
466 case OPTION_BIT:
467 case OPTION_SET_INT:
468 case OPTION_SET_PTR:
469 @@ -73,6 +74,10 @@ static int get_value(struct parse_opt_ct
470 return 0;
471
472 case OPTION_BOOLEAN:
473 + *(bool *)opt->value = unset ? false : true;
474 + return 0;
475 +
476 + case OPTION_INCR:
477 *(int *)opt->value = unset ? 0 : *(int *)opt->value + 1;
478 return 0;
479
480 @@ -478,6 +483,7 @@ int usage_with_options_internal(const ch
481 case OPTION_GROUP:
482 case OPTION_BIT:
483 case OPTION_BOOLEAN:
484 + case OPTION_INCR:
485 case OPTION_SET_INT:
486 case OPTION_SET_PTR:
487 case OPTION_LONG:
488 --- a/tools/perf/util/parse-options.h
489 +++ b/tools/perf/util/parse-options.h
490 @@ -8,7 +8,8 @@ enum parse_opt_type {
491 OPTION_GROUP,
492 /* options with no arguments */
493 OPTION_BIT,
494 - OPTION_BOOLEAN, /* _INCR would have been a better name */
495 + OPTION_BOOLEAN,
496 + OPTION_INCR,
497 OPTION_SET_INT,
498 OPTION_SET_PTR,
499 /* options with arguments (usually) */
500 @@ -95,6 +96,7 @@ struct option {
501 #define OPT_GROUP(h) { .type = OPTION_GROUP, .help = (h) }
502 #define OPT_BIT(s, l, v, h, b) { .type = OPTION_BIT, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (b) }
503 #define OPT_BOOLEAN(s, l, v, h) { .type = OPTION_BOOLEAN, .short_name = (s), .long_name = (l), .value = (v), .help = (h) }
504 +#define OPT_INCR(s, l, v, h) { .type = OPTION_INCR, .short_name = (s), .long_name = (l), .value = (v), .help = (h) }
505 #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) }
506 #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) }
507 #define OPT_INTEGER(s, l, v, h) { .type = OPTION_INTEGER, .short_name = (s), .long_name = (l), .value = (v), .help = (h) }
508 --- a/tools/perf/util/trace-event-parse.c
509 +++ b/tools/perf/util/trace-event-parse.c
510 @@ -40,7 +40,7 @@ int header_page_size_size;
511 int header_page_data_offset;
512 int header_page_data_size;
513
514 -int latency_format;
515 +bool latency_format;
516
517 static char *input_buf;
518 static unsigned long long input_buf_ptr;
519 --- a/tools/perf/util/trace-event.h
520 +++ b/tools/perf/util/trace-event.h
521 @@ -1,6 +1,7 @@
522 #ifndef __PERF_TRACE_EVENTS_H
523 #define __PERF_TRACE_EVENTS_H
524
525 +#include <stdbool.h>
526 #include "parse-events.h"
527
528 #define __unused __attribute__((unused))
529 @@ -241,7 +242,7 @@ extern int header_page_size_size;
530 extern int header_page_data_offset;
531 extern int header_page_data_size;
532
533 -extern int latency_format;
534 +extern bool latency_format;
535
536 int parse_header_page(char *buf, unsigned long size);
537 int trace_parse_common_type(void *data);