All of lore.kernel.org
 help / color / mirror / Atom feed
From: tip-bot for Jiri Olsa <tipbot@zytor.com>
To: linux-tip-commits@vger.kernel.org
Cc: dsahern@gmail.com, acme@redhat.com, mingo@kernel.org,
	linux-kernel@vger.kernel.org, jolsa@kernel.org, hpa@zytor.com,
	a.p.zijlstra@chello.nl, namhyung@kernel.org, tglx@linutronix.de
Subject: [tip:perf/urgent] perf tools: Fail on using multiple bits long terms without value
Date: Tue, 21 Feb 2017 00:14:20 -0800	[thread overview]
Message-ID: <tip-99e7138eb7897aa0ccc6661173ae2d7e79721e05@git.kernel.org> (raw)
In-Reply-To: <1487340058-10496-4-git-send-email-jolsa@kernel.org>

Commit-ID:  99e7138eb7897aa0ccc6661173ae2d7e79721e05
Gitweb:     http://git.kernel.org/tip/99e7138eb7897aa0ccc6661173ae2d7e79721e05
Author:     Jiri Olsa <jolsa@kernel.org>
AuthorDate: Fri, 17 Feb 2017 15:00:56 +0100
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Fri, 17 Feb 2017 17:28:22 -0300

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: 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 |  2 ++
 tools/perf/util/parse-events.h |  2 ++
 tools/perf/util/parse-events.y | 14 +++++++-------
 tools/perf/util/pmu.c          | 13 +++++++++++--
 4 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 984d99a..67a8aeb 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -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,
 	};
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index da246a3..1af6a26 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -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,
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index a14b47a..30f018e 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -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;
 }
diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c
index 49bfee0..63cb46c 100644
--- a/tools/perf/util/pmu.c
+++ b/tools/perf/util/pmu.c
@@ -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",

  reply	other threads:[~2017-02-21  8:14 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-17 14:00 [PATCH 0/5] perf tools: Few fixes Jiri Olsa
2017-02-17 14:00 ` [PATCH 1/5] perf build: Add special fixdep cleaning rule Jiri Olsa
2017-02-21  8:13   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2017-02-17 14:00 ` [PATCH 2/5] perf tools: Move new_term arguments into struct parse_events_term template Jiri Olsa
2017-02-21  8:13   ` [tip:perf/urgent] " tip-bot for Jiri Olsa
2017-02-17 14:00 ` [PATCH 3/5] perf tools: Fail on using multiple bits long terms without value Jiri Olsa
2017-02-21  8:14   ` tip-bot for Jiri Olsa [this message]
2017-02-17 14:00 ` [PATCH 4/5] perf stat: Add -a as a default target Jiri Olsa
2017-02-17 14:27   ` Arnaldo Carvalho de Melo
2017-02-17 14:33     ` Jiri Olsa
2017-02-17 14:41       ` Arnaldo Carvalho de Melo
2017-02-17 14:43         ` Jiri Olsa
2017-02-17 17:00         ` [PATCHv2 " Jiri Olsa
2017-02-17 17:48           ` Boris Petkov
2017-02-18 17:52             ` Borislav Petkov
2017-02-20  7:13               ` Jiri Olsa
     [not found]                 ` <20170220134433.GI4109@kernel.org>
2017-02-20 20:31                   ` Borislav Petkov
2017-02-20 21:22                     ` Arnaldo Carvalho de Melo
2017-02-20 22:47                       ` Borislav Petkov
2017-02-21  7:54                         ` Jiri Olsa
2017-02-21 11:04                           ` Jiri Olsa
2017-02-21 11:20                             ` Borislav Petkov
2017-02-21 13:34                               ` Arnaldo Carvalho de Melo
2017-02-21 14:05                                 ` Borislav Petkov
2017-02-21 14:20                                   ` Arnaldo Carvalho de Melo
2017-02-21  8:14           ` [tip:perf/urgent] perf stat: Add -a as " tip-bot for Jiri Olsa
2017-02-17 14:00 ` [PATCH 5/5] perf record: Add -a as a " Jiri Olsa
2017-02-17 14:28   ` Arnaldo Carvalho de Melo
2017-02-17 17:00     ` Jiri Olsa
2017-02-21  8:15       ` [tip:perf/urgent] perf record: Add -a as " tip-bot for Jiri Olsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tip-99e7138eb7897aa0ccc6661173ae2d7e79721e05@git.kernel.org \
    --to=tipbot@zytor.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=dsahern@gmail.com \
    --cc=hpa@zytor.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.