Skip to contentSkip to conversation

perf tools: fixes and tweaks

PATCH Superseded Adrian Hunter 5 participants 54 messages Oct 18, 2013 – Oct 23, 2013 perf events

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Adrian Hunter

author reviewer
#0 lore raw

cover perf tools: fixes and tweaks

Hi

Here are some fixes and tweaks for perf tools.

Adrian Hunter (19):
perf evsel: Add missing 'mmap2' from debug print
perf evsel: Add a debug print if perf_event_open fails perf record: Improve write_output error message
perf evsel: Add missing decrement in id sample parsing perf session: Add missing sample flush for piped events perf session: Add missing members to perf_event__attr_swap() perf script: Set up output options for in-stream attributes perf inject: Do not repipe attributes to a perf.data file perf tools: Fix 32-bit cross build
perf evlist: Fix 32-bit build error
perf tools: Fix test_on_exit for 32-bit build
perf tools: Fix bench/numa.c for 32-bit build
perf tools: Fix libunwind build and feature detection for 32-bit build perf evlist: Add a debug print if event buffer mmap fails perf tools: fix perf_evlist__mmap comments
perf tools: factor out duplicated evlist mmap code
perf script: print addr by default for BTS
perf record: add an option to force per-cpu mmaps
perf tools: allow non-matching sample types

 tools/perf/Documentation/perf-record.txt        |   6 ++
 tools/perf/Makefile.perf                        |   2 +-
 tools/perf/bench/numa.c                         |   4 +-
 tools/perf/builtin-inject.c                     |   5 +
 tools/perf/builtin-record.c                     |   4 +-
 tools/perf/builtin-script.c                     | 106 ++++++++++++++------
 tools/perf/config/Makefile                      |   8 +-
 tools/perf/config/feature-checks/Makefile       |   6 +-
 tools/perf/config/feature-checks/test-on-exit.c |   1 +
 tools/perf/util/event.h                         |  16 +++
 tools/perf/util/evlist.c                        | 126 ++++++++++++++----------
 tools/perf/util/evlist.h                        |   1 +
 tools/perf/util/evsel.c                         |   8 +-
 tools/perf/util/record.c                        |   5 +-
 tools/perf/util/session.c                       |  11 ++-
 tools/perf/util/target.h                        |   1 +
 16 files changed, 211 insertions(+), 99 deletions(-)

Regards
Adrian

author reviewer
#1 lore raw

PATCH 1/19 perf evsel: Add missing 'mmap2' from debug print

struct perf_event_attr now has 'mmap2'. Add it to perf_event_attr__fprintf().

---
 tools/perf/util/evsel.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/evsel.c +1 -0
index bfebc1e..291b18a 100644
@@ -986,6 +986,7 @@ static size_t perf_event_attr__fprintf(struct perf_event_attr *attr, FILE *fp)
 	ret += PRINT_ATTR2(exclude_host, exclude_guest);
 	ret += PRINT_ATTR2N("excl.callchain_kern", exclude_callchain_kernel,
 			    "excl.callchain_user", exclude_callchain_user);
+	ret += PRINT_ATTR_U32(mmap2);
 
 	ret += PRINT_ATTR_U32(wakeup_events);
 	ret += PRINT_ATTR_U32(wakeup_watermark);
Signature · 1 line
1.7.11.7
#2 lore raw

[tip:perf/core] perf evsel: Add missing 'mmap2' from debug print

perf evsel: Add missing 'mmap2' from debug print
Commit-ID:  40d54ec2f77edc52340dcae236aaabe8c3cc3a07
Gitweb:     http://git.kernel.org/tip/40d54ec2f77edc52340dcae236aaabe8c3cc3a07
Author:     Adrian Hunter <[email protected]>
AuthorDate: Fri, 18 Oct 2013 15:28:58 +0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 18 Oct 2013 10:43:14 -0300

perf evsel: Add missing 'mmap2' from debug print

The struct perf_event_attr now has a 'mmap2' member. Add it to perf_event_attr__fprintf().

Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/util/evsel.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/evsel.c +1 -0
index bfebc1e..291b18a 100644
@@ -986,6 +986,7 @@ static size_t perf_event_attr__fprintf(struct perf_event_attr *attr, FILE *fp)
 	ret += PRINT_ATTR2(exclude_host, exclude_guest);
 	ret += PRINT_ATTR2N("excl.callchain_kern", exclude_callchain_kernel,
 			    "excl.callchain_user", exclude_callchain_user);
+	ret += PRINT_ATTR_U32(mmap2);
 
 	ret += PRINT_ATTR_U32(wakeup_events);
 	ret += PRINT_ATTR_U32(wakeup_watermark);
author reviewer
#3 lore raw

PATCH 2/19 perf evsel: Add a debug print if perf_event_open fails

In reply to Adrian Hunter

There is a debug print (at verbose level 2) for each call to perf_event_open. Add another debug print if the call fails, and print the error number.

---
 tools/perf/util/evsel.c | 2 ++
 1 file changed, 2 insertions(+)
tools/perf/util/evsel.c +2 -0
index 291b18a..1bb4f19 100644
@@ -1052,6 +1052,8 @@ retry_open:
 								     group_fd, flags);
 			if (FD(evsel, cpu, thread) < 0) {
 				err = -errno;
+				pr_debug2("perf_event_open failed, error %d\n",
+					  err);
 				goto try_fallback;
 			}
 			set_rlimit = NO_CHANGE;
Signature · 1 line
1.7.11.7
author reviewer
#4 lore raw

PATCH 3/19 perf record: Improve write_output error message

In reply to Adrian Hunter

Improve the error message from write_output() to say what failed to write and give the error number.

---
 tools/perf/builtin-record.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-record.c +1 -1
index 92ca541..d269dfa 100644
@@ -88,7 +88,7 @@ static int write_output(struct perf_record *rec, void *buf, size_t size)
 		int ret = write(rec->output, buf, size);
 
 		if (ret < 0) {
-			pr_err("failed to write\n");
+			pr_err("failed to write perf data, error: %m\n");
 			return -1;
 		}
 
Signature · 1 line
1.7.11.7
#5 lore raw

Re: [PATCH 03/19] perf record: Improve write_output error message

Quoted 13 lines · Adrian Hunter

Improve the error message from write_output() to say what failed to write and give the error number.

---
 tools/perf/builtin-record.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-record.c +0 -0
index 92ca541..d269dfa 100644

tools/perf/builtin-record.c static int write_output(struct perf_record *rec, void *buf, size_t size) · line 91

Quoted 5 lines
tools/perf/builtin-record.c +1 -1
@@ -88,7 +88,7 @@ static int write_output(struct perf_record *rec, void *buf, size_t size)
 		int ret = write(rec->output, buf, size);
 
 		if (ret < 0) {
-			pr_err("failed to write\n");
+			pr_err("failed to write perf data, error: %m\n");

is this some kind of format magic? ;-) you wanted
to print out 'ret' value, right?

jirka

author reviewer
#6 lore raw

Re: [PATCH 03/19] perf record: Improve write_output error message

Quoted 16 lines · Jiri Olsa
Quoted 15 lines · Adrian Hunter

Improve the error message from write_output() to say what failed to write and give the error number.

---
 tools/perf/builtin-record.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-record.c +0 -0
index 92ca541..d269dfa 100644
@@ -88,7 +88,7 @@ static int write_output(struct perf_record *rec, void *buf, size_t size)
 		int ret = write(rec->output, buf, size);
 
Quoted 5 lines

tools/perf/builtin-record.c static int write_output(struct perf_record *rec, void *buf, size_t size) · line 91

Quoted 3 lines
tools/perf/builtin-record.c +1 -1
 		if (ret < 0) {
-			pr_err("failed to write\n");
+			pr_err("failed to write perf data, error: %m\n");

is this some kind of format magic? ;-) you wanted

It is a glibc extension.

Quoted 1 line

to print out 'ret' value, right?

No, errno

#7 lore raw

Re: [PATCH 03/19] perf record: Improve write_output error message

Quoted 23 lines · Adrian Hunter
Quoted 16 lines · Jiri Olsa
Quoted 15 lines · Adrian Hunter

Improve the error message from write_output() to say what failed to write and give the error number.

---
 tools/perf/builtin-record.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-record.c +0 -0
index 92ca541..d269dfa 100644
@@ -88,7 +88,7 @@ static int write_output(struct perf_record *rec, void *buf, size_t size)
 		int ret = write(rec->output, buf, size);
 
Quoted 5 lines

tools/perf/builtin-record.c static int write_output(struct perf_record *rec, void *buf, size_t size) · line 91

Quoted 3 lines
tools/perf/builtin-record.c +1 -1
 		if (ret < 0) {
-			pr_err("failed to write\n");
+			pr_err("failed to write perf data, error: %m\n");

is this some kind of format magic? ;-) you wanted

Quoted 6 lines

It is a glibc extension.

Quoted 1 line

to print out 'ret' value, right?

No, errno

ok, thanks

jirka

#8 lore raw

[tip:perf/core] perf record: Improve write_output error message

In reply to Adrian Hunter
perf record: Improve write_output error message
Commit-ID:  4f624685f92719565981eb6f8d9195bb578522a3
Gitweb:     http://git.kernel.org/tip/4f624685f92719565981eb6f8d9195bb578522a3
Author:     Adrian Hunter <[email protected]>
AuthorDate: Fri, 18 Oct 2013 15:29:00 +0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 21 Oct 2013 11:19:06 -0300

perf record: Improve write_output error message

Improve the error message from write_output() to say what failed to write and give the error number.

Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/builtin-record.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-record.c +1 -1
index 92ca541..d269dfa 100644
@@ -88,7 +88,7 @@ static int write_output(struct perf_record *rec, void *buf, size_t size)
 		int ret = write(rec->output, buf, size);
 
 		if (ret < 0) {
-			pr_err("failed to write\n");
+			pr_err("failed to write perf data, error: %m\n");
 			return -1;
 		}
 
author reviewer
#9 lore raw

PATCH 4/19 perf evsel: Add missing decrement in id sample parsing

In reply to Adrian Hunter

The final array decrement in id sample parsing is missing, which may trip up the next person adding a sample format, so add it in.

---
 tools/perf/util/evsel.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/evsel.c +1 -0
index 1bb4f19..e09c7e6 100644
@@ -1220,6 +1220,7 @@ static int perf_evsel__parse_id_sample(const struct perf_evsel *evsel,
 
 		sample->pid = u.val32[0];
 		sample->tid = u.val32[1];
+		array--;
 	}
 
 	return 0;
Signature · 1 line
1.7.11.7
Acked-by on v1 4/19
#10 lore raw

Re: [PATCH 04/19] perf evsel: Add missing decrement in id sample parsing

Quoted 3 lines · Adrian Hunter

The final array decrement in id sample parsing is missing, which may trip up the next person adding a sample format, so add it in.

jirka

#11 lore raw

[tip:perf/core] perf evsel: Add missing decrement in id sample parsing

In reply to Adrian Hunter
perf evsel: Add missing decrement in id sample parsing
Commit-ID:  dd44bc6be05e4a948124053c8105cfa581177554
Gitweb:     http://git.kernel.org/tip/dd44bc6be05e4a948124053c8105cfa581177554
Author:     Adrian Hunter <[email protected]>
AuthorDate: Fri, 18 Oct 2013 15:29:01 +0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 21 Oct 2013 11:18:49 -0300

perf evsel: Add missing decrement in id sample parsing

The final array decrement in id sample parsing is missing, which may trip up the next person adding a sample format, so add it in.

Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/util/evsel.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/evsel.c +1 -0
index 291b18a..ec0cc1e 100644
@@ -1218,6 +1218,7 @@ static int perf_evsel__parse_id_sample(const struct perf_evsel *evsel,
 
 		sample->pid = u.val32[0];
 		sample->tid = u.val32[1];
+		array--;
 	}
 
 	return 0;
author reviewer
#12 lore raw

PATCH 5/19 perf session: Add missing sample flush for piped events

In reply to Adrian Hunter

Piped events can be sorted so a final flush is needed. Add that and remove a redundant 'err = 0'.

---
 tools/perf/util/session.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
tools/perf/util/session.c +5 -3
index d1e4495..d51e62d 100644
@@ -1263,7 +1263,9 @@ more:
 	if (!session_done())
 		goto more;
 done:
-	err = 0;
+	/* do the final flush for ordered samples */
+	self->ordered_samples.next_flush = ULLONG_MAX;
+	err = flush_sample_queue(self, tool);
 out_err:
 	free(buf);
 	perf_session__warn_about_errors(self, tool);
@@ -1392,13 +1394,13 @@ more:
 				    "Processing events...");
 	}
 
-	err = 0;
 	if (session_done())
-		goto out_err;
+		goto out;
 
 	if (file_pos < file_size)
 		goto more;
 
+out:
 	/* do the final flush for ordered samples */
 	session->ordered_samples.next_flush = ULLONG_MAX;
 	err = flush_sample_queue(session, tool);
Signature · 1 line
1.7.11.7
#14 lore raw

[tip:perf/core] perf session: Add missing sample flush for piped events

In reply to Adrian Hunter
perf session: Add missing sample flush for piped events
Commit-ID:  8c16b649606ff9f6d742ad6f71c76fc0ee996c8e
Gitweb:     http://git.kernel.org/tip/8c16b649606ff9f6d742ad6f71c76fc0ee996c8e
Author:     Adrian Hunter <[email protected]>
AuthorDate: Fri, 18 Oct 2013 15:29:02 +0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 21 Oct 2013 11:19:07 -0300

perf session: Add missing sample flush for piped events

Piped events can be sorted so a final flush is needed.

Add that and remove a redundant 'err = 0'.

Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/util/session.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
tools/perf/util/session.c +5 -3
index d1e4495..d51e62d 100644
@@ -1263,7 +1263,9 @@ more:
 	if (!session_done())
 		goto more;
 done:
-	err = 0;
+	/* do the final flush for ordered samples */
+	self->ordered_samples.next_flush = ULLONG_MAX;
+	err = flush_sample_queue(self, tool);
 out_err:
 	free(buf);
 	perf_session__warn_about_errors(self, tool);
@@ -1392,13 +1394,13 @@ more:
 				    "Processing events...");
 	}
 
-	err = 0;
 	if (session_done())
-		goto out_err;
+		goto out;
 
 	if (file_pos < file_size)
 		goto more;
 
+out:
 	/* do the final flush for ordered samples */
 	session->ordered_samples.next_flush = ULLONG_MAX;
 	err = flush_sample_queue(session, tool);
author reviewer
#15 lore raw

PATCH 6/19 perf session: Add missing members to perf_event__attr_swap()

In reply to Adrian Hunter

perf_event__attr_swap() needs to swap all members of struct perf_event_attr. Add mssing ones.

---
 tools/perf/util/session.c | 3 +++
 1 file changed, 3 insertions(+)
tools/perf/util/session.c +3 -0
index d51e62d..d4559ca 100644
@@ -453,6 +453,9 @@ void perf_event__attr_swap(struct perf_event_attr *attr)
 	attr->bp_type		= bswap_32(attr->bp_type);
 	attr->bp_addr		= bswap_64(attr->bp_addr);
 	attr->bp_len		= bswap_64(attr->bp_len);
+	attr->branch_sample_type = bswap_64(attr->branch_sample_type);
+	attr->sample_regs_user	 = bswap_64(attr->sample_regs_user);
+	attr->sample_stack_user  = bswap_32(attr->sample_stack_user);
 
 	swap_bitfield((u8 *) (&attr->read_format + 1), sizeof(u64));
 }
Signature · 1 line
1.7.11.7
Acked-by on v1 6/19
#16 lore raw

Re: [PATCH 06/19] perf session: Add missing members to perf_event__attr_swap()

Quoted 2 lines · Adrian Hunter

perf_event__attr_swap() needs to swap all members of struct perf_event_attr. Add mssing ones.

jirka

#17 lore raw

[tip:perf/core] perf session: Add missing members to perf_event__attr_swap()

In reply to Adrian Hunter
perf session: Add missing members to perf_event__attr_swap()
Commit-ID:  7db5952846dfa015d74e64b5e8656acac979490b
Gitweb:     http://git.kernel.org/tip/7db5952846dfa015d74e64b5e8656acac979490b
Author:     Adrian Hunter <[email protected]>
AuthorDate: Fri, 18 Oct 2013 15:29:03 +0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 21 Oct 2013 11:19:24 -0300

perf session: Add missing members to perf_event__attr_swap()

The perf_event__attr_swap() method needs to swap all members of struct perf_event_attr. Add missing ones.

Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/util/session.c | 3 +++
 1 file changed, 3 insertions(+)
tools/perf/util/session.c +3 -0
index d51e62d..d4559ca 100644
@@ -453,6 +453,9 @@ void perf_event__attr_swap(struct perf_event_attr *attr)
 	attr->bp_type		= bswap_32(attr->bp_type);
 	attr->bp_addr		= bswap_64(attr->bp_addr);
 	attr->bp_len		= bswap_64(attr->bp_len);
+	attr->branch_sample_type = bswap_64(attr->branch_sample_type);
+	attr->sample_regs_user	 = bswap_64(attr->sample_regs_user);
+	attr->sample_stack_user  = bswap_32(attr->sample_stack_user);
 
 	swap_bitfield((u8 *) (&attr->read_format + 1), sizeof(u64));
 }
author reviewer
#18 lore raw

PATCH 7/19 perf script: Set up output options for in-stream attributes

In reply to Adrian Hunter

Attributes (struct perf_event_attr) are recorded separately in the perf.data file. perf script uses them to set up output options. However attributes can also be in the event stream, for example when the input is a pipe (i.e. live mode). This patch makes perf script process in-stream attributes in the same way as on-file attributes.

Here is an example:

Before this patch:

$ perf record uname | perf script
Linux
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.015 MB (null) (~655 samples) ]
:4220  4220 [-01] 2933367.838906: cycles:

:4220 4220 [-01] 2933367.838910: cycles:

:4220 4220 [-01] 2933367.838912: cycles:

:4220 4220 [-01] 2933367.838914: cycles:

:4220 4220 [-01] 2933367.838916: cycles:

:4220 4220 [-01] 2933367.838918: cycles:

uname 4220 [-01] 2933367.838938: cycles:

uname 4220 [-01] 2933367.839207: cycles:

After this patch:

$ perf record uname | perf script
Linux
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.015 MB (null) (~655 samples) ]
           :4582  4582 2933425.707724: cycles:  ffffffff81043ffa native_write_msr_safe ([kernel.kallsyms])
           :4582  4582 2933425.707728: cycles:  ffffffff81043ffa native_write_msr_safe ([kernel.kallsyms])
           :4582  4582 2933425.707730: cycles:  ffffffff81043ffa native_write_msr_safe ([kernel.kallsyms])
           :4582  4582 2933425.707732: cycles:  ffffffff81043ffa native_write_msr_safe ([kernel.kallsyms])
           :4582  4582 2933425.707734: cycles:  ffffffff81043ffa native_write_msr_safe ([kernel.kallsyms])
           :4582  4582 2933425.707736: cycles:  ffffffff81309a24 memcpy ([kernel.kallsyms])
           uname  4582 2933425.707760: cycles:  ffffffff8109c1c7 enqueue_task_fair ([kernel.kallsyms])
           uname  4582 2933425.707978: cycles:  ffffffff81308457 clear_page_c ([kernel.kallsyms])
---
 tools/perf/builtin-script.c | 102 ++++++++++++++++++++++++++++++--------------
 1 file changed, 71 insertions(+), 31 deletions(-)
tools/perf/builtin-script.c +71 -31
index 9c333ff..3f9a9bf 100644
@@ -228,6 +228,24 @@ static int perf_evsel__check_attr(struct perf_evsel *evsel,
 	return 0;
 }
 
+static void set_print_ip_opts(struct perf_event_attr *attr)
+{
+	unsigned int type = attr->type;
+
+	output[type].print_ip_opts = 0;
+	if (PRINT_FIELD(IP))
+		output[type].print_ip_opts |= PRINT_IP_OPT_IP;
+
+	if (PRINT_FIELD(SYM))
+		output[type].print_ip_opts |= PRINT_IP_OPT_SYM;
+
+	if (PRINT_FIELD(DSO))
+		output[type].print_ip_opts |= PRINT_IP_OPT_DSO;
+
+	if (PRINT_FIELD(SYMOFFSET))
+		output[type].print_ip_opts |= PRINT_IP_OPT_SYMOFFSET;
+}
+
 /*
  * verify all user requested events exist and the samples
  * have the expected data
@@ -236,7 +254,6 @@ static int perf_session__check_output_opt(struct perf_session *session)
 {
 	int j;
 	struct perf_evsel *evsel;
-	struct perf_event_attr *attr;
 
 	for (j = 0; j < PERF_TYPE_MAX; ++j) {
 		evsel = perf_session__find_first_evtype(session, j);
@@ -259,20 +276,7 @@ static int perf_session__check_output_opt(struct perf_session *session)
 		if (evsel == NULL)
 			continue;
 
-		attr = &evsel->attr;
-
-		output[j].print_ip_opts = 0;
-		if (PRINT_FIELD(IP))
-			output[j].print_ip_opts |= PRINT_IP_OPT_IP;
-
-		if (PRINT_FIELD(SYM))
-			output[j].print_ip_opts |= PRINT_IP_OPT_SYM;
-
-		if (PRINT_FIELD(DSO))
-			output[j].print_ip_opts |= PRINT_IP_OPT_DSO;
-
-		if (PRINT_FIELD(SYMOFFSET))
-			output[j].print_ip_opts |= PRINT_IP_OPT_SYMOFFSET;
+		set_print_ip_opts(&evsel->attr);
 	}
 
 	return 0;
@@ -539,32 +543,51 @@ static int process_sample_event(struct perf_tool *tool __maybe_unused,
 	return 0;
 }
 
-static struct perf_tool perf_script = {
-	.sample		 = process_sample_event,
-	.mmap		 = perf_event__process_mmap,
-	.mmap2		 = perf_event__process_mmap2,
-	.comm		 = perf_event__process_comm,
-	.exit		 = perf_event__process_exit,
-	.fork		 = perf_event__process_fork,
-	.attr		 = perf_event__process_attr,
-	.tracing_data	 = perf_event__process_tracing_data,
-	.build_id	 = perf_event__process_build_id,
-	.ordered_samples = true,
-	.ordering_requires_timestamps = true,
+struct perf_script {
+	struct perf_tool	tool;
+	struct perf_session	*session;
 };
 
+static int process_attr(struct perf_tool *tool, union perf_event *event,
+			struct perf_evlist **pevlist)
+{
+	struct perf_script *scr = container_of(tool, struct perf_script, tool);
+	struct perf_evlist *evlist;
+	struct perf_evsel *evsel, *pos;
+	int err;
+
+	err = perf_event__process_attr(tool, event, pevlist);
+	if (err)
+		return err;
+
+	evlist = *pevlist;
+	evsel = perf_evlist__last(*pevlist);
+
+	if (evsel->attr.type >= PERF_TYPE_MAX)
+		return 0;
+
+	list_for_each_entry(pos, &evlist->entries, node) {
+		if (pos->attr.type == evsel->attr.type && pos != evsel)
+			return 0;
+	}
+
+	set_print_ip_opts(&evsel->attr);
+
+	return perf_evsel__check_attr(evsel, scr->session);
+}
+
 static void sig_handler(int sig __maybe_unused)
 {
 	session_done = 1;
 }
 
-static int __cmd_script(struct perf_session *session)
+static int __cmd_script(struct perf_script *scr)
 {
 	int ret;
 
 	signal(SIGINT, sig_handler);
 
-	ret = perf_session__process_events(session, &perf_script);
+	ret = perf_session__process_events(scr->session, &scr->tool);
 
 	if (debug_mode)
 		pr_err("Misordered timestamps: %" PRIu64 "\n", nr_unordered);
@@ -1266,6 +1289,21 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 	char *script_path = NULL;
 	const char **__argv;
 	int i, j, err;
+	struct perf_script perf_script = {
+		.tool = {
+			.sample		 = process_sample_event,
+			.mmap		 = perf_event__process_mmap,
+			.mmap2		 = perf_event__process_mmap2,
+			.comm		 = perf_event__process_comm,
+			.exit		 = perf_event__process_exit,
+			.fork		 = perf_event__process_fork,
+			.attr		 = process_attr,
+			.tracing_data	 = perf_event__process_tracing_data,
+			.build_id	 = perf_event__process_build_id,
+			.ordered_samples = true,
+			.ordering_requires_timestamps = true,
+		},
+	};
 	const struct option options[] = {
 	OPT_BOOLEAN('D', "dump-raw-trace", &dump_trace,
 		    "dump raw trace in ASCII"),
@@ -1487,10 +1525,12 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 		setup_pager();
 
 	session = perf_session__new(input_name, O_RDONLY, 0, false,
-				    &perf_script);
+				    &perf_script.tool);
 	if (session == NULL)
 		return -ENOMEM;
 
+	perf_script.session = session;
+
 	if (cpu_list) {
 		if (perf_session__cpu_bitmap(session, cpu_list, cpu_bitmap))
 			return -1;
@@ -1554,7 +1594,7 @@ int cmd_script(int argc, const char **argv, const char *prefix __maybe_unused)
 	if (err < 0)
 		goto out;
 
-	err = __cmd_script(session);
+	err = __cmd_script(&perf_script);
 
 	perf_session__delete(session);
 	cleanup_scripting();
Signature · 1 line
1.7.11.7
#19 lore raw

Re: [PATCH 07/19] perf script: Set up output options for in-stream attributes

Quoted 7 lines · Adrian Hunter

Attributes (struct perf_event_attr) are recorded separately in the perf.data file. perf script uses them to set up output options. However attributes can also be in the event stream, for example when the input is a pipe (i.e. live mode). This patch makes perf script process in-stream attributes in the same way as on-file attributes.

You have multiple changes in this patch -- expanding attribute processing to set output options per the description above and you are also making perf_script a stack variable. The latter should be a separate patch.

David

#20 lore raw

Re: [PATCH 07/19] perf script: Set up output options for in-stream attributes

Em Fri, Oct 18, 2013 at 07:30:13AM -0600, David Ahern escreveu:

Quoted 8 lines · Adrian Hunter
Quoted 6 lines

Attributes (struct perf_event_attr) are recorded separately in the perf.data file. perf script uses them to set up output options. However attributes can also be in the event stream, for example when the input is a pipe (i.e. live mode). This patch makes perf script process in-stream attributes in the same way as on-file attributes.

Quoted 4 lines

You have multiple changes in this patch -- expanding attribute processing to set output options per the description above and you are also making perf_script a stack variable. The latter should be a separate patch.

Agreed, and this conversion of struct perf_script to be a stack variable is nice (killing globals, a favourite pastime, yeah!), I like it, but in the past one such conversion showed something nasty that made several people stare at the build seeing builtin-sched.o take ages to build...

Please consider testing before/after that specific stack move:

commit f36f83f947ede547833e462696893f866df77324

Author: Namhyung Kim <[email protected]>
Date:   Tue Jun 4 14:46:19 2013 +0900

perf sched: Move struct perf_sched definition out of cmd_sched()

For some reason it consumed quite amount of compile time when declared as local variable, and it disappeared when moved out of the function. Moving other variables/tables didn't help.

On my system this single-file-change build time reduced from 11s to 3s.

author reviewer
#21 lore raw

Re: [PATCH 07/19] perf script: Set up output options for in-stream attributes

Quoted 14 lines · Arnaldo Carvalho de Melo

Em Fri, Oct 18, 2013 at 07:30:13AM -0600, David Ahern escreveu:

Quoted 8 lines · Adrian Hunter
Quoted 6 lines

Attributes (struct perf_event_attr) are recorded separately in the perf.data file. perf script uses them to set up output options. However attributes can also be in the event stream, for example when the input is a pipe (i.e. live mode). This patch makes perf script process in-stream attributes in the same way as on-file attributes.

Quoted 4 lines

You have multiple changes in this patch -- expanding attribute processing to set output options per the description above and you are also making perf_script a stack variable. The latter should be a separate patch.

Quoted 4 lines

Agreed, and this conversion of struct perf_script to be a stack variable is nice (killing globals, a favourite pastime, yeah!), I like it, but in the past one such conversion showed something nasty that made several people stare at the build seeing builtin-sched.o take ages to build...

Fixed in V2

Quoted 16 lines

Please consider testing before/after that specific stack move:

commit f36f83f947ede547833e462696893f866df77324

Author: Namhyung Kim <[email protected]>
Date:   Tue Jun 4 14:46:19 2013 +0900

perf sched: Move struct perf_sched definition out of cmd_sched()

For some reason it consumed quite amount of compile time when declared as local variable, and it disappeared when moved out of the function. Moving other variables/tables didn't help.

On my system this single-file-change build time reduced from 11s to 3s.

author reviewer
#22 lore raw

PATCH 8/19 perf inject: Do not repipe attributes to a perf.data file

In reply to Adrian Hunter

perf.data files contain the attributes separately, do not put them in the event stream as well.

---
 tools/perf/builtin-inject.c | 5 +++++
 1 file changed, 5 insertions(+)
tools/perf/builtin-inject.c +5 -0
index f51a963..2a88a72 100644
@@ -71,12 +71,17 @@ static int perf_event__repipe_attr(struct perf_tool *tool,
 				   union perf_event *event,
 				   struct perf_evlist **pevlist)
 {
+	struct perf_inject *inject = container_of(tool, struct perf_inject,
+						  tool);
 	int ret;
 
 	ret = perf_event__process_attr(tool, event, pevlist);
 	if (ret)
 		return ret;
 
+	if (!inject->pipe_output)
+		return 0;
+
 	return perf_event__repipe_synth(tool, event);
 }
 
Signature · 1 line
1.7.11.7
author reviewer
#23 lore raw

PATCH 9/19 perf tools: Fix 32-bit cross build

In reply to Adrian Hunter

Setting EXTRA_CFLAGS=-m32 did not work because CFLAGS was not passed around.

---
 tools/perf/Makefile.perf                  | 2 +-
 tools/perf/config/Makefile                | 4 ++--
 tools/perf/config/feature-checks/Makefile | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
tools/perf/Makefile.perf +1 -1
index c873e03..699cdb7 100644
@@ -706,7 +706,7 @@ $(LIB_FILE): $(LIB_OBJS)
 TE_SOURCES = $(wildcard $(TRACE_EVENT_DIR)*.[ch])
 
 $(LIBTRACEEVENT): $(TE_SOURCES)
-	$(QUIET_SUBDIR0)$(TRACE_EVENT_DIR) $(QUIET_SUBDIR1) O=$(OUTPUT) libtraceevent.a
+	$(QUIET_SUBDIR0)$(TRACE_EVENT_DIR) $(QUIET_SUBDIR1) O=$(OUTPUT) CFLAGS="-g -Wall $(EXTRA_CFLAGS)" libtraceevent.a
 
 $(LIBTRACEEVENT)-clean:
 	$(call QUIET_CLEAN, libtraceevent)
tools/perf/config/Makefile +2 -2
index c516d6b..c94a06b 100644
@@ -92,7 +92,7 @@ endif
 
 feature_check = $(eval $(feature_check_code))
 define feature_check_code
-  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) LDFLAGS=$(LDFLAGS) -C config/feature-checks test-$1 >/dev/null 2>/dev/null && echo 1 || echo 0)
+  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(CFLAGS)" LDFLAGS=$(LDFLAGS) -C config/feature-checks test-$1 >/dev/null 2>/dev/null && echo 1 || echo 0)
 endef
 
 feature_set = $(eval $(feature_set_code))
@@ -169,7 +169,7 @@ ifeq ($(feature-all), 1)
   #
   $(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_set,$(feat)))
 else
-  $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) LDFLAGS=$(LDFLAGS) -i -j -C config/feature-checks $(CORE_FEATURE_TESTS) >/dev/null 2>&1)
+  $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(CFLAGS)" LDFLAGS=$(LDFLAGS) -i -j -C config/feature-checks $(CORE_FEATURE_TESTS) >/dev/null 2>&1)
   $(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_check,$(feat)))
 endif
 
tools/perf/config/feature-checks/Makefile +1 -1
index 452b67c..353c00c 100644
@@ -31,7 +31,7 @@ CC := $(CC) -MD
 
 all: $(FILES)
 
-BUILD = $(CC) $(LDFLAGS) -o $(OUTPUT)$@ [email protected]
+BUILD = $(CC) $(CFLAGS) $(LDFLAGS) -o $(OUTPUT)$@ [email protected]
 
 ###############################
 
Signature · 1 line
1.7.11.7
#24 lore raw

Re: [PATCH 09/19] perf tools: Fix 32-bit cross build

Quoted 2 lines · Adrian Hunter

Setting EXTRA_CFLAGS=-m32 did not work because CFLAGS was not passed around.

this breaks feature detection for me on x86_64, I've got following errors misdetection with this patch:

... libperl: [ OFF ]
... on-exit: [ OFF ]

and the build fails as well:

CC builtin-stat.o
builtin-record.c:42:12: error: static declaration of ‘on_exit’ follows non-static declaration In file included from util/util.h:51:0,
from builtin.h:4,
from builtin-record.c:8:
/usr/include/stdlib.h:536:12: note: previous declaration of ‘on_exit’ was here make[1]: *** [builtin-record.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [all] Error 2

jirka

author reviewer
#25 lore raw

Re: [PATCH 09/19] perf tools: Fix 32-bit cross build

Quoted 12 lines · Jiri Olsa
Quoted 2 lines · Adrian Hunter

Setting EXTRA_CFLAGS=-m32 did not work because CFLAGS was not passed around.

this breaks feature detection for me on x86_64, I've got following errors misdetection with this patch:

... libperl: [ OFF ]
... on-exit: [ OFF ]

and the build fails as well:

Quoted 9 lines

CC builtin-stat.o
builtin-record.c:42:12: error: static declaration of ‘on_exit’ follows non-static declaration In file included from util/util.h:51:0,
from builtin.h:4,
from builtin-record.c:8:
/usr/include/stdlib.h:536:12: note: previous declaration of ‘on_exit’ was here make[1]: *** [builtin-record.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [all] Error 2

That is fixed in patch 11: perf tools: Fix test_on_exit for 32-bit build

#26 lore raw

Re: [PATCH 09/19] perf tools: Fix 32-bit cross build

Quoted 9 lines · Adrian Hunter
Quoted 8 lines · Jiri Olsa
Quoted 2 lines · Adrian Hunter

Setting EXTRA_CFLAGS=-m32 did not work because CFLAGS was not passed around.

this breaks feature detection for me on x86_64, I've got following errors misdetection with this patch:

... libperl: [ OFF ]

how about this one?

Quoted 14 lines
Quoted 4 lines

... on-exit: [ OFF ]

and the build fails as well:

Quoted 9 lines

CC builtin-stat.o
builtin-record.c:42:12: error: static declaration of ‘on_exit’ follows non-static declaration In file included from util/util.h:51:0,
from builtin.h:4,
from builtin-record.c:8:
/usr/include/stdlib.h:536:12: note: previous declaration of ‘on_exit’ was here make[1]: *** [builtin-record.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [all] Error 2

Quoted 1 line

That is fixed in patch 11: perf tools: Fix test_on_exit for 32-bit build

hum, could we apply those patches in reverse order? I think the notion is not to break build deliberatelly for the bisection sake.

jirka

author reviewer
#27 lore raw

Re: [PATCH 09/19] perf tools: Fix 32-bit cross build

Quoted 6 lines · Jiri Olsa
Quoted 5 lines · Adrian Hunter
Quoted 4 lines · Jiri Olsa
Quoted 2 lines · Adrian Hunter

Setting EXTRA_CFLAGS=-m32 did not work because CFLAGS was not passed around.

Quoted 6 lines
Quoted 4 lines
Quoted 4 lines

this breaks feature detection for me on x86_64, I've got following errors misdetection with this patch:

... libperl: [ OFF ]

how about this one?

I will check it out.

Quoted 15 lines
Quoted 15 lines
Quoted 14 lines

... on-exit: [ OFF ]

and the build fails as well:

CC builtin-stat.o
builtin-record.c:42:12: error: static declaration of ‘on_exit’ follows non-static declaration In file included from util/util.h:51:0,
from builtin.h:4,
from builtin-record.c:8:
/usr/include/stdlib.h:536:12: note: previous declaration of ‘on_exit’ was here make[1]: *** [builtin-record.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [all] Error 2

Quoted 5 lines
Quoted 1 line

That is fixed in patch 11: perf tools: Fix test_on_exit for 32-bit build

hum, could we apply those patches in reverse order? I think the notion is not to break build deliberatelly for the bisection sake.

Oh, I had thought it was a 32-bit only problem.
Yes, I will re-order the patches.

#28 lore raw

Re: [PATCH 09/19] perf tools: Fix 32-bit cross build

In reply to Adrian Hunter

Em Fri, Oct 18, 2013 at 03:29:06PM +0300, Adrian Hunter escreveu:

Quoted 2 lines

Setting EXTRA_CFLAGS=-m32 did not work because CFLAGS was not passed around.

<SNIP>

tools/perf/Makefile.perf $(LIB_FILE): $(LIB_OBJS) · line 709

Quoted 9 lines

index c873e03..699cdb7 100644

tools/perf/Makefile.perf +1 -1
@@ -706,7 +706,7 @@ $(LIB_FILE): $(LIB_OBJS)
 TE_SOURCES = $(wildcard $(TRACE_EVENT_DIR)*.[ch])
 
 $(LIBTRACEEVENT): $(TE_SOURCES)
-	$(QUIET_SUBDIR0)$(TRACE_EVENT_DIR) $(QUIET_SUBDIR1) O=$(OUTPUT) libtraceevent.a
+	$(QUIET_SUBDIR0)$(TRACE_EVENT_DIR) $(QUIET_SUBDIR1) O=$(OUTPUT) CFLAGS="-g -Wall $(EXTRA_CFLAGS)" libtraceevent.a

So are we unconditionally set -g and -Wall?

And by making CFLAGS be $(EXTRA_CFLAGS) implies EXTRA_CFLAGS already contains "$(CFLAGS)?

- Arnaldo

Quoted 40 lines
tools/perf/Makefile.perf +0 -0
 $(LIBTRACEEVENT)-clean:
 	$(call QUIET_CLEAN, libtraceevent)
tools/perf/config/Makefile +2 -2
index c516d6b..c94a06b 100644
@@ -92,7 +92,7 @@ endif
 
 feature_check = $(eval $(feature_check_code))
 define feature_check_code
-  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) LDFLAGS=$(LDFLAGS) -C config/feature-checks test-$1 >/dev/null 2>/dev/null && echo 1 || echo 0)
+  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(CFLAGS)" LDFLAGS=$(LDFLAGS) -C config/feature-checks test-$1 >/dev/null 2>/dev/null && echo 1 || echo 0)
 endef
 
 feature_set = $(eval $(feature_set_code))
@@ -169,7 +169,7 @@ ifeq ($(feature-all), 1)
   #
   $(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_set,$(feat)))
 else
-  $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) LDFLAGS=$(LDFLAGS) -i -j -C config/feature-checks $(CORE_FEATURE_TESTS) >/dev/null 2>&1)
+  $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(CFLAGS)" LDFLAGS=$(LDFLAGS) -i -j -C config/feature-checks $(CORE_FEATURE_TESTS) >/dev/null 2>&1)
   $(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_check,$(feat)))
 endif
 
tools/perf/config/feature-checks/Makefile +1 -1
index 452b67c..353c00c 100644
@@ -31,7 +31,7 @@ CC := $(CC) -MD
 
 all: $(FILES)
 
-BUILD = $(CC) $(LDFLAGS) -o $(OUTPUT)$@ [email protected]
+BUILD = $(CC) $(CFLAGS) $(LDFLAGS) -o $(OUTPUT)$@ [email protected]
 
 ###############################
 
Signature · 1 line
1.7.11.7
author reviewer
#29 lore raw

Re: [PATCH 09/19] perf tools: Fix 32-bit cross build

Quoted 3 lines · Arnaldo Carvalho de Melo

Em Fri, Oct 18, 2013 at 03:29:06PM +0300, Adrian Hunter escreveu:

Quoted 2 lines

Setting EXTRA_CFLAGS=-m32 did not work because CFLAGS was not passed around.

Unfortunately passing CFLAGS seems to break some of the tests, so this needs more work.

Quoted 9 lines

<SNIP>

Quoted 6 lines

index c873e03..699cdb7 100644

tools/perf/Makefile.perf +0 -0
@@ -706,7 +706,7 @@ $(LIB_FILE): $(LIB_OBJS)
  TE_SOURCES = $(wildcard $(TRACE_EVENT_DIR)*.[ch])
 
Quoted 5 lines

tools/perf/Makefile.perf $(LIB_FILE): $(LIB_OBJS) · line 709

Quoted 3 lines
tools/perf/Makefile.perf +1 -1
  $(LIBTRACEEVENT): $(TE_SOURCES)
-	$(QUIET_SUBDIR0)$(TRACE_EVENT_DIR) $(QUIET_SUBDIR1) O=$(OUTPUT) libtraceevent.a
+	$(QUIET_SUBDIR0)$(TRACE_EVENT_DIR) $(QUIET_SUBDIR1) O=$(OUTPUT) CFLAGS="-g -Wall $(EXTRA_CFLAGS)" libtraceevent.a

So are we unconditionally set -g and -Wall?

They are the defaults from tools/lib/traceevent/Makefile if CFLAGS is not set. It seemed reasonably to keep them the same.

Quoted 3 lines

And by making CFLAGS be $(EXTRA_CFLAGS) implies EXTRA_CFLAGS already contains "$(CFLAGS)?

No I was intending to pass only -m32

Quoted 43 lines

- Arnaldo

Quoted 40 lines
tools/perf/Makefile.perf +0 -0
  $(LIBTRACEEVENT)-clean:
  	$(call QUIET_CLEAN, libtraceevent)
tools/perf/config/Makefile +2 -2
index c516d6b..c94a06b 100644
@@ -92,7 +92,7 @@ endif
 
  feature_check = $(eval $(feature_check_code))
  define feature_check_code
-  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) LDFLAGS=$(LDFLAGS) -C config/feature-checks test-$1 >/dev/null 2>/dev/null && echo 1 || echo 0)
+  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(CFLAGS)" LDFLAGS=$(LDFLAGS) -C config/feature-checks test-$1 >/dev/null 2>/dev/null && echo 1 || echo 0)
  endef
 
  feature_set = $(eval $(feature_set_code))
@@ -169,7 +169,7 @@ ifeq ($(feature-all), 1)
    #
    $(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_set,$(feat)))
  else
-  $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) LDFLAGS=$(LDFLAGS) -i -j -C config/feature-checks $(CORE_FEATURE_TESTS) >/dev/null 2>&1)
+  $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(CFLAGS)" LDFLAGS=$(LDFLAGS) -i -j -C config/feature-checks $(CORE_FEATURE_TESTS) >/dev/null 2>&1)
    $(foreach feat,$(CORE_FEATURE_TESTS),$(call feature_check,$(feat)))
  endif
 
tools/perf/config/feature-checks/Makefile +1 -2
index 452b67c..353c00c 100644
@@ -31,7 +31,7 @@ CC := $(CC) -MD
 
  all: $(FILES)
 
-BUILD = $(CC) $(LDFLAGS) -o $(OUTPUT)$@ [email protected]
+BUILD = $(CC) $(CFLAGS) $(LDFLAGS) -o $(OUTPUT)$@ [email protected]
 
  ###############################
 
--

1.7.11.7

author reviewer
#30 lore raw

PATCH 10/19 perf evlist: Fix 32-bit build error

In reply to Adrian Hunter

util/evlist.c: In function 'perf_evlist__mmap':
util/evlist.c:772:2: error: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'size_t' [-Werror=format]
cc1: all warnings being treated as errors

---
 tools/perf/util/evlist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/evlist.c +1 -1
index 0b5425b..07ba0a4 100644
@@ -769,7 +769,7 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
 
 	evlist->overwrite = overwrite;
 	evlist->mmap_len = perf_evlist__mmap_size(pages);
-	pr_debug("mmap size %luB\n", evlist->mmap_len);
+	pr_debug("mmap size %zuB\n", evlist->mmap_len);
 	mask = evlist->mmap_len - page_size - 1;
 
 	list_for_each_entry(evsel, &evlist->entries, node) {
Signature · 1 line
1.7.11.7
#31 lore raw

[tip:perf/core] perf evlist: Fix 32-bit build error

perf evlist: Fix 32-bit build error
Commit-ID:  2af68ef50c6afc1632edc984e9c834545d90f597
Gitweb:     http://git.kernel.org/tip/2af68ef50c6afc1632edc984e9c834545d90f597
Author:     Adrian Hunter <[email protected]>
AuthorDate: Fri, 18 Oct 2013 15:29:07 +0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 21 Oct 2013 11:19:41 -0300

perf evlist: Fix 32-bit build error

util/evlist.c: In function 'perf_evlist__mmap':
util/evlist.c:772:2: error: format '%lu' expects argument of type 'long unsigned int', but argument 3 has type 'size_t' [-Werror=format]
cc1: all warnings being treated as errors

Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/util/evlist.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/util/evlist.c +1 -1
index 0b5425b..07ba0a4 100644
@@ -769,7 +769,7 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
 
 	evlist->overwrite = overwrite;
 	evlist->mmap_len = perf_evlist__mmap_size(pages);
-	pr_debug("mmap size %luB\n", evlist->mmap_len);
+	pr_debug("mmap size %zuB\n", evlist->mmap_len);
 	mask = evlist->mmap_len - page_size - 1;
 
 	list_for_each_entry(evsel, &evlist->entries, node) {
author reviewer
#32 lore raw

PATCH 11/19 perf tools: Fix test_on_exit for 32-bit build

In reply to Adrian Hunter

builtin-record.c:42:12: error: static declaration of 'on_exit' follows non-static declaration In file included from util/util.h:51:0,
from builtin.h:4,
from builtin-record.c:8:
/usr/include/stdlib.h:536:12: note: previous declaration of 'on_exit' was here

---
 tools/perf/config/feature-checks/test-on-exit.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/config/feature-checks/test-on-exit.c +1 -0
index 8f64ed3..8e88b16 100644
@@ -1,4 +1,5 @@
 #include <stdio.h>
+#include <stdlib.h>
 
 static void exit_fn(int status, void *__data)
 {
Signature · 1 line
1.7.11.7
#33 lore raw

[tip:perf/core] perf tools: Fix test_on_exit for 32-bit build

perf tools: Fix test_on_exit for 32-bit build
Commit-ID:  9402802a416c96b48b2bd9331c070ba2d7550b36
Gitweb:     http://git.kernel.org/tip/9402802a416c96b48b2bd9331c070ba2d7550b36
Author:     Adrian Hunter <[email protected]>
AuthorDate: Fri, 18 Oct 2013 15:29:08 +0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 21 Oct 2013 11:19:42 -0300

perf tools: Fix test_on_exit for 32-bit build

builtin-record.c:42:12: error: static declaration of 'on_exit' follows non-static declaration In file included from util/util.h:51:0,
from builtin.h:4,
from builtin-record.c:8:
/usr/include/stdlib.h:536:12: note: previous declaration of 'on_exit' was here

Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/config/feature-checks/test-on-exit.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/config/feature-checks/test-on-exit.c +1 -0
index 8f64ed3..8e88b16 100644
@@ -1,4 +1,5 @@
 #include <stdio.h>
+#include <stdlib.h>
 
 static void exit_fn(int status, void *__data)
 {
author reviewer
#34 lore raw

PATCH 12/19 perf tools: Fix bench/numa.c for 32-bit build

In reply to Adrian Hunter

bench/numa.c: In function 'worker_thread':
bench/numa.c:1123:20: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] bench/numa.c:1171:6: error: format '%lx' expects argument of type 'long unsigned int', but argument 5 has type 'u64' [-Werror=format]
cc1: all warnings being treated as errors

---
 tools/perf/bench/numa.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/bench/numa.c +2 -2
index 64fa01c..d4c83c6 100644
@@ -1120,7 +1120,7 @@ static void *worker_thread(void *__tdata)
 		/* Check whether our max runtime timed out: */
 		if (g->p.nr_secs) {
 			timersub(&stop, &start0, &diff);
-			if (diff.tv_sec >= g->p.nr_secs) {
+			if ((u32)diff.tv_sec >= g->p.nr_secs) {
 				g->stop_work = true;
 				break;
 			}
@@ -1167,7 +1167,7 @@ static void *worker_thread(void *__tdata)
 			runtime_ns_max += diff.tv_usec * 1000;
 
 			if (details >= 0) {
-				printf(" #%2d / %2d: %14.2lf nsecs/op [val: %016lx]\n",
+				printf(" #%2d / %2d: %14.2lf nsecs/op [val: %016"PRIx64"]\n",
 					process_nr, thread_nr, runtime_ns_max / bytes_done, val);
 			}
 			fflush(stdout);
Signature · 1 line
1.7.11.7
#35 lore raw

[tip:perf/core] perf tools: Fix bench/numa.c for 32-bit build

perf tools: Fix bench/numa.c for 32-bit build
Commit-ID:  2100f778d44b9c25bd13d38c24a999e2caf1ae3d
Gitweb:     http://git.kernel.org/tip/2100f778d44b9c25bd13d38c24a999e2caf1ae3d
Author:     Adrian Hunter <[email protected]>
AuthorDate: Fri, 18 Oct 2013 15:29:09 +0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 21 Oct 2013 11:19:42 -0300

perf tools: Fix bench/numa.c for 32-bit build

bench/numa.c: In function 'worker_thread':
bench/numa.c:1123:20: error: comparison between signed and unsigned integer expressions [-Werror=sign-compare] bench/numa.c:1171:6: error: format '%lx' expects argument of type 'long unsigned int', but argument 5 has type 'u64' [-Werror=format]
cc1: all warnings being treated as errors

Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/bench/numa.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/bench/numa.c +2 -2
index 64fa01c..d4c83c6 100644
@@ -1120,7 +1120,7 @@ static void *worker_thread(void *__tdata)
 		/* Check whether our max runtime timed out: */
 		if (g->p.nr_secs) {
 			timersub(&stop, &start0, &diff);
-			if (diff.tv_sec >= g->p.nr_secs) {
+			if ((u32)diff.tv_sec >= g->p.nr_secs) {
 				g->stop_work = true;
 				break;
 			}
@@ -1167,7 +1167,7 @@ static void *worker_thread(void *__tdata)
 			runtime_ns_max += diff.tv_usec * 1000;
 
 			if (details >= 0) {
-				printf(" #%2d / %2d: %14.2lf nsecs/op [val: %016lx]\n",
+				printf(" #%2d / %2d: %14.2lf nsecs/op [val: %016"PRIx64"]\n",
 					process_nr, thread_nr, runtime_ns_max / bytes_done, val);
 			}
 			fflush(stdout);
author reviewer
#36 lore raw

PATCH 13/19 perf tools: Fix libunwind build and feature detection for 32-bit build

In reply to Adrian Hunter

Use -lunwind-x86 instead of -lunwind-x86_64 for
32-bit build.

---
 tools/perf/config/Makefile                | 6 ++++--
 tools/perf/config/feature-checks/Makefile | 4 ++--
 2 files changed, 6 insertions(+), 4 deletions(-)
tools/perf/config/Makefile +4 -2
index c94a06b..abb32f3 100644
@@ -25,9 +25,11 @@ ifeq ($(ARCH),x86_64)
     RAW_ARCH := x86_64
     CFLAGS += -DHAVE_ARCH_X86_64_SUPPORT
     ARCH_INCLUDE = ../../arch/x86/lib/memcpy_64.S ../../arch/x86/lib/memset_64.S
+    LIBUNWIND_LIBS = -lunwind -lunwind-x86_64
+  else
+    LIBUNWIND_LIBS = -lunwind -lunwind-x86
   endif
   NO_PERF_REGS := 0
-  LIBUNWIND_LIBS = -lunwind -lunwind-x86_64
 endif
 
 ifeq ($(NO_PERF_REGS),0)
@@ -92,7 +94,7 @@ endif
 
 feature_check = $(eval $(feature_check_code))
 define feature_check_code
-  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(CFLAGS)" LDFLAGS=$(LDFLAGS) -C config/feature-checks test-$1 >/dev/null 2>/dev/null && echo 1 || echo 0)
+  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(CFLAGS)" LDFLAGS=$(LDFLAGS) LIBUNWIND_LIBS="$(LIBUNWIND_LIBS)" -C config/feature-checks test-$1 >/dev/null 2>/dev/null && echo 1 || echo 0)
 endef
 
 feature_set = $(eval $(feature_set_code))
tools/perf/config/feature-checks/Makefile +2 -2
index 353c00c..d37d58d 100644
@@ -36,7 +36,7 @@ BUILD = $(CC) $(CFLAGS) $(LDFLAGS) -o $(OUTPUT)$@ [email protected]
 ###############################
 
 test-all:
-	$(BUILD) -Werror -fstack-protector -fstack-protector-all -O2 -Werror -D_FORTIFY_SOURCE=2 -ldw -lelf -lnuma -lunwind -lunwind-x86_64 -lelf -laudit -I/usr/include/slang -lslang $(shell pkg-config --libs --cflags gtk+-2.0 2>/dev/null) $(FLAGS_PERL_EMBED) $(FLAGS_PYTHON_EMBED) -DPACKAGE='"perf"' -lbfd -ldl
+	$(BUILD) -Werror -fstack-protector -fstack-protector-all -O2 -Werror -D_FORTIFY_SOURCE=2 -ldw -lelf -lnuma $(LIBUNWIND_LIBS) -lelf -laudit -I/usr/include/slang -lslang $(shell pkg-config --libs --cflags gtk+-2.0 2>/dev/null) $(FLAGS_PERL_EMBED) $(FLAGS_PYTHON_EMBED) -DPACKAGE='"perf"' -lbfd -ldl
 
 test-hello:
 	$(BUILD)
@@ -72,7 +72,7 @@ test-libnuma:
 	$(BUILD) -lnuma
 
 test-libunwind:
-	$(BUILD) -lunwind -lunwind-x86_64 -lelf
+	$(BUILD) $(LIBUNWIND_LIBS) -lelf
 
 test-libaudit:
 	$(BUILD) -laudit
Signature · 1 line
1.7.11.7
#38 lore raw

Re: [PATCH 13/19] perf tools: Fix libunwind build and feature detection for 32-bit build

Em Sun, Oct 20, 2013 at 10:43:46PM +0200, Jiri Olsa escreveu:

Quoted 6 lines · Adrian Hunter
Quoted 3 lines

Use -lunwind-x86 instead of -lunwind-x86_64 for 32-bit build.

Doesn't apply because it depends on a patch in this series that I made a question about, the "CFLAGS=-g ... one, but then can we avoid touching this feature_check_code line with feature specific stuff, i.e. can't we just touch LDFLAGS or CFLAGS?

- Arnaldo

perf/config/Makefile +1 -1
@@ -94,7 +96,7 @@
 
 feature_check = $(eval $(feature_check_code))
 define feature_check_code
-  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(CFLAGS)" LDFLAGS=$(LDFLAGS) -C config/feature-checks test-$1 >/dev/null 2>/dev/null && echo 1 || echo 0)
+  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(CFLAGS)" LDFLAGS=$(LDFLAGS) LIBUNWIND_LIBS="$(LIBUNWIND_LIBS)" -C config/feature-checks test-$1 >/dev/null 2>/dev/null && echo 1 || echo 0)
 endef
 
 feature_set = $(eval $(feature_set_code))
author reviewer
#39 lore raw

Re: [PATCH 13/19] perf tools: Fix libunwind build and feature detection for 32-bit build

Quoted 4 lines · Arnaldo Carvalho de Melo

Em Sun, Oct 20, 2013 at 10:43:46PM +0200, Jiri Olsa escreveu:

Quoted 2 lines · Adrian Hunter
Quoted 1 line

Use -lunwind-x86 instead of -lunwind-x86_64 for 32-bit build.

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Doesn't apply because it depends on a patch in this series that I made a question about, the "CFLAGS=-g ... one, but then can we avoid touching this feature_check_code line with feature specific stuff, i.e. can't we just touch LDFLAGS or CFLAGS?

Because LDFLAGS and CFLAGS are used for all tests, all tests would fail if any feature libraries were not present.

Also because 'make' invokes 'make' via a shell, it is not possible to export variables.

That just leaves the command line as far as I can see.

Quoted 16 lines

- Arnaldo

perf/config/Makefile +1 -1
@@ -94,7 +96,7 @@
 
 feature_check = $(eval $(feature_check_code))
 define feature_check_code
-  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(CFLAGS)" LDFLAGS=$(LDFLAGS) -C config/feature-checks test-$1 >/dev/null 2>/dev/null && echo 1 || echo 0)
+  feature-$(1) := $(shell $(MAKE) OUTPUT=$(OUTPUT_FEATURES) CFLAGS="$(CFLAGS)" LDFLAGS=$(LDFLAGS) LIBUNWIND_LIBS="$(LIBUNWIND_LIBS)" -C config/feature-checks test-$1 >/dev/null 2>/dev/null && echo 1 || echo 0)
 endef
 
 feature_set = $(eval $(feature_set_code))
author reviewer
#40 lore raw

PATCH 14/19 perf evlist: Add a debug print if event buffer mmap fails

In reply to Adrian Hunter

Add a debug print if mmap of the perf event
ring buffer fails.

---
 tools/perf/util/evlist.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/evlist.c +1 -0
index 07ba0a4..52e434a 100644
@@ -600,6 +600,7 @@ static int __perf_evlist__mmap(struct perf_evlist *evlist,
 	evlist->mmap[idx].base = mmap(NULL, evlist->mmap_len, prot,
 				      MAP_SHARED, fd, 0);
 	if (evlist->mmap[idx].base == MAP_FAILED) {
+		pr_debug2("failed to mmap perf event ring buffer\n");
 		evlist->mmap[idx].base = NULL;
 		return -1;
 	}
Signature · 1 line
1.7.11.7
#41 lore raw

Re: [PATCH 14/19] perf evlist: Add a debug print if event buffer mmap fails

Quoted 13 lines · Adrian Hunter

Add a debug print if mmap of the perf event
ring buffer fails.

---
 tools/perf/util/evlist.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/evlist.c +0 -0
index 07ba0a4..52e434a 100644

tools/perf/util/evlist.c static int __perf_evlist__mmap(struct perf_evlist *evlist, · line 603

Quoted 4 lines
tools/perf/util/evlist.c +1 -0
@@ -600,6 +600,7 @@ static int __perf_evlist__mmap(struct perf_evlist *evlist,
 	evlist->mmap[idx].base = mmap(NULL, evlist->mmap_len, prot,
 				      MAP_SHARED, fd, 0);
 	if (evlist->mmap[idx].base == MAP_FAILED) {
+		pr_debug2("failed to mmap perf event ring buffer\n");

while at it, we could display errno

jirka

author reviewer
#42 lore raw

PATCH 15/19 perf tools: fix perf_evlist__mmap comments

In reply to Adrian Hunter

Put the comments into the correct kernel-doc format and correct reference to perf_evlist__read_on_cpu() which should be perf_evlist__mmap_read().

---
 tools/perf/util/evlist.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
tools/perf/util/evlist.c +9 -12
index 52e434a..a4529af 100644
@@ -739,20 +739,17 @@ int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,
 	return 0;
 }
 
-/** perf_evlist__mmap - Create per cpu maps to receive events
- *
- * @evlist - list of events
- * @pages - map length in pages
- * @overwrite - overwrite older events?
- *
- * If overwrite is false the user needs to signal event consuption using:
- *
- *	struct perf_mmap *m = &evlist->mmap[cpu];
- *	unsigned int head = perf_mmap__read_head(m);
+/**
+ * perf_evlist__mmap - Create mmaps to receive events.
+ * @evlist: list of events
+ * @pages: map length in pages
+ * @overwrite: overwrite older events?
  *
- *	perf_mmap__write_tail(m, head)
+ * If @overwrite is %false the user needs to signal event consumption using
+ * perf_mmap__write_tail().  Using perf_evlist__mmap_read() does this
+ * automatically.
  *
- * Using perf_evlist__read_on_cpu does this automatically.
+ * Return: %0 on success, negative error code otherwise.
  */
 int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
 		      bool overwrite)
Signature · 1 line
1.7.11.7
#43 lore raw

[tip:perf/core] perf evlist: Fix perf_evlist__mmap comments

perf evlist: Fix perf_evlist__mmap comments
Commit-ID:  c83fa7f2549cb60bc4d429de31096546f659ce6d
Gitweb:     http://git.kernel.org/tip/c83fa7f2549cb60bc4d429de31096546f659ce6d
Author:     Adrian Hunter <[email protected]>
AuthorDate: Fri, 18 Oct 2013 15:29:12 +0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 21 Oct 2013 11:19:43 -0300

perf evlist: Fix perf_evlist__mmap comments

Put the comments into the correct kernel-doc format and correct reference to perf_evlist__read_on_cpu() which should be perf_evlist__mmap_read().

Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/util/evlist.c | 21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)
tools/perf/util/evlist.c +9 -12
index 07ba0a4..acef94a 100644
@@ -738,20 +738,17 @@ int perf_evlist__parse_mmap_pages(const struct option *opt, const char *str,
 	return 0;
 }
 
-/** perf_evlist__mmap - Create per cpu maps to receive events
- *
- * @evlist - list of events
- * @pages - map length in pages
- * @overwrite - overwrite older events?
- *
- * If overwrite is false the user needs to signal event consuption using:
- *
- *	struct perf_mmap *m = &evlist->mmap[cpu];
- *	unsigned int head = perf_mmap__read_head(m);
+/**
+ * perf_evlist__mmap - Create mmaps to receive events.
+ * @evlist: list of events
+ * @pages: map length in pages
+ * @overwrite: overwrite older events?
  *
- *	perf_mmap__write_tail(m, head)
+ * If @overwrite is %false the user needs to signal event consumption using
+ * perf_mmap__write_tail().  Using perf_evlist__mmap_read() does this
+ * automatically.
  *
- * Using perf_evlist__read_on_cpu does this automatically.
+ * Return: %0 on success, negative error code otherwise.
  */
 int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
 		      bool overwrite)
author reviewer
#44 lore raw

PATCH 16/19 perf tools: factor out duplicated evlist mmap code

In reply to Adrian Hunter

The same code is used in perf_evlist__mmap_per_cpu() and perf_evlist__mmap_per_thread(). Factor it out into a separate function perf_evlist__mmap_per_evsel().

---
 tools/perf/util/evlist.c | 73 ++++++++++++++++++++++++------------------------
 1 file changed, 36 insertions(+), 37 deletions(-)
tools/perf/util/evlist.c +36 -37
index a4529af..18784dc 100644
@@ -609,9 +609,36 @@ static int __perf_evlist__mmap(struct perf_evlist *evlist,
 	return 0;
 }
 
-static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot, int mask)
+static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx,
+				       int prot, int mask, int cpu, int thread,
+				       int *output)
 {
 	struct perf_evsel *evsel;
+
+	list_for_each_entry(evsel, &evlist->entries, node) {
+		int fd = FD(evsel, cpu, thread);
+
+		if (*output == -1) {
+			*output = fd;
+			if (__perf_evlist__mmap(evlist, idx, prot, mask,
+						*output) < 0)
+				return -1;
+		} else {
+			if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, *output) != 0)
+				return -1;
+		}
+
+		if ((evsel->attr.read_format & PERF_FORMAT_ID) &&
+		    perf_evlist__id_add_fd(evlist, evsel, cpu, thread, fd) < 0)
+			return -1;
+	}
+
+	return 0;
+}
+
+static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot,
+				     int mask)
+{
 	int cpu, thread;
 	int nr_cpus = cpu_map__nr(evlist->cpus);
 	int nr_threads = thread_map__nr(evlist->threads);
@@ -621,23 +648,9 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot, int m
 		int output = -1;
 
 		for (thread = 0; thread < nr_threads; thread++) {
-			list_for_each_entry(evsel, &evlist->entries, node) {
-				int fd = FD(evsel, cpu, thread);
-
-				if (output == -1) {
-					output = fd;
-					if (__perf_evlist__mmap(evlist, cpu,
-								prot, mask, output) < 0)
-						goto out_unmap;
-				} else {
-					if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, output) != 0)
-						goto out_unmap;
-				}
-
-				if ((evsel->attr.read_format & PERF_FORMAT_ID) &&
-				    perf_evlist__id_add_fd(evlist, evsel, cpu, thread, fd) < 0)
-					goto out_unmap;
-			}
+			if (perf_evlist__mmap_per_evsel(evlist, cpu, prot, mask,
+							cpu, thread, &output))
+				goto out_unmap;
 		}
 	}
 
@@ -649,9 +662,9 @@ out_unmap:
 	return -1;
 }
 
-static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist, int prot, int mask)
+static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist, int prot,
+					int mask)
 {
-	struct perf_evsel *evsel;
 	int thread;
 	int nr_threads = thread_map__nr(evlist->threads);
 
@@ -659,23 +672,9 @@ static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist, int prot, in
 	for (thread = 0; thread < nr_threads; thread++) {
 		int output = -1;
 
-		list_for_each_entry(evsel, &evlist->entries, node) {
-			int fd = FD(evsel, 0, thread);
-
-			if (output == -1) {
-				output = fd;
-				if (__perf_evlist__mmap(evlist, thread,
-							prot, mask, output) < 0)
-					goto out_unmap;
-			} else {
-				if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, output) != 0)
-					goto out_unmap;
-			}
-
-			if ((evsel->attr.read_format & PERF_FORMAT_ID) &&
-			    perf_evlist__id_add_fd(evlist, evsel, 0, thread, fd) < 0)
-				goto out_unmap;
-		}
+		if (perf_evlist__mmap_per_evsel(evlist, thread, prot, mask, 0,
+						thread, &output))
+			goto out_unmap;
 	}
 
 	return 0;
Signature · 1 line
1.7.11.7
#45 lore raw

[tip:perf/core] perf evlist: Factor out duplicated mmap code

perf evlist: Factor out duplicated mmap code
Commit-ID:  04e213148c434544e3aa88d227b5375fd375738b
Gitweb:     http://git.kernel.org/tip/04e213148c434544e3aa88d227b5375fd375738b
Author:     Adrian Hunter <[email protected]>
AuthorDate: Fri, 18 Oct 2013 15:29:13 +0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 21 Oct 2013 11:19:43 -0300

perf evlist: Factor out duplicated mmap code

The same code is used in perf_evlist__mmap_per_cpu() and perf_evlist__mmap_per_thread().

Factor it out into a separate function perf_evlist__mmap_per_evsel().

Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/util/evlist.c | 73 ++++++++++++++++++++++++------------------------
 1 file changed, 36 insertions(+), 37 deletions(-)
tools/perf/util/evlist.c +36 -37
index acef94a..85c4c80 100644
@@ -608,9 +608,36 @@ static int __perf_evlist__mmap(struct perf_evlist *evlist,
 	return 0;
 }
 
-static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot, int mask)
+static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx,
+				       int prot, int mask, int cpu, int thread,
+				       int *output)
 {
 	struct perf_evsel *evsel;
+
+	list_for_each_entry(evsel, &evlist->entries, node) {
+		int fd = FD(evsel, cpu, thread);
+
+		if (*output == -1) {
+			*output = fd;
+			if (__perf_evlist__mmap(evlist, idx, prot, mask,
+						*output) < 0)
+				return -1;
+		} else {
+			if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, *output) != 0)
+				return -1;
+		}
+
+		if ((evsel->attr.read_format & PERF_FORMAT_ID) &&
+		    perf_evlist__id_add_fd(evlist, evsel, cpu, thread, fd) < 0)
+			return -1;
+	}
+
+	return 0;
+}
+
+static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot,
+				     int mask)
+{
 	int cpu, thread;
 	int nr_cpus = cpu_map__nr(evlist->cpus);
 	int nr_threads = thread_map__nr(evlist->threads);
@@ -620,23 +647,9 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot, int m
 		int output = -1;
 
 		for (thread = 0; thread < nr_threads; thread++) {
-			list_for_each_entry(evsel, &evlist->entries, node) {
-				int fd = FD(evsel, cpu, thread);
-
-				if (output == -1) {
-					output = fd;
-					if (__perf_evlist__mmap(evlist, cpu,
-								prot, mask, output) < 0)
-						goto out_unmap;
-				} else {
-					if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, output) != 0)
-						goto out_unmap;
-				}
-
-				if ((evsel->attr.read_format & PERF_FORMAT_ID) &&
-				    perf_evlist__id_add_fd(evlist, evsel, cpu, thread, fd) < 0)
-					goto out_unmap;
-			}
+			if (perf_evlist__mmap_per_evsel(evlist, cpu, prot, mask,
+							cpu, thread, &output))
+				goto out_unmap;
 		}
 	}
 
@@ -648,9 +661,9 @@ out_unmap:
 	return -1;
 }
 
-static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist, int prot, int mask)
+static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist, int prot,
+					int mask)
 {
-	struct perf_evsel *evsel;
 	int thread;
 	int nr_threads = thread_map__nr(evlist->threads);
 
@@ -658,23 +671,9 @@ static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist, int prot, in
 	for (thread = 0; thread < nr_threads; thread++) {
 		int output = -1;
 
-		list_for_each_entry(evsel, &evlist->entries, node) {
-			int fd = FD(evsel, 0, thread);
-
-			if (output == -1) {
-				output = fd;
-				if (__perf_evlist__mmap(evlist, thread,
-							prot, mask, output) < 0)
-					goto out_unmap;
-			} else {
-				if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, output) != 0)
-					goto out_unmap;
-			}
-
-			if ((evsel->attr.read_format & PERF_FORMAT_ID) &&
-			    perf_evlist__id_add_fd(evlist, evsel, 0, thread, fd) < 0)
-				goto out_unmap;
-		}
+		if (perf_evlist__mmap_per_evsel(evlist, thread, prot, mask, 0,
+						thread, &output))
+			goto out_unmap;
 	}
 
 	return 0;
author reviewer
#46 lore raw

PATCH 17/19 perf script: print addr by default for BTS

In reply to Adrian Hunter

addr is not displayed by default for hardware events, however for branch events it is the target of the branch so for BTS display it by default if it was recorded.

---
 tools/perf/builtin-script.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/builtin-script.c +3 -1
index 3f9a9bf..1a91621 100644
@@ -413,7 +413,9 @@ static void print_sample_bts(union perf_event *event,
 	printf(" => ");
 
 	/* print branch_to information */
-	if (PRINT_FIELD(ADDR))
+	if (PRINT_FIELD(ADDR) ||
+	    ((evsel->attr.sample_type & PERF_SAMPLE_ADDR) &&
+	     !output[attr->type].user_set))
 		print_sample_addr(event, sample, machine, thread, attr);
 
 	printf("\n");
Signature · 1 line
1.7.11.7
#47 lore raw

Re: [PATCH 17/19] perf script: print addr by default for BTS

Quoted 15 lines · Adrian Hunter

addr is not displayed by default for hardware events, however for branch events it is the target of the branch so for BTS display it by default if it was recorded.

---
  tools/perf/builtin-script.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/builtin-script.c +0 -0
index 3f9a9bf..1a91621 100644

tools/perf/builtin-script.c static void print_sample_bts(union perf_event *event, · line 421

Quoted 10 lines
tools/perf/builtin-script.c +3 -1
@@ -413,7 +413,9 @@ static void print_sample_bts(union perf_event *event,
  	printf(" => ");
 
  	/* print branch_to information */
-	if (PRINT_FIELD(ADDR))
+	if (PRINT_FIELD(ADDR) ||
+	    ((evsel->attr.sample_type & PERF_SAMPLE_ADDR) &&
+	     !output[attr->type].user_set))
  		print_sample_addr(event, sample, machine, thread, attr);
 
  	printf("\n");

Looks ok to me. Acked-by: David Ahern <[email protected]>

#48 lore raw

[tip:perf/core] perf script: Print addr by default for BTS

In reply to Adrian Hunter
perf script: Print addr by default for BTS
Commit-ID:  243be3dd7c14454899e51334a6d66d29a41ae6ab
Gitweb:     http://git.kernel.org/tip/243be3dd7c14454899e51334a6d66d29a41ae6ab
Author:     Adrian Hunter <[email protected]>
AuthorDate: Fri, 18 Oct 2013 15:29:14 +0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Mon, 21 Oct 2013 17:33:22 -0300

perf script: Print addr by default for BTS

The addr field is not displayed by default for hardware events, however for branch events it is the target of the branch so for BTS display it by default if it was recorded.

Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Mike Galbraith <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/builtin-script.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tools/perf/builtin-script.c +3 -1
index 9c333ff..ebb2b5f 100644
@@ -409,7 +409,9 @@ static void print_sample_bts(union perf_event *event,
 	printf(" => ");
 
 	/* print branch_to information */
-	if (PRINT_FIELD(ADDR))
+	if (PRINT_FIELD(ADDR) ||
+	    ((evsel->attr.sample_type & PERF_SAMPLE_ADDR) &&
+	     !output[attr->type].user_set))
 		print_sample_addr(event, sample, machine, thread, attr);
 
 	printf("\n");
author reviewer
#49 lore raw

PATCH 18/19 perf record: add an option to force per-cpu mmaps

In reply to Adrian Hunter

By default, when tasks are specified (i.e. -p, -t or -u options) per-thread mmaps are created. Add an option to override that and force per-cpu mmaps.

---
 tools/perf/Documentation/perf-record.txt | 6 ++++++
 tools/perf/builtin-record.c              | 2 ++
 tools/perf/util/evlist.c                 | 4 +++-
 tools/perf/util/evsel.c                  | 4 ++--
 tools/perf/util/target.h                 | 1 +
 5 files changed, 14 insertions(+), 3 deletions(-)
tools/perf/Documentation/perf-record.txt +6 -0
index f10ab63..2ea6685 100644
@@ -189,6 +189,12 @@ abort events and some memory events in precise mode on modern Intel CPUs.
 --transaction::
 Record transaction flags for transaction related events.
 
+--force-per-cpu::
+Force the use of per-cpu mmaps.  By default, when tasks are specified (i.e. -p,
+-t or -u options) per-thread mmaps are created.  This option overrides that and
+forces per-cpu mmaps.  A side-effect of that is that inheritance is
+automatically enabled.  Add the -i option also to disable inheritance.
+
 SEE ALSO
 --------
 linkperf:perf-stat[1], linkperf:perf-list[1]
tools/perf/builtin-record.c +2 -0
index d269dfa..fb09430 100644
@@ -890,6 +890,8 @@ const struct option record_options[] = {
 		    "sample by weight (on special events only)"),
 	OPT_BOOLEAN(0, "transaction", &record.opts.sample_transaction,
 		    "sample transaction flags (special events only)"),
+	OPT_BOOLEAN(0, "force-per-cpu", &record.opts.target.force_per_cpu,
+		    "force the use of per-cpu mmaps"),
 	OPT_END()
 };
 
tools/perf/util/evlist.c +3 -1
index 18784dc..ffcccdd 100644
@@ -791,7 +791,9 @@ int perf_evlist__create_maps(struct perf_evlist *evlist,
 	if (evlist->threads == NULL)
 		return -1;
 
-	if (perf_target__has_task(target))
+	if (target->force_per_cpu)
+		evlist->cpus = cpu_map__new(target->cpu_list);
+	else if (perf_target__has_task(target))
 		evlist->cpus = cpu_map__dummy_new();
 	else if (!perf_target__has_cpu(target) && !target->uses_mmap)
 		evlist->cpus = cpu_map__dummy_new();
tools/perf/util/evsel.c +2 -2
index e09c7e6..f1839b0 100644
@@ -645,7 +645,7 @@ void perf_evsel__config(struct perf_evsel *evsel,
 		}
 	}
 
-	if (perf_target__has_cpu(&opts->target))
+	if (perf_target__has_cpu(&opts->target) || opts->target.force_per_cpu)
 		perf_evsel__set_sample_bit(evsel, CPU);
 
 	if (opts->period)
@@ -653,7 +653,7 @@ void perf_evsel__config(struct perf_evsel *evsel,
 
 	if (!perf_missing_features.sample_id_all &&
 	    (opts->sample_time || !opts->no_inherit ||
-	     perf_target__has_cpu(&opts->target)))
+	     perf_target__has_cpu(&opts->target) || opts->target.force_per_cpu))
 		perf_evsel__set_sample_bit(evsel, TIME);
 
 	if (opts->raw_samples) {
tools/perf/util/target.h +1 -0
index a4be857..6d7efbd 100644
@@ -12,6 +12,7 @@ struct perf_target {
 	uid_t	     uid;
 	bool	     system_wide;
 	bool	     uses_mmap;
+	bool	     force_per_cpu;
 };
 
 enum perf_target_errno {
Signature · 1 line
1.7.11.7
author reviewer
#50 lore raw

PATCH 19/19 perf tools: allow non-matching sample types

In reply to Adrian Hunter

For kernels that do not support PERF_SAMPLE_IDENTIFIER, sample types need not be identical to determine the sample id from the event. Only the position of the sample id needs to be the same.

Compatible sample types are ones in which the bits defined by PERF_COMPAT_MASK are the same. 'perf_evlist__config()' forces sample types to be compatible on that basis.

---
 tools/perf/util/event.h  | 16 ++++++++++++++++
 tools/perf/util/evlist.c | 25 +++++++++++++++++++++++++
 tools/perf/util/evlist.h |  1 +
 tools/perf/util/record.c |  5 ++++-
 4 files changed, 46 insertions(+), 1 deletion(-)
tools/perf/util/event.h +16 -0
index 752709c..ca0689c 100644
@@ -78,6 +78,22 @@ struct throttle_event {
 /* perf sample has 16 bits size limit */
 #define PERF_SAMPLE_MAX_SIZE (1 << 16)
 
+/*
+ * Events have compatible sample types if the following bits all have the same
+ * value.  This is because the order of sample members is fixed.  For sample
+ * events the order is: PERF_SAMPLE_IP, PERF_SAMPLE_TID, PERF_SAMPLE_TIME,
+ * PERF_SAMPLE_ADDR, PERF_SAMPLE_ID.  For non-sample events the sample members
+ * are accessed in reverse order.  The order is: PERF_SAMPLE_ID,
+ * PERF_SAMPLE_STREAM_ID, PERF_SAMPLE_CPU.  PERF_SAMPLE_IDENTIFIER is added for
+ * completeness but it should not be used with PERF_SAMPLE_ID.  Sample types
+ * that include PERF_SAMPLE_IDENTIFIER are always compatible.
+ */
+#define PERF_COMPAT_MASK				\
+	(PERF_SAMPLE_IP   | PERF_SAMPLE_TID       |	\
+	 PERF_SAMPLE_TIME | PERF_SAMPLE_ADDR      |	\
+	 PERF_SAMPLE_ID   | PERF_SAMPLE_STREAM_ID |	\
+	 PERF_SAMPLE_CPU  | PERF_SAMPLE_IDENTIFIER)
+
 struct sample_event {
 	struct perf_event_header        header;
 	u64 array[];
tools/perf/util/evlist.c +25 -0
index ffcccdd..04c3fc8 100644
@@ -87,6 +87,31 @@ static void perf_evlist__update_id_pos(struct perf_evlist *evlist)
 	perf_evlist__set_id_pos(evlist);
 }
 
+/**
+ * perf_evlist__make_sample_types_compatible - make sample types compatible.
+ * @evlist: selected event list
+ *
+ * Events with compatible sample types all have the same id_pos and is_pos.
+ * This can be achieved by matching the bits of PERF_COMPAT_MASK.
+ */
+void perf_evlist__make_sample_types_compatible(struct perf_evlist *evlist)
+{
+	struct perf_evsel *evsel;
+	u64 compat = 0;
+
+	list_for_each_entry(evsel, &evlist->entries, node)
+		compat |= evsel->attr.sample_type & PERF_COMPAT_MASK;
+
+	list_for_each_entry(evsel, &evlist->entries, node) {
+		evsel->attr.sample_type |= compat;
+		evsel->sample_size =
+			__perf_evsel__sample_size(evsel->attr.sample_type);
+		perf_evsel__calc_id_pos(evsel);
+	}
+
+	perf_evlist__set_id_pos(evlist);
+}
+
 static void perf_evlist__purge(struct perf_evlist *evlist)
 {
 	struct perf_evsel *pos, *n;
tools/perf/util/evlist.h +1 -0
index 7f8f1ae..8c5cdb9 100644
@@ -94,6 +94,7 @@ int perf_evlist__open(struct perf_evlist *evlist);
 void perf_evlist__close(struct perf_evlist *evlist);
 
 void perf_evlist__set_id_pos(struct perf_evlist *evlist);
+void perf_evlist__make_sample_types_compatible(struct perf_evlist *evlist);
 bool perf_can_sample_identifier(void);
 void perf_evlist__config(struct perf_evlist *evlist,
 			 struct perf_record_opts *opts);
tools/perf/util/record.c +4 -1
index 18d73aa..6e01bf2 100644
@@ -104,5 +104,8 @@ void perf_evlist__config(struct perf_evlist *evlist,
 			perf_evsel__set_sample_id(evsel, use_sample_identifier);
 	}
 
-	perf_evlist__set_id_pos(evlist);
+	if (use_sample_identifier)
+		perf_evlist__set_id_pos(evlist);
+	else
+		perf_evlist__make_sample_types_compatible(evlist);
 }
Signature · 1 line
1.7.11.7
#51 lore raw

Re: [PATCH 19/19] perf tools: allow non-matching sample types

Quoted 9 lines · Adrian Hunter

For kernels that do not support PERF_SAMPLE_IDENTIFIER, sample types need not be identical to determine the sample id from the event. Only the position of the sample id needs to be the same.

Compatible sample types are ones in which the bits defined by PERF_COMPAT_MASK are the same. 'perf_evlist__config()' forces sample types to be compatible on that basis.

Arnaldo and I have discussed adding callchain handling to perf-trace. To do that we only need stack data (including IP) for one event -- eg, raw_syscalls:sys_enter. That means raw_syscalls:sys_enter and raw_syscalls:sys_exit will have different attributes set - including ones in the MASK.

David

author reviewer
#52 lore raw

Re: [PATCH 19/19] perf tools: allow non-matching sample types

Quoted 11 lines · David Ahern
Quoted 9 lines · Adrian Hunter

For kernels that do not support PERF_SAMPLE_IDENTIFIER, sample types need not be identical to determine the sample id from the event. Only the position of the sample id needs to be the same.

Compatible sample types are ones in which the bits defined by PERF_COMPAT_MASK are the same. 'perf_evlist__config()' forces sample types to be compatible on that basis.

Quoted 5 lines

Arnaldo and I have discussed adding callchain handling to perf-trace. To do that we only need stack data (including IP) for one event -- eg, raw_syscalls:sys_enter. That means raw_syscalls:sys_enter and raw_syscalls:sys_exit will have different attributes set - including ones in the MASK.

So how do you know which sample is which?

#53 lore raw

Re: [PATCH 19/19] perf tools: allow non-matching sample types

Quoted 8 lines · Adrian Hunter
Quoted 5 lines · David Ahern

Arnaldo and I have discussed adding callchain handling to perf-trace. To do that we only need stack data (including IP) for one event -- eg, raw_syscalls:sys_enter. That means raw_syscalls:sys_enter and raw_syscalls:sys_exit will have different attributes set - including ones in the MASK.

So how do you know which sample is which?

We need a solution to the problem, and my point is I don't want to increase data in all samples.

David