Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1338147 > unrolled thread

[PATCH 00/55] perf tools: Bugfix, BPF improvements and overwrite ring buffer support

Started byWang Nan <wangnan0@huawei.com>
First post2016-02-19 13:10 +0100
Last post2016-02-20 12:40 +0100
Articles 8 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH 00/55] perf tools: Bugfix, BPF improvements and overwrite ring buffer support Wang Nan <wangnan0@huawei.com> - 2016-02-19 13:10 +0100
    [PATCH 45/55] perf record: Don't poll on overwrite channel Wang Nan <wangnan0@huawei.com> - 2016-02-19 13:10 +0100
    [PATCH 22/55] perf core: Prepare writing into ring buffer from end Wang Nan <wangnan0@huawei.com> - 2016-02-19 13:10 +0100
    [PATCH 12/55] perf tools: Enable config raw and numeric events Wang Nan <wangnan0@huawei.com> - 2016-02-19 13:20 +0100
      Re: [PATCH 12/55] perf tools: Enable config raw and numeric events Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-02-19 16:10 +0100
        Re: [PATCH 12/55] perf tools: Enable config raw and numeric events Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-02-19 16:20 +0100
          Re: [PATCH 12/55] perf tools: Enable config raw and numeric events Arnaldo Carvalho de Melo <acme@kernel.org> - 2016-02-19 23:00 +0100
      [tip:perf/core] perf tools: Enable config raw and numeric events tip-bot for Wang Nan <tipbot@zytor.com> - 2016-02-20 12:40 +0100

#1338147 — [PATCH 00/55] perf tools: Bugfix, BPF improvements and overwrite ring buffer support

FromWang Nan <wangnan0@huawei.com>
Date2016-02-19 13:10 +0100
Subject[PATCH 00/55] perf tools: Bugfix, BPF improvements and overwrite ring buffer support
Message-ID<r3RJo-4w0-7@gated-at.bofh.it>
Hi Arnaldo,

This is this week's perf BPF and overwrite ring buffer patch set.

Please note that this patch set is based on your perf/core, not
tmp.perf/bpf_map, because there is a bug similar to what Jiri pointed
out in commit 5c78fe3 in the bpf_map branch.

A bug related to newest libbabeltrace is found and fixed. Similar to
commit 5141d73, this fix is safe to old version of libbabeltrace.

The following changes since commit 1a3dcca461e81fbee1e588b2e6e1eae0b2b911d3:

  perf stat: Handled scaled == -1 case for counters (2016-02-18 13:50:49 -0300)

are available in the git repository at:

  https://git.kernel.org/pub/scm/linux/kernel/git/pi3orama/linux.git tags/perf-core-for-acme

for you to fetch changes up to 6b8e82587380be165876e423b9d46f41cb5b4020:

  perf tools: Don't warn about out of order event if write_backward is used (2016-02-19 11:26:57 +0000)

----------------------------------------------------------------
perf improvements:

 - Bug fix: byte order of the first BPF output sample incorrect when
   converting to CTF.

 - Fix compiling warning Jiri found.

 - Improve error messages.

Signed-off-by: Wang Nan <wangnan0@huawei.com>

----------------------------------------------------------------
Wang Nan (55):
      perf tools: Record text offset in dso to calculate objdump address
      perf tools: Adjust symbol for shared objects
      perf tools: Rename bpf_prog_priv__clear() to clear_prog_priv()
      perf tools: Fix checking asprintf return value
      perf tools: Add API to config maps in bpf object
      perf tools: Enable BPF object configure syntax
      perf record: Apply config to BPF objects before recording
      perf tools: Enable passing event to BPF object
      perf tools: Create config_term_names array
      perf stat: Forbid user passing improper config terms
      perf tools: Rename and move pmu_event_name to get_config_name
      perf tools: Enable config raw and numeric events
      perf tools: Enable config and setting names for legacy cache events
      perf tools: Support setting different slots in a BPF map separately
      perf tools: Enable indices setting syntax for BPF maps
      perf tools: Pass tracepoint options to BPF script
      perf tools: Introduce bpf-output event
      perf data: Support converting data from bpf_perf_event_output()
      perf data: Explicitly set byte order for integer types
      perf core: Introduce new ioctl options to pause and resume ring buffer
      perf core: Set event's default overflow_handler
      perf core: Prepare writing into ring buffer from end
      perf core: Add backward attribute to perf event
      perf core: Reduce perf event output overhead by new overflow handler
      perf tools: Only validate is_pos for tracking evsels
      perf tools: Print write_backward value in perf_event_attr__fprintf
      perf tools: Make ordered_events reusable
      perf record: Extract synthesize code to record__synthesize()
      perf tools: Add perf_data_file__switch() helper
      perf record: Turns auxtrace_snapshot_enable into 3 states
      perf record: Introduce record__finish_output() to finish a perf.data
      perf record: Add '--timestamp-filename' option to append timestamp to output filename
      perf record: Split output into multiple files via '--switch-output'
      perf record: Force enable --timestamp-filename when --switch-output is provided
      perf record: Disable buildid cache options by default in switch output mode
      perf record: Re-synthesize tracking events after output switching
      perf record: Generate tracking events for process forked by perf
      perf record: Ensure return non-zero rc when mmap fail
      perf record: Prevent reading invalid data in record__mmap_read
      perf tools: Add evlist channel helpers
      perf tools: Automatically add new channel according to evlist
      perf tools: Operate multiple channels
      perf tools: Squash overwrite setting into channel
      perf record: Don't read from and poll overwrite channel
      perf record: Don't poll on overwrite channel
      perf tools: Detect avalibility of write_backward
      perf tools: Enable overwrite settings
      perf tools: Set write_backward attribut bit for overwrite events
      perf tools: Record fd into perf_mmap
      perf tools: Add API to pause a channel
      perf record: Toggle overwrite ring buffer for reading
      perf record: Rename variable to make code clear
      perf record: Read from backward ring buffer
      perf record: Allow generate tracking events at the end of output
      perf tools: Don't warn about out of order event if write_backward is used

 include/linux/perf_event.h        |  22 +-
 include/uapi/linux/perf_event.h   |   4 +-
 kernel/events/core.c              |  73 +++-
 kernel/events/internal.h          |  11 +
 kernel/events/ring_buffer.c       |  63 +++-
 tools/perf/builtin-record.c       | 598 ++++++++++++++++++++++++++-----
 tools/perf/builtin-stat.c         |   1 +
 tools/perf/perf.h                 |   2 +
 tools/perf/tests/bpf.c            |   2 +-
 tools/perf/tests/parse-events.c   |  52 +++
 tools/perf/util/bpf-loader.c      | 724 +++++++++++++++++++++++++++++++++++++-
 tools/perf/util/bpf-loader.h      |  59 ++++
 tools/perf/util/data-convert-bt.c | 118 ++++++-
 tools/perf/util/data.c            |  36 ++
 tools/perf/util/data.h            |  11 +-
 tools/perf/util/dso.h             |   1 +
 tools/perf/util/evlist.c          | 355 +++++++++++++++++--
 tools/perf/util/evlist.h          |  70 +++-
 tools/perf/util/evsel.c           |  23 ++
 tools/perf/util/evsel.h           |  11 +
 tools/perf/util/map.c             |  14 +
 tools/perf/util/ordered-events.c  |   5 +
 tools/perf/util/parse-events.c    | 309 ++++++++++++++--
 tools/perf/util/parse-events.h    |  27 +-
 tools/perf/util/parse-events.l    |  21 +-
 tools/perf/util/parse-events.y    | 134 ++++++-
 tools/perf/util/record.c          |  11 +
 tools/perf/util/session.c         |  22 +-
 tools/perf/util/symbol-elf.c      |  25 +-
 29 files changed, 2565 insertions(+), 239 deletions(-)

[toc] | [next] | [standalone]


#1338148 — [PATCH 45/55] perf record: Don't poll on overwrite channel

FromWang Nan <wangnan0@huawei.com>
Date2016-02-19 13:10 +0100
Subject[PATCH 45/55] perf record: Don't poll on overwrite channel
Message-ID<r3S2M-4Vi-67@gated-at.bofh.it>
In reply to#1338147
There's no need to receive events from overwrite ring buffer. Instead,
perf should make them run background until something happen. This patch
makes events from overwrite ring buffer is ignored except POLLERR and
POLLHUP.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Signed-off-by: He Kuang <hekuang@huawei.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
---
 tools/perf/util/evlist.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 9175c83..7cf0435 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -461,9 +461,9 @@ int perf_evlist__alloc_pollfd(struct perf_evlist *evlist)
 	return 0;
 }
 
-static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, int idx)
+static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, int idx, short revent)
 {
-	int pos = fdarray__add(&evlist->pollfd, fd, POLLIN | POLLERR | POLLHUP);
+	int pos = fdarray__add(&evlist->pollfd, fd, revent | POLLERR | POLLHUP);
 	/*
 	 * Save the idx so that when we filter out fds POLLHUP'ed we can
 	 * close the associated evlist->mmap[] entry.
@@ -479,7 +479,7 @@ static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, int idx
 
 int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd)
 {
-	return __perf_evlist__add_pollfd(evlist, fd, -1);
+	return __perf_evlist__add_pollfd(evlist, fd, -1, POLLIN);
 }
 
 static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd)
@@ -1007,6 +1007,18 @@ perf_evlist__channel_complete(struct perf_evlist *evlist)
 	return 0;
 }
 
+static bool
+perf_evlist__should_poll(struct perf_evlist *evlist,
+			 struct perf_evsel *evsel,
+			 int channel)
+{
+	if (evsel->system_wide)
+		return false;
+	if (perf_evlist__channel_check(evlist, channel, RDONLY))
+		return false;
+	return true;
+}
+
 static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int _idx,
 				       struct mmap_params *mp, int cpu,
 				       int thread, int *outputs)
@@ -1015,6 +1027,7 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int _idx,
 
 	evlist__for_each(evlist, evsel) {
 		int fd, channel, idx, err;
+		short revent = POLLIN;
 
 		channel = perf_evlist__channel_find(evlist, evsel, false);
 		if (channel < 0) {
@@ -1044,6 +1057,8 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int _idx,
 			perf_evlist__mmap_get(evlist, idx);
 		}
 
+		if (!perf_evlist__should_poll(evlist, evsel, channel))
+			revent = 0;
 		/*
 		 * The system_wide flag causes a selected event to be opened
 		 * always without a pid.  Consequently it will never get a
@@ -1052,7 +1067,7 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int _idx,
 		 * Therefore don't add it for polling.
 		 */
 		if (!evsel->system_wide &&
-		    __perf_evlist__add_pollfd(evlist, fd, idx) < 0) {
+		    __perf_evlist__add_pollfd(evlist, fd, idx, revent) < 0) {
 			perf_evlist__mmap_put(evlist, idx);
 			return -1;
 		}
-- 
1.8.3.4

[toc] | [prev] | [next] | [standalone]


#1338150 — [PATCH 22/55] perf core: Prepare writing into ring buffer from end

FromWang Nan <wangnan0@huawei.com>
Date2016-02-19 13:10 +0100
Subject[PATCH 22/55] perf core: Prepare writing into ring buffer from end
Message-ID<r3S2M-4Vi-69@gated-at.bofh.it>
In reply to#1338147
Convert perf_output_begin to __perf_output_begin and make the later
function able to write records from the end of the ring buffer.
Following commits will utilize the 'backward' flag.

This patch doesn't introduce any extra performance overhead since we
use always_inline.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
---
 kernel/events/ring_buffer.c | 42 ++++++++++++++++++++++++++++++++++++------
 1 file changed, 36 insertions(+), 6 deletions(-)

diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c
index 22e1a47..37c11c6 100644
--- a/kernel/events/ring_buffer.c
+++ b/kernel/events/ring_buffer.c
@@ -102,8 +102,21 @@ out:
 	preempt_enable();
 }
 
-int perf_output_begin(struct perf_output_handle *handle,
-		      struct perf_event *event, unsigned int size)
+static bool __always_inline
+ring_buffer_has_space(unsigned long head, unsigned long tail,
+		      unsigned long data_size, unsigned int size,
+		      bool backward)
+{
+	if (!backward)
+		return CIRC_SPACE(head, tail, data_size) >= size;
+	else
+		return CIRC_SPACE(tail, head, data_size) >= size;
+}
+
+static int __always_inline
+__perf_output_begin(struct perf_output_handle *handle,
+		    struct perf_event *event, unsigned int size,
+		    bool backward)
 {
 	struct ring_buffer *rb;
 	unsigned long tail, offset, head;
@@ -146,9 +159,12 @@ int perf_output_begin(struct perf_output_handle *handle,
 	do {
 		tail = READ_ONCE(rb->user_page->data_tail);
 		offset = head = local_read(&rb->head);
-		if (!rb->overwrite &&
-		    unlikely(CIRC_SPACE(head, tail, perf_data_size(rb)) < size))
-			goto fail;
+		if (!rb->overwrite) {
+			if (unlikely(!ring_buffer_has_space(head, tail,
+							    perf_data_size(rb),
+							    size, backward)))
+				goto fail;
+		}
 
 		/*
 		 * The above forms a control dependency barrier separating the
@@ -162,9 +178,17 @@ int perf_output_begin(struct perf_output_handle *handle,
 		 * See perf_output_put_handle().
 		 */
 
-		head += size;
+		if (!backward)
+			head += size;
+		else
+			head -= size;
 	} while (local_cmpxchg(&rb->head, offset, head) != offset);
 
+	if (backward) {
+		offset = head;
+		head = (u64)(-head);
+	}
+
 	/*
 	 * We rely on the implied barrier() by local_cmpxchg() to ensure
 	 * none of the data stores below can be lifted up by the compiler.
@@ -206,6 +230,12 @@ out:
 	return -ENOSPC;
 }
 
+int perf_output_begin(struct perf_output_handle *handle,
+		      struct perf_event *event, unsigned int size)
+{
+	return __perf_output_begin(handle, event, size, false);
+}
+
 unsigned int perf_output_copy(struct perf_output_handle *handle,
 		      const void *buf, unsigned int len)
 {
-- 
1.8.3.4

[toc] | [prev] | [next] | [standalone]


#1338153 — [PATCH 12/55] perf tools: Enable config raw and numeric events

FromWang Nan <wangnan0@huawei.com>
Date2016-02-19 13:20 +0100
Subject[PATCH 12/55] perf tools: Enable config raw and numeric events
Message-ID<r3Scq-4Z3-11@gated-at.bofh.it>
In reply to#1338147
This patch allows setting config terms for raw and numeric events.
For example:

 # perf stat -e cycles/name=cyc/ ls
 ...
 1821108      cyc
 ...

 # perf stat -e r6530160/name=event/ ls
 ...
 1103195      event
 ...

 # perf record -e cycles -e 4:0x6530160/name=evtx,call-graph=fp/ -a sleep 1
 ...
 # perf report --stdio
 ...
 # Samples: 124  of event 'cycles'
 46.61%     0.00%  swapper        [kernel.vmlinux]            [k] cpu_startup_entry
 41.26%     0.00%  swapper        [kernel.vmlinux]            [k] start_secondary
 ...
 # Samples: 91  of event 'evtx'
 ...
 93.76%     0.00%  swapper      [kernel.vmlinux]            [k] cpu_startup_entry
         |
         ---cpu_startup_entry
            |
            |--66.63%--call_cpuidle
            |          cpuidle_enter
            |          |
 ...

3 test cases are introduced to test config terms for symbol, raw and
numeric events.

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: He Kuang <hekuang@huawei.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
---
 tools/perf/tests/parse-events.c | 40 ++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/parse-events.c  |  3 ++-
 tools/perf/util/parse-events.y  | 10 ++++++----
 3 files changed, 48 insertions(+), 5 deletions(-)

diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index 6648274..15e2d05 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -1271,6 +1271,31 @@ static int test__checkevent_precise_max_modifier(struct perf_evlist *evlist)
 	return 0;
 }
 
+static int test__checkevent_config_symbol(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = perf_evlist__first(evlist);
+
+	TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "insn") == 0);
+	return 0;
+}
+
+static int test__checkevent_config_raw(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = perf_evlist__first(evlist);
+
+	TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "rawpmu") == 0);
+	return 0;
+}
+
+static int test__checkevent_config_num(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = perf_evlist__first(evlist);
+
+	TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "numpmu") == 0);
+	return 0;
+}
+
+
 static int count_tracepoints(void)
 {
 	struct dirent *events_ent;
@@ -1579,6 +1604,21 @@ static struct evlist_test test__events[] = {
 		.check = test__checkevent_precise_max_modifier,
 		.id    = 47,
 	},
+	{
+		.name  = "instructions/name=insn/",
+		.check = test__checkevent_config_symbol,
+		.id    = 48,
+	},
+	{
+		.name  = "r1234/name=rawpmu/",
+		.check = test__checkevent_config_raw,
+		.id    = 49,
+	},
+	{
+		.name  = "4:0x6530160/name=numpmu/",
+		.check = test__checkevent_config_num,
+		.id    = 50,
+	},
 };
 
 static struct evlist_test test__events_pmu[] = {
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 87911ae..68a3871 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -1094,7 +1094,8 @@ int parse_events_add_numeric(struct parse_events_evlist *data,
 			return -ENOMEM;
 	}
 
-	return add_event(list, &data->idx, &attr, NULL, &config_terms);
+	return add_event(list, &data->idx, &attr,
+			 get_config_name(head_config), &config_terms);
 }
 
 int parse_events_add_pmu(struct parse_events_evlist *data,
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index 448c1ec..7ce8633 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -434,24 +434,26 @@ PE_NAME ':' PE_NAME
 }
 
 event_legacy_numeric:
-PE_VALUE ':' PE_VALUE
+PE_VALUE ':' PE_VALUE opt_event_config
 {
 	struct parse_events_evlist *data = _data;
 	struct list_head *list;
 
 	ALLOC_LIST(list);
-	ABORT_ON(parse_events_add_numeric(data, list, (u32)$1, $3, NULL));
+	ABORT_ON(parse_events_add_numeric(data, list, (u32)$1, $3, $4));
+	parse_events_terms__delete($4);
 	$$ = list;
 }
 
 event_legacy_raw:
-PE_RAW
+PE_RAW opt_event_config
 {
 	struct parse_events_evlist *data = _data;
 	struct list_head *list;
 
 	ALLOC_LIST(list);
-	ABORT_ON(parse_events_add_numeric(data, list, PERF_TYPE_RAW, $1, NULL));
+	ABORT_ON(parse_events_add_numeric(data, list, PERF_TYPE_RAW, $1, $2));
+	parse_events_terms__delete($2);
 	$$ = list;
 }
 
-- 
1.8.3.4

[toc] | [prev] | [next] | [standalone]


#1338274 — Re: [PATCH 12/55] perf tools: Enable config raw and numeric events

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2016-02-19 16:10 +0100
SubjectRe: [PATCH 12/55] perf tools: Enable config raw and numeric events
Message-ID<r3UQW-6RV-21@gated-at.bofh.it>
In reply to#1338153
Em Fri, Feb 19, 2016 at 11:44:00AM +0000, Wang Nan escreveu:
> This patch allows setting config terms for raw and numeric events.
> For example:
> 
>  # perf stat -e cycles/name=cyc/ ls
>  ...
>  1821108      cyc
>  ...
> 
>  # perf stat -e r6530160/name=event/ ls
>  ...
>  1103195      event
>  ...
> 
>  # perf record -e cycles -e 4:0x6530160/name=evtx,call-graph=fp/ -a sleep 1
>  ...
>  # perf report --stdio

Nice stuff, but I'm investigating now why I'm getting this:

  [acme@jouet linux]$ make O=/tmp/build/perf -C tools/perf install-bin
  make: Entering directory '/home/acme/git/linux/tools/perf'
    BUILD:   Doing 'make -j4' parallel build
    BISON    /tmp/build/perf/util/parse-events-bison.c
  util/parse-events.y:436.23-38: error: symbol opt_event_config is used, but is not defined as a token and has no rules
   PE_VALUE ':' PE_VALUE opt_event_config
                         ^^^^^^^^^^^^^^^^
  util/parse-events.y:442.68-69: error: $4 of ‘event_legacy_numeric’ has no declared type
   	ABORT_ON(parse_events_add_numeric(data, list, (u32)$1, $3, $4));
                                                                      ^^
  util/parse-events.y:443.36-37: error: $4 of ‘event_legacy_numeric’ has no declared type
   	parse_events_terms__delete($4);
                                      ^^
  util/parse-events.y:454.74-75: error: $2 of ‘event_legacy_raw’ has no declared type
   	ABORT_ON(parse_events_add_numeric(data, list, PERF_TYPE_RAW, $1, $2));
                                                                            ^^
  util/parse-events.y:455.36-37: error: $2 of ‘event_legacy_raw’ has no declared type
   	parse_events_terms__delete($2);
                                    ^^
  util/Build:122: recipe for target '/tmp/build/perf/util/parse-events-bison.c' failed
  make[3]: *** [/tmp/build/perf/util/parse-events-bison.c] Error 1
  /home/acme/git/linux/tools/build/Makefile.build:116: recipe for target 'util' failed
  make[2]: *** [util] Error 2
  Makefile.perf:434: recipe for target '/tmp/build/perf/libperf-in.o' failed
  make[1]: *** [/tmp/build/perf/libperf-in.o] Error 2
  make[1]: *** Waiting for unfinished jobs....
  Makefile:108: recipe for target 'install-bin' failed
  make: *** [install-bin] Error 2
  make: Leaving directory '/home/acme/git/linux/tools/perf'
  [acme@jouet linux]$ 

[toc] | [prev] | [next] | [standalone]


#1338281 — Re: [PATCH 12/55] perf tools: Enable config raw and numeric events

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2016-02-19 16:20 +0100
SubjectRe: [PATCH 12/55] perf tools: Enable config raw and numeric events
Message-ID<r3V0C-6Wq-3@gated-at.bofh.it>
In reply to#1338274
Em Fri, Feb 19, 2016 at 12:08:47PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, Feb 19, 2016 at 11:44:00AM +0000, Wang Nan escreveu:
> > This patch allows setting config terms for raw and numeric events.
> > For example:
> > 
> >  # perf stat -e cycles/name=cyc/ ls
> >  ...
> >  1821108      cyc
> >  ...
> > 
> >  # perf stat -e r6530160/name=event/ ls
> >  ...
> >  1103195      event
> >  ...
> > 
> >  # perf record -e cycles -e 4:0x6530160/name=evtx,call-graph=fp/ -a sleep 1
> >  ...
> >  # perf report --stdio
> 
> Nice stuff, but I'm investigating now why I'm getting this:
> 
>   [acme@jouet linux]$ make O=/tmp/build/perf -C tools/perf install-bin
>   make: Entering directory '/home/acme/git/linux/tools/perf'
>     BUILD:   Doing 'make -j4' parallel build
>     BISON    /tmp/build/perf/util/parse-events-bison.c
>   util/parse-events.y:436.23-38: error: symbol opt_event_config is used, but is not defined as a token and has no rules
>    PE_VALUE ':' PE_VALUE opt_event_config
>                          ^^^^^^^^^^^^^^^^

Ok, this is because I deferred the patch that introduces this
'opt_event_config' thing, that is buried in a BPF patch, when it
could've probably have stood out in a separate patch, trying that now.

- Arnaldo

[toc] | [prev] | [next] | [standalone]


#1338509 — Re: [PATCH 12/55] perf tools: Enable config raw and numeric events

FromArnaldo Carvalho de Melo <acme@kernel.org>
Date2016-02-19 23:00 +0100
SubjectRe: [PATCH 12/55] perf tools: Enable config raw and numeric events
Message-ID<r41fI-3j1-1@gated-at.bofh.it>
In reply to#1338281
Em Fri, Feb 19, 2016 at 12:15:33PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, Feb 19, 2016 at 12:08:47PM -0300, Arnaldo Carvalho de Melo escreveu:
> > Em Fri, Feb 19, 2016 at 11:44:00AM +0000, Wang Nan escreveu:
> > > This patch allows setting config terms for raw and numeric events.
> > > For example:
> > > 
> > >  # perf stat -e cycles/name=cyc/ ls
> > >  ...
> > >  1821108      cyc
> > >  ...
> > > 
> > >  # perf stat -e r6530160/name=event/ ls
> > >  ...
> > >  1103195      event
> > >  ...
> > > 
> > >  # perf record -e cycles -e 4:0x6530160/name=evtx,call-graph=fp/ -a sleep 1
> > >  ...
> > >  # perf report --stdio
> > 
> > Nice stuff, but I'm investigating now why I'm getting this:
> > 
> >   [acme@jouet linux]$ make O=/tmp/build/perf -C tools/perf install-bin
> >   make: Entering directory '/home/acme/git/linux/tools/perf'
> >     BUILD:   Doing 'make -j4' parallel build
> >     BISON    /tmp/build/perf/util/parse-events-bison.c
> >   util/parse-events.y:436.23-38: error: symbol opt_event_config is used, but is not defined as a token and has no rules
> >    PE_VALUE ':' PE_VALUE opt_event_config
> >                          ^^^^^^^^^^^^^^^^
> 
> Ok, this is because I deferred the patch that introduces this
> 'opt_event_config' thing, that is buried in a BPF patch, when it
> could've probably have stood out in a separate patch, trying that now.

Ok, so I added the patch below, that uses this opt_event_config thing to
simplify other places where the event config is optional, like
tracepoints, please see if this is ok, my bison skills are limited:

commit 095d8d6283cf8556432673c408cf85de4bbcd64d
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
Date:   Fri Feb 19 18:45:12 2016 -0300

    perf tools: Introduce opt_event_config nonterminal
    
    To remove duplicated code that differs only in using the matching
    '/a,b,c/' part or NULL if no event configuration is done ('//' or no
    pair of slashes at all).
    
    Will be used by some new targets allowing the configuration of hardware
    events, etc.
    
    Lifted part of the 'opt_event_config' nonterminal from a patch by Wang
    Nan.
    
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexei Starovoitov <ast@kernel.org>
    Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
    Cc: Cody P Schafer <dev@codyps.com>
    Cc: He Kuang <hekuang@huawei.com>
    Cc: Jeremie Galarneau <jeremie.galarneau@efficios.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Kirill Smelkov <kirr@nexedi.com>
    Cc: Li Zefan <lizefan@huawei.com>
    Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Zefan Li <lizefan@huawei.com>
    Cc: pi3orama@163.com
    Link: http://lkml.kernel.org/n/tip-e3xzpx9cqsmwnaguaxyw6r42@git.kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index c0eac88ef474..ce68746bdc89 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -64,6 +64,7 @@ static inc_group_count(struct list_head *list,
 %type <str> PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT
 %type <num> value_sym
 %type <head> event_config
+%type <head> opt_event_config
 %type <term> event_term
 %type <head> event_pmu
 %type <head> event_legacy_symbol
@@ -222,16 +223,6 @@ PE_NAME '/' event_config '/'
 	$$ = list;
 }
 |
-PE_NAME '/' '/'
-{
-	struct parse_events_evlist *data = _data;
-	struct list_head *list;
-
-	ALLOC_LIST(list);
-	ABORT_ON(parse_events_add_pmu(data, list, $1, NULL));
-	$$ = list;
-}
-|
 PE_KERNEL_PMU_EVENT sep_dc
 {
 	struct parse_events_evlist *data = _data;
@@ -378,7 +369,7 @@ PE_PREFIX_MEM PE_VALUE sep_dc
 }
 
 event_legacy_tracepoint:
-tracepoint_name
+tracepoint_name opt_event_config
 {
 	struct parse_events_evlist *data = _data;
 	struct parse_events_error *error = data->error;
@@ -389,24 +380,7 @@ tracepoint_name
 		error->idx = @1.first_column;
 
 	if (parse_events_add_tracepoint(list, &data->idx, $1.sys, $1.event,
-					error, NULL))
-		return -1;
-
-	$$ = list;
-}
-|
-tracepoint_name '/' event_config '/'
-{
-	struct parse_events_evlist *data = _data;
-	struct parse_events_error *error = data->error;
-	struct list_head *list;
-
-	ALLOC_LIST(list);
-	if (error)
-		error->idx = @1.first_column;
-
-	if (parse_events_add_tracepoint(list, &data->idx, $1.sys, $1.event,
-					error, $3))
+					error, $2))
 		return -1;
 
 	$$ = list;
@@ -476,6 +450,21 @@ PE_BPF_SOURCE
 	$$ = list;
 }
 
+opt_event_config:
+'/' event_config '/'
+{
+	$$ = $2;
+}
+|
+'/' '/'
+{
+	$$ = NULL;
+}
+|
+{
+	$$ = NULL;
+}
+
 start_terms: event_config
 {
 	struct parse_events_terms *data = _data;

[toc] | [prev] | [next] | [standalone]


#1338711 — [tip:perf/core] perf tools: Enable config raw and numeric events

Fromtip-bot for Wang Nan <tipbot@zytor.com>
Date2016-02-20 12:40 +0100
Subject[tip:perf/core] perf tools: Enable config raw and numeric events
Message-ID<r4e3j-4EY-83@gated-at.bofh.it>
In reply to#1338153
Commit-ID:  10bf358a1b79fa1311eb05ee31f2cefdcad01741
Gitweb:     http://git.kernel.org/tip/10bf358a1b79fa1311eb05ee31f2cefdcad01741
Author:     Wang Nan <wangnan0@huawei.com>
AuthorDate: Fri, 19 Feb 2016 11:44:00 +0000
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Fri, 19 Feb 2016 19:12:50 -0300

perf tools: Enable config raw and numeric events

This patch allows setting config terms for raw and numeric events.
For example:

  # perf stat -e cycles/name=cyc/ ls
  ...
  1821108      cyc
  ...

  # perf stat -e r6530160/name=event/ ls
  ...
  1103195      event
  ...

  # perf record -e cycles -e 4:0x6530160/name=evtx,call-graph=fp/ -a sleep 1
  ...
  # perf report --stdio
  ...
  # Samples: 124  of event 'cycles'
  46.61%     0.00%  swapper        [kernel.vmlinux]            [k] cpu_startup_entry
  41.26%     0.00%  swapper        [kernel.vmlinux]            [k] start_secondary
  ...
  # Samples: 91  of event 'evtx'
  ...
  93.76%     0.00%  swapper      [kernel.vmlinux]            [k] cpu_startup_entry
          |
          ---cpu_startup_entry
             |
             |--66.63%--call_cpuidle
             |          cpuidle_enter
             |          |
  ...

3 test cases are introduced to test config terms for symbol, raw and
numeric events.

Committer note:

Further testing shows that we can retrieve the event name using 'perf
evlist -v' and looking at the 'config' perf_event_attr field, i.e.:

  # perf record -e cycles -e 4:0x6530160/name=evtx,call-graph=fp/ -a sleep 1
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 1.724 MB perf.data (2076 samples) ]
  # perf evlist
  cycles
  evtx
  # perf evlist -v
  cycles: size: 112, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CPU|PERIOD|IDENTIFIER, read_format: ID, disabled: 1, inherit: 1, mmap: 1, comm: 1, freq: 1, task: 1, sample_id_all: 1, exclude_guest: 1, mmap2: 1, comm_exec: 1
evtx: type: 4, size: 112, config: 0x6530160, { sample_period, sample_freq }: 4000, sample_type: IP|TID|TIME|CALLCHAIN|CPU|PERIOD|IDENTIFIER, read_format: ID, disabled: 1, inherit: 1, freq: 1, sample_id_all: 1, exclude_guest: 1
  #

Signed-off-by: Wang Nan <wangnan0@huawei.com>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Cody P Schafer <dev@codyps.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jeremie Galarneau <jeremie.galarneau@efficios.com>
Cc: Kirill Smelkov <kirr@nexedi.com>
Cc: Li Zefan <lizefan@huawei.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Zefan Li <lizefan@huawei.com>
Cc: pi3orama@163.com
Link: http://lkml.kernel.org/r/1455882283-79592-13-git-send-email-wangnan0@huawei.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/tests/parse-events.c | 40 ++++++++++++++++++++++++++++++++++++++++
 tools/perf/util/parse-events.c  |  3 ++-
 tools/perf/util/parse-events.y  | 10 ++++++----
 3 files changed, 48 insertions(+), 5 deletions(-)

diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index 6648274..15e2d05 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -1271,6 +1271,31 @@ static int test__checkevent_precise_max_modifier(struct perf_evlist *evlist)
 	return 0;
 }
 
+static int test__checkevent_config_symbol(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = perf_evlist__first(evlist);
+
+	TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "insn") == 0);
+	return 0;
+}
+
+static int test__checkevent_config_raw(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = perf_evlist__first(evlist);
+
+	TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "rawpmu") == 0);
+	return 0;
+}
+
+static int test__checkevent_config_num(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel = perf_evlist__first(evlist);
+
+	TEST_ASSERT_VAL("wrong name setting", strcmp(evsel->name, "numpmu") == 0);
+	return 0;
+}
+
+
 static int count_tracepoints(void)
 {
 	struct dirent *events_ent;
@@ -1579,6 +1604,21 @@ static struct evlist_test test__events[] = {
 		.check = test__checkevent_precise_max_modifier,
 		.id    = 47,
 	},
+	{
+		.name  = "instructions/name=insn/",
+		.check = test__checkevent_config_symbol,
+		.id    = 48,
+	},
+	{
+		.name  = "r1234/name=rawpmu/",
+		.check = test__checkevent_config_raw,
+		.id    = 49,
+	},
+	{
+		.name  = "4:0x6530160/name=numpmu/",
+		.check = test__checkevent_config_num,
+		.id    = 50,
+	},
 };
 
 static struct evlist_test test__events_pmu[] = {
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 3243e95..75576e1 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -1043,7 +1043,8 @@ int parse_events_add_numeric(struct parse_events_evlist *data,
 			return -ENOMEM;
 	}
 
-	return add_event(list, &data->idx, &attr, NULL, &config_terms);
+	return add_event(list, &data->idx, &attr,
+			 get_config_name(head_config), &config_terms);
 }
 
 int parse_events_add_pmu(struct parse_events_evlist *data,
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index ce68746..82029f9 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -407,24 +407,26 @@ PE_NAME ':' PE_NAME
 }
 
 event_legacy_numeric:
-PE_VALUE ':' PE_VALUE
+PE_VALUE ':' PE_VALUE opt_event_config
 {
 	struct parse_events_evlist *data = _data;
 	struct list_head *list;
 
 	ALLOC_LIST(list);
-	ABORT_ON(parse_events_add_numeric(data, list, (u32)$1, $3, NULL));
+	ABORT_ON(parse_events_add_numeric(data, list, (u32)$1, $3, $4));
+	parse_events_terms__delete($4);
 	$$ = list;
 }
 
 event_legacy_raw:
-PE_RAW
+PE_RAW opt_event_config
 {
 	struct parse_events_evlist *data = _data;
 	struct list_head *list;
 
 	ALLOC_LIST(list);
-	ABORT_ON(parse_events_add_numeric(data, list, PERF_TYPE_RAW, $1, NULL));
+	ABORT_ON(parse_events_add_numeric(data, list, PERF_TYPE_RAW, $1, $2));
+	parse_events_terms__delete($2);
 	$$ = list;
 }
 

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web