]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
perf tools: Fail on using multiple bits long terms without value
authorJiri Olsa <jolsa@kernel.org>
Fri, 17 Feb 2017 14:00:56 +0000 (15:00 +0100)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 17 Feb 2017 20:28:22 +0000 (17:28 -0300)
Currently we allow not to specify value for numeric terms and we set
them to value 1. This was originaly meant just for single bit terms to
allow user to type:

  $ perf record -e 'cpu/cpu-cycles,any'

instead of:

  $ perf record -e 'cpu/cpu-cycles,any=1'

However it works also for multi bits terms like:

  $ perf record -e 'cpu/event/' ls
  ...
  $ perf evlist -v
  ..., config: 0x1, ...

After discussion with Peter we decided making such term usage to fail,
like:

  $ perf record -e 'cpu/event/' ls
  event syntax error: 'cpu/event/'
                       \___ no value assigned for term
  ...

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1487340058-10496-4-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/parse-events.c
tools/perf/util/parse-events.h
tools/perf/util/parse-events.y
tools/perf/util/pmu.c

index 984d99a8fdc561c840bfb55d2d80b3029360b94b..67a8aebc67ab492a9936ad56ae9655526f9d9781 100644 (file)
@@ -2349,6 +2349,7 @@ static int new_term(struct parse_events_term **_term,
 
 int parse_events_term__num(struct parse_events_term **term,
                           int type_term, char *config, u64 num,
+                          bool no_value,
                           void *loc_term_, void *loc_val_)
 {
        YYLTYPE *loc_term = loc_term_;
@@ -2358,6 +2359,7 @@ int parse_events_term__num(struct parse_events_term **term,
                .type_val  = PARSE_EVENTS__TERM_TYPE_NUM,
                .type_term = type_term,
                .config    = config,
+               .no_value  = no_value,
                .err_term  = loc_term ? loc_term->first_column : 0,
                .err_val   = loc_val  ? loc_val->first_column  : 0,
        };
index da246a3ddb69f7700316dedf0b00beb054046f15..1af6a267c21bfd3a437e3bed1f2122f96c4dced7 100644 (file)
@@ -94,6 +94,7 @@ struct parse_events_term {
        int type_term;
        struct list_head list;
        bool used;
+       bool no_value;
 
        /* error string indexes for within parsed string */
        int err_term;
@@ -122,6 +123,7 @@ void parse_events__shrink_config_terms(void);
 int parse_events__is_hardcoded_term(struct parse_events_term *term);
 int parse_events_term__num(struct parse_events_term **term,
                           int type_term, char *config, u64 num,
+                          bool novalue,
                           void *loc_term, void *loc_val);
 int parse_events_term__str(struct parse_events_term **term,
                           int type_term, char *config, char *str,
index a14b47ab3879bd67db8854d495ba2e195c4f9068..30f018ea137096c22d6798e4bcd7723373db26af 100644 (file)
@@ -252,7 +252,7 @@ PE_KERNEL_PMU_EVENT sep_dc
                        if (!strcasecmp(alias->name, $1)) {
                                ALLOC_LIST(head);
                                ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
-                                       $1, 1, &@1, NULL));
+                                       $1, 1, false, &@1, NULL));
                                list_add_tail(&term->list, head);
 
                                if (!parse_events_add_pmu(data, list,
@@ -282,7 +282,7 @@ PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc
 
        ALLOC_LIST(head);
        ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
-                                       &pmu_name, 1, &@1, NULL));
+                                       &pmu_name, 1, false, &@1, NULL));
        list_add_tail(&term->list, head);
 
        ALLOC_LIST(list);
@@ -548,7 +548,7 @@ PE_NAME '=' PE_VALUE
        struct parse_events_term *term;
 
        ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
-                                       $1, $3, &@1, &@3));
+                                       $1, $3, false, &@1, &@3));
        $$ = term;
 }
 |
@@ -566,7 +566,7 @@ PE_NAME
        struct parse_events_term *term;
 
        ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
-                                       $1, 1, &@1, NULL));
+                                       $1, 1, true, &@1, NULL));
        $$ = term;
 }
 |
@@ -591,7 +591,7 @@ PE_TERM '=' PE_VALUE
 {
        struct parse_events_term *term;
 
-       ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3, &@1, &@3));
+       ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3, false, &@1, &@3));
        $$ = term;
 }
 |
@@ -599,7 +599,7 @@ PE_TERM
 {
        struct parse_events_term *term;
 
-       ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, &@1, NULL));
+       ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, true, &@1, NULL));
        $$ = term;
 }
 |
@@ -620,7 +620,7 @@ PE_NAME array '=' PE_VALUE
        struct parse_events_term *term;
 
        ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
-                                       $1, $4, &@1, &@4));
+                                       $1, $4, false, &@1, &@4));
        term->array = $2;
        $$ = term;
 }
index 49bfee0e3d9ed0b483180a74b7bfd96954f4968b..63cb46cb9b0f436a708d9f02a05eeaf025285718 100644 (file)
@@ -834,9 +834,18 @@ static int pmu_config_term(struct list_head *formats,
         * Either directly use a numeric term, or try to translate string terms
         * using event parameters.
         */
-       if (term->type_val == PARSE_EVENTS__TERM_TYPE_NUM)
+       if (term->type_val == PARSE_EVENTS__TERM_TYPE_NUM) {
+               if (term->no_value &&
+                   bitmap_weight(format->bits, PERF_PMU_FORMAT_BITS) > 1) {
+                       if (err) {
+                               err->idx = term->err_val;
+                               err->str = strdup("no value assigned for term");
+                       }
+                       return -EINVAL;
+               }
+
                val = term->val.num;
-       else if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR) {
+       else if (term->type_val == PARSE_EVENTS__TERM_TYPE_STR) {
                if (strcmp(term->val.str, "?")) {
                        if (verbose) {
                                pr_info("Invalid sysfs entry %s=%s\n",