Commit 99e7138e authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo

perf tools: Fail on using multiple bits long terms without value

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: default avatarJiri 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.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 67b49b38
......@@ -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,
};
......
......@@ -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,
......
......@@ -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;
}
......
......@@ -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",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment