Skip to contentSkip to conversation

perf top: Fix freeze on --call-graph flat/folded

PATCH Applied Namhyung Kim 6 participants 22 messages Nov 26, 2015 – Dec 2, 2015 perf events

lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

PATCH 1/3 perf top: Fix freeze on --call-graph flat/folded

The callchain rbtree is rebuilt periodically, so it needs to reinitialize the root everytime. Otherwise it can be stuck in the rbtree insertion with stale pointers.

---
 tools/perf/util/callchain.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/callchain.c +1 -0
index fc3b1e0d09ee..564377d2bebf 100644
@@ -290,6 +290,7 @@ static void
 sort_chain_flat(struct rb_root *rb_root, struct callchain_root *root,
 		u64 min_hit, struct callchain_param *param __maybe_unused)
 {
+	*rb_root = RB_ROOT;
 	__sort_chain_flat(rb_root, &root->node, min_hit);
 }
 
Signature · 1 line
2.6.2
author maintainer
#1 lore raw

PATCH 2/3 perf callchain: Stop resolving callchains after invalid address

Unwinding optimized binaries using frame pointer gives garbage. Check callchain address and stop if it's under vm.mmap_min_addr sysctl value.

Before:

  $ perf report --stdio --no-children -g callee
  ...

1.37% perf [kernel.vmlinux] [k] smp_call_function_single

               |
               ---smp_call_function_single
                  _perf_event_enable
                  perf_event_for_each_child
                  perf_ioctl
                  do_vfs_ioctl
                  sys_ioctl
                  entry_SYSCALL_64_fastpath
                  __GI___ioctl
                  0
                  0
                  0x1c5aa70
                  0x1c5b910
                  0x1c5aa70
                  0x1c5b910
                  0x1c5aa70
                  0x1c5b910
                  0x1c5aa70
                  0x1c5b910
                  0x1c5aa70
                  0x1c5b910
		  ...

After:

  $ perf report --stdio --no-children -g callee
  ...

1.37% perf [kernel.vmlinux] [k] smp_call_function_single

               |
               ---smp_call_function_single
                  _perf_event_enable
                  perf_event_for_each_child
                  perf_ioctl
                  do_vfs_ioctl
                  sys_ioctl
                  entry_SYSCALL_64_fastpath
                  __GI___ioctl
  $ perf report --stdio --no-children -g caller
  ...

1.37% perf [kernel.vmlinux] [k] smp_call_function_single

               |
               ---__GI__ioctl
                  entry_SYSCALL_64_fastpath
                  sys_ioctl
                  do_vfs_ioctl
                  perf_ioctl
                  perf_event_for_each_child
                  _perf_event_enable
                  smp_call_function_single
---
 tools/perf/perf.c         |  6 ++++++
 tools/perf/util/machine.c | 13 +++++++++++++
 tools/perf/util/util.c    |  1 +
 tools/perf/util/util.h    |  1 +
 4 files changed, 21 insertions(+)
tools/perf/perf.c +6 -0
index 4bee53c3f796..0075a6d38e3a 100644
@@ -18,6 +18,7 @@
 #include "util/bpf-loader.h"
 #include "util/debug.h"
 #include <api/fs/tracing_path.h>
+#include <api/fs/fs.h>
 #include <pthread.h>
 
 const char perf_usage_string[] =
@@ -528,11 +529,16 @@ int main(int argc, const char **argv)
 {
 	const char *cmd;
 	char sbuf[STRERR_BUFSIZE];
+	int min_addr;
 
 	/* The page_size is placed in util object. */
 	page_size = sysconf(_SC_PAGE_SIZE);
 	cacheline_size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
 
+	if (sysctl__read_int("vm/mmap_min_addr", &min_addr) < 0)
+		min_addr = page_size;
+	mmap_min_addr = min_addr;
+
 	cmd = perf_extract_argv0_path(argv[0]);
 	if (!cmd)
 		cmd = "perf-help";
tools/perf/util/machine.c +13 -0
index 7f5071a4d9aa..0a2f35e0d737 100644
@@ -1860,6 +1860,19 @@ static int thread__resolve_callchain_sample(struct thread *thread,
 #endif
 		ip = chain->ips[j];
 
+		/*
+		 * Callchain value under mmap_min_addr means it's broken
+		 * or the end of callchain.  Stop.
+		 */
+		if (ip < mmap_min_addr) {
+			if (callchain_param.order == ORDER_CALLEE)
+				break;
+
+			/* ignore current callchains for CALLER order */
+			callchain_cursor_reset(&callchain_cursor);
+			continue;
+		}
+
 		err = add_callchain_ip(thread, parent, root_al, &cpumode, ip);
 
 		if (err)
tools/perf/util/util.c +1 -0
index 75759aebc7b8..8e198acd9fa6 100644
@@ -30,6 +30,7 @@ struct callchain_param	callchain_param = {
  */
 unsigned int page_size;
 int cacheline_size;
+unsigned long mmap_min_addr;
 
 bool test_attr__enabled;
 
tools/perf/util/util.h +1 -0
index dcc659017976..506d4dbb58be 100644
@@ -281,6 +281,7 @@ void sighandler_dump_stack(int sig);
 
 extern unsigned int page_size;
 extern int cacheline_size;
+extern unsigned long mmap_min_addr;
 
 void get_term_dimensions(struct winsize *ws);
 void set_term_quiet_input(struct termios *old);
Signature · 1 line
2.6.2
#2 lore raw

Re: [PATCH 2/3] perf callchain: Stop resolving callchains after invalid address

Quoted 35 lines · Namhyung Kim

Unwinding optimized binaries using frame pointer gives garbage. Check callchain address and stop if it's under vm.mmap_min_addr sysctl value.

Before:

  $ perf report --stdio --no-children -g callee
  ...
   1.37%  perf    [kernel.vmlinux]    [k] smp_call_function_single
               |
               ---smp_call_function_single
                  _perf_event_enable
                  perf_event_for_each_child
                  perf_ioctl
                  do_vfs_ioctl
                  sys_ioctl
                  entry_SYSCALL_64_fastpath
                  __GI___ioctl
                  0
                  0
                  0x1c5aa70
                  0x1c5b910
                  0x1c5aa70
                  0x1c5b910
                  0x1c5aa70
                  0x1c5b910
                  0x1c5aa70
                  0x1c5b910
                  0x1c5aa70
                  0x1c5b910
		  ...

After:

  $ perf report --stdio --no-children -g callee
  ...
Quoted 10 lines
   1.37%  perf    [kernel.vmlinux]    [k] smp_call_function_single
               |
               ---smp_call_function_single
                  _perf_event_enable
                  perf_event_for_each_child
                  perf_ioctl
                  do_vfs_ioctl
                  sys_ioctl
                  entry_SYSCALL_64_fastpath
                  __GI___ioctl

In addition to that, would it make sense to terminate the callchain with an indicator that we found something anomalous? Such an extra line:

                    ...

would not be intrusive, but would tell the informed reader that it's not a normal ending of the call chain.

This assumes that we can tell apart 'normal end of call chain' from 'seems to end with garbage poiner' cases - can do we that?

Thanks,

Ingo

author maintainer
#3 lore raw

Re: [PATCH 2/3] perf callchain: Stop resolving callchains after invalid address

Hi Ingo,

Quoted 52 lines · Ingo Molnar
Quoted 35 lines · Namhyung Kim

Unwinding optimized binaries using frame pointer gives garbage. Check callchain address and stop if it's under vm.mmap_min_addr sysctl value.

Before:

  $ perf report --stdio --no-children -g callee
  ...
   1.37%  perf    [kernel.vmlinux]    [k] smp_call_function_single
               |
               ---smp_call_function_single
                  _perf_event_enable
                  perf_event_for_each_child
                  perf_ioctl
                  do_vfs_ioctl
                  sys_ioctl
                  entry_SYSCALL_64_fastpath
                  __GI___ioctl
                  0
                  0
                  0x1c5aa70
                  0x1c5b910
                  0x1c5aa70
                  0x1c5b910
                  0x1c5aa70
                  0x1c5b910
                  0x1c5aa70
                  0x1c5b910
                  0x1c5aa70
                  0x1c5b910
		  ...

After:

  $ perf report --stdio --no-children -g callee
  ...
Quoted 10 lines
   1.37%  perf    [kernel.vmlinux]    [k] smp_call_function_single
               |
               ---smp_call_function_single
                  _perf_event_enable
                  perf_event_for_each_child
                  perf_ioctl
                  do_vfs_ioctl
                  sys_ioctl
                  entry_SYSCALL_64_fastpath
                  __GI___ioctl

In addition to that, would it make sense to terminate the callchain with an indicator that we found something anomalous? Such an extra line:

Quoted 7 lines
                    ...

would not be intrusive, but would tell the informed reader that it's not a normal ending of the call chain.

This assumes that we can tell apart 'normal end of call chain' from 'seems to end with garbage poiner' cases - can do we that?

In case of fp unwind, I'm not sure we can determine whether it's normal end or not especially for optimized binaries. It seems kernel also can stop callchain anytime if it sees a broken frame.

For dwarf unwind, I think it's also hard to tell since it can be stopped for various reasons like insufficient dump size or broken CFI,
...

Thanks,
Namhyung

#4 lore raw

Re: [PATCH 2/3] perf callchain: Stop resolving callchains after invalid address

Quoted 63 lines · Namhyung Kim

Hi Ingo,

Quoted 52 lines · Ingo Molnar
Quoted 35 lines · Namhyung Kim

Unwinding optimized binaries using frame pointer gives garbage. Check callchain address and stop if it's under vm.mmap_min_addr sysctl value.

Before:

  $ perf report --stdio --no-children -g callee
  ...
   1.37%  perf    [kernel.vmlinux]    [k] smp_call_function_single
               |
               ---smp_call_function_single
                  _perf_event_enable
                  perf_event_for_each_child
                  perf_ioctl
                  do_vfs_ioctl
                  sys_ioctl
                  entry_SYSCALL_64_fastpath
                  __GI___ioctl
                  0
                  0
                  0x1c5aa70
                  0x1c5b910
                  0x1c5aa70
                  0x1c5b910
                  0x1c5aa70
                  0x1c5b910
                  0x1c5aa70
                  0x1c5b910
                  0x1c5aa70
                  0x1c5b910
		  ...

After:

  $ perf report --stdio --no-children -g callee
  ...
Quoted 10 lines
   1.37%  perf    [kernel.vmlinux]    [k] smp_call_function_single
               |
               ---smp_call_function_single
                  _perf_event_enable
                  perf_event_for_each_child
                  perf_ioctl
                  do_vfs_ioctl
                  sys_ioctl
                  entry_SYSCALL_64_fastpath
                  __GI___ioctl

In addition to that, would it make sense to terminate the callchain with an indicator that we found something anomalous? Such an extra line:

Quoted 7 lines
                    ...

would not be intrusive, but would tell the informed reader that it's not a normal ending of the call chain.

This assumes that we can tell apart 'normal end of call chain' from 'seems to end with garbage poiner' cases - can do we that?

Quoted 6 lines

In case of fp unwind, I'm not sure we can determine whether it's normal end or not especially for optimized binaries. It seems kernel also can stop callchain anytime if it sees a broken frame.

For dwarf unwind, I think it's also hard to tell since it can be stopped for various reasons like insufficient dump size or broken CFI,

But but. Doesn't your patch 'detect' an anomaly to begin with?

+ /*

+                * Callchain value under mmap_min_addr means it's broken
+                * or the end of callchain.  Stop.
+                */

+ if (ip < mmap_min_addr) {
+ if (callchain_param.order == ORDER_CALLEE)
+ break;

all I'm asking for is to indicate it in some low-key visual fashion when we encounter such a 'broken' call-chain.

I presume the 'old' way of ending the call-chain was that 'ip' was zero, right? We should not print the indicator in that case.

Also, in the dwarf case I'd also see value in indicating if any of these events occured:

Quoted 2 lines

For dwarf unwind, I think it's also hard to tell since it can be stopped for various reasons like insufficient dump size or broken CFI,

even if we cannot catch all anomalies. Performance analysis must stand firm on a hard rock of reliability and dependability, and we should always propagate information about possible profiling data corruption/unreliability. That's why we print the 'IO overload' messages during perf record for example.

Even if the problem is not caused by perf, but by external factors such as the compiler/linker.

Thanks,

Ingo

#5 lore raw

Re: [PATCH 2/3] perf callchain: Stop resolving callchains after invalid address

In reply to Namhyung Kim

tools/perf/perf.c int main(int argc, const char **argv) · line 538

Quoted 11 lines · Namhyung Kim
tools/perf/perf.c +2 -0
@@ -528,11 +529,16 @@ int main(int argc, const char **argv)
  {
  	const char *cmd;
  	char sbuf[STRERR_BUFSIZE];
+	int min_addr;
 
  	/* The page_size is placed in util object. */
  	page_size = sysconf(_SC_PAGE_SIZE);
  	cacheline_size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
 
+	if (sysctl__read_int("vm/mmap_min_addr", &min_addr) < 0)

This assumes the record and analysis are done on the same system.

David

author maintainer
#6 lore raw

Re: [PATCH 2/3] perf callchain: Stop resolving callchains after invalid address

Hi David,

Quoted 7 lines · David Ahern
Quoted 6 lines · Namhyung Kim
tools/perf/perf.c +1 -0
@@ -528,11 +529,16 @@ int main(int argc, const char **argv)
 {
 	const char *cmd;
 	char sbuf[STRERR_BUFSIZE];
+	int min_addr;
 
Quoted 7 lines

tools/perf/perf.c int main(int argc, const char **argv) · line 538

Quoted 5 lines
tools/perf/perf.c +1 -0
 	/* The page_size is placed in util object. */
 	page_size = sysconf(_SC_PAGE_SIZE);
 	cacheline_size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
 
+	if (sysctl__read_int("vm/mmap_min_addr", &min_addr) < 0)

This assumes the record and analysis are done on the same system.

Right. Maybe we can just use minimal size (or page size?) or save and pass it through somewhere in the feature bit?

Thanks,
Namhyung

#7 lore raw

Re: [PATCH 2/3] perf callchain: Stop resolving callchains after invalid address

Quoted 14 lines · Namhyung Kim

Hi David,

Quoted 11 lines · David Ahern
Quoted 10 lines · Namhyung Kim
tools/perf/perf.c +1 -0
@@ -528,11 +529,16 @@ int main(int argc, const char **argv)
  {
  	const char *cmd;
  	char sbuf[STRERR_BUFSIZE];
+	int min_addr;
 
  	/* The page_size is placed in util object. */
  	page_size = sysconf(_SC_PAGE_SIZE);
  	cacheline_size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
 
Quoted 6 lines
Quoted 3 lines

tools/perf/perf.c int main(int argc, const char **argv) · line 538

Quoted 1 line
tools/perf/perf.c +1 -0
+	if (sysctl__read_int("vm/mmap_min_addr", &min_addr) < 0)

This assumes the record and analysis are done on the same system.

Right. Maybe we can just use minimal size (or page size?) or save and pass it through somewhere in the feature bit?

no preference, but it should work with cross arch analysis as well (e.g., record on arm/ppc and analysis on x86)

#8 lore raw

Re: [PATCH 2/3] perf callchain: Stop resolving callchains after invalid address

Quoted 19 lines · David Ahern
Quoted 18 lines · Namhyung Kim

Hi David,

Quoted 14 lines · David Ahern

tools/perf/perf.c int main(int argc, const char **argv) · line 538

Quoted 11 lines · Namhyung Kim
tools/perf/perf.c +2 -0
@@ -528,11 +529,16 @@ int main(int argc, const char **argv)
 {
 	const char *cmd;
 	char sbuf[STRERR_BUFSIZE];
+	int min_addr;
 
 	/* The page_size is placed in util object. */
 	page_size = sysconf(_SC_PAGE_SIZE);
 	cacheline_size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
 
+	if (sysctl__read_int("vm/mmap_min_addr", &min_addr) < 0)

This assumes the record and analysis are done on the same system.

Quoted 5 lines
Quoted 2 lines

Right. Maybe we can just use minimal size (or page size?) or save and pass it through somewhere in the feature bit?

no preference, but it should work with cross arch analysis as well (e.g., record on arm/ppc and analysis on x86)

I think we should store it in perf.data in features, but seems like a waste to spend one bit just for this number.

I remember commenting on new CPU related FEATURE data, that would contain cpu specific data in extensible form like TAG,VALUE,TAG,VALUE..

but I think the design changed or something, because I cannot find it in now ;-)

maybe we could add something like that

jirka

#9 lore raw

Re: [PATCH 2/3] perf callchain: Stop resolving callchains after invalid address

Em Thu, Nov 26, 2015 at 04:58:57PM +0100, Jiri Olsa escreveu:

Quoted 12 lines · David Ahern
Quoted 11 lines · Namhyung Kim
Quoted 10 lines

Hi David,

Quoted 7 lines · David Ahern
Quoted 6 lines · Namhyung Kim
tools/perf/perf.c +1 -0
@@ -528,11 +529,16 @@ int main(int argc, const char **argv)
 {
 	const char *cmd;
 	char sbuf[STRERR_BUFSIZE];
+	int min_addr;
 
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

tools/perf/perf.c int main(int argc, const char **argv) · line 538

Quoted 5 lines
tools/perf/perf.c +1 -0
 	/* The page_size is placed in util object. */
 	page_size = sysconf(_SC_PAGE_SIZE);
 	cacheline_size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
 
+	if (sysctl__read_int("vm/mmap_min_addr", &min_addr) < 0)

Please put this in that symbol_conf kitchen sink :-)

I'm unsure though if there would be a reason for having both the local min_addr and the one at perf record time, i.e. from perf.data :-\

Quoted 11 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

This assumes the record and analysis are done on the same system.

Right. Maybe we can just use minimal size (or page size?) or save and pass it through somewhere in the feature bit?

no preference, but it should work with cross arch analysis as well (e.g., record on arm/ppc and analysis on x86)

I think we should store it in perf.data in features, but seems like a waste to spend one bit just for this number.

Quoted 6 lines

I remember commenting on new CPU related FEATURE data, that would contain cpu specific data in extensible form like TAG,VALUE,TAG,VALUE..

but I think the design changed or something, because I cannot find it in now ;-)

maybe we could add something like that

Right, isn't that one part of the perf/stat patchkit?

- Arnaldo

author maintainer
#10 lore raw

Re: [PATCH 2/3] perf callchain: Stop resolving callchains after invalid address

Quoted 17 lines · Arnaldo Carvalho de Melo

Em Thu, Nov 26, 2015 at 04:58:57PM +0100, Jiri Olsa escreveu:

Quoted 16 lines · David Ahern
Quoted 15 lines · Namhyung Kim
Quoted 14 lines

Hi David,

Quoted 11 lines · David Ahern
Quoted 10 lines · Namhyung Kim
tools/perf/perf.c +1 -0
@@ -528,11 +529,16 @@ int main(int argc, const char **argv)
 {
 	const char *cmd;
 	char sbuf[STRERR_BUFSIZE];
+	int min_addr;
 
 	/* The page_size is placed in util object. */
 	page_size = sysconf(_SC_PAGE_SIZE);
 	cacheline_size = sysconf(_SC_LEVEL1_DCACHE_LINESIZE);
 
Quoted 6 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

tools/perf/perf.c int main(int argc, const char **argv) · line 538

Quoted 1 line
tools/perf/perf.c +1 -0
+	if (sysctl__read_int("vm/mmap_min_addr", &min_addr) < 0)

Please put this in that symbol_conf kitchen sink :-)

I'm unsure though if there would be a reason for having both the local min_addr and the one at perf record time, i.e. from perf.data :-\

Otherwise, it can use different value and can treat valid addresses as invalid especially if the difference is huge.

Btw, I think it should be kernel to cut off these invalid callchains in the first place, no?

Quoted 12 lines
Quoted 12 lines
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

This assumes the record and analysis are done on the same system.

Right. Maybe we can just use minimal size (or page size?) or save and pass it through somewhere in the feature bit?

no preference, but it should work with cross arch analysis as well (e.g., record on arm/ppc and analysis on x86)

I think we should store it in perf.data in features, but seems like a waste to spend one bit just for this number.

Quoted 8 lines
Quoted 6 lines

I remember commenting on new CPU related FEATURE data, that would contain cpu specific data in extensible form like TAG,VALUE,TAG,VALUE..

but I think the design changed or something, because I cannot find it in now ;-)

maybe we could add something like that

Right, isn't that one part of the perf/stat patchkit?

I'll take a look. Jiri, could you give the link if you have it?

Thanks,
Namhyung

author maintainer
#11 lore raw

PATCH 3/3 perf callchain: Honor hide_unresolved

In reply to Namhyung Kim

If user requested to hide unresolved entries, skip unresolved callchains as well as hist entries.

---
 tools/perf/builtin-report.c | 7 +++----
 tools/perf/util/machine.c   | 5 +++++
 tools/perf/util/symbol.h    | 3 ++-
 3 files changed, 10 insertions(+), 5 deletions(-)
tools/perf/builtin-report.c +3 -4
index 14428342b47b..8a9c6908f54e 100644
@@ -45,7 +45,6 @@ struct report {
 	struct perf_tool	tool;
 	struct perf_session	*session;
 	bool			use_tui, use_gtk, use_stdio;
-	bool			hide_unresolved;
 	bool			dont_use_callchains;
 	bool			show_full_info;
 	bool			show_threads;
@@ -146,7 +145,7 @@ static int process_sample_event(struct perf_tool *tool,
 	struct hist_entry_iter iter = {
 		.evsel 			= evsel,
 		.sample 		= sample,
-		.hide_unresolved 	= rep->hide_unresolved,
+		.hide_unresolved 	= symbol_conf.hide_unresolved,
 		.add_entry_cb 		= hist_iter__report_callback,
 	};
 	int ret = 0;
@@ -157,7 +156,7 @@ static int process_sample_event(struct perf_tool *tool,
 		return -1;
 	}
 
-	if (rep->hide_unresolved && al.sym == NULL)
+	if (symbol_conf.hide_unresolved && al.sym == NULL)
 		goto out_put;
 
 	if (rep->cpu_list && !test_bit(sample->cpu, rep->cpu_bitmap))
@@ -740,7 +739,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
 	OPT_STRING_NOEMPTY('t', "field-separator", &symbol_conf.field_sep, "separator",
 		   "separator for columns, no spaces will be added between "
 		   "columns '.' is reserved."),
-	OPT_BOOLEAN('U', "hide-unresolved", &report.hide_unresolved,
+	OPT_BOOLEAN('U', "hide-unresolved", &symbol_conf.hide_unresolved,
 		    "Only display entries resolved to a symbol"),
 	OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
 		    "Look for files with symbols relative to this directory"),
tools/perf/util/machine.c +5 -0
index 0a2f35e0d737..9843fe680cb0 100644
@@ -1618,6 +1618,8 @@ static int add_callchain_ip(struct thread *thread,
 		}
 	}
 
+	if (symbol_conf.hide_unresolved && al.sym == NULL)
+		return 0;
 	return callchain_cursor_append(&callchain_cursor, al.addr, al.map, al.sym);
 }
 
@@ -1885,6 +1887,9 @@ static int thread__resolve_callchain_sample(struct thread *thread,
 static int unwind_entry(struct unwind_entry *entry, void *arg)
 {
 	struct callchain_cursor *cursor = arg;
+
+	if (symbol_conf.hide_unresolved && entry->sym == NULL)
+		return 0;
 	return callchain_cursor_append(cursor, entry->ip,
 				       entry->map, entry->sym);
 }
tools/perf/util/symbol.h +2 -1
index dcd786e364f2..857f707ac12b 100644
@@ -108,7 +108,8 @@ struct symbol_conf {
 			show_hist_headers,
 			branch_callstack,
 			has_filter,
-			show_ref_callgraph;
+			show_ref_callgraph,
+			hide_unresolved;
 	const char	*vmlinux_name,
 			*kallsyms_name,
 			*source_prefix,
Signature · 1 line
2.6.2
#14 lore raw

[tip:perf/core] perf callchain: Honor hide_unresolved

In reply to Namhyung Kim
perf callchain: Honor hide_unresolved
Commit-ID:  b49a8fe52626814968b9a9d27d7ad1cadc5532ed
Gitweb:     http://git.kernel.org/tip/b49a8fe52626814968b9a9d27d7ad1cadc5532ed
Author:     Namhyung Kim <[email protected]>
AuthorDate: Thu, 26 Nov 2015 16:08:20 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 26 Nov 2015 13:19:39 -0300

perf callchain: Honor hide_unresolved

If user requested to hide unresolved entries, skip unresolved callchains as well as hist entries.

---
 tools/perf/builtin-report.c | 7 +++----
 tools/perf/util/machine.c   | 5 +++++
 tools/perf/util/symbol.h    | 3 ++-
 3 files changed, 10 insertions(+), 5 deletions(-)
tools/perf/builtin-report.c +3 -4
index 1442834..8a9c690 100644
@@ -45,7 +45,6 @@ struct report {
 	struct perf_tool	tool;
 	struct perf_session	*session;
 	bool			use_tui, use_gtk, use_stdio;
-	bool			hide_unresolved;
 	bool			dont_use_callchains;
 	bool			show_full_info;
 	bool			show_threads;
@@ -146,7 +145,7 @@ static int process_sample_event(struct perf_tool *tool,
 	struct hist_entry_iter iter = {
 		.evsel 			= evsel,
 		.sample 		= sample,
-		.hide_unresolved 	= rep->hide_unresolved,
+		.hide_unresolved 	= symbol_conf.hide_unresolved,
 		.add_entry_cb 		= hist_iter__report_callback,
 	};
 	int ret = 0;
@@ -157,7 +156,7 @@ static int process_sample_event(struct perf_tool *tool,
 		return -1;
 	}
 
-	if (rep->hide_unresolved && al.sym == NULL)
+	if (symbol_conf.hide_unresolved && al.sym == NULL)
 		goto out_put;
 
 	if (rep->cpu_list && !test_bit(sample->cpu, rep->cpu_bitmap))
@@ -740,7 +739,7 @@ int cmd_report(int argc, const char **argv, const char *prefix __maybe_unused)
 	OPT_STRING_NOEMPTY('t', "field-separator", &symbol_conf.field_sep, "separator",
 		   "separator for columns, no spaces will be added between "
 		   "columns '.' is reserved."),
-	OPT_BOOLEAN('U', "hide-unresolved", &report.hide_unresolved,
+	OPT_BOOLEAN('U', "hide-unresolved", &symbol_conf.hide_unresolved,
 		    "Only display entries resolved to a symbol"),
 	OPT_STRING(0, "symfs", &symbol_conf.symfs, "directory",
 		    "Look for files with symbols relative to this directory"),
tools/perf/util/machine.c +5 -0
index 7f5071a..f0019b7 100644
@@ -1618,6 +1618,8 @@ static int add_callchain_ip(struct thread *thread,
 		}
 	}
 
+	if (symbol_conf.hide_unresolved && al.sym == NULL)
+		return 0;
 	return callchain_cursor_append(&callchain_cursor, al.addr, al.map, al.sym);
 }
 
@@ -1872,6 +1874,9 @@ check_calls:
 static int unwind_entry(struct unwind_entry *entry, void *arg)
 {
 	struct callchain_cursor *cursor = arg;
+
+	if (symbol_conf.hide_unresolved && entry->sym == NULL)
+		return 0;
 	return callchain_cursor_append(cursor, entry->ip,
 				       entry->map, entry->sym);
 }
tools/perf/util/symbol.h +2 -1
index dcd786e..857f707 100644
@@ -108,7 +108,8 @@ struct symbol_conf {
 			show_hist_headers,
 			branch_callstack,
 			has_filter,
-			show_ref_callgraph;
+			show_ref_callgraph,
+			hide_unresolved;
 	const char	*vmlinux_name,
 			*kallsyms_name,
 			*source_prefix,
#15 lore raw
In reply to Namhyung Kim
Quoted 14 lines · Namhyung Kim

The callchain rbtree is rebuilt periodically, so it needs to reinitialize the root everytime. Otherwise it can be stuck in the rbtree insertion with stale pointers.

---
 tools/perf/util/callchain.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/callchain.c +0 -0
index fc3b1e0d09ee..564377d2bebf 100644

tools/perf/util/callchain.c static void · line 293

Quoted 4 lines
tools/perf/util/callchain.c +1 -0
@@ -290,6 +290,7 @@ static void
 sort_chain_flat(struct rb_root *rb_root, struct callchain_root *root,
 		u64 min_hit, struct callchain_param *param __maybe_unused)
 {
+	*rb_root = RB_ROOT;

it seems ok, but I did not find how this could be called twice?

the only sort I can see is done within:
__hists__insert_output_entry

do we allow resorting of the callchains?

thanks,
jirka

Quoted 6 lines
tools/perf/util/callchain.c +0 -0
 	__sort_chain_flat(rb_root, &root->node, min_hit);
 }
 
Signature · 1 line
2.6.2
author maintainer
#16 lore raw

Hi Jiri,

Quoted 22 lines · Jiri Olsa
Quoted 14 lines · Namhyung Kim

The callchain rbtree is rebuilt periodically, so it needs to reinitialize the root everytime. Otherwise it can be stuck in the rbtree insertion with stale pointers.

---
 tools/perf/util/callchain.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/callchain.c +0 -0
index fc3b1e0d09ee..564377d2bebf 100644

tools/perf/util/callchain.c static void · line 293

Quoted 4 lines
tools/perf/util/callchain.c +1 -0
@@ -290,6 +290,7 @@ static void
 sort_chain_flat(struct rb_root *rb_root, struct callchain_root *root,
 		u64 min_hit, struct callchain_param *param __maybe_unused)
 {
+	*rb_root = RB_ROOT;

it seems ok, but I did not find how this could be called twice?

Quoted 4 lines

the only sort I can see is done within:
__hists__insert_output_entry

do we allow resorting of the callchains?

No, but I think it's possible though.

It's called from perf top's display thread.

display_thread()
-> while (!done)

     -> perf_top__print_sym_table()
        -> hists__output_resort()
           -> __hists__insert_output_entry()

Thanks,
Namhyung

#17 lore raw
Quoted 25 lines · Namhyung Kim

Hi Jiri,

Quoted 22 lines · Jiri Olsa
Quoted 14 lines · Namhyung Kim

The callchain rbtree is rebuilt periodically, so it needs to reinitialize the root everytime. Otherwise it can be stuck in the rbtree insertion with stale pointers.

---
 tools/perf/util/callchain.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/callchain.c +0 -0
index fc3b1e0d09ee..564377d2bebf 100644

tools/perf/util/callchain.c static void · line 293

Quoted 4 lines
tools/perf/util/callchain.c +1 -0
@@ -290,6 +290,7 @@ static void
 sort_chain_flat(struct rb_root *rb_root, struct callchain_root *root,
 		u64 min_hit, struct callchain_param *param __maybe_unused)
 {
+	*rb_root = RB_ROOT;

it seems ok, but I did not find how this could be called twice?

Quoted 8 lines
Quoted 4 lines

the only sort I can see is done within:
__hists__insert_output_entry

do we allow resorting of the callchains?

No, but I think it's possible though.

It's called from perf top's display thread.

ah right.. top ;-) ok

isn't there analogical issue with the other sorts? graph_abs, graph_rel... I dont see that code doing this

thanks,
jirka

Quoted 9 lines

display_thread()
-> while (!done)

     -> perf_top__print_sym_table()
        -> hists__output_resort()
           -> __hists__insert_output_entry()

Thanks,
Namhyung

author maintainer
#18 lore raw
Quoted 31 lines · Jiri Olsa
Quoted 30 lines · Namhyung Kim

Hi Jiri,

Quoted 26 lines · Jiri Olsa
Quoted 14 lines · Namhyung Kim

The callchain rbtree is rebuilt periodically, so it needs to reinitialize the root everytime. Otherwise it can be stuck in the rbtree insertion with stale pointers.

---
 tools/perf/util/callchain.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/callchain.c +0 -0
index fc3b1e0d09ee..564377d2bebf 100644

tools/perf/util/callchain.c static void · line 293

Quoted 4 lines
tools/perf/util/callchain.c +1 -0
@@ -290,6 +290,7 @@ static void
 sort_chain_flat(struct rb_root *rb_root, struct callchain_root *root,
 		u64 min_hit, struct callchain_param *param __maybe_unused)
 {
+	*rb_root = RB_ROOT;

it seems ok, but I did not find how this could be called twice?

the only sort I can see is done within:
__hists__insert_output_entry

do we allow resorting of the callchains?

Quoted 8 lines
Quoted 3 lines

No, but I think it's possible though.

It's called from perf top's display thread.

ah right.. top ;-) ok

isn't there analogical issue with the other sorts? graph_abs, graph_rel... I dont see that code doing this

The sort_chain_graph_abs/rel() already do this. Unlike flat/folded callchains, they put child into each callchain_node's rbtree. So they reinitialize node->rb_root in __sort_chain_graph_abs/rel() and reset rb_root after finishing sort.

Thanks,
Namhyung

Acked-by
#19 lore raw
Quoted 38 lines · Namhyung Kim
Quoted 37 lines · Jiri Olsa
Quoted 25 lines · Namhyung Kim

Hi Jiri,

Quoted 22 lines · Jiri Olsa
Quoted 14 lines · Namhyung Kim

The callchain rbtree is rebuilt periodically, so it needs to reinitialize the root everytime. Otherwise it can be stuck in the rbtree insertion with stale pointers.

---
 tools/perf/util/callchain.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/callchain.c +0 -0
index fc3b1e0d09ee..564377d2bebf 100644

tools/perf/util/callchain.c static void · line 293

Quoted 4 lines
tools/perf/util/callchain.c +1 -0
@@ -290,6 +290,7 @@ static void
 sort_chain_flat(struct rb_root *rb_root, struct callchain_root *root,
 		u64 min_hit, struct callchain_param *param __maybe_unused)
 {
+	*rb_root = RB_ROOT;

it seems ok, but I did not find how this could be called twice?

Quoted 8 lines
Quoted 4 lines

the only sort I can see is done within:
__hists__insert_output_entry

do we allow resorting of the callchains?

No, but I think it's possible though.

It's called from perf top's display thread.

ah right.. top ;-) ok

Quoted 7 lines
Quoted 2 lines

isn't there analogical issue with the other sorts? graph_abs, graph_rel... I dont see that code doing this

The sort_chain_graph_abs/rel() already do this. Unlike flat/folded callchains, they put child into each callchain_node's rbtree. So they reinitialize node->rb_root in __sort_chain_graph_abs/rel() and reset rb_root after finishing sort.

ook, thanks for explanation

jirka

#21 lore raw
In reply to Namhyung Kim
perf top: Fix freeze on --call-graph flat/folded
Commit-ID:  0356218a68551f051998f4fb5074a1eed7a346fe
Gitweb:     http://git.kernel.org/tip/0356218a68551f051998f4fb5074a1eed7a346fe
Author:     Namhyung Kim <[email protected]>
AuthorDate: Thu, 26 Nov 2015 16:08:18 +0900
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Thu, 26 Nov 2015 13:32:08 -0300

perf top: Fix freeze on --call-graph flat/folded

The callchain rbtree is rebuilt periodically, so it needs to reinitialize the root everytime. Otherwise it can be stuck in the rbtree insertion with stale pointers.

---
 tools/perf/util/callchain.c | 1 +
 1 file changed, 1 insertion(+)
tools/perf/util/callchain.c +1 -0
index fc3b1e0..564377d 100644
@@ -290,6 +290,7 @@ static void
 sort_chain_flat(struct rb_root *rb_root, struct callchain_root *root,
 		u64 min_hit, struct callchain_param *param __maybe_unused)
 {
+	*rb_root = RB_ROOT;
 	__sort_chain_flat(rb_root, &root->node, min_hit);
 }