Skip to contentSkip to conversation

perf/core improvements and fixes

GIT PULL In review Arnaldo Carvalho de Melo 5 participants 25 messages Nov 14, 2013 – Nov 30, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

From: Arnaldo Carvalho de Melo <[email protected]>

Hi Ingo,

Please consider pulling, done on top of tip/perf/urgent.

- Arnaldo

The following changes since commit e310718d0e83aeb9969264dc577c45db16d9104d:

tools/perf/build: Fix feature-libunwind-debug-frame handling (2013-11-14 18:00:45 +0100)

are available in the git repository at:

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

for you to fetch changes up to 539e6bb71e350541105e67e3d6c31392d9da25ef:

perf record: Add an option to force per-cpu mmaps (2013-11-14 16:10:27 -0300)

----------------------------------------------------------------
perf/core improvements and fixes:

. Synthesize anon MMAP records again, fix from Don Zickus.

. Add an option in 'perf record' to force per-cpu mmaps, from Adrian Hunter.

. Limit max callchain using max_stack on DWARF unwinding too.

. Fix segfault in the UI browser caused by off by one handling END key.

. Add '--demangle'/'--no-demangle' to perf probe, so that we can overcome
current limitations in handling C++ symbols, from Azat Khuzhin .

. Tweak 'perf trace' summary output, from Pekka Enberg.

----------------------------------------------------------------
Adrian Hunter (1):
perf record: Add an option to force per-cpu mmaps

Arnaldo Carvalho de Melo (4):
perf tools: Use perf_evlist__{first,last}, perf_evsel__next perf evsel: Introduce perf_evsel__prev() method
perf symbols: Limit max callchain using max_stack on DWARF unwinding too perf ui browser: Fix segfault caused by off by one handling END key

Azat Khuzhin (1):
perf probe: Add '--demangle'/'--no-demangle'

Davidlohr Bueso (1):
perf tools: Remove trivial extra semincolon

Don Zickus (1):
perf tools: Synthesize anon MMAP records again

Ingo Molnar (1):
perf top: Add missing newline if the 'uid' is invalid

Pekka Enberg (1):
perf trace: Tweak summary output

 tools/perf/Documentation/perf-record.txt |  6 ++++++
 tools/perf/builtin-probe.c               |  2 ++
 tools/perf/builtin-record.c              |  2 ++
 tools/perf/builtin-top.c                 |  4 ++--
 tools/perf/builtin-trace.c               | 10 +++++-----
 tools/perf/tests/parse-events.c          |  3 +--
 tools/perf/ui/browser.c                  |  4 ++--
 tools/perf/ui/browsers/hists.c           | 11 +++++------
 tools/perf/util/event.c                  |  6 ++++--
 tools/perf/util/evlist.c                 |  6 ++++--
 tools/perf/util/evsel.c                  |  4 ++--
 tools/perf/util/evsel.h                  |  5 +++++
 tools/perf/util/machine.c                |  2 +-
 tools/perf/util/target.h                 |  1 +
 tools/perf/util/unwind.c                 |  9 +++++----
 tools/perf/util/unwind.h                 |  5 +++--
 16 files changed, 50 insertions(+), 30 deletions(-)
#1 lore raw

PATCH 1/10 perf trace: Tweak summary output

From: Pekka Enberg <[email protected]>

Tweak the summary output as suggested by Ingo Molnar:

  [penberg@localhost ~]$ perf trace -a --duration 10000 --summary -- sleep 1
  ^C
   Summary of events:

Xorg (817), 148 events, 0.0%, 0.000 msec

     syscall            calls      min       avg       max      stddev
                                 (msec)    (msec)    (msec)        (%)
     --------------- -------- --------- --------- ---------     ------
     read                   7     0.002     0.004     0.011     32.00%
     rt_sigprocmask        40     0.001     0.001     0.002      1.31%
     ioctl                  6     0.002     0.003     0.005     19.45%
     writev                 7     0.004     0.018     0.059     43.76%
     select                 9     0.000    74.513   507.869     74.61%
     setitimer              4     0.001     0.002     0.002     10.08%
---
 tools/perf/builtin-trace.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
tools/perf/builtin-trace.c +5 -5
index 6b230af940e2..8be17fc462ba 100644
@@ -2112,9 +2112,9 @@ static size_t thread__dump_stats(struct thread_trace *ttrace,
 
 	printed += fprintf(fp, "\n");
 
-	printed += fprintf(fp, "                                                    msec/call\n");
-	printed += fprintf(fp, "   syscall            calls      min      avg      max stddev\n");
-	printed += fprintf(fp, "   --------------- -------- -------- -------- -------- ------\n");
+	printed += fprintf(fp, "   syscall            calls      min       avg       max      stddev\n");
+	printed += fprintf(fp, "                               (msec)    (msec)    (msec)        (%%)\n");
+	printed += fprintf(fp, "   --------------- -------- --------- --------- ---------     ------\n");
 
 	/* each int_node is a syscall */
 	while (inode) {
@@ -2131,9 +2131,9 @@ static size_t thread__dump_stats(struct thread_trace *ttrace,
 
 			sc = &trace->syscalls.table[inode->i];
 			printed += fprintf(fp, "   %-15s", sc->name);
-			printed += fprintf(fp, " %8" PRIu64 " %8.3f %8.3f",
+			printed += fprintf(fp, " %8" PRIu64 " %9.3f %9.3f",
 					   n, min, avg);
-			printed += fprintf(fp, " %8.3f %6.2f\n", max, pct);
+			printed += fprintf(fp, " %9.3f %9.2f%%\n", max, pct);
 		}
 
 		inode = intlist__next(inode);
Signature · 1 line
1.8.1.4
#2 lore raw

PATCH 2/10 perf tools: Remove trivial extra semincolon

In reply to Arnaldo Carvalho de Melo

From: Davidlohr Bueso <[email protected]>

Accidentally ran into these, get rid of them.

---
 tools/perf/ui/browser.c  | 2 +-
 tools/perf/util/evlist.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
tools/perf/ui/browser.c +1 -1
index bbc782e364b0..3648d4ec041f 100644
@@ -680,7 +680,7 @@ static void __ui_browser__line_arrow_down(struct ui_browser *browser,
 	if (end >= browser->top_idx + browser->height)
 		end_row = browser->height - 1;
 	else
-		end_row = end - browser->top_idx;;
+		end_row = end - browser->top_idx;
 
 	ui_browser__gotorc(browser, row, column);
 	SLsmg_draw_vline(end_row - row + 1);
tools/perf/util/evlist.c +1 -1
index dc6fa3fbb180..5ce2ace2d6c1 100644
@@ -1148,7 +1148,7 @@ size_t perf_evlist__fprintf(struct perf_evlist *evlist, FILE *fp)
 				   perf_evsel__name(evsel));
 	}
 
-	return printed + fprintf(fp, "\n");;
+	return printed + fprintf(fp, "\n");
 }
 
 int perf_evlist__strerror_tp(struct perf_evlist *evlist __maybe_unused,
Signature · 1 line
1.8.1.4
#3 lore raw

PATCH 3/10 perf top: Add missing newline if the 'uid' is invalid

In reply to Arnaldo Carvalho de Melo

From: Ingo Molnar <[email protected]>

Add missing newline if the 'uid' is invalid:

  hubble:~> perf top --stdio -u help
  Error:
  Invalid User: helphubble:~>

Fixed by this patch:

  comet:~/tip/tools/perf> perf top --stdio -u help
  Error:
  Invalid User: help
  comet:~/tip/tools/perf>
---
 tools/perf/builtin-top.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-top.c +2 -2
index b8f8e29db332..71e6402729a8 100644
@@ -1172,7 +1172,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
 	status = target__validate(target);
 	if (status) {
 		target__strerror(target, status, errbuf, BUFSIZ);
-		ui__warning("%s", errbuf);
+		ui__warning("%s\n", errbuf);
 	}
 
 	status = target__parse_uid(target);
@@ -1180,7 +1180,7 @@ int cmd_top(int argc, const char **argv, const char *prefix __maybe_unused)
 		int saved_errno = errno;
 
 		target__strerror(target, status, errbuf, BUFSIZ);
-		ui__error("%s", errbuf);
+		ui__error("%s\n", errbuf);
 
 		status = -saved_errno;
 		goto out_delete_evlist;
Signature · 1 line
1.8.1.4
#4 lore raw

PATCH 4/10 perf tools: Synthesize anon MMAP records again

In reply to Arnaldo Carvalho de Melo

From: Don Zickus <[email protected]>

When introducing the PERF_RECORD_MMAP2 in:

5c5e854bc760 perf tools: Add attr->mmap2 support

A check for the number of entries parsed by sscanf was introduced that assumed all of the 8 fields needed to be correctly parsed so that particular /proc/pid/maps line would be considered synthesizable.

That broke anon records synthesizing, as it doesn't have the 'execname' field.

Fix it by keeping the sscanf return check, changing it to not require that the 'execname' variable be parsed, so that the preexisting logic can kick in and set it to '//anon'.

This should get things like JIT profiling working again.

Cc Bill Gray <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Joe Mario <[email protected]>
Cc Richard Fowles <[email protected]>
Cc Stephane Eranian <[email protected]>
[ commit log message is mine, dzickus reported the problem with a patch ]
---
 tools/perf/util/event.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
tools/perf/util/event.c +4 -2
index 6e3a846aed0e..bb788c109fe6 100644
@@ -209,8 +209,10 @@ static int perf_event__synthesize_mmap_events(struct perf_tool *tool,
 		       &event->mmap.start, &event->mmap.len, prot,
 		       &event->mmap.pgoff,
 		       execname);
-
-		if (n != 5)
+		/*
+ 		 * Anon maps don't have the execname.
+ 		 */
+		if (n < 4)
 			continue;
 		/*
 		 * Just like the kernel, see __perf_event_mmap in kernel/perf_event.c
Signature · 1 line
1.8.1.4
#5 lore raw

PATCH 5/10 perf tools: Use perf_evlist__{first,last}, perf_evsel__next

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

In a few remaining places where the equivalent open coded variant was still being used.

Cc Adrian Hunter <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[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/tests/parse-events.c | 3 +--
 tools/perf/ui/browsers/hists.c  | 9 ++++-----
 2 files changed, 5 insertions(+), 7 deletions(-)
tools/perf/tests/parse-events.c +1 -2
index ef671cd41bb3..3cbd10496087 100644
@@ -441,9 +441,8 @@ static int test__checkevent_pmu_name(struct perf_evlist *evlist)
 
 static int test__checkevent_pmu_events(struct perf_evlist *evlist)
 {
-	struct perf_evsel *evsel;
+	struct perf_evsel *evsel = perf_evlist__first(evlist);
 
-	evsel = list_entry(evlist->entries.next, struct perf_evsel, node);
 	TEST_ASSERT_VAL("wrong number of entries", 1 == evlist->nr_entries);
 	TEST_ASSERT_VAL("wrong type", PERF_TYPE_RAW == evsel->attr.type);
 	TEST_ASSERT_VAL("wrong exclude_user",
tools/perf/ui/browsers/hists.c +4 -5
index 16848bb4c418..089fd3713783 100644
@@ -1847,13 +1847,13 @@ browse_hists:
 			switch (key) {
 			case K_TAB:
 				if (pos->node.next == &evlist->entries)
-					pos = list_entry(evlist->entries.next, struct perf_evsel, node);
+					pos = perf_evlist__first(evlist);
 				else
-					pos = list_entry(pos->node.next, struct perf_evsel, node);
+					pos = perf_evsel__next(pos);
 				goto browse_hists;
 			case K_UNTAB:
 				if (pos->node.prev == &evlist->entries)
-					pos = list_entry(evlist->entries.prev, struct perf_evsel, node);
+					pos = perf_evlist__last(evlist);
 				else
 					pos = list_entry(pos->node.prev, struct perf_evsel, node);
 				goto browse_hists;
@@ -1943,8 +1943,7 @@ int perf_evlist__tui_browse_hists(struct perf_evlist *evlist, const char *help,
 
 single_entry:
 	if (nr_entries == 1) {
-		struct perf_evsel *first = list_entry(evlist->entries.next,
-						      struct perf_evsel, node);
+		struct perf_evsel *first = perf_evlist__first(evlist);
 		const char *ev_name = perf_evsel__name(first);
 
 		return perf_evsel__hists_browse(first, nr_entries, help,
Signature · 1 line
1.8.1.4
#6 lore raw

PATCH 6/10 perf evsel: Introduce perf_evsel__prev() method

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Just one use so far, on the hists browser, for completeness since there we use perf_evlist__{first,last} and perf_evsel__next() for handling the TAB and UNTAB keys.

Cc Adrian Hunter <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[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/ui/browsers/hists.c | 2 +-
 tools/perf/util/evsel.h        | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)
tools/perf/ui/browsers/hists.c +1 -1
index 089fd3713783..a440e03cd8c2 100644
@@ -1855,7 +1855,7 @@ browse_hists:
 				if (pos->node.prev == &evlist->entries)
 					pos = perf_evlist__last(evlist);
 				else
-					pos = list_entry(pos->node.prev, struct perf_evsel, node);
+					pos = perf_evsel__prev(pos);
 				goto browse_hists;
 			case K_ESC:
 				if (!ui_browser__dialog_yesno(&menu->b,
tools/perf/util/evsel.h +5 -0
index f5029653dcd7..1ea7c92e6e33 100644
@@ -279,6 +279,11 @@ static inline struct perf_evsel *perf_evsel__next(struct perf_evsel *evsel)
 	return list_entry(evsel->node.next, struct perf_evsel, node);
 }
 
+static inline struct perf_evsel *perf_evsel__prev(struct perf_evsel *evsel)
+{
+	return list_entry(evsel->node.prev, struct perf_evsel, node);
+}
+
 /**
  * perf_evsel__is_group_leader - Return whether given evsel is a leader event
  *
Signature · 1 line
1.8.1.4
#7 lore raw

PATCH 7/10 perf symbols: Limit max callchain using max_stack on DWARF unwinding too

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

It was affecting only frame-pointer (fp) based callchain processing.

Usage example:

  perf top --call-graph dwarf,1024 --max-stack 2

Works for any tool that does callchain resolving and provides a --max-stack option.

Cc Adrian Hunter <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[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]>
Cc Waiman Long <[email protected]>
---
 tools/perf/util/machine.c | 2 +-
 tools/perf/util/unwind.c  | 9 +++++----
 tools/perf/util/unwind.h  | 5 +++--
 3 files changed, 9 insertions(+), 7 deletions(-)
tools/perf/util/machine.c +1 -1
index 0393912d8033..84cdb072ac83 100644
@@ -1368,7 +1368,7 @@ int machine__resolve_callchain(struct machine *machine,
 
 	return unwind__get_entries(unwind_entry, &callchain_cursor, machine,
 				   thread, evsel->attr.sample_regs_user,
-				   sample);
+				   sample, max_stack);
 
 }
 
tools/perf/util/unwind.c +5 -4
index 5390d0b8862a..0efd5393de85 100644
@@ -559,7 +559,7 @@ static unw_accessors_t accessors = {
 };
 
 static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb,
-		       void *arg)
+		       void *arg, int max_stack)
 {
 	unw_addr_space_t addr_space;
 	unw_cursor_t c;
@@ -575,7 +575,7 @@ static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb,
 	if (ret)
 		display_error(ret);
 
-	while (!ret && (unw_step(&c) > 0)) {
+	while (!ret && (unw_step(&c) > 0) && max_stack--) {
 		unw_word_t ip;
 
 		unw_get_reg(&c, UNW_REG_IP, &ip);
@@ -588,7 +588,8 @@ static int get_entries(struct unwind_info *ui, unwind_entry_cb_t cb,
 
 int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
 			struct machine *machine, struct thread *thread,
-			u64 sample_uregs, struct perf_sample *data)
+			u64 sample_uregs, struct perf_sample *data,
+			int max_stack)
 {
 	unw_word_t ip;
 	struct unwind_info ui = {
@@ -610,5 +611,5 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
 	if (ret)
 		return -ENOMEM;
 
-	return get_entries(&ui, cb, arg);
+	return get_entries(&ui, cb, arg, max_stack);
 }
tools/perf/util/unwind.h +3 -2
index ec0c71a2ca2e..d5966f49e22c 100644
@@ -18,7 +18,7 @@ int unwind__get_entries(unwind_entry_cb_t cb, void *arg,
 			struct machine *machine,
 			struct thread *thread,
 			u64 sample_uregs,
-			struct perf_sample *data);
+			struct perf_sample *data, int max_stack);
 int unwind__arch_reg_id(int regnum);
 #else
 static inline int
@@ -27,7 +27,8 @@ unwind__get_entries(unwind_entry_cb_t cb __maybe_unused,
 		    struct machine *machine __maybe_unused,
 		    struct thread *thread __maybe_unused,
 		    u64 sample_uregs __maybe_unused,
-		    struct perf_sample *data __maybe_unused)
+		    struct perf_sample *data __maybe_unused,
+		    int max_stack __maybe_unused)
 {
 	return 0;
 }
Signature · 1 line
1.8.1.4
#8 lore raw

PATCH 8/10 perf ui browser: Fix segfault caused by off by one handling END key

In reply to Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

$ perf record ls
$ perf report

Press 'down enter end'

Result:

Program received signal SIGSEGV, Segmentation fault.

The UI browser, used on a argv array would access past the end of the array on SEEK_END because it wasn't using 'nr_entries - 1', fix it.

---
 tools/perf/ui/browser.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/ui/browser.c +1 -1
index 3648d4ec041f..cbaa7af45513 100644
@@ -569,7 +569,7 @@ void ui_browser__argv_seek(struct ui_browser *browser, off_t offset, int whence)
 		browser->top = browser->top + browser->top_idx + offset;
 		break;
 	case SEEK_END:
-		browser->top = browser->top + browser->nr_entries + offset;
+		browser->top = browser->top + browser->nr_entries - 1 + offset;
 		break;
 	default:
 		return;
Signature · 1 line
1.8.1.4
#9 lore raw

PATCH 9/10 perf probe: Add '--demangle'/'--no-demangle'

In reply to Arnaldo Carvalho de Melo

From: Azat Khuzhin <[email protected]>

You can't pass demangled name into "perf probe", because of special chars:
./perf probe -f -x /tmp/a.out 'foo(int)'
Semantic error :There is non-digit char in line number.

And you can't even pass without demangling (because it search symbol in DSO with demangle=true):
./perf probe -f -x /tmp/a.out _Z3fooi
no symbols found in /tmp/a.out, maybe install a debug package?

However:
nm /tmp/a.out | grep foo
000000000040056d T _Z3fooi

After this patch, using the next command:
./perf probe -f --no-demangle -x /tmp/a.out _Z3fooi

probe will be successfully added.

---
 tools/perf/builtin-probe.c | 2 ++
 1 file changed, 2 insertions(+)
tools/perf/builtin-probe.c +2 -0
index 89acc17cf2a0..6ea9e85bdc00 100644
@@ -325,6 +325,8 @@ int cmd_probe(int argc, const char **argv, const char *prefix __maybe_unused)
 		     opt_set_filter),
 	OPT_CALLBACK('x', "exec", NULL, "executable|path",
 			"target executable name or path", opt_set_target),
+	OPT_BOOLEAN(0, "demangle", &symbol_conf.demangle,
+		    "Disable symbol demangling"),
 	OPT_END()
 	};
 	int ret;
Signature · 1 line
1.8.1.4
#10 lore raw

PATCH 10/10 perf record: Add an option to force per-cpu mmaps

In reply to Arnaldo Carvalho de Melo

From: Adrian Hunter <[email protected]>

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.

Further comments by peterz:

So this option allows -t/-p/-u to create one buffer per cpu and attach all the various thread/process/user tasks' their counters to that one buffer?

As opposed to the current state where each such counter would have its own buffer.

---
 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 052f7c4dc00c..43b42c4f4a91 100644
@@ -201,6 +201,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 4d644fe2d5b7..7c8020a32784 100644
@@ -888,6 +888,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 5ce2ace2d6c1..bbc746aa5716 100644
@@ -819,7 +819,9 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)
 	if (evlist->threads == NULL)
 		return -1;
 
-	if (target__has_task(target))
+	if (target->force_per_cpu)
+		evlist->cpus = cpu_map__new(target->cpu_list);
+	else if (target__has_task(target))
 		evlist->cpus = cpu_map__dummy_new();
 	else if (!target__has_cpu(target) && !target->uses_mmap)
 		evlist->cpus = cpu_map__dummy_new();
tools/perf/util/evsel.c +2 -2
index 18f7c188ff63..46dd4c2a41ce 100644
@@ -645,7 +645,7 @@ void perf_evsel__config(struct perf_evsel *evsel,
 		}
 	}
 
-	if (target__has_cpu(&opts->target))
+	if (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 ||
-	     target__has_cpu(&opts->target)))
+	     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 89bab7129de4..2d0c50690892 100644
@@ -12,6 +12,7 @@ struct target {
 	uid_t	     uid;
 	bool	     system_wide;
 	bool	     uses_mmap;
+	bool	     force_per_cpu;
 };
 
 enum target_errno {
Signature · 1 line
1.8.1.4
#11 lore raw

Re: [PATCH 10/10] perf record: Add an option to force per-cpu mmaps

Quoted 5 lines · Arnaldo Carvalho de Melo
+--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.

So I still haven't seen an explanation why it's called 'force' anything. AFAICS nothing is 'forced' really, this is simply another trace-ringbuffer setup method, right?

And I also raised why this shouldn't be the default event tracing method instead of a weird config option. Per-cpu tracing is cache compact, it is easier to size properly and in general it is pretty easy to think about. (It also has less of the TSC timestamp ordering problems as per thread tracing, at least in theory.)

Is there something that makes per cpu tracing undesirable as the default?

Thanks,

Ingo

reviewer
#12 lore raw

Re: [PATCH 10/10] perf record: Add an option to force per-cpu mmaps

Quoted 9 lines · Ingo Molnar
Quoted 5 lines · Arnaldo Carvalho de Melo
+--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.
Quoted 3 lines

So I still haven't seen an explanation why it's called 'force' anything. AFAICS nothing is 'forced' really, this is simply another trace-ringbuffer setup method, right?

The option itself does not determine whether or not per-cpu mmaps are used. For example you cannot get a per-thread mmap for a workload by:

    perf record --no-force-per-cpu ls

So the option, as implemented, is a modifier of other options, not an option in itself. That is why its called 'force'.

To drop 'force':

From: Adrian Hunter <[email protected]>
Date: Fri, 15 Nov 2013 09:40:00 +0200
Subject: [PATCH] perf record: Drop 'force' from --force-per-cpu option

'force' is confusing so rename the option and change the documentation accordingly.

---
 tools/perf/Documentation/perf-record.txt | 10 +++++-----
 tools/perf/builtin-record.c              |  4 ++--
 2 files changed, 7 insertions(+), 7 deletions(-)
tools/perf/Documentation/perf-record.txt +5 -5
index 43b42c4..98a7d66 100644
@@ -201,11 +201,11 @@ 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.
+--per-cpu::
+Use 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 uses
+per-cpu mmaps.  A side-effect of that is that inheritance is automatically
+enabled.  Add the -i option also to disable inheritance.
 
 SEE ALSO
 --------
tools/perf/builtin-record.c +2 -2
index 7c8020a..56ca57d 100644
@@ -888,8 +888,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_BOOLEAN(0, "per-cpu", &record.opts.target.force_per_cpu,
+		    "use per-cpu mmaps"),
 	OPT_END()
 };
 
Signature · 31 lines
1.7.11.7




But really then --no-per-cpu needs to be implemented:




From: Adrian Hunter <[email protected]>
Date: Fri, 15 Nov 2013 10:26:50 +0200
Subject: [PATCH 2/2] perf record: Allow --no-per-cpu to select per-thread
 mmaps

The effect of --no-per-cpu is:

	-p, -t, -u	no difference
	-C, -a		no difference (causes a
			warning)
	otherwise	record the workload as a
			single thread i.e.
			no-inheritance

Signed-off-by: Adrian Hunter <[email protected]>
---
 tools/perf/builtin-record.c | 20 ++++++++++++++++++--
 tools/perf/util/evlist.c    |  2 +-
 tools/perf/util/target.c    | 11 ++++++++++-
 tools/perf/util/target.h    |  2 ++
 4 files changed, 31 insertions(+), 4 deletions(-)
tools/perf/builtin-record.c +18 -2
index 56ca57d..d2dbb01 100644
@@ -776,6 +776,22 @@ int record_callchain_opt(const struct option *opt,
 	return 0;
 }
 
+static int parse_per_cpu(const struct option *opt,
+			 const char *arg __maybe_unused, int unset)
+{
+	struct target *target = opt->value;
+
+	if (unset) {
+		target->force_per_cpu = false;
+		target->force_per_thread = true;
+	} else {
+		target->force_per_cpu = true;
+		target->force_per_thread = false;
+	}
+
+	return 0;
+}
+
 static const char * const record_usage[] = {
 	"perf record [<options>] [<command>]",
 	"perf record [<options>] -- <command> [<options>]",
@@ -888,8 +904,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, "per-cpu", &record.opts.target.force_per_cpu,
-		    "use per-cpu mmaps"),
+	OPT_CALLBACK_NOOPT(0, "per-cpu", &record.opts.target, "per-cpu",
+			   "use per-cpu mmaps", parse_per_cpu),
 	OPT_END()
 };
 
tools/perf/util/evlist.c +1 -1
index bbc746a..3ed4674 100644
@@ -821,7 +821,7 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)
 
 	if (target->force_per_cpu)
 		evlist->cpus = cpu_map__new(target->cpu_list);
-	else if (target__has_task(target))
+	else if (target__has_task(target) || target->force_per_thread)
 		evlist->cpus = cpu_map__dummy_new();
 	else if (!target__has_cpu(target) && !target->uses_mmap)
 		evlist->cpus = cpu_map__dummy_new();
tools/perf/util/target.c +10 -1
index 3c778a0..11d4527 100644
@@ -55,6 +55,13 @@ enum target_errno target__validate(struct target *target)
 			ret = TARGET_ERRNO__UID_OVERRIDE_SYSTEM;
 	}
 
+	if (target->force_per_thread &&
+	    (target->system_wide || target->cpu_list)) {
+		target->force_per_thread = false;
+		if (ret == TARGET_ERRNO__SUCCESS)
+			ret = TARGET_ERRNO__SYSTEM_OVERRIDE_THREAD;
+	}
+
 	return ret;
 }
 
@@ -100,6 +107,7 @@ static const char *target__error_str[] = {
 	"UID switch overriding CPU",
 	"PID/TID switch overriding SYSTEM",
 	"UID switch overriding SYSTEM",
+	"SYSTEM/CPU switch overriding NO-PER-CPU",
 	"Invalid User: %s",
 	"Problems obtaining information for user %s",
 };
@@ -131,7 +139,8 @@ int target__strerror(struct target *target, int errnum,
 	msg = target__error_str[idx];
 
 	switch (errnum) {
-	case TARGET_ERRNO__PID_OVERRIDE_CPU ... TARGET_ERRNO__UID_OVERRIDE_SYSTEM:
+	case TARGET_ERRNO__PID_OVERRIDE_CPU ...
+	     TARGET_ERRNO__SYSTEM_OVERRIDE_THREAD:
 		snprintf(buf, buflen, "%s", msg);
 		break;
 
tools/perf/util/target.h +2 -0
index 2d0c506..65494c1b 100644
@@ -13,6 +13,7 @@ struct target {
 	bool	     system_wide;
 	bool	     uses_mmap;
 	bool	     force_per_cpu;
+	bool	     force_per_thread;
 };
 
 enum target_errno {
@@ -33,6 +34,7 @@ enum target_errno {
 	TARGET_ERRNO__UID_OVERRIDE_CPU,
 	TARGET_ERRNO__PID_OVERRIDE_SYSTEM,
 	TARGET_ERRNO__UID_OVERRIDE_SYSTEM,
+	TARGET_ERRNO__SYSTEM_OVERRIDE_THREAD,
 
 	/* for target__parse_uid() */
 	TARGET_ERRNO__INVALID_UID,
Signature · 1 line
1.7.11.7
Quoted 9 lines

And I also raised why this shouldn't be the default event tracing method instead of a weird config option. Per-cpu tracing is cache compact, it is easier to size properly and in general it is pretty easy to think about. (It also has less of the TSC timestamp ordering problems as per thread tracing, at least in theory.)

Is there something that makes per cpu tracing undesirable as the default?

One reason is to avoid changing the meaning of existing options.

To flip it around, ignore the patches above and apply:

From: Adrian Hunter <[email protected]>
Date: Fri, 15 Nov 2013 11:17:56 +0200
Subject: [PATCH] perf record: Make per-cpu mmaps the default.

This affects the -p, -t and -u options that previously defaulted to per-thread mmaps.

Consequently add an option to select per-thread mmaps to support the old behaviour.

Note that per-thread can be used with a workload-only (i.e. none of -p, -t, -u, -a or -C is selected) to get a per-thread mmap with no inheritance.

---
 tools/perf/Documentation/perf-record.txt | 10 +++++-----
 tools/perf/builtin-record.c              |  5 +++--
 tools/perf/util/evlist.c                 |  6 ++++--
 tools/perf/util/evsel.c                  |  4 ++--
 tools/perf/util/target.c                 | 11 ++++++++++-
 tools/perf/util/target.h                 |  4 +++-
 6 files changed, 27 insertions(+), 13 deletions(-)
tools/perf/Documentation/perf-record.txt +5 -5
index 43b42c4..6ac867e 100644
@@ -201,11 +201,11 @@ 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.
+--per-thread::
+Use per-thread mmaps.  By default per-cpu mmaps are created.  This option
+overrides that and uses per-thread mmaps.  A side-effect of that is that
+inheritance is automatically disabled.  --per-thread is ignored with a warning
+if combined with -a or -C options.
 
 SEE ALSO
 --------
tools/perf/builtin-record.c +3 -2
index 7c8020a..f5b18b8 100644
@@ -800,6 +800,7 @@ static struct perf_record record = {
 		.freq		     = 4000,
 		.target		     = {
 			.uses_mmap   = true,
+			.default_per_cpu = true,
 		},
 	},
 };
@@ -888,8 +889,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_BOOLEAN(0, "per-thread", &record.opts.target.per_thread,
+		    "use per-thread mmaps"),
 	OPT_END()
 };
 
tools/perf/util/evlist.c +4 -2
index bbc746a..76fa764 100644
@@ -819,8 +819,10 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)
 	if (evlist->threads == NULL)
 		return -1;
 
-	if (target->force_per_cpu)
-		evlist->cpus = cpu_map__new(target->cpu_list);
+	if (target->default_per_cpu)
+		evlist->cpus = target->per_thread ?
+					cpu_map__dummy_new() :
+					cpu_map__new(target->cpu_list);
 	else if (target__has_task(target))
 		evlist->cpus = cpu_map__dummy_new();
 	else if (!target__has_cpu(target) && !target->uses_mmap)
tools/perf/util/evsel.c +2 -2
index 46dd4c2..18f7c18 100644
@@ -645,7 +645,7 @@ void perf_evsel__config(struct perf_evsel *evsel,
 		}
 	}
 
-	if (target__has_cpu(&opts->target) || opts->target.force_per_cpu)
+	if (target__has_cpu(&opts->target))
 		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 ||
-	     target__has_cpu(&opts->target) || opts->target.force_per_cpu))
+	     target__has_cpu(&opts->target)))
 		perf_evsel__set_sample_bit(evsel, TIME);
 
 	if (opts->raw_samples) {
tools/perf/util/target.c +10 -1
index 3c778a0..e74c596 100644
@@ -55,6 +55,13 @@ enum target_errno target__validate(struct target *target)
 			ret = TARGET_ERRNO__UID_OVERRIDE_SYSTEM;
 	}
 
+	/* THREAD and SYSTEM/CPU are mutually exclusive */
+	if (target->per_thread && (target->system_wide || target->cpu_list)) {
+		target->per_thread = false;
+		if (ret == TARGET_ERRNO__SUCCESS)
+			ret = TARGET_ERRNO__SYSTEM_OVERRIDE_THREAD;
+	}
+
 	return ret;
 }
 
@@ -100,6 +107,7 @@ static const char *target__error_str[] = {
 	"UID switch overriding CPU",
 	"PID/TID switch overriding SYSTEM",
 	"UID switch overriding SYSTEM",
+	"SYSTEM/CPU switch overriding PER-THREAD",
 	"Invalid User: %s",
 	"Problems obtaining information for user %s",
 };
@@ -131,7 +139,8 @@ int target__strerror(struct target *target, int errnum,
 	msg = target__error_str[idx];
 
 	switch (errnum) {
-	case TARGET_ERRNO__PID_OVERRIDE_CPU ... TARGET_ERRNO__UID_OVERRIDE_SYSTEM:
+	case TARGET_ERRNO__PID_OVERRIDE_CPU ...
+	     TARGET_ERRNO__SYSTEM_OVERRIDE_THREAD:
 		snprintf(buf, buflen, "%s", msg);
 		break;
 
tools/perf/util/target.h +3 -1
index 2d0c506..31dd2e9 100644
@@ -12,7 +12,8 @@ struct target {
 	uid_t	     uid;
 	bool	     system_wide;
 	bool	     uses_mmap;
-	bool	     force_per_cpu;
+	bool	     default_per_cpu;
+	bool	     per_thread;
 };
 
 enum target_errno {
@@ -33,6 +34,7 @@ enum target_errno {
 	TARGET_ERRNO__UID_OVERRIDE_CPU,
 	TARGET_ERRNO__PID_OVERRIDE_SYSTEM,
 	TARGET_ERRNO__UID_OVERRIDE_SYSTEM,
+	TARGET_ERRNO__SYSTEM_OVERRIDE_THREAD,
 
 	/* for target__parse_uid() */
 	TARGET_ERRNO__INVALID_UID,
Signature · 1 line
1.7.11.7
Acked-by
#13 lore raw

Re: [PATCH 10/10] perf record: Add an option to force per-cpu mmaps

Quoted 10 lines · Adrian Hunter
Quoted 8 lines

And I also raised why this shouldn't be the default event tracing method instead of a weird config option. Per-cpu tracing is cache compact, it is easier to size properly and in general it is pretty easy to think about. (It also has less of the TSC timestamp ordering problems as per thread tracing, at least in theory.)

Is there something that makes per cpu tracing undesirable as the default?

One reason is to avoid changing the meaning of existing options.

Well, the way the tracing buffers are set up is a mostly tool internal matter so in that sense it should be just fine to change the default behavior - as long as output remains unchanged (which it should).

Or is there any material change in behavior somewhere?

Quoted 3 lines

To flip it around, ignore the patches above and apply:

Subject: [PATCH] perf record: Make per-cpu mmaps the default.

Yay!

tools/perf/Documentation/perf-record.txt abort events and some memory events in precise mode on modern Intel CPUs. · line 208

Quoted 5 lines

+--per-thread::

tools/perf/Documentation/perf-record.txt +4 -0
+Use per-thread mmaps.  By default per-cpu mmaps are created.  This option
+overrides that and uses per-thread mmaps.  A side-effect of that is that
+inheritance is automatically disabled.  --per-thread is ignored with a warning
+if combined with -a or -C options.

I think this is the natural thing to do, --per-thread is the 'somewhat weird' option that cannot be used in all modes.

:-)

Thanks,

Ingo

reviewer
#14 lore raw

Re: [PATCH 10/10] perf record: Add an option to force per-cpu mmaps

Quoted 12 lines · Ingo Molnar
Quoted 9 lines · Adrian Hunter
Quoted 8 lines

And I also raised why this shouldn't be the default event tracing method instead of a weird config option. Per-cpu tracing is cache compact, it is easier to size properly and in general it is pretty easy to think about. (It also has less of the TSC timestamp ordering problems as per thread tracing, at least in theory.)

Is there something that makes per cpu tracing undesirable as the default?

Quoted 7 lines
Quoted 1 line

One reason is to avoid changing the meaning of existing options.

Well, the way the tracing buffers are set up is a mostly tool internal matter so in that sense it should be just fine to change the default behavior - as long as output remains unchanged (which it should).

Or is there any material change in behavior somewhere?

Inheritance is enabled automatically with per-cpu mmaps, although that is one of the reasons people want per-cpu mmaps.

Quoted 25 lines
Quoted 4 lines

To flip it around, ignore the patches above and apply:

Subject: [PATCH] perf record: Make per-cpu mmaps the default.

Yay!

tools/perf/Documentation/perf-record.txt abort events and some memory events in precise mode on modern Intel CPUs. · line 208

Quoted 5 lines

+--per-thread::

tools/perf/Documentation/perf-record.txt +4 -0
+Use per-thread mmaps.  By default per-cpu mmaps are created.  This option
+overrides that and uses per-thread mmaps.  A side-effect of that is that
+inheritance is automatically disabled.  --per-thread is ignored with a warning
+if combined with -a or -C options.

I think this is the natural thing to do, --per-thread is the 'somewhat weird' option that cannot be used in all modes.

:-)

Thanks,

Ingo

#15 lore raw

Re: [PATCH 10/10] perf record: Add an option to force per-cpu mmaps

Quoted 19 lines · Adrian Hunter
Quoted 18 lines · Ingo Molnar
Quoted 10 lines · Adrian Hunter
Quoted 8 lines

And I also raised why this shouldn't be the default event tracing method instead of a weird config option. Per-cpu tracing is cache compact, it is easier to size properly and in general it is pretty easy to think about. (It also has less of the TSC timestamp ordering problems as per thread tracing, at least in theory.)

Is there something that makes per cpu tracing undesirable as the default?

One reason is to avoid changing the meaning of existing options.

Well, the way the tracing buffers are set up is a mostly tool internal matter so in that sense it should be just fine to change the default behavior - as long as output remains unchanged (which it should).

Quoted 5 lines
Quoted 1 line

Or is there any material change in behavior somewhere?

Inheritance is enabled automatically with per-cpu mmaps, although that is one of the reasons people want per-cpu mmaps.

So, here's the current status quo, there's 4 basic types of profiling that 99% of the people are using, in order of popularity:

perf record <cmd>
perf record -a sleep N
perf record -p <PID>
perf record -t <TID>

The first two (which I'd guess comprise about 95% of real-world usage) have inheritance enabled.

The last two (-p/-t) have inheritance disabled by default.

Correct?

Thanks,

Ingo

maintainer
#16 lore raw

Re: [PATCH 10/10] perf record: Add an option to force per-cpu mmaps

Quoted 8 lines · Ingo Molnar

So, here's the current status quo, there's 4 basic types of profiling that 99% of the people are using, in order of popularity:

perf record <cmd>
perf record -a sleep N
perf record -p <PID>
perf record -t <TID>

Quoted 4 lines

The first two (which I'd guess comprise about 95% of real-world usage) have inheritance enabled.

The last two (-p/-t) have inheritance disabled by default.

Yes, and I would expect it to be disabled for the TID option as you explicitly select a single threads.

For the process wide thing it would make sense to enable inheritance by default though.

So the big trade-off is that for single threaded processes which do not fork you now have a single buffer, whereas with the inheritance option you'll end up with nr_cpus buffers by default.

I suppose for most normal people that's not really an issue; and I suppose all people with silly large machines already pay extra attention -- but at least make it explicit and very clear that this is so.

#17 lore raw

Re: [PATCH 10/10] perf record: Add an option to force per-cpu mmaps

Quoted 9 lines · Peter Zijlstra
Quoted 8 lines · Ingo Molnar

So, here's the current status quo, there's 4 basic types of profiling that 99% of the people are using, in order of popularity:

perf record <cmd>
perf record -a sleep N
perf record -p <PID>
perf record -t <TID>

Quoted 7 lines
Quoted 4 lines

The first two (which I'd guess comprise about 95% of real-world usage) have inheritance enabled.

The last two (-p/-t) have inheritance disabled by default.

Yes, and I would expect it to be disabled for the TID option as you explicitly select a single threads.

Correct.

Quoted 11 lines

For the process wide thing it would make sense to enable inheritance by default though.

So the big trade-off is that for single threaded processes which do not fork you now have a single buffer, whereas with the inheritance option you'll end up with nr_cpus buffers by default.

I suppose for most normal people that's not really an issue; and I suppose all people with silly large machines already pay extra attention -- but at least make it explicit and very clear that this is so.

Do the first variant, 'perf record <cmd>', already use per CPU buffers?

Thanks,

Ingo

reviewer
#18 lore raw

Re: [PATCH 10/10] perf record: Add an option to force per-cpu mmaps

Quoted 29 lines · Ingo Molnar
Quoted 9 lines · Peter Zijlstra
Quoted 8 lines · Ingo Molnar

So, here's the current status quo, there's 4 basic types of profiling that 99% of the people are using, in order of popularity:

perf record <cmd>
perf record -a sleep N
perf record -p <PID>
perf record -t <TID>

Quoted 7 lines
Quoted 4 lines

The first two (which I'd guess comprise about 95% of real-world usage) have inheritance enabled.

The last two (-p/-t) have inheritance disabled by default.

Yes, and I would expect it to be disabled for the TID option as you explicitly select a single threads.

Correct.

Quoted 7 lines

For the process wide thing it would make sense to enable inheritance by default though.

So the big trade-off is that for single threaded processes which do not fork you now have a single buffer, whereas with the inheritance option you'll end up with nr_cpus buffers by default.

Quoted 7 lines
Quoted 4 lines

I suppose for most normal people that's not really an issue; and I suppose all people with silly large machines already pay extra attention -- but at least make it explicit and very clear that this is so.

Do the first variant, 'perf record <cmd>', already use per CPU buffers?

Yes.

Another difference (and I need to fix the patch) is that per-cpu mmaps require PERF_SAMPLE_TIME so that the events do not appear out of order.

maintainer
#19 lore raw

Re: [PATCH 10/10] perf record: Add an option to force per-cpu mmaps

In reply to Ingo Molnar
Quoted 2 lines · Ingo Molnar

Do the first variant, 'perf record <cmd>', already use per CPU buffers?

Yes.. this is required for inheritance to work.

reviewer
#20 lore raw

Re: [PATCH 10/10] perf record: Add an option to force per-cpu mmaps

In reply to Peter Zijlstra
Quoted 9 lines · Peter Zijlstra
Quoted 8 lines · Ingo Molnar

So, here's the current status quo, there's 4 basic types of profiling that 99% of the people are using, in order of popularity:

perf record <cmd>
perf record -a sleep N
perf record -p <PID>
perf record -t <TID>

Quoted 7 lines
Quoted 4 lines

The first two (which I'd guess comprise about 95% of real-world usage) have inheritance enabled.

The last two (-p/-t) have inheritance disabled by default.

Yes, and I would expect it to be disabled for the TID option as you explicitly select a single threads.

So you want -t to imply -i ?

That means if you want inheritance you have to do

	-t <TID> --no-no-inherit

Or do you want another option --inherit

Quoted 15 lines

For the process wide thing it would make sense to enable inheritance by default though.

So the big trade-off is that for single threaded processes which do not fork you now have a single buffer, whereas with the inheritance option you'll end up with nr_cpus buffers by default.

I suppose for most normal people that's not really an issue; and I suppose all people with silly large machines already pay extra attention -- but at least make it explicit and very clear that this is so.

maintainer
#21 lore raw

Re: [PATCH 10/10] perf record: Add an option to force per-cpu mmaps

Quoted 18 lines · Adrian Hunter
Quoted 9 lines · Peter Zijlstra
Quoted 8 lines · Ingo Molnar

So, here's the current status quo, there's 4 basic types of profiling that 99% of the people are using, in order of popularity:

perf record <cmd>
perf record -a sleep N
perf record -p <PID>
perf record -t <TID>

Quoted 7 lines
Quoted 4 lines

The first two (which I'd guess comprise about 95% of real-world usage) have inheritance enabled.

The last two (-p/-t) have inheritance disabled by default.

Yes, and I would expect it to be disabled for the TID option as you explicitly select a single threads.

Quoted 7 lines

So you want -t to imply -i ?

That means if you want inheritance you have to do

	-t <TID> --no-no-inherit

Or do you want another option --inherit

/me boggles, they're not the same? ;-)

Maybe we should extend the option parser to know that a double negative is a nop :-)

reviewer
#22 lore raw

PATCH v2 1/1 perf record: Make per-cpu mmaps the default.

In reply to Adrian Hunter

This affects the -p, -t and -u options that previously defaulted to per-thread mmaps.

Consequently add an option to select per-thread mmaps to support the old behaviour.

Note that per-thread can be used with a workload-only (i.e. none of -p, -t, -u, -a or -C is selected) to get a per-thread mmap with no inheritance.

---

Changes in V2:

Ensure PERF_SAMPLE_TIME is set for per-cpu mmaps.

 tools/perf/Documentation/perf-record.txt     | 10 +++++-----
 tools/perf/builtin-record.c                  |  5 +++--
 tools/perf/tests/attr/test-record-no-inherit |  2 +-
 tools/perf/util/evlist.c                     |  6 ++++--
 tools/perf/util/evsel.c                      |  5 +++--
 tools/perf/util/target.c                     | 11 ++++++++++-
 tools/perf/util/target.h                     |  4 +++-
 7 files changed, 29 insertions(+), 14 deletions(-)
tools/perf/Documentation/perf-record.txt +5 -5
index 43b42c4..6ac867e 100644
@@ -201,11 +201,11 @@ 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.
+--per-thread::
+Use per-thread mmaps.  By default per-cpu mmaps are created.  This option
+overrides that and uses per-thread mmaps.  A side-effect of that is that
+inheritance is automatically disabled.  --per-thread is ignored with a warning
+if combined with -a or -C options.
 
 SEE ALSO
 --------
tools/perf/builtin-record.c +3 -2
index 7c8020a..f5b18b8 100644
@@ -800,6 +800,7 @@ static struct perf_record record = {
 		.freq		     = 4000,
 		.target		     = {
 			.uses_mmap   = true,
+			.default_per_cpu = true,
 		},
 	},
 };
@@ -888,8 +889,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_BOOLEAN(0, "per-thread", &record.opts.target.per_thread,
+		    "use per-thread mmaps"),
 	OPT_END()
 };
 
tools/perf/tests/attr/test-record-no-inherit +1 -1
index 9079a25..44edcb2 100644
@@ -3,5 +3,5 @@ command = record
 args    = -i kill >/dev/null 2>&1
 
 [event:base-record]
-sample_type=259
+sample_type=263
 inherit=0
tools/perf/util/evlist.c +4 -2
index bbc746a..76fa764 100644
@@ -819,8 +819,10 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)
 	if (evlist->threads == NULL)
 		return -1;
 
-	if (target->force_per_cpu)
-		evlist->cpus = cpu_map__new(target->cpu_list);
+	if (target->default_per_cpu)
+		evlist->cpus = target->per_thread ?
+					cpu_map__dummy_new() :
+					cpu_map__new(target->cpu_list);
 	else if (target__has_task(target))
 		evlist->cpus = cpu_map__dummy_new();
 	else if (!target__has_cpu(target) && !target->uses_mmap)
tools/perf/util/evsel.c +3 -2
index 46dd4c2..77e38ff 100644
@@ -572,6 +572,7 @@ void perf_evsel__config(struct perf_evsel *evsel,
 	struct perf_evsel *leader = evsel->leader;
 	struct perf_event_attr *attr = &evsel->attr;
 	int track = !evsel->idx; /* only the first counter needs these */
+	bool per_cpu = opts->target.default_per_cpu && !opts->target.per_thread;
 
 	attr->sample_id_all = perf_missing_features.sample_id_all ? 0 : 1;
 	attr->inherit	    = !opts->no_inherit;
@@ -645,7 +646,7 @@ void perf_evsel__config(struct perf_evsel *evsel,
 		}
 	}
 
-	if (target__has_cpu(&opts->target) || opts->target.force_per_cpu)
+	if (target__has_cpu(&opts->target))
 		perf_evsel__set_sample_bit(evsel, CPU);
 
 	if (opts->period)
@@ -653,7 +654,7 @@ void perf_evsel__config(struct perf_evsel *evsel,
 
 	if (!perf_missing_features.sample_id_all &&
 	    (opts->sample_time || !opts->no_inherit ||
-	     target__has_cpu(&opts->target) || opts->target.force_per_cpu))
+	     target__has_cpu(&opts->target) || per_cpu))
 		perf_evsel__set_sample_bit(evsel, TIME);
 
 	if (opts->raw_samples) {
tools/perf/util/target.c +10 -1
index 3c778a0..e74c596 100644
@@ -55,6 +55,13 @@ enum target_errno target__validate(struct target *target)
 			ret = TARGET_ERRNO__UID_OVERRIDE_SYSTEM;
 	}
 
+	/* THREAD and SYSTEM/CPU are mutually exclusive */
+	if (target->per_thread && (target->system_wide || target->cpu_list)) {
+		target->per_thread = false;
+		if (ret == TARGET_ERRNO__SUCCESS)
+			ret = TARGET_ERRNO__SYSTEM_OVERRIDE_THREAD;
+	}
+
 	return ret;
 }
 
@@ -100,6 +107,7 @@ static const char *target__error_str[] = {
 	"UID switch overriding CPU",
 	"PID/TID switch overriding SYSTEM",
 	"UID switch overriding SYSTEM",
+	"SYSTEM/CPU switch overriding PER-THREAD",
 	"Invalid User: %s",
 	"Problems obtaining information for user %s",
 };
@@ -131,7 +139,8 @@ int target__strerror(struct target *target, int errnum,
 	msg = target__error_str[idx];
 
 	switch (errnum) {
-	case TARGET_ERRNO__PID_OVERRIDE_CPU ... TARGET_ERRNO__UID_OVERRIDE_SYSTEM:
+	case TARGET_ERRNO__PID_OVERRIDE_CPU ...
+	     TARGET_ERRNO__SYSTEM_OVERRIDE_THREAD:
 		snprintf(buf, buflen, "%s", msg);
 		break;
 
tools/perf/util/target.h +3 -1
index 2d0c506..31dd2e9 100644
@@ -12,7 +12,8 @@ struct target {
 	uid_t	     uid;
 	bool	     system_wide;
 	bool	     uses_mmap;
-	bool	     force_per_cpu;
+	bool	     default_per_cpu;
+	bool	     per_thread;
 };
 
 enum target_errno {
@@ -33,6 +34,7 @@ enum target_errno {
 	TARGET_ERRNO__UID_OVERRIDE_CPU,
 	TARGET_ERRNO__PID_OVERRIDE_SYSTEM,
 	TARGET_ERRNO__UID_OVERRIDE_SYSTEM,
+	TARGET_ERRNO__SYSTEM_OVERRIDE_THREAD,
 
 	/* for target__parse_uid() */
 	TARGET_ERRNO__INVALID_UID,
Signature · 1 line
1.7.11.7
#23 lore raw

[tip:perf/core] perf record: Make per-cpu mmaps the default.

perf record: Make per-cpu mmaps the default.
Commit-ID:  3aa5939d71fa22a947808ba9c798b8537c35097a
Gitweb:     http://git.kernel.org/tip/3aa5939d71fa22a947808ba9c798b8537c35097a
Author:     Adrian Hunter <[email protected]>
AuthorDate: Fri, 15 Nov 2013 15:52:29 +0200
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 27 Nov 2013 14:58:36 -0300

perf record: Make per-cpu mmaps the default.

This affects the -p, -t and -u options that previously defaulted to per-thread mmaps.

Consequently add an option to select per-thread mmaps to support the old behaviour.

Note that per-thread can be used with a workload-only (i.e. none of -p, -t, -u, -a or -C is selected) to get a per-thread mmap with no inheritance.

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 Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Stephane Eranian <[email protected]>
---
 tools/perf/Documentation/perf-record.txt     | 10 +++++-----
 tools/perf/builtin-record.c                  |  5 +++--
 tools/perf/tests/attr/test-record-no-inherit |  2 +-
 tools/perf/util/evlist.c                     |  6 ++++--
 tools/perf/util/evsel.c                      |  5 +++--
 tools/perf/util/target.c                     | 11 ++++++++++-
 tools/perf/util/target.h                     |  4 +++-
 7 files changed, 29 insertions(+), 14 deletions(-)
tools/perf/Documentation/perf-record.txt +5 -5
index 43b42c4..6ac867e 100644
@@ -201,11 +201,11 @@ 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.
+--per-thread::
+Use per-thread mmaps.  By default per-cpu mmaps are created.  This option
+overrides that and uses per-thread mmaps.  A side-effect of that is that
+inheritance is automatically disabled.  --per-thread is ignored with a warning
+if combined with -a or -C options.
 
 SEE ALSO
 --------
tools/perf/builtin-record.c +3 -2
index 7c8020a..f5b18b8 100644
@@ -800,6 +800,7 @@ static struct perf_record record = {
 		.freq		     = 4000,
 		.target		     = {
 			.uses_mmap   = true,
+			.default_per_cpu = true,
 		},
 	},
 };
@@ -888,8 +889,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_BOOLEAN(0, "per-thread", &record.opts.target.per_thread,
+		    "use per-thread mmaps"),
 	OPT_END()
 };
 
tools/perf/tests/attr/test-record-no-inherit +1 -1
index 9079a25..44edcb2 100644
@@ -3,5 +3,5 @@ command = record
 args    = -i kill >/dev/null 2>&1
 
 [event:base-record]
-sample_type=259
+sample_type=263
 inherit=0
tools/perf/util/evlist.c +4 -2
index bbc746a..76fa764 100644
@@ -819,8 +819,10 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)
 	if (evlist->threads == NULL)
 		return -1;
 
-	if (target->force_per_cpu)
-		evlist->cpus = cpu_map__new(target->cpu_list);
+	if (target->default_per_cpu)
+		evlist->cpus = target->per_thread ?
+					cpu_map__dummy_new() :
+					cpu_map__new(target->cpu_list);
 	else if (target__has_task(target))
 		evlist->cpus = cpu_map__dummy_new();
 	else if (!target__has_cpu(target) && !target->uses_mmap)
tools/perf/util/evsel.c +3 -2
index dad6492..b5fe7f9 100644
@@ -574,6 +574,7 @@ void perf_evsel__config(struct perf_evsel *evsel,
 	struct perf_evsel *leader = evsel->leader;
 	struct perf_event_attr *attr = &evsel->attr;
 	int track = !evsel->idx; /* only the first counter needs these */
+	bool per_cpu = opts->target.default_per_cpu && !opts->target.per_thread;
 
 	attr->sample_id_all = perf_missing_features.sample_id_all ? 0 : 1;
 	attr->inherit	    = !opts->no_inherit;
@@ -647,7 +648,7 @@ void perf_evsel__config(struct perf_evsel *evsel,
 		}
 	}
 
-	if (target__has_cpu(&opts->target) || opts->target.force_per_cpu)
+	if (target__has_cpu(&opts->target))
 		perf_evsel__set_sample_bit(evsel, CPU);
 
 	if (opts->period)
@@ -655,7 +656,7 @@ void perf_evsel__config(struct perf_evsel *evsel,
 
 	if (!perf_missing_features.sample_id_all &&
 	    (opts->sample_time || !opts->no_inherit ||
-	     target__has_cpu(&opts->target) || opts->target.force_per_cpu))
+	     target__has_cpu(&opts->target) || per_cpu))
 		perf_evsel__set_sample_bit(evsel, TIME);
 
 	if (opts->raw_samples) {
tools/perf/util/target.c +10 -1
index 3c778a0..e74c596 100644
@@ -55,6 +55,13 @@ enum target_errno target__validate(struct target *target)
 			ret = TARGET_ERRNO__UID_OVERRIDE_SYSTEM;
 	}
 
+	/* THREAD and SYSTEM/CPU are mutually exclusive */
+	if (target->per_thread && (target->system_wide || target->cpu_list)) {
+		target->per_thread = false;
+		if (ret == TARGET_ERRNO__SUCCESS)
+			ret = TARGET_ERRNO__SYSTEM_OVERRIDE_THREAD;
+	}
+
 	return ret;
 }
 
@@ -100,6 +107,7 @@ static const char *target__error_str[] = {
 	"UID switch overriding CPU",
 	"PID/TID switch overriding SYSTEM",
 	"UID switch overriding SYSTEM",
+	"SYSTEM/CPU switch overriding PER-THREAD",
 	"Invalid User: %s",
 	"Problems obtaining information for user %s",
 };
@@ -131,7 +139,8 @@ int target__strerror(struct target *target, int errnum,
 	msg = target__error_str[idx];
 
 	switch (errnum) {
-	case TARGET_ERRNO__PID_OVERRIDE_CPU ... TARGET_ERRNO__UID_OVERRIDE_SYSTEM:
+	case TARGET_ERRNO__PID_OVERRIDE_CPU ...
+	     TARGET_ERRNO__SYSTEM_OVERRIDE_THREAD:
 		snprintf(buf, buflen, "%s", msg);
 		break;
 
tools/perf/util/target.h +3 -1
index 2d0c506..31dd2e9 100644
@@ -12,7 +12,8 @@ struct target {
 	uid_t	     uid;
 	bool	     system_wide;
 	bool	     uses_mmap;
-	bool	     force_per_cpu;
+	bool	     default_per_cpu;
+	bool	     per_thread;
 };
 
 enum target_errno {
@@ -33,6 +34,7 @@ enum target_errno {
 	TARGET_ERRNO__UID_OVERRIDE_CPU,
 	TARGET_ERRNO__PID_OVERRIDE_SYSTEM,
 	TARGET_ERRNO__UID_OVERRIDE_SYSTEM,
+	TARGET_ERRNO__SYSTEM_OVERRIDE_THREAD,
 
 	/* for target__parse_uid() */
 	TARGET_ERRNO__INVALID_UID,
#24 lore raw
In reply to Arnaldo Carvalho de Melo
Quoted 72 lines · Arnaldo Carvalho de Melo

From: Arnaldo Carvalho de Melo <[email protected]>

Hi Ingo,

Please consider pulling, done on top of tip/perf/urgent.

- Arnaldo

The following changes since commit e310718d0e83aeb9969264dc577c45db16d9104d:

tools/perf/build: Fix feature-libunwind-debug-frame handling (2013-11-14 18:00:45 +0100)

are available in the git repository at:

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

for you to fetch changes up to 539e6bb71e350541105e67e3d6c31392d9da25ef:

perf record: Add an option to force per-cpu mmaps (2013-11-14 16:10:27 -0300)

----------------------------------------------------------------
perf/core improvements and fixes:

. Synthesize anon MMAP records again, fix from Don Zickus.

. Add an option in 'perf record' to force per-cpu mmaps, from Adrian Hunter.

. Limit max callchain using max_stack on DWARF unwinding too.

. Fix segfault in the UI browser caused by off by one handling END key.

. Add '--demangle'/'--no-demangle' to perf probe, so that we can overcome
current limitations in handling C++ symbols, from Azat Khuzhin .

. Tweak 'perf trace' summary output, from Pekka Enberg.

----------------------------------------------------------------
Adrian Hunter (1):
perf record: Add an option to force per-cpu mmaps

Arnaldo Carvalho de Melo (4):
perf tools: Use perf_evlist__{first,last}, perf_evsel__next perf evsel: Introduce perf_evsel__prev() method
perf symbols: Limit max callchain using max_stack on DWARF unwinding too perf ui browser: Fix segfault caused by off by one handling END key

Azat Khuzhin (1):
perf probe: Add '--demangle'/'--no-demangle'

Davidlohr Bueso (1):
perf tools: Remove trivial extra semincolon

Don Zickus (1):
perf tools: Synthesize anon MMAP records again

Ingo Molnar (1):
perf top: Add missing newline if the 'uid' is invalid

Pekka Enberg (1):
perf trace: Tweak summary output

 tools/perf/Documentation/perf-record.txt |  6 ++++++
 tools/perf/builtin-probe.c               |  2 ++
 tools/perf/builtin-record.c              |  2 ++
 tools/perf/builtin-top.c                 |  4 ++--
 tools/perf/builtin-trace.c               | 10 +++++-----
 tools/perf/tests/parse-events.c          |  3 +--
 tools/perf/ui/browser.c                  |  4 ++--
 tools/perf/ui/browsers/hists.c           | 11 +++++------
 tools/perf/util/event.c                  |  6 ++++--
Quoted 8 lines
 tools/perf/util/evlist.c                 |  6 ++++--
 tools/perf/util/evsel.c                  |  4 ++--
 tools/perf/util/evsel.h                  |  5 +++++
 tools/perf/util/machine.c                |  2 +-
 tools/perf/util/target.h                 |  1 +
 tools/perf/util/unwind.c                 |  9 +++++----
 tools/perf/util/unwind.h                 |  5 +++--
 16 files changed, 50 insertions(+), 30 deletions(-)

Pulled, thanks a lot Arnaldo!

Ingo