{"thread":{"id":"23453","subject":"Re: [PATCH] perf: Fix endianness argument compatibility","startedAt":"2010-04-14T09:28:43Z","lastAt":"2010-04-14T15:12:40Z","messageCount":5,"participants":["Ingo Molnar","tip-bot for Ian Munsie","Jeff King","Erik Faye-Lund"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"139461","messageId":"20100414092843.GD10537@elte.hu","threadId":"23453","inReplyTo":"20100413.014821.34906166.davem@davemloft.net","subject":"Re: [PATCH] perf: Fix endianness argument compatibility","fromName":"Ingo Molnar","fromEmail":"mingo@elte.hu","sentAt":"2010-04-14T09:28:43Z","receivedAt":"2010-04-14T09:28:43Z","isPatch":true,"sender":{"key":"mingo@elte.hu","avatar":null},"body":"\n* David Miller <davem@davemloft.net> wrote:\n\n> From: \"Ian Munsie\" <imunsie@au1.ibm.com>\n> Date: Tue, 13 Apr 2010 18:37:33 +1000\n> \n> > From: Ian Munsie <imunsie@au.ibm.com>\n> > \n> > Parsing an option from the command line with OPT_BOOLEAN on a bool data\n> > type would not work on a big-endian machine due to the manner in which\n> > the boolean was being cast into an int and incremented. For example,\n> > running 'perf probe --list' on a PowerPC machine would fail to properly\n> > set the list_events bool and would therefore print out the usage\n> > information and terminate.\n> > \n> > This patch makes OPT_BOOLEAN work as expected with a bool datatype. For\n> > cases where the original OPT_BOOLEAN was intentionally being used to\n> > increment an int each time it was passed in on the command line, this\n> > patch introduces OPT_INCR with the old behaviour of OPT_BOOLEAN (the\n> > verbose variable is currently the only such example of this).\n> > \n> > I have reviewed every use of OPT_BOOLEAN to verify that a true C99 bool\n> > was passed. Where integers were used, I verified that they were only\n> > being used for boolean logic and changed them to bools to ensure that\n> > they would not be mistakenly used as ints. The major exception was the\n> > verbose variable which now uses OPT_INCR instead of OPT_BOOLEAN.\n> > \n> > Signed-off-by: Ian Munsie <imunsie@au.ibm.com>\n> \n> Thanks for finding and fixing this bug.\n\nNice fix!\n\nBtw., perf got the option parser from the Git project - i'm wondering how the \nGit folks solved this endianness problem?\n\n\tIngo\n"},{"id":"139463","messageId":"tip-c05556421742eb47f80301767653a4bcb19de9de@git.kernel.org","threadId":"23453","inReplyTo":"1271147857-11604-1-git-send-email-imunsie@au.ibm.com","subject":"[tip:perf/core] perf: Fix endianness argument compatibility with OPT_BOOLEAN() and introduce OPT_INCR()","fromName":"tip-bot for Ian Munsie","fromEmail":"imunsie@au.ibm.com","sentAt":"2010-04-14T09:36:38Z","receivedAt":"2010-04-14T09:36:38Z","isPatch":false,"sender":{"key":"imunsie@au.ibm.com","avatar":null},"body":"Commit-ID:  c05556421742eb47f80301767653a4bcb19de9de\nGitweb:     http://git.kernel.org/tip/c05556421742eb47f80301767653a4bcb19de9de\nAuthor:     Ian Munsie <imunsie@au.ibm.com>\nAuthorDate: Tue, 13 Apr 2010 18:37:33 +1000\nCommitter:  Ingo Molnar <mingo@elte.hu>\nCommitDate: Wed, 14 Apr 2010 11:26:44 +0200\n\nperf: Fix endianness argument compatibility with OPT_BOOLEAN() and introduce OPT_INCR()\n\nParsing an option from the command line with OPT_BOOLEAN on a\nbool data type would not work on a big-endian machine due to the\nmanner in which the boolean was being cast into an int and\nincremented. For example, running 'perf probe --list' on a\nPowerPC machine would fail to properly set the list_events bool\nand would therefore print out the usage information and\nterminate.\n\nThis patch makes OPT_BOOLEAN work as expected with a bool\ndatatype. For cases where the original OPT_BOOLEAN was\nintentionally being used to increment an int each time it was\npassed in on the command line, this patch introduces OPT_INCR\nwith the old behaviour of OPT_BOOLEAN (the verbose variable is\ncurrently the only such example of this).\n\nI have reviewed every use of OPT_BOOLEAN to verify that a true\nC99 bool was passed. Where integers were used, I verified that\nthey were only being used for boolean logic and changed them to\nbools to ensure that they would not be mistakenly used as ints.\nThe major exception was the verbose variable which now uses\nOPT_INCR instead of OPT_BOOLEAN.\n\nSigned-off-by: Ian Munsie <imunsie@au.ibm.com>\nAcked-by: David S. Miller <davem@davemloft.net>\nCc: <stable@kernel.org> # NOTE: wont apply to .3[34].x cleanly, please backport\nCc: Git development list <git@vger.kernel.org>\nCc: Ian Munsie <imunsie@au1.ibm.com>\nCc: Peter Zijlstra <a.p.zijlstra@chello.nl>\nCc: Paul Mackerras <paulus@samba.org>\nCc: Arnaldo Carvalho de Melo <acme@redhat.com>\nCc: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>\nCc: Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>\nCc: Rusty Russell <rusty@rustcorp.com.au>\nCc: Frederic Weisbecker <fweisbec@gmail.com>\nCc: Eric B Munson <ebmunson@us.ibm.com>\nCc: Valdis.Kletnieks@vt.edu\nCc: WANG Cong <amwang@redhat.com>\nCc: Thiago Farina <tfransosi@gmail.com>\nCc: Masami Hiramatsu <mhiramat@redhat.com>\nCc: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>\nCc: Jaswinder Singh Rajput <jaswinderrajput@gmail.com>\nCc: Arjan van de Ven <arjan@linux.intel.com>\nCc: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>\nCc: Mike Galbraith <efault@gmx.de>\nCc: Tom Zanussi <tzanussi@gmail.com>\nCc: Anton Blanchard <anton@samba.org>\nCc: John Kacur <jkacur@redhat.com>\nCc: Li Zefan <lizf@cn.fujitsu.com>\nCc: Steven Rostedt <rostedt@goodmis.org>\nLKML-Reference: <1271147857-11604-1-git-send-email-imunsie@au.ibm.com>\nSigned-off-by: Ingo Molnar <mingo@elte.hu>\n---\n tools/perf/bench/mem-memcpy.c       |    2 +-\n tools/perf/bench/sched-messaging.c  |    4 ++--\n tools/perf/builtin-annotate.c       |    8 ++++----\n tools/perf/builtin-buildid-cache.c  |    2 +-\n tools/perf/builtin-buildid-list.c   |    4 ++--\n tools/perf/builtin-diff.c           |    4 ++--\n tools/perf/builtin-help.c           |    2 +-\n tools/perf/builtin-lock.c           |    2 +-\n tools/perf/builtin-probe.c          |    2 +-\n tools/perf/builtin-record.c         |   24 ++++++++++++------------\n tools/perf/builtin-report.c         |    6 +++---\n tools/perf/builtin-sched.c          |    6 +++---\n tools/perf/builtin-stat.c           |   10 +++++-----\n tools/perf/builtin-timechart.c      |    2 +-\n tools/perf/builtin-top.c            |   14 +++++++-------\n tools/perf/builtin-trace.c          |    2 +-\n tools/perf/util/debug.c             |    2 +-\n tools/perf/util/debug.h             |    3 ++-\n tools/perf/util/parse-options.c     |    6 ++++++\n tools/perf/util/parse-options.h     |    4 +++-\n tools/perf/util/trace-event-parse.c |    2 +-\n tools/perf/util/trace-event.h       |    3 ++-\n 22 files changed, 62 insertions(+), 52 deletions(-)\n\ndiff --git a/tools/perf/bench/mem-memcpy.c b/tools/perf/bench/mem-memcpy.c\nindex 52e646e..38dae74 100644\n--- a/tools/perf/bench/mem-memcpy.c\n+++ b/tools/perf/bench/mem-memcpy.c\n@@ -23,7 +23,7 @@\n \n static const char\t*length_str\t= \"1MB\";\n static const char\t*routine\t= \"default\";\n-static int\t\tuse_clock\t= 0;\n+static bool\t\tuse_clock\t= false;\n static int\t\tclock_fd;\n \n static const struct option options[] = {\ndiff --git a/tools/perf/bench/sched-messaging.c b/tools/perf/bench/sched-messaging.c\nindex 81cee78..da1b2e9 100644\n--- a/tools/perf/bench/sched-messaging.c\n+++ b/tools/perf/bench/sched-messaging.c\n@@ -31,9 +31,9 @@\n \n #define DATASIZE 100\n \n-static int use_pipes = 0;\n+static bool use_pipes = false;\n static unsigned int loops = 100;\n-static unsigned int thread_mode = 0;\n+static bool thread_mode = false;\n static unsigned int num_groups = 10;\n \n struct sender_context {\ndiff --git a/tools/perf/builtin-annotate.c b/tools/perf/builtin-annotate.c\nindex ee0d917..06eaebe 100644\n--- a/tools/perf/builtin-annotate.c\n+++ b/tools/perf/builtin-annotate.c\n@@ -28,11 +28,11 @@\n \n static char\t\tconst *input_name = \"perf.data\";\n \n-static int\t\tforce;\n+static bool\t\tforce;\n \n-static int\t\tfull_paths;\n+static bool\t\tfull_paths;\n \n-static int\t\tprint_line;\n+static bool\t\tprint_line;\n \n struct sym_hist {\n \tu64\t\tsum;\n@@ -595,7 +595,7 @@ static const struct option options[] = {\n \tOPT_STRING('s', \"symbol\", &sym_hist_filter, \"symbol\",\n \t\t    \"symbol to annotate\"),\n \tOPT_BOOLEAN('f', \"force\", &force, \"don't complain, do it\"),\n-\tOPT_BOOLEAN('v', \"verbose\", &verbose,\n+\tOPT_INCR('v', \"verbose\", &verbose,\n \t\t    \"be more verbose (show symbol address, etc)\"),\n \tOPT_BOOLEAN('D', \"dump-raw-trace\", &dump_trace,\n \t\t    \"dump raw trace in ASCII\"),\ndiff --git a/tools/perf/builtin-buildid-cache.c b/tools/perf/builtin-buildid-cache.c\nindex 30a05f5..f8e3d18 100644\n--- a/tools/perf/builtin-buildid-cache.c\n+++ b/tools/perf/builtin-buildid-cache.c\n@@ -27,7 +27,7 @@ static const struct option buildid_cache_options[] = {\n \t\t   \"file list\", \"file(s) to add\"),\n \tOPT_STRING('r', \"remove\", &remove_name_list_str, \"file list\",\n \t\t    \"file(s) to remove\"),\n-\tOPT_BOOLEAN('v', \"verbose\", &verbose, \"be more verbose\"),\n+\tOPT_INCR('v', \"verbose\", &verbose, \"be more verbose\"),\n \tOPT_END()\n };\n \ndiff --git a/tools/perf/builtin-buildid-list.c b/tools/perf/builtin-buildid-list.c\nindex d0675c0..af2ad8b 100644\n--- a/tools/perf/builtin-buildid-list.c\n+++ b/tools/perf/builtin-buildid-list.c\n@@ -16,7 +16,7 @@\n #include \"util/symbol.h\"\n \n static char const *input_name = \"perf.data\";\n-static int force;\n+static bool force;\n static bool with_hits;\n \n static const char * const buildid_list_usage[] = {\n@@ -29,7 +29,7 @@ static const struct option options[] = {\n \tOPT_STRING('i', \"input\", &input_name, \"file\",\n \t\t    \"input file name\"),\n \tOPT_BOOLEAN('f', \"force\", &force, \"don't complain, do it\"),\n-\tOPT_BOOLEAN('v', \"verbose\", &verbose,\n+\tOPT_INCR('v', \"verbose\", &verbose,\n \t\t    \"be more verbose\"),\n \tOPT_END()\n };\ndiff --git a/tools/perf/builtin-diff.c b/tools/perf/builtin-diff.c\nindex 1ea15d8..3a1d94d 100644\n--- a/tools/perf/builtin-diff.c\n+++ b/tools/perf/builtin-diff.c\n@@ -19,7 +19,7 @@\n static char const *input_old = \"perf.data.old\",\n \t\t  *input_new = \"perf.data\";\n static char\t  diff__default_sort_order[] = \"dso,symbol\";\n-static int  force;\n+static bool  force;\n static bool show_displacement;\n \n static int perf_session__add_hist_entry(struct perf_session *self,\n@@ -188,7 +188,7 @@ static const char * const diff_usage[] = {\n };\n \n static const struct option options[] = {\n-\tOPT_BOOLEAN('v', \"verbose\", &verbose,\n+\tOPT_INCR('v', \"verbose\", &verbose,\n \t\t    \"be more verbose (show symbol address, etc)\"),\n \tOPT_BOOLEAN('m', \"displacement\", &show_displacement,\n \t\t    \"Show position displacement relative to baseline\"),\ndiff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c\nindex 215b584..81e3ecc 100644\n--- a/tools/perf/builtin-help.c\n+++ b/tools/perf/builtin-help.c\n@@ -29,7 +29,7 @@ enum help_format {\n \tHELP_FORMAT_WEB,\n };\n \n-static int show_all = 0;\n+static bool show_all = false;\n static enum help_format help_format = HELP_FORMAT_MAN;\n static struct option builtin_help_options[] = {\n \tOPT_BOOLEAN('a', \"all\", &show_all, \"print all available commands\"),\ndiff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c\nindex e12c844..6c38e4f 100644\n--- a/tools/perf/builtin-lock.c\n+++ b/tools/perf/builtin-lock.c\n@@ -744,7 +744,7 @@ static const char * const lock_usage[] = {\n \n static const struct option lock_options[] = {\n \tOPT_STRING('i', \"input\", &input_name, \"file\", \"input file name\"),\n-\tOPT_BOOLEAN('v', \"verbose\", &verbose, \"be more verbose (show symbol address, etc)\"),\n+\tOPT_INCR('v', \"verbose\", &verbose, \"be more verbose (show symbol address, etc)\"),\n \tOPT_BOOLEAN('D', \"dump-raw-trace\", &dump_trace, \"dump raw trace in ASCII\"),\n \tOPT_END()\n };\ndiff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c\nindex b3ba25a..bfc47ff 100644\n--- a/tools/perf/builtin-probe.c\n+++ b/tools/perf/builtin-probe.c\n@@ -133,7 +133,7 @@ static const char * const probe_usage[] = {\n };\n \n static const struct option options[] = {\n-\tOPT_BOOLEAN('v', \"verbose\", &verbose,\n+\tOPT_INCR('v', \"verbose\", &verbose,\n \t\t    \"be more verbose (show parsed arguments, etc)\"),\n \tOPT_BOOLEAN('l', \"list\", &params.list_events,\n \t\t    \"list up current probe events\"),\ndiff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c\nindex dc61f1b..9a95136 100644\n--- a/tools/perf/builtin-record.c\n+++ b/tools/perf/builtin-record.c\n@@ -38,22 +38,22 @@ static int\t\t\toutput;\n static const char\t\t*output_name\t\t\t= \"perf.data\";\n static int\t\t\tgroup\t\t\t\t=      0;\n static unsigned int\t\trealtime_prio\t\t\t=      0;\n-static int\t\t\traw_samples\t\t\t=      0;\n-static int\t\t\tsystem_wide\t\t\t=      0;\n+static bool\t\t\traw_samples\t\t\t=  false;\n+static bool\t\t\tsystem_wide\t\t\t=  false;\n static int\t\t\tprofile_cpu\t\t\t=     -1;\n static pid_t\t\t\ttarget_pid\t\t\t=     -1;\n static pid_t\t\t\ttarget_tid\t\t\t=     -1;\n static pid_t\t\t\t*all_tids\t\t\t=      NULL;\n static int\t\t\tthread_num\t\t\t=      0;\n static pid_t\t\t\tchild_pid\t\t\t=     -1;\n-static int\t\t\tinherit\t\t\t\t=      1;\n-static int\t\t\tforce\t\t\t\t=      0;\n-static int\t\t\tappend_file\t\t\t=      0;\n-static int\t\t\tcall_graph\t\t\t=      0;\n-static int\t\t\tinherit_stat\t\t\t=      0;\n-static int\t\t\tno_samples\t\t\t=      0;\n-static int\t\t\tsample_address\t\t\t=      0;\n-static int\t\t\tmultiplex\t\t\t=      0;\n+static bool\t\t\tinherit\t\t\t\t=   true;\n+static bool\t\t\tforce\t\t\t\t=  false;\n+static bool\t\t\tappend_file\t\t\t=  false;\n+static bool\t\t\tcall_graph\t\t\t=  false;\n+static bool\t\t\tinherit_stat\t\t\t=  false;\n+static bool\t\t\tno_samples\t\t\t=  false;\n+static bool\t\t\tsample_address\t\t\t=  false;\n+static bool\t\t\tmultiplex\t\t\t=  false;\n static int\t\t\tmultiplex_fd\t\t\t=     -1;\n \n static long\t\t\tsamples\t\t\t\t=      0;\n@@ -465,7 +465,7 @@ static int __cmd_record(int argc, const char **argv)\n \t\t\trename(output_name, oldname);\n \t\t}\n \t} else {\n-\t\tappend_file = 0;\n+\t\tappend_file = false;\n \t}\n \n \tflags = O_CREAT|O_RDWR;\n@@ -701,7 +701,7 @@ static const struct option options[] = {\n \t\t    \"number of mmap data pages\"),\n \tOPT_BOOLEAN('g', \"call-graph\", &call_graph,\n \t\t    \"do call-graph (stack chain/backtrace) recording\"),\n-\tOPT_BOOLEAN('v', \"verbose\", &verbose,\n+\tOPT_INCR('v', \"verbose\", &verbose,\n \t\t    \"be more verbose (show counter open errors, etc)\"),\n \tOPT_BOOLEAN('s', \"stat\", &inherit_stat,\n \t\t    \"per thread counts\"),\ndiff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c\nindex e93c69a..daee082 100644\n--- a/tools/perf/builtin-report.c\n+++ b/tools/perf/builtin-report.c\n@@ -32,11 +32,11 @@\n \n static char\t\tconst *input_name = \"perf.data\";\n \n-static int\t\tforce;\n+static bool\t\tforce;\n static bool\t\thide_unresolved;\n static bool\t\tdont_use_callchains;\n \n-static int\t\tshow_threads;\n+static bool\t\tshow_threads;\n static struct perf_read_values\tshow_threads_values;\n \n static char\t\tdefault_pretty_printing_style[] = \"normal\";\n@@ -418,7 +418,7 @@ static const char * const report_usage[] = {\n static const struct option options[] = {\n \tOPT_STRING('i', \"input\", &input_name, \"file\",\n \t\t    \"input file name\"),\n-\tOPT_BOOLEAN('v', \"verbose\", &verbose,\n+\tOPT_INCR('v', \"verbose\", &verbose,\n \t\t    \"be more verbose (show symbol address, etc)\"),\n \tOPT_BOOLEAN('D', \"dump-raw-trace\", &dump_trace,\n \t\t    \"dump raw trace in ASCII\"),\ndiff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c\nindex 5e59c0c..09ddc8e 100644\n--- a/tools/perf/builtin-sched.c\n+++ b/tools/perf/builtin-sched.c\n@@ -1790,7 +1790,7 @@ static const char * const sched_usage[] = {\n static const struct option sched_options[] = {\n \tOPT_STRING('i', \"input\", &input_name, \"file\",\n \t\t    \"input file name\"),\n-\tOPT_BOOLEAN('v', \"verbose\", &verbose,\n+\tOPT_INCR('v', \"verbose\", &verbose,\n \t\t    \"be more verbose (show symbol address, etc)\"),\n \tOPT_BOOLEAN('D', \"dump-raw-trace\", &dump_trace,\n \t\t    \"dump raw trace in ASCII\"),\n@@ -1805,7 +1805,7 @@ static const char * const latency_usage[] = {\n static const struct option latency_options[] = {\n \tOPT_STRING('s', \"sort\", &sort_order, \"key[,key2...]\",\n \t\t   \"sort by key(s): runtime, switch, avg, max\"),\n-\tOPT_BOOLEAN('v', \"verbose\", &verbose,\n+\tOPT_INCR('v', \"verbose\", &verbose,\n \t\t    \"be more verbose (show symbol address, etc)\"),\n \tOPT_INTEGER('C', \"CPU\", &profile_cpu,\n \t\t    \"CPU to profile on\"),\n@@ -1822,7 +1822,7 @@ static const char * const replay_usage[] = {\n static const struct option replay_options[] = {\n \tOPT_INTEGER('r', \"repeat\", &replay_repeat,\n \t\t    \"repeat the workload replay N times (-1: infinite)\"),\n-\tOPT_BOOLEAN('v', \"verbose\", &verbose,\n+\tOPT_INCR('v', \"verbose\", &verbose,\n \t\t    \"be more verbose (show symbol address, etc)\"),\n \tOPT_BOOLEAN('D', \"dump-raw-trace\", &dump_trace,\n \t\t    \"dump raw trace in ASCII\"),\ndiff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c\nindex 1036ca7..e619ac8 100644\n--- a/tools/perf/builtin-stat.c\n+++ b/tools/perf/builtin-stat.c\n@@ -67,19 +67,19 @@ static struct perf_event_attr default_attrs[] = {\n \n };\n \n-static int\t\t\tsystem_wide\t\t\t=  0;\n+static bool\t\t\tsystem_wide\t\t\t=  false;\n static unsigned int\t\tnr_cpus\t\t\t\t=  0;\n static int\t\t\trun_idx\t\t\t\t=  0;\n \n static int\t\t\trun_count\t\t\t=  1;\n-static int\t\t\tinherit\t\t\t\t=  1;\n-static int\t\t\tscale\t\t\t\t=  1;\n+static bool\t\t\tinherit\t\t\t\t=  true;\n+static bool\t\t\tscale\t\t\t\t=  true;\n static pid_t\t\t\ttarget_pid\t\t\t= -1;\n static pid_t\t\t\ttarget_tid\t\t\t= -1;\n static pid_t\t\t\t*all_tids\t\t\t=  NULL;\n static int\t\t\tthread_num\t\t\t=  0;\n static pid_t\t\t\tchild_pid\t\t\t= -1;\n-static int\t\t\tnull_run\t\t\t=  0;\n+static bool\t\t\tnull_run\t\t\t=  false;\n \n static int\t\t\t*fd[MAX_NR_CPUS][MAX_COUNTERS];\n \n@@ -528,7 +528,7 @@ static const struct option options[] = {\n \t\t    \"system-wide collection from all CPUs\"),\n \tOPT_BOOLEAN('c', \"scale\", &scale,\n \t\t    \"scale/normalize counters\"),\n-\tOPT_BOOLEAN('v', \"verbose\", &verbose,\n+\tOPT_INCR('v', \"verbose\", &verbose,\n \t\t    \"be more verbose (show counter open errors, etc)\"),\n \tOPT_INTEGER('r', \"repeat\", &run_count,\n \t\t    \"repeat command and print average + stddev (max: 100)\"),\ndiff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c\nindex 369c1b4..96f4a09 100644\n--- a/tools/perf/builtin-timechart.c\n+++ b/tools/perf/builtin-timechart.c\n@@ -42,7 +42,7 @@ static u64\t\tturbo_frequency;\n \n static u64\t\tfirst_time, last_time;\n \n-static int\t\tpower_only;\n+static bool\t\tpower_only;\n \n \n struct per_pid;\ndiff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c\nindex 4abdd9b..40f24dd 100644\n--- a/tools/perf/builtin-top.c\n+++ b/tools/perf/builtin-top.c\n@@ -57,7 +57,7 @@\n \n static int\t\t\t*fd[MAX_NR_CPUS][MAX_COUNTERS];\n \n-static int\t\t\tsystem_wide\t\t\t=      0;\n+static bool\t\t\tsystem_wide\t\t\t=  false;\n \n static int\t\t\tdefault_interval\t\t=      0;\n \n@@ -68,18 +68,18 @@ static int\t\t\ttarget_pid\t\t\t=     -1;\n static int\t\t\ttarget_tid\t\t\t=     -1;\n static pid_t\t\t\t*all_tids\t\t\t=      NULL;\n static int\t\t\tthread_num\t\t\t=      0;\n-static int\t\t\tinherit\t\t\t\t=      0;\n+static bool\t\t\tinherit\t\t\t\t=  false;\n static int\t\t\tprofile_cpu\t\t\t=     -1;\n static int\t\t\tnr_cpus\t\t\t\t=      0;\n static unsigned int\t\trealtime_prio\t\t\t=      0;\n-static int\t\t\tgroup\t\t\t\t=      0;\n+static bool\t\t\tgroup\t\t\t\t=  false;\n static unsigned int\t\tpage_size;\n static unsigned int\t\tmmap_pages\t\t\t=     16;\n static int\t\t\tfreq\t\t\t\t=   1000; /* 1 KHz */\n \n static int\t\t\tdelay_secs\t\t\t=      2;\n-static int\t\t\tzero                            =      0;\n-static int\t\t\tdump_symtab                     =      0;\n+static bool\t\t\tzero                            =  false;\n+static bool\t\t\tdump_symtab                     =  false;\n \n static bool\t\t\thide_kernel_symbols\t\t=  false;\n static bool\t\t\thide_user_symbols\t\t=  false;\n@@ -854,7 +854,7 @@ static void handle_keypress(int c)\n \t\t\tdisplay_weighted = ~display_weighted;\n \t\t\tbreak;\n \t\tcase 'z':\n-\t\t\tzero = ~zero;\n+\t\t\tzero = !zero;\n \t\t\tbreak;\n \t\tdefault:\n \t\t\tbreak;\n@@ -1335,7 +1335,7 @@ static const struct option options[] = {\n \t\t    \"display this many functions\"),\n \tOPT_BOOLEAN('U', \"hide_user_symbols\", &hide_user_symbols,\n \t\t    \"hide user symbols\"),\n-\tOPT_BOOLEAN('v', \"verbose\", &verbose,\n+\tOPT_INCR('v', \"verbose\", &verbose,\n \t\t    \"be more verbose (show counter open errors, etc)\"),\n \tOPT_END()\n };\ndiff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c\nindex 407041d..8fc50d8 100644\n--- a/tools/perf/builtin-trace.c\n+++ b/tools/perf/builtin-trace.c\n@@ -505,7 +505,7 @@ static const char * const trace_usage[] = {\n static const struct option options[] = {\n \tOPT_BOOLEAN('D', \"dump-raw-trace\", &dump_trace,\n \t\t    \"dump raw trace in ASCII\"),\n-\tOPT_BOOLEAN('v', \"verbose\", &verbose,\n+\tOPT_INCR('v', \"verbose\", &verbose,\n \t\t    \"be more verbose (show symbol address, etc)\"),\n \tOPT_BOOLEAN('L', \"Latency\", &latency_format,\n \t\t    \"show latency attributes (irqs/preemption disabled, etc)\"),\ndiff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c\nindex 033d66d..dd824cf 100644\n--- a/tools/perf/util/debug.c\n+++ b/tools/perf/util/debug.c\n@@ -13,7 +13,7 @@\n #include \"util.h\"\n \n int verbose = 0;\n-int dump_trace = 0;\n+bool dump_trace = false;\n \n int eprintf(int level, const char *fmt, ...)\n {\ndiff --git a/tools/perf/util/debug.h b/tools/perf/util/debug.h\nindex 5cb0a1b..047ac33 100644\n--- a/tools/perf/util/debug.h\n+++ b/tools/perf/util/debug.h\n@@ -2,10 +2,11 @@\n #ifndef __PERF_DEBUG_H\n #define __PERF_DEBUG_H\n \n+#include <stdbool.h>\n #include \"event.h\"\n \n extern int verbose;\n-extern int dump_trace;\n+extern bool dump_trace;\n \n int dump_printf(const char *fmt, ...) __attribute__((format(printf, 1, 2)));\n void trace_event(event_t *event);\ndiff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c\nindex 79dfa0c..ed88764 100644\n--- a/tools/perf/util/parse-options.c\n+++ b/tools/perf/util/parse-options.c\n@@ -49,6 +49,7 @@ static int get_value(struct parse_opt_ctx_t *p,\n \t\t\t\tbreak;\n \t\t\t/* FALLTHROUGH */\n \t\tcase OPTION_BOOLEAN:\n+\t\tcase OPTION_INCR:\n \t\tcase OPTION_BIT:\n \t\tcase OPTION_SET_INT:\n \t\tcase OPTION_SET_PTR:\n@@ -73,6 +74,10 @@ static int get_value(struct parse_opt_ctx_t *p,\n \t\treturn 0;\n \n \tcase OPTION_BOOLEAN:\n+\t\t*(bool *)opt->value = unset ? false : true;\n+\t\treturn 0;\n+\n+\tcase OPTION_INCR:\n \t\t*(int *)opt->value = unset ? 0 : *(int *)opt->value + 1;\n \t\treturn 0;\n \n@@ -478,6 +483,7 @@ int usage_with_options_internal(const char * const *usagestr,\n \t\tcase OPTION_GROUP:\n \t\tcase OPTION_BIT:\n \t\tcase OPTION_BOOLEAN:\n+\t\tcase OPTION_INCR:\n \t\tcase OPTION_SET_INT:\n \t\tcase OPTION_SET_PTR:\n \t\tcase OPTION_LONG:\ndiff --git a/tools/perf/util/parse-options.h b/tools/perf/util/parse-options.h\nindex 948805a..b2da725 100644\n--- a/tools/perf/util/parse-options.h\n+++ b/tools/perf/util/parse-options.h\n@@ -8,7 +8,8 @@ enum parse_opt_type {\n \tOPTION_GROUP,\n \t/* options with no arguments */\n \tOPTION_BIT,\n-\tOPTION_BOOLEAN, /* _INCR would have been a better name */\n+\tOPTION_BOOLEAN,\n+\tOPTION_INCR,\n \tOPTION_SET_INT,\n \tOPTION_SET_PTR,\n \t/* options with arguments (usually) */\n@@ -95,6 +96,7 @@ struct option {\n #define OPT_GROUP(h)                { .type = OPTION_GROUP, .help = (h) }\n #define OPT_BIT(s, l, v, h, b)      { .type = OPTION_BIT, .short_name = (s), .long_name = (l), .value = (v), .help = (h), .defval = (b) }\n #define OPT_BOOLEAN(s, l, v, h)     { .type = OPTION_BOOLEAN, .short_name = (s), .long_name = (l), .value = (v), .help = (h) }\n+#define OPT_INCR(s, l, v, h)        { .type = OPTION_INCR, .short_name = (s), .long_name = (l), .value = (v), .help = (h) }\n #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) }\n #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) }\n #define OPT_INTEGER(s, l, v, h)     { .type = OPTION_INTEGER, .short_name = (s), .long_name = (l), .value = (v), .help = (h) }\ndiff --git a/tools/perf/util/trace-event-parse.c b/tools/perf/util/trace-event-parse.c\nindex 3b81250..17d6d66 100644\n--- a/tools/perf/util/trace-event-parse.c\n+++ b/tools/perf/util/trace-event-parse.c\n@@ -42,7 +42,7 @@ int header_page_overwrite_size;\n int header_page_data_offset;\n int header_page_data_size;\n \n-int latency_format;\n+bool latency_format;\n \n static char *input_buf;\n static unsigned long long input_buf_ptr;\ndiff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h\nindex c3269b9..81f2fd2 100644\n--- a/tools/perf/util/trace-event.h\n+++ b/tools/perf/util/trace-event.h\n@@ -1,6 +1,7 @@\n #ifndef __PERF_TRACE_EVENTS_H\n #define __PERF_TRACE_EVENTS_H\n \n+#include <stdbool.h>\n #include \"parse-events.h\"\n \n #define __unused __attribute__((unused))\n@@ -241,7 +242,7 @@ extern int header_page_size_size;\n extern int header_page_data_offset;\n extern int header_page_data_size;\n \n-extern int latency_format;\n+extern bool latency_format;\n \n int parse_header_page(char *buf, unsigned long size);\n int trace_parse_common_type(void *data);\n"},{"id":"139466","messageId":"20100414095252.GA17884@coredump.intra.peff.net","threadId":"23453","inReplyTo":"20100414092843.GD10537@elte.hu","subject":"Re: [PATCH] perf: Fix endianness argument compatibility","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-04-14T09:52:52Z","receivedAt":"2010-04-14T09:52:52Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Apr 14, 2010 at 11:28:43AM +0200, Ingo Molnar wrote:\n\n> > > Parsing an option from the command line with OPT_BOOLEAN on a bool data\n> > > type would not work on a big-endian machine due to the manner in which\n> > > the boolean was being cast into an int and incremented. For example,\n> > > running 'perf probe --list' on a PowerPC machine would fail to properly\n> > > set the list_events bool and would therefore print out the usage\n> > > information and terminate.\n> [...]\n>\n> Nice fix!\n> \n> Btw., perf got the option parser from the Git project - i'm wondering how the \n> Git folks solved this endianness problem?\n\nWe didn't. We pass only actual ints for the value field in all cases. We\ndon't use C99 bools at all. We do use bit-fields, but the compiler\ncatches the error, since OPT_BOOLEAN tries to take its address.\n\n-Peff\n"},{"id":"139486","messageId":"j2k40aa078e1004140812s3d9fab4auf559b1e87af60b5b__18406.0360807509$1271258034$gmane$org@mail.gmail.com","threadId":"23453","inReplyTo":"tip-c05556421742eb47f80301767653a4bcb19de9de@git.kernel.org","subject":"Re: [tip:perf/core] perf: Fix endianness argument compatibility with OPT_BOOLEAN() and introduce OPT_INCR()","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@googlemail.com","sentAt":"2010-04-14T15:12:40Z","receivedAt":"2010-04-14T15:12:40Z","isPatch":false,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"I'd just like to point out that I'm commenting from the Git\npont-of-view, since this patch was CC'ed to the Git mailing-list.\n\nOn Wed, Apr 14, 2010 at 11:36 AM, tip-bot for Ian Munsie\n<imunsie@au.ibm.com> wrote:\n> Commit-ID:  c05556421742eb47f80301767653a4bcb19de9de\n> Gitweb:     http://git.kernel.org/tip/c05556421742eb47f80301767653a4bcb19de9de\n> Author:     Ian Munsie <imunsie@au.ibm.com>\n> AuthorDate: Tue, 13 Apr 2010 18:37:33 +1000\n> Committer:  Ingo Molnar <mingo@elte.hu>\n> CommitDate: Wed, 14 Apr 2010 11:26:44 +0200\n>\n> perf: Fix endianness argument compatibility with OPT_BOOLEAN() and introduce OPT_INCR()\n>\n> Parsing an option from the command line with OPT_BOOLEAN on a\n> bool data type would not work on a big-endian machine due to the\n> manner in which the boolean was being cast into an int and\n> incremented.\n\nWe don't use C99 features like the \"bool\"-type in Git, so this\nshouldn't really be a problem in our end.\n\n> For example, running 'perf probe --list' on a\n> PowerPC machine would fail to properly set the list_events bool\n> and would therefore print out the usage information and\n> terminate.\n>\n\nI don't know what this 'perf'-thing is, but it sounds like it's some\nexternal client for the parse-options-API that uses OPT_BOOLEAN\nincorrectly.\n\nLooking at linux-next.git, it seems so. The code in tools/perf/ seems\nto use OPT_BOOLEAN with C99 bools, and it seems to have imported git's\nparse-options API (in commit 0780060124011b94af55830939c86cc0916be0f5,\nit seems).\n\nI'd suggest either fixing the call-sites to use int, or just keeping\nthese changes in linux-next.git.\n\n-- \nErik \"kusma\" Faye-Lund\n"},{"id":"299176","messageId":"j2k40aa078e1004140812s3d9fab4auf559b1e87af60b5b@mail.gmail.com","threadId":"23453","inReplyTo":"tip-c05556421742eb47f80301767653a4bcb19de9de@git.kernel.org","subject":"Re: [tip:perf/core] perf: Fix endianness argument compatibility with OPT_BOOLEAN() and introduce OPT_INCR()","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@googlemail.com","sentAt":"2010-04-14T15:12:40Z","receivedAt":"2010-04-14T15:12:40Z","isPatch":false,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"I'd just like to point out that I'm commenting from the Git\npont-of-view, since this patch was CC'ed to the Git mailing-list.\n\nOn Wed, Apr 14, 2010 at 11:36 AM, tip-bot for Ian Munsie\n<imunsie@au.ibm.com> wrote:\n> Commit-ID:  c05556421742eb47f80301767653a4bcb19de9de\n> Gitweb:     http://git.kernel.org/tip/c05556421742eb47f80301767653a4bcb19de9de\n> Author:     Ian Munsie <imunsie@au.ibm.com>\n> AuthorDate: Tue, 13 Apr 2010 18:37:33 +1000\n> Committer:  Ingo Molnar <mingo@elte.hu>\n> CommitDate: Wed, 14 Apr 2010 11:26:44 +0200\n>\n> perf: Fix endianness argument compatibility with OPT_BOOLEAN() and introduce OPT_INCR()\n>\n> Parsing an option from the command line with OPT_BOOLEAN on a\n> bool data type would not work on a big-endian machine due to the\n> manner in which the boolean was being cast into an int and\n> incremented.\n\nWe don't use C99 features like the \"bool\"-type in Git, so this\nshouldn't really be a problem in our end.\n\n> For example, running 'perf probe --list' on a\n> PowerPC machine would fail to properly set the list_events bool\n> and would therefore print out the usage information and\n> terminate.\n>\n\nI don't know what this 'perf'-thing is, but it sounds like it's some\nexternal client for the parse-options-API that uses OPT_BOOLEAN\nincorrectly.\n\nLooking at linux-next.git, it seems so. The code in tools/perf/ seems\nto use OPT_BOOLEAN with C99 bools, and it seems to have imported git's\nparse-options API (in commit 0780060124011b94af55830939c86cc0916be0f5,\nit seems).\n\nI'd suggest either fixing the call-sites to use int, or just keeping\nthese changes in linux-next.git.\n\n-- \nErik \"kusma\" Faye-Lund\n"}]}