All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHv2 00/12] perf tools: Display eBPF code in intel_pt trace
@ 2019-05-03  8:18 Jiri Olsa
  2019-05-03  8:18 ` [PATCH 01/12] perf tools: Separate generic code in dso__data_file_size Jiri Olsa
                   ` (12 more replies)
  0 siblings, 13 replies; 28+ messages in thread
From: Jiri Olsa @ 2019-05-03  8:18 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Jesper Dangaard Brouer, Alexei Starovoitov, Daniel Borkmann,
	lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
	Peter Zijlstra, Stanislav Fomichev, Song Liu, Adrian Hunter,
	Andi Kleen

hi,
this patchset adds dso support to read and display
bpf code in intel_pt trace output. I had to change
some of the kernel maps processing code, so hopefully
I did not break too many things ;-)

It's now possible to see bpf code flow via:

  # perf-with-kcore record pt -e intel_pt//ku -- sleep 1
  # perf-with-kcore script pt --insn-trace --xed
  ...
           sleep 36660 [016] 1057036.806464404:  ffffffff811dfba5 trace_call_bpf+0x65 ([kernel.kallsyms])               nopl  %eax, (%rax,%rax,1)
           sleep 36660 [016] 1057036.806464404:  ffffffff811dfbaa trace_call_bpf+0x6a ([kernel.kallsyms])               movq  0x30(%rbx), %rax
           sleep 36660 [016] 1057036.806464404:  ffffffff811dfbae trace_call_bpf+0x6e ([kernel.kallsyms])               leaq  0x38(%rbx), %rsi
           sleep 36660 [016] 1057036.806464404:  ffffffff811dfbb2 trace_call_bpf+0x72 ([kernel.kallsyms])               mov %r13, %rdi
           sleep 36660 [016] 1057036.806464404:  ffffffff811dfbb5 trace_call_bpf+0x75 ([kernel.kallsyms])               callq  0xffffffff81c00c30
           sleep 36660 [016] 1057036.806464404:  ffffffff81c00c30 __x86_indirect_thunk_rax+0x0 ([kernel.kallsyms])              callq  0xffffffff81c00c3c
           sleep 36660 [016] 1057036.806464404:  ffffffff81c00c3c __x86_indirect_thunk_rax+0xc ([kernel.kallsyms])              movq  %rax, (%rsp)
           sleep 36660 [016] 1057036.806464404:  ffffffff81c00c40 __x86_indirect_thunk_rax+0x10 ([kernel.kallsyms])             retq
           sleep 36660 [016] 1057036.806464725:  ffffffffa05e89ef bpf_prog_da4fe6b3d2c29b25_trace_return+0x0 (bpf_prog_da4fe6b3d2c29b25_trace_return)           pushq  %rbp
           sleep 36660 [016] 1057036.806464725:  ffffffffa05e89f0 bpf_prog_da4fe6b3d2c29b25_trace_return+0x1 (bpf_prog_da4fe6b3d2c29b25_trace_return)           mov %rsp, %rbp
           sleep 36660 [016] 1057036.806464725:  ffffffffa05e89f3 bpf_prog_da4fe6b3d2c29b25_trace_return+0x4 (bpf_prog_da4fe6b3d2c29b25_trace_return)           sub $0x158, %rsp
           sleep 36660 [016] 1057036.806464725:  ffffffffa05e89fa bpf_prog_da4fe6b3d2c29b25_trace_return+0xb (bpf_prog_da4fe6b3d2c29b25_trace_return)           sub $0x28, %rbp
           sleep 36660 [016] 1057036.806464725:  ffffffffa05e89fe bpf_prog_da4fe6b3d2c29b25_trace_return+0xf (bpf_prog_da4fe6b3d2c29b25_trace_return)           movq  %rbx, (%rbp)
           sleep 36660 [016] 1057036.806464725:  ffffffffa05e8a02 bpf_prog_da4fe6b3d2c29b25_trace_return+0x13 (bpf_prog_da4fe6b3d2c29b25_trace_return)          movq  %r13, 0x8(%rbp)
           sleep 36660 [016] 1057036.806464725:  ffffffffa05e8a06 bpf_prog_da4fe6b3d2c29b25_trace_return+0x17 (bpf_prog_da4fe6b3d2c29b25_trace_return)          movq  %r14, 0x10(%rbp)
           sleep 36660 [016] 1057036.806464725:  ffffffffa05e8a0a bpf_prog_da4fe6b3d2c29b25_trace_return+0x1b (bpf_prog_da4fe6b3d2c29b25_trace_return)          movq  %r15, 0x18(%rbp)
           sleep 36660 [016] 1057036.806464725:  ffffffffa05e8a0e bpf_prog_da4fe6b3d2c29b25_trace_return+0x1f (bpf_prog_da4fe6b3d2c29b25_trace_return)          xor %eax, %eax
           sleep 36660 [016] 1057036.806464725:  ffffffffa05e8a10 bpf_prog_da4fe6b3d2c29b25_trace_return+0x21 (bpf_prog_da4fe6b3d2c29b25_trace_return)          movq  %rax, 0x20(%rbp)
           sleep 36660 [016] 1057036.806464725:  ffffffffa05e8a14 bpf_prog_da4fe6b3d2c29b25_trace_return+0x25 (bpf_prog_da4fe6b3d2c29b25_trace_return)          mov %rdi, %rbx
           sleep 36660 [016] 1057036.806464725:  ffffffffa05e8a17 bpf_prog_da4fe6b3d2c29b25_trace_return+0x28 (bpf_prog_da4fe6b3d2c29b25_trace_return)          callq  0xffffffff811fed50
           sleep 36660 [016] 1057036.806464725:  ffffffff811fed50 bpf_get_current_pid_tgid+0x0 ([kernel.kallsyms])              nopl  %eax, (%rax,%rax,1)
           sleep 36660 [016] 1057036.806464725:  ffffffff811fed55 bpf_get_current_pid_tgid+0x5 ([kernel.kallsyms])              movq  %gs:0x15c00, %rdx
           sleep 36660 [016] 1057036.806464725:  ffffffff811fed5e bpf_get_current_pid_tgid+0xe ([kernel.kallsyms])              test %rdx, %rdx
           sleep 36660 [016] 1057036.806464725:  ffffffff811fed61 bpf_get_current_pid_tgid+0x11 ([kernel.kallsyms])             jz 0xffffffff811fed79
           sleep 36660 [016] 1057036.806464725:  ffffffff811fed63 bpf_get_current_pid_tgid+0x13 ([kernel.kallsyms])             movsxdl  0x494(%rdx), %rax
           sleep 36660 [016] 1057036.806464725:  ffffffff811fed6a bpf_get_current_pid_tgid+0x1a ([kernel.kallsyms])             movsxdl  0x490(%rdx), %rdx
           sleep 36660 [016] 1057036.806464725:  ffffffff811fed71 bpf_get_current_pid_tgid+0x21 ([kernel.kallsyms])             shl $0x20, %rax
           sleep 36660 [016] 1057036.806464725:  ffffffff811fed75 bpf_get_current_pid_tgid+0x25 ([kernel.kallsyms])             or %rdx, %rax
           sleep 36660 [016] 1057036.806464725:  ffffffff811fed78 bpf_get_current_pid_tgid+0x28 ([kernel.kallsyms])             retq
           sleep 36660 [016] 1057036.806464725:  ffffffffa05e8a1c bpf_prog_da4fe6b3d2c29b25_trace_return+0x2d (bpf_prog_da4fe6b3d2c29b25_trace_return)          movq  %rax, -0x8(%rbp)
           sleep 36660 [016] 1057036.806464725:  ffffffffa05e8a20 bpf_prog_da4fe6b3d2c29b25_trace_return+0x31 (bpf_prog_da4fe6b3d2c29b25_trace_return)          xor %edi, %edi
           sleep 36660 [016] 1057036.806464725:  ffffffffa05e8a22 bpf_prog_da4fe6b3d2c29b25_trace_return+0x33 (bpf_prog_da4fe6b3d2c29b25_trace_return)          movq  %rdi, -0x10(%rbp)
           sleep 36660 [016] 1057036.806464725:  ffffffffa05e8a26 bpf_prog_da4fe6b3d2c29b25_trace_return+0x37 (bpf_prog_da4fe6b3d2c29b25_trace_return)          movq  %rdi, -0x18(%rbp)

  # perf-core/perf-with-kcore script pt --call-trace
  ...
           sleep 36660 [016] 1057036.806464404: ([kernel.kallsyms]                       )                kretprobe_perf_func
           sleep 36660 [016] 1057036.806464404: ([kernel.kallsyms]                       )                    trace_call_bpf
           sleep 36660 [016] 1057036.806464404: ([kernel.kallsyms]                       )                        __x86_indirect_thunk_rax
           sleep 36660 [016] 1057036.806464404: ([kernel.kallsyms]                       )                            __x86_indirect_thunk_rax
           sleep 36660 [016] 1057036.806464725: (bpf_prog_da4fe6b3d2c29b25_trace_return  )                                bpf_get_current_pid_tgid
           sleep 36660 [016] 1057036.806464725: (bpf_prog_da4fe6b3d2c29b25_trace_return  )                                bpf_ktime_get_ns
           sleep 36660 [016] 1057036.806464725: ([kernel.kallsyms]                       )                                    __x86_indirect_thunk_rax
           sleep 36660 [016] 1057036.806464725: ([kernel.kallsyms]                       )                                        __x86_indirect_thunk_rax
           sleep 36660 [016] 1057036.806465045: (bpf_prog_da4fe6b3d2c29b25_trace_return  )                                __htab_map_lookup_elem
           sleep 36660 [016] 1057036.806465366: ([kernel.kallsyms]                       )                                    memcmp
           sleep 36660 [016] 1057036.806465687: (bpf_prog_da4fe6b3d2c29b25_trace_return  )                                bpf_probe_read
           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                    probe_kernel_read
           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                        __check_object_size
           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                            check_stack_object
           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                        copy_user_enhanced_fast_string
           sleep 36660 [016] 1057036.806465687: (bpf_prog_da4fe6b3d2c29b25_trace_return  )                                bpf_probe_read
           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                    probe_kernel_read
           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                        __check_object_size
           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                            check_stack_object
           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                        copy_user_enhanced_fast_string
           sleep 36660 [016] 1057036.806466008: (bpf_prog_da4fe6b3d2c29b25_trace_return  )                                bpf_get_current_uid_gid
           sleep 36660 [016] 1057036.806466008: ([kernel.kallsyms]                       )                                    from_kgid
           sleep 36660 [016] 1057036.806466008: ([kernel.kallsyms]                       )                                    from_kuid
           sleep 36660 [016] 1057036.806466008: (bpf_prog_da4fe6b3d2c29b25_trace_return  )                                bpf_perf_event_output
           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms]                       )                                    perf_event_output
           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms]                       )                                        perf_prepare_sample
           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms]                       )                                            perf_misc_flags
           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms]                       )                                                __x86_indirect_thunk_rax
           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms]                       )                                                    __x86_indirect_thunk_rax


v2 changes:
  - fix missing pthread_mutex_unlock [Stanislav Fomichev]
  - removed eBPF dso reusing [Adrian Hunter]
  - merge eBPF and kcore maps [Adrian Hunter]
  - few patches already applied
  - added some perf script helper options
  - patches are rebased on top of Arnaldo's perf/core with perf/urgent merged in

It's also available in here:
  git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
  perf/fixes

thanks,
jirka


Cc: Jesper Dangaard Brouer <brouer@redhat.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
---
Jiri Olsa (12):
      perf tools: Separate generic code in dso__data_file_size
      perf tools: Separate generic code in dso_cache__read
      perf tools: Simplify dso_cache__read function
      perf tools: Add bpf dso read and size hooks
      perf tools: Read also the end of the kernel
      perf tools: Keep zero in pgoff bpf map
      perf script: Pad dso name for --call-trace
      perf tools: Preserve eBPF maps when loading kcore
      perf tests: Add map_groups__merge_in test
      perf script: Add --show-bpf-events to show eBPF related events
      perf script: Remove superfluous bpf event titles
      perf script: Add --show-all-events option

 tools/include/linux/kernel.h             |   1 +
 tools/lib/vsprintf.c                     |  19 +++++++++++++++++++
 tools/perf/Documentation/perf-script.txt |   6 ++++++
 tools/perf/builtin-script.c              |  56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/tests/Build                   |   1 +
 tools/perf/tests/builtin-test.c          |   4 ++++
 tools/perf/tests/map_groups.c            | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 tools/perf/tests/tests.h                 |   1 +
 tools/perf/util/dso.c                    | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------
 tools/perf/util/event.c                  |   4 ++--
 tools/perf/util/machine.c                |  31 ++++++++++++++++++++-----------
 tools/perf/util/map.c                    |   6 ++++++
 tools/perf/util/map_groups.h             |   2 ++
 tools/perf/util/symbol.c                 |  97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
 tools/perf/util/symbol_conf.h            |   1 +
 15 files changed, 421 insertions(+), 53 deletions(-)
 create mode 100644 tools/perf/tests/map_groups.c

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 01/12] perf tools: Separate generic code in dso__data_file_size
  2019-05-03  8:18 [PATCHv2 00/12] perf tools: Display eBPF code in intel_pt trace Jiri Olsa
@ 2019-05-03  8:18 ` Jiri Olsa
  2019-05-03  8:18 ` [PATCH 02/12] perf tools: Separate generic code in dso_cache__read Jiri Olsa
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 28+ messages in thread
From: Jiri Olsa @ 2019-05-03  8:18 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
	Peter Zijlstra, Stanislav Fomichev, Song Liu, Adrian Hunter,
	Andi Kleen

Moving file specific code in dso__data_file_size function
into separate file_size function. I'll add bpf specific
code in following patches.

Link: http://lkml.kernel.org/n/tip-rkcsft4a0f8sw33p67llxf0d@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/dso.c | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index e059976d9d93..cb6199c1390a 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -898,18 +898,12 @@ static ssize_t cached_read(struct dso *dso, struct machine *machine,
 	return r;
 }
 
-int dso__data_file_size(struct dso *dso, struct machine *machine)
+static int file_size(struct dso *dso, struct machine *machine)
 {
 	int ret = 0;
 	struct stat st;
 	char sbuf[STRERR_BUFSIZE];
 
-	if (dso->data.file_size)
-		return 0;
-
-	if (dso->data.status == DSO_DATA_STATUS_ERROR)
-		return -1;
-
 	pthread_mutex_lock(&dso__data_open_lock);
 
 	/*
@@ -938,6 +932,17 @@ int dso__data_file_size(struct dso *dso, struct machine *machine)
 	return ret;
 }
 
+int dso__data_file_size(struct dso *dso, struct machine *machine)
+{
+	if (dso->data.file_size)
+		return 0;
+
+	if (dso->data.status == DSO_DATA_STATUS_ERROR)
+		return -1;
+
+	return file_size(dso, machine);
+}
+
 /**
  * dso__data_size - Return dso data size
  * @dso: dso object
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 02/12] perf tools: Separate generic code in dso_cache__read
  2019-05-03  8:18 [PATCHv2 00/12] perf tools: Display eBPF code in intel_pt trace Jiri Olsa
  2019-05-03  8:18 ` [PATCH 01/12] perf tools: Separate generic code in dso__data_file_size Jiri Olsa
@ 2019-05-03  8:18 ` Jiri Olsa
  2019-05-03  8:18 ` [PATCH 03/12] perf tools: Simplify dso_cache__read function Jiri Olsa
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 28+ messages in thread
From: Jiri Olsa @ 2019-05-03  8:18 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
	Peter Zijlstra, Stanislav Fomichev, Song Liu, Adrian Hunter,
	Andi Kleen

Moving file specific code in dso_cache__read function
into separate file_read function. I'll add bpf specific
code in following patches.

Link: http://lkml.kernel.org/n/tip-7f7d717uzrqt5ka2xp29ige3@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/dso.c | 48 ++++++++++++++++++++++++-------------------
 1 file changed, 27 insertions(+), 21 deletions(-)

diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index cb6199c1390a..7734f50a6912 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -794,6 +794,31 @@ dso_cache__memcpy(struct dso_cache *cache, u64 offset,
 	return cache_size;
 }
 
+static ssize_t file_read(struct dso *dso, struct machine *machine,
+			 u64 offset, char *data)
+{
+	ssize_t ret;
+
+	pthread_mutex_lock(&dso__data_open_lock);
+
+	/*
+	 * dso->data.fd might be closed if other thread opened another
+	 * file (dso) due to open file limit (RLIMIT_NOFILE).
+	 */
+	try_to_open_dso(dso, machine);
+
+	if (dso->data.fd < 0) {
+		dso->data.status = DSO_DATA_STATUS_ERROR;
+		ret = -errno;
+		goto out;
+	}
+
+	ret = pread(dso->data.fd, data, DSO__DATA_CACHE_SIZE, offset);
+out:
+	pthread_mutex_unlock(&dso__data_open_lock);
+	return ret;
+}
+
 static ssize_t
 dso_cache__read(struct dso *dso, struct machine *machine,
 		u64 offset, u8 *data, ssize_t size)
@@ -803,37 +828,18 @@ dso_cache__read(struct dso *dso, struct machine *machine,
 	ssize_t ret;
 
 	do {
-		u64 cache_offset;
+		u64 cache_offset = offset & DSO__DATA_CACHE_MASK;
 
 		cache = zalloc(sizeof(*cache) + DSO__DATA_CACHE_SIZE);
 		if (!cache)
 			return -ENOMEM;
 
-		pthread_mutex_lock(&dso__data_open_lock);
-
-		/*
-		 * dso->data.fd might be closed if other thread opened another
-		 * file (dso) due to open file limit (RLIMIT_NOFILE).
-		 */
-		try_to_open_dso(dso, machine);
-
-		if (dso->data.fd < 0) {
-			ret = -errno;
-			dso->data.status = DSO_DATA_STATUS_ERROR;
-			break;
-		}
-
-		cache_offset = offset & DSO__DATA_CACHE_MASK;
-
-		ret = pread(dso->data.fd, cache->data, DSO__DATA_CACHE_SIZE, cache_offset);
-		if (ret <= 0)
-			break;
+		ret = file_read(dso, machine, cache_offset, cache->data);
 
 		cache->offset = cache_offset;
 		cache->size   = ret;
 	} while (0);
 
-	pthread_mutex_unlock(&dso__data_open_lock);
 
 	if (ret > 0) {
 		old = dso_cache__insert(dso, cache);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 03/12] perf tools: Simplify dso_cache__read function
  2019-05-03  8:18 [PATCHv2 00/12] perf tools: Display eBPF code in intel_pt trace Jiri Olsa
  2019-05-03  8:18 ` [PATCH 01/12] perf tools: Separate generic code in dso__data_file_size Jiri Olsa
  2019-05-03  8:18 ` [PATCH 02/12] perf tools: Separate generic code in dso_cache__read Jiri Olsa
@ 2019-05-03  8:18 ` Jiri Olsa
  2019-05-03  8:18 ` [PATCH 04/12] perf tools: Add bpf dso read and size hooks Jiri Olsa
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 28+ messages in thread
From: Jiri Olsa @ 2019-05-03  8:18 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
	Peter Zijlstra, Stanislav Fomichev, Song Liu, Adrian Hunter,
	Andi Kleen

There's no need for the while loop now, also we can
connect two (ret > 0) condition legs together.

Link: http://lkml.kernel.org/n/tip-2vg28bak8euojuvq33cy2hl5@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/dso.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index 7734f50a6912..1e6a045adb8c 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -823,25 +823,20 @@ static ssize_t
 dso_cache__read(struct dso *dso, struct machine *machine,
 		u64 offset, u8 *data, ssize_t size)
 {
+	u64 cache_offset = offset & DSO__DATA_CACHE_MASK;
 	struct dso_cache *cache;
 	struct dso_cache *old;
 	ssize_t ret;
 
-	do {
-		u64 cache_offset = offset & DSO__DATA_CACHE_MASK;
-
-		cache = zalloc(sizeof(*cache) + DSO__DATA_CACHE_SIZE);
-		if (!cache)
-			return -ENOMEM;
-
-		ret = file_read(dso, machine, cache_offset, cache->data);
+	cache = zalloc(sizeof(*cache) + DSO__DATA_CACHE_SIZE);
+	if (!cache)
+		return -ENOMEM;
 
+	ret = file_read(dso, machine, cache_offset, cache->data);
+	if (ret > 0) {
 		cache->offset = cache_offset;
 		cache->size   = ret;
-	} while (0);
-
 
-	if (ret > 0) {
 		old = dso_cache__insert(dso, cache);
 		if (old) {
 			/* we lose the race */
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 04/12] perf tools: Add bpf dso read and size hooks
  2019-05-03  8:18 [PATCHv2 00/12] perf tools: Display eBPF code in intel_pt trace Jiri Olsa
                   ` (2 preceding siblings ...)
  2019-05-03  8:18 ` [PATCH 03/12] perf tools: Simplify dso_cache__read function Jiri Olsa
@ 2019-05-03  8:18 ` Jiri Olsa
  2019-05-03  8:18 ` [PATCH 05/12] perf tools: Read also the end of the kernel Jiri Olsa
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 28+ messages in thread
From: Jiri Olsa @ 2019-05-03  8:18 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
	Peter Zijlstra, Stanislav Fomichev, Song Liu, Adrian Hunter,
	Andi Kleen

Adding bpf related code into dso reading paths to return
size (bpf_size) and read the bpf code (bpf_read).

Link: http://lkml.kernel.org/n/tip-ql6jpegvv5823yc87u0hlzfa@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/dso.c | 49 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/dso.c b/tools/perf/util/dso.c
index 1e6a045adb8c..2c9289621efd 100644
--- a/tools/perf/util/dso.c
+++ b/tools/perf/util/dso.c
@@ -9,6 +9,8 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <libgen.h>
+#include <bpf/libbpf.h>
+#include "bpf-event.h"
 #include "compress.h"
 #include "namespaces.h"
 #include "path.h"
@@ -706,6 +708,44 @@ bool dso__data_status_seen(struct dso *dso, enum dso_data_status_seen by)
 	return false;
 }
 
+static ssize_t bpf_read(struct dso *dso, u64 offset, char *data)
+{
+	struct bpf_prog_info_node *node;
+	ssize_t size = DSO__DATA_CACHE_SIZE;
+	u64 len;
+	u8 *buf;
+
+	node = perf_env__find_bpf_prog_info(dso->bpf_prog.env, dso->bpf_prog.id);
+	if (!node || !node->info_linear) {
+		dso->data.status = DSO_DATA_STATUS_ERROR;
+		return -1;
+	}
+
+	len = node->info_linear->info.jited_prog_len;
+	buf = (u8 *) node->info_linear->info.jited_prog_insns;
+
+	if (offset >= len)
+		return -1;
+
+	size = (ssize_t) min(len - offset, (u64) size);
+	memcpy(data, buf + offset, size);
+	return size;
+}
+
+static int bpf_size(struct dso *dso)
+{
+	struct bpf_prog_info_node *node;
+
+	node = perf_env__find_bpf_prog_info(dso->bpf_prog.env, dso->bpf_prog.id);
+	if (!node || !node->info_linear) {
+		dso->data.status = DSO_DATA_STATUS_ERROR;
+		return -1;
+	}
+
+	dso->data.file_size = node->info_linear->info.jited_prog_len;
+	return 0;
+}
+
 static void
 dso_cache__free(struct dso *dso)
 {
@@ -832,7 +872,11 @@ dso_cache__read(struct dso *dso, struct machine *machine,
 	if (!cache)
 		return -ENOMEM;
 
-	ret = file_read(dso, machine, cache_offset, cache->data);
+	if (dso->binary_type == DSO_BINARY_TYPE__BPF_PROG_INFO)
+		ret = bpf_read(dso, cache_offset, cache->data);
+	else
+		ret = file_read(dso, machine, cache_offset, cache->data);
+
 	if (ret > 0) {
 		cache->offset = cache_offset;
 		cache->size   = ret;
@@ -941,6 +985,9 @@ int dso__data_file_size(struct dso *dso, struct machine *machine)
 	if (dso->data.status == DSO_DATA_STATUS_ERROR)
 		return -1;
 
+	if (dso->binary_type == DSO_BINARY_TYPE__BPF_PROG_INFO)
+		return bpf_size(dso);
+
 	return file_size(dso, machine);
 }
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 05/12] perf tools: Read also the end of the kernel
  2019-05-03  8:18 [PATCHv2 00/12] perf tools: Display eBPF code in intel_pt trace Jiri Olsa
                   ` (3 preceding siblings ...)
  2019-05-03  8:18 ` [PATCH 04/12] perf tools: Add bpf dso read and size hooks Jiri Olsa
@ 2019-05-03  8:18 ` Jiri Olsa
  2019-05-03  8:18 ` [PATCH 06/12] perf tools: Keep zero in pgoff bpf map Jiri Olsa
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 28+ messages in thread
From: Jiri Olsa @ 2019-05-03  8:18 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
	Peter Zijlstra, Stanislav Fomichev, Song Liu, Adrian Hunter,
	Andi Kleen

We mark the end of kernel based on the first module,
but that could cover some bpf program maps. Reading
_etext symbol if it's present to get precise kernel
map end.

Link: http://lkml.kernel.org/n/tip-ynut991ttyyhvo1sbhlm4c42@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/machine.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 3c520baa198c..ad0205fbb506 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -924,7 +924,8 @@ const char *ref_reloc_sym_names[] = {"_text", "_stext", NULL};
  * symbol_name if it's not that important.
  */
 static int machine__get_running_kernel_start(struct machine *machine,
-					     const char **symbol_name, u64 *start)
+					     const char **symbol_name,
+					     u64 *start, u64 *end)
 {
 	char filename[PATH_MAX];
 	int i, err = -1;
@@ -949,6 +950,11 @@ static int machine__get_running_kernel_start(struct machine *machine,
 		*symbol_name = name;
 
 	*start = addr;
+
+	err = kallsyms__get_function_start(filename, "_etext", &addr);
+	if (!err)
+		*end = addr;
+
 	return 0;
 }
 
@@ -1440,7 +1446,7 @@ int machine__create_kernel_maps(struct machine *machine)
 	struct dso *kernel = machine__get_kernel(machine);
 	const char *name = NULL;
 	struct map *map;
-	u64 addr = 0;
+	u64 start = 0, end = ~0ULL;
 	int ret;
 
 	if (kernel == NULL)
@@ -1459,9 +1465,9 @@ int machine__create_kernel_maps(struct machine *machine)
 				 "continuing anyway...\n", machine->pid);
 	}
 
-	if (!machine__get_running_kernel_start(machine, &name, &addr)) {
+	if (!machine__get_running_kernel_start(machine, &name, &start, &end)) {
 		if (name &&
-		    map__set_kallsyms_ref_reloc_sym(machine->vmlinux_map, name, addr)) {
+		    map__set_kallsyms_ref_reloc_sym(machine->vmlinux_map, name, start)) {
 			machine__destroy_kernel_maps(machine);
 			ret = -1;
 			goto out_put;
@@ -1471,16 +1477,19 @@ int machine__create_kernel_maps(struct machine *machine)
 		 * we have a real start address now, so re-order the kmaps
 		 * assume it's the last in the kmaps
 		 */
-		machine__update_kernel_mmap(machine, addr, ~0ULL);
+		machine__update_kernel_mmap(machine, start, end);
 	}
 
 	if (machine__create_extra_kernel_maps(machine, kernel))
 		pr_debug("Problems creating extra kernel maps, continuing anyway...\n");
 
-	/* update end address of the kernel map using adjacent module address */
-	map = map__next(machine__kernel_map(machine));
-	if (map)
-		machine__set_kernel_mmap(machine, addr, map->start);
+	if (end == ~0ULL) {
+		/* update end address of the kernel map using adjacent module address */
+		map = map__next(machine__kernel_map(machine));
+		if (map)
+			machine__set_kernel_mmap(machine, start, map->start);
+	}
+
 out_put:
 	dso__put(kernel);
 	return ret;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 06/12] perf tools: Keep zero in pgoff bpf map
  2019-05-03  8:18 [PATCHv2 00/12] perf tools: Display eBPF code in intel_pt trace Jiri Olsa
                   ` (4 preceding siblings ...)
  2019-05-03  8:18 ` [PATCH 05/12] perf tools: Read also the end of the kernel Jiri Olsa
@ 2019-05-03  8:18 ` Jiri Olsa
  2019-05-03  8:18 ` [PATCH 07/12] perf script: Pad dso name for --call-trace Jiri Olsa
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 28+ messages in thread
From: Jiri Olsa @ 2019-05-03  8:18 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
	Peter Zijlstra, Stanislav Fomichev, Song Liu, Adrian Hunter,
	Andi Kleen

With pgoff set to zero, the map__map_ip function
will return bpf address based from 0, which is
what we need when we read the data from bpf dso.

Adding bpf symbols with mapped ip addresses as well.

Link: http://lkml.kernel.org/n/tip-nqgyzbqgekvxqc5tjmsb3da2@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/machine.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index ad0205fbb506..d4aa44489011 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -704,12 +704,12 @@ static int machine__process_ksymbol_register(struct machine *machine,
 			return -ENOMEM;
 
 		map->start = event->ksymbol_event.addr;
-		map->pgoff = map->start;
 		map->end = map->start + event->ksymbol_event.len;
 		map_groups__insert(&machine->kmaps, map);
 	}
 
-	sym = symbol__new(event->ksymbol_event.addr, event->ksymbol_event.len,
+	sym = symbol__new(map->map_ip(map, map->start),
+			  event->ksymbol_event.len,
 			  0, 0, event->ksymbol_event.name);
 	if (!sym)
 		return -ENOMEM;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 07/12] perf script: Pad dso name for --call-trace
  2019-05-03  8:18 [PATCHv2 00/12] perf tools: Display eBPF code in intel_pt trace Jiri Olsa
                   ` (5 preceding siblings ...)
  2019-05-03  8:18 ` [PATCH 06/12] perf tools: Keep zero in pgoff bpf map Jiri Olsa
@ 2019-05-03  8:18 ` Jiri Olsa
  2019-05-06 21:38   ` Song Liu
  2019-05-03  8:18 ` [PATCH 08/12] perf tools: Preserve eBPF maps when loading kcore Jiri Olsa
                   ` (5 subsequent siblings)
  12 siblings, 1 reply; 28+ messages in thread
From: Jiri Olsa @ 2019-05-03  8:18 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
	Peter Zijlstra, Stanislav Fomichev, Song Liu, Adrian Hunter,
	Andi Kleen

Padding dso name for --call-trace so we don't have the
indent screwed by different dso name lengths, as now
for kernel there's also bpf code displayed.

  # perf-with-kcore record pt -e intel_pt//ku -- sleep 1
  # perf-core/perf-with-kcore script pt --call-trace

Before:
           sleep 36660 [016] 1057036.806464404: ([kernel.kallsyms])                                  kretprobe_perf_func
           sleep 36660 [016] 1057036.806464404: ([kernel.kallsyms])                                      trace_call_bpf
           sleep 36660 [016] 1057036.806464404: ([kernel.kallsyms])                                          __x86_indirect_thunk_rax
           sleep 36660 [016] 1057036.806464404: ([kernel.kallsyms])                                              __x86_indirect_thunk_rax
           sleep 36660 [016] 1057036.806464725: (bpf_prog_da4fe6b3d2c29b25_trace_return)                                                     bpf_get_current_pid_tgid
           sleep 36660 [016] 1057036.806464725: (bpf_prog_da4fe6b3d2c29b25_trace_return)                                                     bpf_ktime_get_ns
           sleep 36660 [016] 1057036.806464725: ([kernel.kallsyms])                                                      __x86_indirect_thunk_rax
           sleep 36660 [016] 1057036.806464725: ([kernel.kallsyms])                                                          __x86_indirect_thunk_rax
           sleep 36660 [016] 1057036.806465045: (bpf_prog_da4fe6b3d2c29b25_trace_return)                                                     __htab_map_lookup_elem
           sleep 36660 [016] 1057036.806465366: ([kernel.kallsyms])                                                      memcmp
           sleep 36660 [016] 1057036.806465687: (bpf_prog_da4fe6b3d2c29b25_trace_return)                                                     bpf_probe_read
           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms])                                                      probe_kernel_read
           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms])                                                          __check_object_size
           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms])                                                              check_stack_object
           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms])                                                          copy_user_enhanced_fast_string
           sleep 36660 [016] 1057036.806465687: (bpf_prog_da4fe6b3d2c29b25_trace_return)                                                     bpf_probe_read
           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms])                                                      probe_kernel_read
           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms])                                                          __check_object_size
           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms])                                                              check_stack_object
           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms])                                                          copy_user_enhanced_fast_string
           sleep 36660 [016] 1057036.806466008: (bpf_prog_da4fe6b3d2c29b25_trace_return)                                                     bpf_get_current_uid_gid
           sleep 36660 [016] 1057036.806466008: ([kernel.kallsyms])                                                      from_kgid
           sleep 36660 [016] 1057036.806466008: ([kernel.kallsyms])                                                      from_kuid
           sleep 36660 [016] 1057036.806466008: (bpf_prog_da4fe6b3d2c29b25_trace_return)                                                     bpf_perf_event_output
           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms])                                                      perf_event_output
           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms])                                                          perf_prepare_sample
           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms])                                                              perf_misc_flags
           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms])                                                                  __x86_indirect_thunk_rax
           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms])                                                                      __x86_indirect_thunk_rax
           sleep 36660 [016] 1057036.806466328: ([kvm])                                                                  kvm_is_in_guest
           sleep 36660 [016] 1057036.806466649: ([kernel.kallsyms])                                                              __perf_event_header__init_id.isra.0
           sleep 36660 [016] 1057036.806466649: ([kernel.kallsyms])                                                          perf_output_begin

After:
           sleep 36660 [016] 1057036.806464404: ([kernel.kallsyms]                       )                kretprobe_perf_func
           sleep 36660 [016] 1057036.806464404: ([kernel.kallsyms]                       )                    trace_call_bpf
           sleep 36660 [016] 1057036.806464404: ([kernel.kallsyms]                       )                        __x86_indirect_thunk_rax
           sleep 36660 [016] 1057036.806464404: ([kernel.kallsyms]                       )                            __x86_indirect_thunk_rax
           sleep 36660 [016] 1057036.806464725: (bpf_prog_da4fe6b3d2c29b25_trace_return  )                                bpf_get_current_pid_tgid
           sleep 36660 [016] 1057036.806464725: (bpf_prog_da4fe6b3d2c29b25_trace_return  )                                bpf_ktime_get_ns
           sleep 36660 [016] 1057036.806464725: ([kernel.kallsyms]                       )                                    __x86_indirect_thunk_rax
           sleep 36660 [016] 1057036.806464725: ([kernel.kallsyms]                       )                                        __x86_indirect_thunk_rax
           sleep 36660 [016] 1057036.806465045: (bpf_prog_da4fe6b3d2c29b25_trace_return  )                                __htab_map_lookup_elem
           sleep 36660 [016] 1057036.806465366: ([kernel.kallsyms]                       )                                    memcmp
           sleep 36660 [016] 1057036.806465687: (bpf_prog_da4fe6b3d2c29b25_trace_return  )                                bpf_probe_read
           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                    probe_kernel_read
           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                        __check_object_size
           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                            check_stack_object
           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                        copy_user_enhanced_fast_string
           sleep 36660 [016] 1057036.806465687: (bpf_prog_da4fe6b3d2c29b25_trace_return  )                                bpf_probe_read
           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                    probe_kernel_read
           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                        __check_object_size
           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                            check_stack_object
           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                        copy_user_enhanced_fast_string
           sleep 36660 [016] 1057036.806466008: (bpf_prog_da4fe6b3d2c29b25_trace_return  )                                bpf_get_current_uid_gid
           sleep 36660 [016] 1057036.806466008: ([kernel.kallsyms]                       )                                    from_kgid
           sleep 36660 [016] 1057036.806466008: ([kernel.kallsyms]                       )                                    from_kuid
           sleep 36660 [016] 1057036.806466008: (bpf_prog_da4fe6b3d2c29b25_trace_return  )                                bpf_perf_event_output
           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms]                       )                                    perf_event_output
           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms]                       )                                        perf_prepare_sample
           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms]                       )                                            perf_misc_flags
           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms]                       )                                                __x86_indirect_thunk_rax
           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms]                       )                                                    __x86_indirect_thunk_rax

Link: http://lkml.kernel.org/n/tip-99g9rg4p20a1o99vr0nkjhq8@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/include/linux/kernel.h  |  1 +
 tools/lib/vsprintf.c          | 19 +++++++++++++++++++
 tools/perf/builtin-script.c   |  1 +
 tools/perf/util/map.c         |  6 ++++++
 tools/perf/util/symbol_conf.h |  1 +
 5 files changed, 28 insertions(+)

diff --git a/tools/include/linux/kernel.h b/tools/include/linux/kernel.h
index 857d9e22826e..cba226948a0c 100644
--- a/tools/include/linux/kernel.h
+++ b/tools/include/linux/kernel.h
@@ -102,6 +102,7 @@
 
 int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
 int scnprintf(char * buf, size_t size, const char * fmt, ...);
+int scnprintf_pad(char * buf, size_t size, const char * fmt, ...);
 
 #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
 
diff --git a/tools/lib/vsprintf.c b/tools/lib/vsprintf.c
index e08ee147eab4..149a15013b23 100644
--- a/tools/lib/vsprintf.c
+++ b/tools/lib/vsprintf.c
@@ -23,3 +23,22 @@ int scnprintf(char * buf, size_t size, const char * fmt, ...)
 
        return (i >= ssize) ? (ssize - 1) : i;
 }
+
+int scnprintf_pad(char * buf, size_t size, const char * fmt, ...)
+{
+	ssize_t ssize = size;
+	va_list args;
+	int i;
+
+	va_start(args, fmt);
+	i = vsnprintf(buf, size, fmt, args);
+	va_end(args);
+
+	if (i < (int) size) {
+		for (; i < (int) size; i++)
+			buf[i] = ' ';
+		buf[i] = 0x0;
+	}
+
+	return (i >= ssize) ? (ssize - 1) : i;
+}
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 61cfd8f70989..7adaa6c63a0b 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -3297,6 +3297,7 @@ static int parse_call_trace(const struct option *opt __maybe_unused,
 	parse_output_fields(NULL, "-ip,-addr,-event,-period,+callindent", 0);
 	itrace_parse_synth_opts(opt, "cewp", 0);
 	symbol_conf.nanosecs = true;
+	symbol_conf.pad_output_len_dso = 50;
 	return 0;
 }
 
diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
index ee71efb9db62..c3fbd6e556b0 100644
--- a/tools/perf/util/map.c
+++ b/tools/perf/util/map.c
@@ -405,6 +405,7 @@ size_t map__fprintf(struct map *map, FILE *fp)
 
 size_t map__fprintf_dsoname(struct map *map, FILE *fp)
 {
+	char buf[PATH_MAX];
 	const char *dsoname = "[unknown]";
 
 	if (map && map->dso) {
@@ -414,6 +415,11 @@ size_t map__fprintf_dsoname(struct map *map, FILE *fp)
 			dsoname = map->dso->name;
 	}
 
+	if (symbol_conf.pad_output_len_dso) {
+		scnprintf_pad(buf, symbol_conf.pad_output_len_dso, "%s", dsoname);
+		dsoname = buf;
+	}
+
 	return fprintf(fp, "%s", dsoname);
 }
 
diff --git a/tools/perf/util/symbol_conf.h b/tools/perf/util/symbol_conf.h
index 6c55fa6fccec..382ba63fc554 100644
--- a/tools/perf/util/symbol_conf.h
+++ b/tools/perf/util/symbol_conf.h
@@ -69,6 +69,7 @@ struct symbol_conf {
 			*tid_list;
 	const char	*symfs;
 	int		res_sample;
+	int		pad_output_len_dso;
 };
 
 extern struct symbol_conf symbol_conf;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 08/12] perf tools: Preserve eBPF maps when loading kcore
  2019-05-03  8:18 [PATCHv2 00/12] perf tools: Display eBPF code in intel_pt trace Jiri Olsa
                   ` (6 preceding siblings ...)
  2019-05-03  8:18 ` [PATCH 07/12] perf script: Pad dso name for --call-trace Jiri Olsa
@ 2019-05-03  8:18 ` Jiri Olsa
  2019-05-03  8:18 ` [PATCH 09/12] perf tests: Add map_groups__merge_in test Jiri Olsa
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 28+ messages in thread
From: Jiri Olsa @ 2019-05-03  8:18 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Adrian Hunter, lkml, Ingo Molnar, Namhyung Kim,
	Alexander Shishkin, Peter Zijlstra, Stanislav Fomichev, Song Liu,
	Andi Kleen

We need to preserve eBPF maps even if they are
covered by kcore, because we need to access
eBPF dso for source data.

Adding map_groups__merge_in function to do that.
It merges map into map_groups by splitting the
new map within the existing map regions.

Suggested-by: Adrian Hunter <adrian.hunter@intel.com>
Link: http://lkml.kernel.org/n/tip-mlu13e9zl6rbsz4fa00x7mfa@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/symbol.c | 97 ++++++++++++++++++++++++++++++++++++++--
 1 file changed, 93 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 5cbad55cd99d..29780fcd049c 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1166,6 +1166,85 @@ static int kcore_mapfn(u64 start, u64 len, u64 pgoff, void *data)
 	return 0;
 }
 
+/*
+ * Merges map into map_groups by splitting the new map
+ * within the existing map regions.
+ */
+static int map_groups__merge_in(struct map_groups *kmaps, struct map *new_map)
+{
+	struct map *old_map;
+	LIST_HEAD(merged);
+
+	for (old_map = map_groups__first(kmaps); old_map;
+	     old_map = map_groups__next(old_map)) {
+
+		/* no overload with this one */
+		if (new_map->end < old_map->start ||
+		    new_map->start >= old_map->end)
+			continue;
+
+		if (new_map->start < old_map->start) {
+			/*
+			 * |new......
+			 *       |old....
+			 */
+			if (new_map->end < old_map->end) {
+				/*
+				 * |new......|     -> |new..|
+				 *       |old....| ->       |old....|
+				 */
+				new_map->end = old_map->start;
+			} else {
+				/*
+				 * |new.............| -> |new..|       |new..|
+				 *       |old....|    ->       |old....|
+				 */
+				struct map *m = map__clone(new_map);
+
+				if (!m)
+					return -ENOMEM;
+
+				m->end = old_map->start;
+				list_add_tail(&m->node, &merged);
+				new_map->start = old_map->end;
+			}
+		} else {
+			/*
+			 *      |new......
+			 * |old....
+			 */
+			if (new_map->end < old_map->end) {
+				/*
+				 *      |new..|   -> x
+				 * |old.........| -> |old.........|
+				 */
+				map__put(new_map);
+				new_map = NULL;
+				break;
+			} else {
+				/*
+				 *      |new......| ->         |new...|
+				 * |old....|        -> |old....|
+				 */
+				new_map->start = old_map->end;
+			}
+		}
+	}
+
+	while (!list_empty(&merged)) {
+		old_map = list_entry(merged.next, struct map, node);
+		list_del_init(&old_map->node);
+		map_groups__insert(kmaps, old_map);
+		map__put(old_map);
+	}
+
+	if (new_map) {
+		map_groups__insert(kmaps, new_map);
+		map__put(new_map);
+	}
+	return 0;
+}
+
 static int dso__load_kcore(struct dso *dso, struct map *map,
 			   const char *kallsyms_filename)
 {
@@ -1222,7 +1301,12 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
 	while (old_map) {
 		struct map *next = map_groups__next(old_map);
 
-		if (old_map != map)
+		/*
+		 * We need to preserve eBPF maps even if they are
+		 * covered by kcore, because we need to access
+		 * eBPF dso for source data.
+		 */
+		if (old_map != map && !__map__is_bpf_prog(old_map))
 			map_groups__remove(kmaps, old_map);
 		old_map = next;
 	}
@@ -1256,11 +1340,16 @@ static int dso__load_kcore(struct dso *dso, struct map *map,
 			map_groups__remove(kmaps, map);
 			map_groups__insert(kmaps, map);
 			map__put(map);
+			map__put(new_map);
 		} else {
-			map_groups__insert(kmaps, new_map);
+			/*
+			 * Merge kcore map into existing maps,
+			 * and ensure that current maps (eBPF)
+			 * stay intact.
+			 */
+			if (map_groups__merge_in(kmaps, new_map))
+				goto out_err;
 		}
-
-		map__put(new_map);
 	}
 
 	if (machine__is(machine, "x86_64")) {
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 09/12] perf tests: Add map_groups__merge_in test
  2019-05-03  8:18 [PATCHv2 00/12] perf tools: Display eBPF code in intel_pt trace Jiri Olsa
                   ` (7 preceding siblings ...)
  2019-05-03  8:18 ` [PATCH 08/12] perf tools: Preserve eBPF maps when loading kcore Jiri Olsa
@ 2019-05-03  8:18 ` Jiri Olsa
  2019-05-03  8:18 ` [PATCH 10/12] perf script: Add --show-bpf-events to show eBPF related events Jiri Olsa
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 28+ messages in thread
From: Jiri Olsa @ 2019-05-03  8:18 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
	Peter Zijlstra, Stanislav Fomichev, Song Liu, Adrian Hunter,
	Andi Kleen

Adding map_groups__merge_in to test map_groups__merge_in
function usage - merging kcore maps into existing eBPF
maps.

Link: http://lkml.kernel.org/n/tip-dj6v01kbt4upvkw3hccmc3vp@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/tests/Build          |   1 +
 tools/perf/tests/builtin-test.c |   4 ++
 tools/perf/tests/map_groups.c   | 120 ++++++++++++++++++++++++++++++++
 tools/perf/tests/tests.h        |   1 +
 tools/perf/util/map_groups.h    |   2 +
 tools/perf/util/symbol.c        |   2 +-
 6 files changed, 129 insertions(+), 1 deletion(-)
 create mode 100644 tools/perf/tests/map_groups.c

diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index 0b2b8305c965..4afb6319ed51 100644
--- a/tools/perf/tests/Build
+++ b/tools/perf/tests/Build
@@ -50,6 +50,7 @@ perf-y += perf-hooks.o
 perf-y += clang.o
 perf-y += unit_number__scnprintf.o
 perf-y += mem2node.o
+perf-y += map_groups.o
 
 $(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c tests/Build
 	$(call rule_mkdir)
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 9852b5d624a5..941c5456d625 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -289,6 +289,10 @@ static struct test generic_tests[] = {
 		.desc = "mem2node",
 		.func = test__mem2node,
 	},
+	{
+		.desc = "map_groups__merge_in",
+		.func = test__map_groups__merge_in,
+	},
 	{
 		.func = NULL,
 	},
diff --git a/tools/perf/tests/map_groups.c b/tools/perf/tests/map_groups.c
new file mode 100644
index 000000000000..70d96acc6dcf
--- /dev/null
+++ b/tools/perf/tests/map_groups.c
@@ -0,0 +1,120 @@
+#include <linux/compiler.h>
+#include <linux/kernel.h>
+#include "tests.h"
+#include "map.h"
+#include "map_groups.h"
+#include "dso.h"
+#include "debug.h"
+
+struct map_def {
+	const char *name;
+	u64 start;
+	u64 end;
+};
+
+static int check_maps(struct map_def *merged, unsigned int size, struct map_groups *mg)
+{
+	struct map *map;
+	unsigned int i = 0;
+
+	map = map_groups__first(mg);
+	while (map) {
+		TEST_ASSERT_VAL("wrong map start",  map->start == merged[i].start);
+		TEST_ASSERT_VAL("wrong map end",    map->end == merged[i].end);
+		TEST_ASSERT_VAL("wrong map name",  !strcmp(map->dso->name, merged[i].name));
+		TEST_ASSERT_VAL("wrong map refcnt", refcount_read(&map->refcnt) == 2);
+
+		i++;
+		map = map_groups__next(map);
+
+		TEST_ASSERT_VAL("less maps expected", (map && i < size) || (!map && i == size));
+	}
+
+	return TEST_OK;
+}
+
+int test__map_groups__merge_in(struct test *t __maybe_unused, int subtest __maybe_unused)
+{
+	struct map_groups mg;
+	unsigned int i;
+	struct map_def bpf_progs[] = {
+		{ "bpf_prog_1", 200, 300 },
+		{ "bpf_prog_2", 500, 600 },
+		{ "bpf_prog_3", 800, 900 },
+	};
+	struct map_def merged12[] = {
+		{ "kcore1",     100,  200 },
+		{ "bpf_prog_1", 200,  300 },
+		{ "kcore1",     300,  500 },
+		{ "bpf_prog_2", 500,  600 },
+		{ "kcore1",     600,  800 },
+		{ "bpf_prog_3", 800,  900 },
+		{ "kcore1",     900, 1000 },
+	};
+	struct map_def merged3[] = {
+		{ "kcore1",      100,  200 },
+		{ "bpf_prog_1",  200,  300 },
+		{ "kcore1",      300,  500 },
+		{ "bpf_prog_2",  500,  600 },
+		{ "kcore1",      600,  800 },
+		{ "bpf_prog_3",  800,  900 },
+		{ "kcore1",      900, 1000 },
+		{ "kcore3",     1000, 1100 },
+	};
+	struct map *map_kcore1, *map_kcore2, *map_kcore3;
+	int ret;
+
+	map_groups__init(&mg, NULL);
+
+	for (i = 0; i < ARRAY_SIZE(bpf_progs); i++) {
+		struct map *map;
+
+		map = dso__new_map(bpf_progs[i].name);
+		TEST_ASSERT_VAL("failed to create map", map);
+
+		map->start = bpf_progs[i].start;
+		map->end   = bpf_progs[i].end;
+		map_groups__insert(&mg, map);
+		map__put(map);
+	}
+
+	map_kcore1 = dso__new_map("kcore1");
+	TEST_ASSERT_VAL("failed to create map", map_kcore1);
+
+	map_kcore2 = dso__new_map("kcore2");
+	TEST_ASSERT_VAL("failed to create map", map_kcore2);
+
+	map_kcore3 = dso__new_map("kcore3");
+	TEST_ASSERT_VAL("failed to create map", map_kcore3);
+
+	/* kcore1 map overlaps over all bpf maps */
+	map_kcore1->start = 100;
+	map_kcore1->end   = 1000;
+
+	/* kcore2 map hides behind bpf_prog_2 */
+	map_kcore2->start = 550;
+	map_kcore2->end   = 570;
+
+	/* kcore3 map hides behind bpf_prog_3, kcore1 and adds new map */
+	map_kcore3->start = 880;
+	map_kcore3->end   = 1100;
+
+	ret = map_groups__merge_in(&mg, map_kcore1);
+	TEST_ASSERT_VAL("failed to merge map", !ret);
+
+	ret = check_maps(merged12, ARRAY_SIZE(merged12), &mg);
+	TEST_ASSERT_VAL("merge check failed", !ret);
+
+	ret = map_groups__merge_in(&mg, map_kcore2);
+	TEST_ASSERT_VAL("failed to merge map", !ret);
+
+	ret = check_maps(merged12, ARRAY_SIZE(merged12), &mg);
+	TEST_ASSERT_VAL("merge check failed", !ret);
+
+	ret = map_groups__merge_in(&mg, map_kcore3);
+	TEST_ASSERT_VAL("failed to merge map", !ret);
+
+	ret = check_maps(merged3, ARRAY_SIZE(merged3), &mg);
+	TEST_ASSERT_VAL("merge check failed", !ret);
+	return TEST_OK;
+}
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 399f18ca71a3..e5e3a57cd373 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -107,6 +107,7 @@ const char *test__clang_subtest_get_desc(int subtest);
 int test__clang_subtest_get_nr(void);
 int test__unit_number__scnprint(struct test *test, int subtest);
 int test__mem2node(struct test *t, int subtest);
+int test__map_groups__merge_in(struct test *t, int subtest);
 
 bool test__bp_signal_is_supported(void);
 bool test__wp_is_supported(void);
diff --git a/tools/perf/util/map_groups.h b/tools/perf/util/map_groups.h
index 4dcda33e0fdf..5f25efa6d6bc 100644
--- a/tools/perf/util/map_groups.h
+++ b/tools/perf/util/map_groups.h
@@ -88,4 +88,6 @@ int map_groups__fixup_overlappings(struct map_groups *mg, struct map *map, FILE
 
 struct map *map_groups__find_by_name(struct map_groups *mg, const char *name);
 
+int map_groups__merge_in(struct map_groups *kmaps, struct map *new_map);
+
 #endif // __PERF_MAP_GROUPS_H
diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c
index 29780fcd049c..f4540f8bbed1 100644
--- a/tools/perf/util/symbol.c
+++ b/tools/perf/util/symbol.c
@@ -1170,7 +1170,7 @@ static int kcore_mapfn(u64 start, u64 len, u64 pgoff, void *data)
  * Merges map into map_groups by splitting the new map
  * within the existing map regions.
  */
-static int map_groups__merge_in(struct map_groups *kmaps, struct map *new_map)
+int map_groups__merge_in(struct map_groups *kmaps, struct map *new_map)
 {
 	struct map *old_map;
 	LIST_HEAD(merged);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 10/12] perf script: Add --show-bpf-events to show eBPF related events
  2019-05-03  8:18 [PATCHv2 00/12] perf tools: Display eBPF code in intel_pt trace Jiri Olsa
                   ` (8 preceding siblings ...)
  2019-05-03  8:18 ` [PATCH 09/12] perf tests: Add map_groups__merge_in test Jiri Olsa
@ 2019-05-03  8:18 ` Jiri Olsa
  2019-05-06 21:42   ` Song Liu
  2019-05-03  8:18 ` [PATCH 11/12] perf script: Remove superfluous bpf event titles Jiri Olsa
                   ` (2 subsequent siblings)
  12 siblings, 1 reply; 28+ messages in thread
From: Jiri Olsa @ 2019-05-03  8:18 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
	Peter Zijlstra, Stanislav Fomichev, Song Liu, Adrian Hunter,
	Andi Kleen

Adding --show-bpf-events to show eBPF related events:
  PERF_RECORD_KSYMBOL
  PERF_RECORD_BPF_EVENT

Usage:
  # perf record -a
  ...
  # perf script --show-bpf-events
  ...
  swapper     0 [000]     0.000000: PERF_RECORD_KSYMBOL ksymbol event with addr ffffffffc0ef971d len 229 type 1 flags 0x0 name bpf_prog_2a142ef67aaad174
  swapper     0 [000]     0.000000: PERF_RECORD_BPF_EVENT bpf event with type 1, flags 0, id 36
  ...

Link: http://lkml.kernel.org/n/tip-9kvkcw7z4i1464jb7gasv4lb@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/Documentation/perf-script.txt |  3 ++
 tools/perf/builtin-script.c              | 42 ++++++++++++++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index 9b0d04dd2a61..af8282782911 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -313,6 +313,9 @@ OPTIONS
 --show-round-events
 	Display finished round events i.e. events of type PERF_RECORD_FINISHED_ROUND.
 
+--show-bpf-events
+	Display bpf events i.e. events of type PERF_RECORD_KSYMBOL and PERF_RECORD_BPF_EVENT.
+
 --demangle::
 	Demangle symbol names to human readable form. It's enabled by default,
 	disable with --no-demangle.
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 7adaa6c63a0b..3a48a2627670 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1606,6 +1606,7 @@ struct perf_script {
 	bool			show_namespace_events;
 	bool			show_lost_events;
 	bool			show_round_events;
+	bool			show_bpf_events;
 	bool			allocated;
 	bool			per_event_dump;
 	struct cpu_map		*cpus;
@@ -2318,6 +2319,41 @@ process_finished_round_event(struct perf_tool *tool __maybe_unused,
 	return 0;
 }
 
+static int
+process_bpf_events(struct perf_tool *tool __maybe_unused,
+		   union perf_event *event,
+		   struct perf_sample *sample,
+		   struct machine *machine)
+{
+	struct thread *thread;
+	struct perf_script *script = container_of(tool, struct perf_script, tool);
+	struct perf_session *session = script->session;
+	struct perf_evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id);
+
+	if (machine__process_ksymbol(machine, event, sample) < 0)
+		return -1;
+
+	if (!evsel->attr.sample_id_all) {
+		perf_event__fprintf(event, stdout);
+		return 0;
+	}
+
+	thread = machine__findnew_thread(machine, sample->pid, sample->tid);
+	if (thread == NULL) {
+		pr_debug("problem processing MMAP event, skipping it.\n");
+		return -1;
+	}
+
+	if (!filter_cpu(sample)) {
+		perf_sample__fprintf_start(sample, thread, evsel,
+					   event->header.type, stdout);
+		perf_event__fprintf(event, stdout);
+	}
+
+	thread__put(thread);
+	return 0;
+}
+
 static void sig_handler(int sig __maybe_unused)
 {
 	session_done = 1;
@@ -2420,6 +2456,10 @@ static int __cmd_script(struct perf_script *script)
 		script->tool.ordered_events = false;
 		script->tool.finished_round = process_finished_round_event;
 	}
+	if (script->show_bpf_events) {
+		script->tool.ksymbol   = process_bpf_events;
+		script->tool.bpf_event = process_bpf_events;
+	}
 
 	if (perf_script__setup_per_event_dump(script)) {
 		pr_err("Couldn't create the per event dump files\n");
@@ -3439,6 +3479,8 @@ int cmd_script(int argc, const char **argv)
 		    "Show lost events (if recorded)"),
 	OPT_BOOLEAN('\0', "show-round-events", &script.show_round_events,
 		    "Show round events (if recorded)"),
+	OPT_BOOLEAN('\0', "show-bpf-events", &script.show_bpf_events,
+		    "Show bpf related events (if recorded)"),
 	OPT_BOOLEAN('\0', "per-event-dump", &script.per_event_dump,
 		    "Dump trace output to files named by the monitored events"),
 	OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"),
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 11/12] perf script: Remove superfluous bpf event titles
  2019-05-03  8:18 [PATCHv2 00/12] perf tools: Display eBPF code in intel_pt trace Jiri Olsa
                   ` (9 preceding siblings ...)
  2019-05-03  8:18 ` [PATCH 10/12] perf script: Add --show-bpf-events to show eBPF related events Jiri Olsa
@ 2019-05-03  8:18 ` Jiri Olsa
  2019-05-03  8:18 ` [PATCH 12/12] perf script: Add --show-all-events option Jiri Olsa
  2019-05-06 21:46 ` [PATCHv2 00/12] perf tools: Display eBPF code in intel_pt trace Song Liu
  12 siblings, 0 replies; 28+ messages in thread
From: Jiri Olsa @ 2019-05-03  8:18 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
	Peter Zijlstra, Stanislav Fomichev, Song Liu, Adrian Hunter,
	Andi Kleen

There's no need to display "ksymbol event with" text
for PERF_RECORD_KSYMBOL event and "bpf event with" test
for PERF_RECORD_BPF_EVENT event.

Removing it so it also goes along with other side-band
events display.

Before:
  # perf script --show-bpf-events
  ...
  swapper     0 [000]     0.000000: PERF_RECORD_KSYMBOL ksymbol event with addr ffffffffc0ef971d len 229 type 1 flags 0x0 name bpf_prog_2a142ef67aaad174
  swapper     0 [000]     0.000000: PERF_RECORD_BPF_EVENT bpf event with type 1, flags 0, id 36

After:
  # perf script --show-bpf-events
  ...
  swapper     0 [000]     0.000000: PERF_RECORD_KSYMBOL addr ffffffffc0ef971d len 229 type 1 flags 0x0 name bpf_prog_2a142ef67aaad174
  swapper     0 [000]     0.000000: PERF_RECORD_BPF_EVENT type 1, flags 0, id 36

Link: http://lkml.kernel.org/n/tip-qe1ehvt6xr00vmqt8dxyooo3@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/event.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index ba7be74fad6e..198920b7c56a 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -1485,7 +1485,7 @@ static size_t perf_event__fprintf_lost(union perf_event *event, FILE *fp)
 
 size_t perf_event__fprintf_ksymbol(union perf_event *event, FILE *fp)
 {
-	return fprintf(fp, " ksymbol event with addr %" PRIx64 " len %u type %u flags 0x%x name %s\n",
+	return fprintf(fp, " addr %" PRIx64 " len %u type %u flags 0x%x name %s\n",
 		       event->ksymbol_event.addr, event->ksymbol_event.len,
 		       event->ksymbol_event.ksym_type,
 		       event->ksymbol_event.flags, event->ksymbol_event.name);
@@ -1493,7 +1493,7 @@ size_t perf_event__fprintf_ksymbol(union perf_event *event, FILE *fp)
 
 size_t perf_event__fprintf_bpf_event(union perf_event *event, FILE *fp)
 {
-	return fprintf(fp, " bpf event with type %u, flags %u, id %u\n",
+	return fprintf(fp, " type %u, flags %u, id %u\n",
 		       event->bpf_event.type, event->bpf_event.flags,
 		       event->bpf_event.id);
 }
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 12/12] perf script: Add --show-all-events option
  2019-05-03  8:18 [PATCHv2 00/12] perf tools: Display eBPF code in intel_pt trace Jiri Olsa
                   ` (10 preceding siblings ...)
  2019-05-03  8:18 ` [PATCH 11/12] perf script: Remove superfluous bpf event titles Jiri Olsa
@ 2019-05-03  8:18 ` Jiri Olsa
  2019-05-06 21:46 ` [PATCHv2 00/12] perf tools: Display eBPF code in intel_pt trace Song Liu
  12 siblings, 0 replies; 28+ messages in thread
From: Jiri Olsa @ 2019-05-03  8:18 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
	Peter Zijlstra, Stanislav Fomichev, Song Liu, Adrian Hunter,
	Andi Kleen

Adding --show-all-events option to show all
side-bad events with single option, like:

  $ perf script --show-all-events
  swapper     0 [000]     0.000000: PERF_RECORD_MMAP -1/0: [0xffffffffa6000000(0xc00e41) @ 0xffffffffa6000000]: x [kernel.kallsyms]_text
  ...
  swapper     0 [000]     0.000000: PERF_RECORD_KSYMBOL addr ffffffffc01bc362 len 229 type 1 flags 0x0 name bpf_prog_7be49e3934a125ba
  swapper     0 [000]     0.000000: PERF_RECORD_BPF_EVENT type 1, flags 0, id 29
  ...
  swapper     0 [000]     0.000000: PERF_RECORD_FORK(1:1):(0:0)
  systemd     0 [000]     0.000000: PERF_RECORD_COMM: systemd:1/1
  ...
  swapper     0 [000] 63587.039518:          1 cycles:  ffffffffa60698b4 [unknown] ([kernel.kallsyms])
  swapper     0 [000] 63587.039522:          1 cycles:  ffffffffa60698b4 [unknown] ([kernel.kallsyms])

Link: http://lkml.kernel.org/n/tip-g7vmuwn6i7pa8cdpnxl9vsur@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/Documentation/perf-script.txt |  3 +++
 tools/perf/builtin-script.c              | 13 +++++++++++++
 2 files changed, 16 insertions(+)

diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
index af8282782911..ddcd08bf0172 100644
--- a/tools/perf/Documentation/perf-script.txt
+++ b/tools/perf/Documentation/perf-script.txt
@@ -316,6 +316,9 @@ OPTIONS
 --show-bpf-events
 	Display bpf events i.e. events of type PERF_RECORD_KSYMBOL and PERF_RECORD_BPF_EVENT.
 
+--show-all-events
+	Display all side-band events i.e. enable all --show-*-events options.
+
 --demangle::
 	Demangle symbol names to human readable form. It's enabled by default,
 	disable with --no-demangle.
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 3a48a2627670..e7462dcab2c6 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1607,6 +1607,7 @@ struct perf_script {
 	bool			show_lost_events;
 	bool			show_round_events;
 	bool			show_bpf_events;
+	bool			show_all_events;
 	bool			allocated;
 	bool			per_event_dump;
 	struct cpu_map		*cpus;
@@ -2436,6 +2437,16 @@ static int __cmd_script(struct perf_script *script)
 
 	perf_stat__init_shadow_stats();
 
+	if (script->show_all_events) {
+		script->show_task_events	= true;
+		script->show_mmap_events	= true;
+		script->show_switch_events	= true;
+		script->show_namespace_events	= true;
+		script->show_lost_events	= true;
+		script->show_round_events	= true;
+		script->show_bpf_events		= true;
+	}
+
 	/* override event processing functions */
 	if (script->show_task_events) {
 		script->tool.comm = process_comm_event;
@@ -3481,6 +3492,8 @@ int cmd_script(int argc, const char **argv)
 		    "Show round events (if recorded)"),
 	OPT_BOOLEAN('\0', "show-bpf-events", &script.show_bpf_events,
 		    "Show bpf related events (if recorded)"),
+	OPT_BOOLEAN('\0', "show-all-events", &script.show_all_events,
+		    "Show all side-band events (if recorded)"),
 	OPT_BOOLEAN('\0', "per-event-dump", &script.per_event_dump,
 		    "Dump trace output to files named by the monitored events"),
 	OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"),
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* Re: [PATCH 07/12] perf script: Pad dso name for --call-trace
  2019-05-03  8:18 ` [PATCH 07/12] perf script: Pad dso name for --call-trace Jiri Olsa
@ 2019-05-06 21:38   ` Song Liu
  2019-05-07  8:13     ` Jiri Olsa
  0 siblings, 1 reply; 28+ messages in thread
From: Song Liu @ 2019-05-06 21:38 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Arnaldo Carvalho de Melo, lkml, Ingo Molnar, Namhyung Kim,
	Alexander Shishkin, Peter Zijlstra, Stanislav Fomichev,
	Adrian Hunter, Andi Kleen



> On May 3, 2019, at 1:18 AM, Jiri Olsa <jolsa@kernel.org> wrote:
> 
> Padding dso name for --call-trace so we don't have the
> indent screwed by different dso name lengths, as now
> for kernel there's also bpf code displayed.
> 
>  # perf-with-kcore record pt -e intel_pt//ku -- sleep 1
>  # perf-core/perf-with-kcore script pt --call-trace
> 
> Before:
>           sleep 36660 [016] 1057036.806464404: ([kernel.kallsyms])                                  kretprobe_perf_func
>           sleep 36660 [016] 1057036.806464404: ([kernel.kallsyms])                                      trace_call_bpf
>           sleep 36660 [016] 1057036.806464404: ([kernel.kallsyms])                                          __x86_indirect_thunk_rax
>           sleep 36660 [016] 1057036.806464404: ([kernel.kallsyms])                                              __x86_indirect_thunk_rax
>           sleep 36660 [016] 1057036.806464725: (bpf_prog_da4fe6b3d2c29b25_trace_return)                                                     bpf_get_current_pid_tgid
>           sleep 36660 [016] 1057036.806464725: (bpf_prog_da4fe6b3d2c29b25_trace_return)                                                     bpf_ktime_get_ns
>           sleep 36660 [016] 1057036.806464725: ([kernel.kallsyms])                                                      __x86_indirect_thunk_rax
>           sleep 36660 [016] 1057036.806464725: ([kernel.kallsyms])                                                          __x86_indirect_thunk_rax
>           sleep 36660 [016] 1057036.806465045: (bpf_prog_da4fe6b3d2c29b25_trace_return)                                                     __htab_map_lookup_elem
>           sleep 36660 [016] 1057036.806465366: ([kernel.kallsyms])                                                      memcmp
>           sleep 36660 [016] 1057036.806465687: (bpf_prog_da4fe6b3d2c29b25_trace_return)                                                     bpf_probe_read
>           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms])                                                      probe_kernel_read
>           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms])                                                          __check_object_size
>           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms])                                                              check_stack_object
>           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms])                                                          copy_user_enhanced_fast_string
>           sleep 36660 [016] 1057036.806465687: (bpf_prog_da4fe6b3d2c29b25_trace_return)                                                     bpf_probe_read
>           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms])                                                      probe_kernel_read
>           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms])                                                          __check_object_size
>           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms])                                                              check_stack_object
>           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms])                                                          copy_user_enhanced_fast_string
>           sleep 36660 [016] 1057036.806466008: (bpf_prog_da4fe6b3d2c29b25_trace_return)                                                     bpf_get_current_uid_gid
>           sleep 36660 [016] 1057036.806466008: ([kernel.kallsyms])                                                      from_kgid
>           sleep 36660 [016] 1057036.806466008: ([kernel.kallsyms])                                                      from_kuid
>           sleep 36660 [016] 1057036.806466008: (bpf_prog_da4fe6b3d2c29b25_trace_return)                                                     bpf_perf_event_output
>           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms])                                                      perf_event_output
>           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms])                                                          perf_prepare_sample
>           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms])                                                              perf_misc_flags
>           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms])                                                                  __x86_indirect_thunk_rax
>           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms])                                                                      __x86_indirect_thunk_rax
>           sleep 36660 [016] 1057036.806466328: ([kvm])                                                                  kvm_is_in_guest
>           sleep 36660 [016] 1057036.806466649: ([kernel.kallsyms])                                                              __perf_event_header__init_id.isra.0
>           sleep 36660 [016] 1057036.806466649: ([kernel.kallsyms])                                                          perf_output_begin
> 
> After:
>           sleep 36660 [016] 1057036.806464404: ([kernel.kallsyms]                       )                kretprobe_perf_func
>           sleep 36660 [016] 1057036.806464404: ([kernel.kallsyms]                       )                    trace_call_bpf
>           sleep 36660 [016] 1057036.806464404: ([kernel.kallsyms]                       )                        __x86_indirect_thunk_rax
>           sleep 36660 [016] 1057036.806464404: ([kernel.kallsyms]                       )                            __x86_indirect_thunk_rax
>           sleep 36660 [016] 1057036.806464725: (bpf_prog_da4fe6b3d2c29b25_trace_return  )                                bpf_get_current_pid_tgid
>           sleep 36660 [016] 1057036.806464725: (bpf_prog_da4fe6b3d2c29b25_trace_return  )                                bpf_ktime_get_ns
>           sleep 36660 [016] 1057036.806464725: ([kernel.kallsyms]                       )                                    __x86_indirect_thunk_rax
>           sleep 36660 [016] 1057036.806464725: ([kernel.kallsyms]                       )                                        __x86_indirect_thunk_rax
>           sleep 36660 [016] 1057036.806465045: (bpf_prog_da4fe6b3d2c29b25_trace_return  )                                __htab_map_lookup_elem
>           sleep 36660 [016] 1057036.806465366: ([kernel.kallsyms]                       )                                    memcmp
>           sleep 36660 [016] 1057036.806465687: (bpf_prog_da4fe6b3d2c29b25_trace_return  )                                bpf_probe_read
>           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                    probe_kernel_read
>           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                        __check_object_size
>           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                            check_stack_object
>           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                        copy_user_enhanced_fast_string
>           sleep 36660 [016] 1057036.806465687: (bpf_prog_da4fe6b3d2c29b25_trace_return  )                                bpf_probe_read
>           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                    probe_kernel_read
>           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                        __check_object_size
>           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                            check_stack_object
>           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                        copy_user_enhanced_fast_string
>           sleep 36660 [016] 1057036.806466008: (bpf_prog_da4fe6b3d2c29b25_trace_return  )                                bpf_get_current_uid_gid
>           sleep 36660 [016] 1057036.806466008: ([kernel.kallsyms]                       )                                    from_kgid
>           sleep 36660 [016] 1057036.806466008: ([kernel.kallsyms]                       )                                    from_kuid
>           sleep 36660 [016] 1057036.806466008: (bpf_prog_da4fe6b3d2c29b25_trace_return  )                                bpf_perf_event_output
>           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms]                       )                                    perf_event_output
>           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms]                       )                                        perf_prepare_sample
>           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms]                       )                                            perf_misc_flags
>           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms]                       )                                                __x86_indirect_thunk_rax
>           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms]                       )                                                    __x86_indirect_thunk_rax
> 
> Link: http://lkml.kernel.org/n/tip-99g9rg4p20a1o99vr0nkjhq8@git.kernel.org
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
> tools/include/linux/kernel.h  |  1 +
> tools/lib/vsprintf.c          | 19 +++++++++++++++++++
> tools/perf/builtin-script.c   |  1 +
> tools/perf/util/map.c         |  6 ++++++
> tools/perf/util/symbol_conf.h |  1 +
> 5 files changed, 28 insertions(+)
> 
> diff --git a/tools/include/linux/kernel.h b/tools/include/linux/kernel.h
> index 857d9e22826e..cba226948a0c 100644
> --- a/tools/include/linux/kernel.h
> +++ b/tools/include/linux/kernel.h
> @@ -102,6 +102,7 @@
> 
> int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
> int scnprintf(char * buf, size_t size, const char * fmt, ...);
> +int scnprintf_pad(char * buf, size_t size, const char * fmt, ...);
> 
> #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
> 
> diff --git a/tools/lib/vsprintf.c b/tools/lib/vsprintf.c
> index e08ee147eab4..149a15013b23 100644
> --- a/tools/lib/vsprintf.c
> +++ b/tools/lib/vsprintf.c
> @@ -23,3 +23,22 @@ int scnprintf(char * buf, size_t size, const char * fmt, ...)
> 
>        return (i >= ssize) ? (ssize - 1) : i;
> }
> +
> +int scnprintf_pad(char * buf, size_t size, const char * fmt, ...)
> +{
> +	ssize_t ssize = size;
> +	va_list args;
> +	int i;

nit: I guess we can avoid mixing int, ssize_t and size_t here?


> +
> +	va_start(args, fmt);
> +	i = vsnprintf(buf, size, fmt, args);
> +	va_end(args);
> +
> +	if (i < (int) size) {
> +		for (; i < (int) size; i++)
> +			buf[i] = ' ';
> +		buf[i] = 0x0;
> +	}
> +
> +	return (i >= ssize) ? (ssize - 1) : i;
> +}
> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> index 61cfd8f70989..7adaa6c63a0b 100644
> --- a/tools/perf/builtin-script.c
> +++ b/tools/perf/builtin-script.c
> @@ -3297,6 +3297,7 @@ static int parse_call_trace(const struct option *opt __maybe_unused,
> 	parse_output_fields(NULL, "-ip,-addr,-event,-period,+callindent", 0);
> 	itrace_parse_synth_opts(opt, "cewp", 0);
> 	symbol_conf.nanosecs = true;
> +	symbol_conf.pad_output_len_dso = 50;
> 	return 0;
> }
> 
> diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
> index ee71efb9db62..c3fbd6e556b0 100644
> --- a/tools/perf/util/map.c
> +++ b/tools/perf/util/map.c
> @@ -405,6 +405,7 @@ size_t map__fprintf(struct map *map, FILE *fp)
> 
> size_t map__fprintf_dsoname(struct map *map, FILE *fp)
> {
> +	char buf[PATH_MAX];

nit: PATH_MAX vs. 50 is a little weird. 

> 	const char *dsoname = "[unknown]";
> 
> 	if (map && map->dso) {
> @@ -414,6 +415,11 @@ size_t map__fprintf_dsoname(struct map *map, FILE *fp)
> 			dsoname = map->dso->name;
> 	}
> 
> +	if (symbol_conf.pad_output_len_dso) {
> +		scnprintf_pad(buf, symbol_conf.pad_output_len_dso, "%s", dsoname);
> +		dsoname = buf;
> +	}
> +
> 	return fprintf(fp, "%s", dsoname);
> }
> 
> diff --git a/tools/perf/util/symbol_conf.h b/tools/perf/util/symbol_conf.h
> index 6c55fa6fccec..382ba63fc554 100644
> --- a/tools/perf/util/symbol_conf.h
> +++ b/tools/perf/util/symbol_conf.h
> @@ -69,6 +69,7 @@ struct symbol_conf {
> 			*tid_list;
> 	const char	*symfs;
> 	int		res_sample;
> +	int		pad_output_len_dso;
> };
> 
> extern struct symbol_conf symbol_conf;
> -- 
> 2.20.1
> 


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 10/12] perf script: Add --show-bpf-events to show eBPF related events
  2019-05-03  8:18 ` [PATCH 10/12] perf script: Add --show-bpf-events to show eBPF related events Jiri Olsa
@ 2019-05-06 21:42   ` Song Liu
  2019-05-07  8:18     ` Jiri Olsa
  0 siblings, 1 reply; 28+ messages in thread
From: Song Liu @ 2019-05-06 21:42 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Arnaldo Carvalho de Melo, lkml, Ingo Molnar, Namhyung Kim,
	Alexander Shishkin, Peter Zijlstra, Stanislav Fomichev,
	Adrian Hunter, Andi Kleen



> On May 3, 2019, at 1:18 AM, Jiri Olsa <jolsa@kernel.org> wrote:
> 
> Adding --show-bpf-events to show eBPF related events:
>  PERF_RECORD_KSYMBOL
>  PERF_RECORD_BPF_EVENT
> 
> Usage:
>  # perf record -a
>  ...
>  # perf script --show-bpf-events
>  ...
>  swapper     0 [000]     0.000000: PERF_RECORD_KSYMBOL ksymbol event with addr ffffffffc0ef971d len 229 type 1 flags 0x0 name bpf_prog_2a142ef67aaad174
>  swapper     0 [000]     0.000000: PERF_RECORD_BPF_EVENT bpf event with type 1, flags 0, id 36
>  ...
> 
> Link: http://lkml.kernel.org/n/tip-9kvkcw7z4i1464jb7gasv4lb@git.kernel.org
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
> tools/perf/Documentation/perf-script.txt |  3 ++
> tools/perf/builtin-script.c              | 42 ++++++++++++++++++++++++
> 2 files changed, 45 insertions(+)
> 
> diff --git a/tools/perf/Documentation/perf-script.txt b/tools/perf/Documentation/perf-script.txt
> index 9b0d04dd2a61..af8282782911 100644
> --- a/tools/perf/Documentation/perf-script.txt
> +++ b/tools/perf/Documentation/perf-script.txt
> @@ -313,6 +313,9 @@ OPTIONS
> --show-round-events
> 	Display finished round events i.e. events of type PERF_RECORD_FINISHED_ROUND.
> 
> +--show-bpf-events
> +	Display bpf events i.e. events of type PERF_RECORD_KSYMBOL and PERF_RECORD_BPF_EVENT.
> +
> --demangle::
> 	Demangle symbol names to human readable form. It's enabled by default,
> 	disable with --no-demangle.
> diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> index 7adaa6c63a0b..3a48a2627670 100644
> --- a/tools/perf/builtin-script.c
> +++ b/tools/perf/builtin-script.c
> @@ -1606,6 +1606,7 @@ struct perf_script {
> 	bool			show_namespace_events;
> 	bool			show_lost_events;
> 	bool			show_round_events;
> +	bool			show_bpf_events;
> 	bool			allocated;
> 	bool			per_event_dump;
> 	struct cpu_map		*cpus;
> @@ -2318,6 +2319,41 @@ process_finished_round_event(struct perf_tool *tool __maybe_unused,
> 	return 0;
> }
> 
> +static int
> +process_bpf_events(struct perf_tool *tool __maybe_unused,
> +		   union perf_event *event,
> +		   struct perf_sample *sample,
> +		   struct machine *machine)
> +{
> +	struct thread *thread;
> +	struct perf_script *script = container_of(tool, struct perf_script, tool);
> +	struct perf_session *session = script->session;
> +	struct perf_evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id);
> +
> +	if (machine__process_ksymbol(machine, event, sample) < 0)
> +		return -1;
> +
> +	if (!evsel->attr.sample_id_all) {
> +		perf_event__fprintf(event, stdout);
> +		return 0;
> +	}
> +
> +	thread = machine__findnew_thread(machine, sample->pid, sample->tid);
> +	if (thread == NULL) {
> +		pr_debug("problem processing MMAP event, skipping it.\n");
> +		return -1;
> +	}
> +
> +	if (!filter_cpu(sample)) {
> +		perf_sample__fprintf_start(sample, thread, evsel,
> +					   event->header.type, stdout);
> +		perf_event__fprintf(event, stdout);
> +	}
> +
> +	thread__put(thread);
> +	return 0;
> +}
> +
> static void sig_handler(int sig __maybe_unused)
> {
> 	session_done = 1;
> @@ -2420,6 +2456,10 @@ static int __cmd_script(struct perf_script *script)
> 		script->tool.ordered_events = false;
> 		script->tool.finished_round = process_finished_round_event;
> 	}
> +	if (script->show_bpf_events) {
> +		script->tool.ksymbol   = process_bpf_events;
> +		script->tool.bpf_event = process_bpf_events;

Why do we need both set to process_bpf_events?

Thanks,
Song

> +	}
> 
> 	if (perf_script__setup_per_event_dump(script)) {
> 		pr_err("Couldn't create the per event dump files\n");
> @@ -3439,6 +3479,8 @@ int cmd_script(int argc, const char **argv)
> 		    "Show lost events (if recorded)"),
> 	OPT_BOOLEAN('\0', "show-round-events", &script.show_round_events,
> 		    "Show round events (if recorded)"),
> +	OPT_BOOLEAN('\0', "show-bpf-events", &script.show_bpf_events,
> +		    "Show bpf related events (if recorded)"),
> 	OPT_BOOLEAN('\0', "per-event-dump", &script.per_event_dump,
> 		    "Dump trace output to files named by the monitored events"),
> 	OPT_BOOLEAN('f', "force", &symbol_conf.force, "don't complain, do it"),
> -- 
> 2.20.1
> 


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCHv2 00/12] perf tools: Display eBPF code in intel_pt trace
  2019-05-03  8:18 [PATCHv2 00/12] perf tools: Display eBPF code in intel_pt trace Jiri Olsa
                   ` (11 preceding siblings ...)
  2019-05-03  8:18 ` [PATCH 12/12] perf script: Add --show-all-events option Jiri Olsa
@ 2019-05-06 21:46 ` Song Liu
  12 siblings, 0 replies; 28+ messages in thread
From: Song Liu @ 2019-05-06 21:46 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Arnaldo Carvalho de Melo, Jesper Dangaard Brouer,
	Alexei Starovoitov, Daniel Borkmann, lkml, Ingo Molnar,
	Namhyung Kim, Alexander Shishkin, Peter Zijlstra,
	Stanislav Fomichev, Adrian Hunter, Andi Kleen



> On May 3, 2019, at 1:18 AM, Jiri Olsa <jolsa@kernel.org> wrote:
> 
> hi,
> this patchset adds dso support to read and display
> bpf code in intel_pt trace output. I had to change
> some of the kernel maps processing code, so hopefully
> I did not break too many things ;-)
> 
> It's now possible to see bpf code flow via:
> 
>  # perf-with-kcore record pt -e intel_pt//ku -- sleep 1
>  # perf-with-kcore script pt --insn-trace --xed
>  ...
>           sleep 36660 [016] 1057036.806464404:  ffffffff811dfba5 trace_call_bpf+0x65 ([kernel.kallsyms])               nopl  %eax, (%rax,%rax,1)
>           sleep 36660 [016] 1057036.806464404:  ffffffff811dfbaa trace_call_bpf+0x6a ([kernel.kallsyms])               movq  0x30(%rbx), %rax
>           sleep 36660 [016] 1057036.806464404:  ffffffff811dfbae trace_call_bpf+0x6e ([kernel.kallsyms])               leaq  0x38(%rbx), %rsi
>           sleep 36660 [016] 1057036.806464404:  ffffffff811dfbb2 trace_call_bpf+0x72 ([kernel.kallsyms])               mov %r13, %rdi
>           sleep 36660 [016] 1057036.806464404:  ffffffff811dfbb5 trace_call_bpf+0x75 ([kernel.kallsyms])               callq  0xffffffff81c00c30
>           sleep 36660 [016] 1057036.806464404:  ffffffff81c00c30 __x86_indirect_thunk_rax+0x0 ([kernel.kallsyms])              callq  0xffffffff81c00c3c
>           sleep 36660 [016] 1057036.806464404:  ffffffff81c00c3c __x86_indirect_thunk_rax+0xc ([kernel.kallsyms])              movq  %rax, (%rsp)
>           sleep 36660 [016] 1057036.806464404:  ffffffff81c00c40 __x86_indirect_thunk_rax+0x10 ([kernel.kallsyms])             retq
>           sleep 36660 [016] 1057036.806464725:  ffffffffa05e89ef bpf_prog_da4fe6b3d2c29b25_trace_return+0x0 (bpf_prog_da4fe6b3d2c29b25_trace_return)           pushq  %rbp
>           sleep 36660 [016] 1057036.806464725:  ffffffffa05e89f0 bpf_prog_da4fe6b3d2c29b25_trace_return+0x1 (bpf_prog_da4fe6b3d2c29b25_trace_return)           mov %rsp, %rbp
>           sleep 36660 [016] 1057036.806464725:  ffffffffa05e89f3 bpf_prog_da4fe6b3d2c29b25_trace_return+0x4 (bpf_prog_da4fe6b3d2c29b25_trace_return)           sub $0x158, %rsp
>           sleep 36660 [016] 1057036.806464725:  ffffffffa05e89fa bpf_prog_da4fe6b3d2c29b25_trace_return+0xb (bpf_prog_da4fe6b3d2c29b25_trace_return)           sub $0x28, %rbp
>           sleep 36660 [016] 1057036.806464725:  ffffffffa05e89fe bpf_prog_da4fe6b3d2c29b25_trace_return+0xf (bpf_prog_da4fe6b3d2c29b25_trace_return)           movq  %rbx, (%rbp)
>           sleep 36660 [016] 1057036.806464725:  ffffffffa05e8a02 bpf_prog_da4fe6b3d2c29b25_trace_return+0x13 (bpf_prog_da4fe6b3d2c29b25_trace_return)          movq  %r13, 0x8(%rbp)
>           sleep 36660 [016] 1057036.806464725:  ffffffffa05e8a06 bpf_prog_da4fe6b3d2c29b25_trace_return+0x17 (bpf_prog_da4fe6b3d2c29b25_trace_return)          movq  %r14, 0x10(%rbp)
>           sleep 36660 [016] 1057036.806464725:  ffffffffa05e8a0a bpf_prog_da4fe6b3d2c29b25_trace_return+0x1b (bpf_prog_da4fe6b3d2c29b25_trace_return)          movq  %r15, 0x18(%rbp)
>           sleep 36660 [016] 1057036.806464725:  ffffffffa05e8a0e bpf_prog_da4fe6b3d2c29b25_trace_return+0x1f (bpf_prog_da4fe6b3d2c29b25_trace_return)          xor %eax, %eax
>           sleep 36660 [016] 1057036.806464725:  ffffffffa05e8a10 bpf_prog_da4fe6b3d2c29b25_trace_return+0x21 (bpf_prog_da4fe6b3d2c29b25_trace_return)          movq  %rax, 0x20(%rbp)
>           sleep 36660 [016] 1057036.806464725:  ffffffffa05e8a14 bpf_prog_da4fe6b3d2c29b25_trace_return+0x25 (bpf_prog_da4fe6b3d2c29b25_trace_return)          mov %rdi, %rbx
>           sleep 36660 [016] 1057036.806464725:  ffffffffa05e8a17 bpf_prog_da4fe6b3d2c29b25_trace_return+0x28 (bpf_prog_da4fe6b3d2c29b25_trace_return)          callq  0xffffffff811fed50
>           sleep 36660 [016] 1057036.806464725:  ffffffff811fed50 bpf_get_current_pid_tgid+0x0 ([kernel.kallsyms])              nopl  %eax, (%rax,%rax,1)
>           sleep 36660 [016] 1057036.806464725:  ffffffff811fed55 bpf_get_current_pid_tgid+0x5 ([kernel.kallsyms])              movq  %gs:0x15c00, %rdx
>           sleep 36660 [016] 1057036.806464725:  ffffffff811fed5e bpf_get_current_pid_tgid+0xe ([kernel.kallsyms])              test %rdx, %rdx
>           sleep 36660 [016] 1057036.806464725:  ffffffff811fed61 bpf_get_current_pid_tgid+0x11 ([kernel.kallsyms])             jz 0xffffffff811fed79
>           sleep 36660 [016] 1057036.806464725:  ffffffff811fed63 bpf_get_current_pid_tgid+0x13 ([kernel.kallsyms])             movsxdl  0x494(%rdx), %rax
>           sleep 36660 [016] 1057036.806464725:  ffffffff811fed6a bpf_get_current_pid_tgid+0x1a ([kernel.kallsyms])             movsxdl  0x490(%rdx), %rdx
>           sleep 36660 [016] 1057036.806464725:  ffffffff811fed71 bpf_get_current_pid_tgid+0x21 ([kernel.kallsyms])             shl $0x20, %rax
>           sleep 36660 [016] 1057036.806464725:  ffffffff811fed75 bpf_get_current_pid_tgid+0x25 ([kernel.kallsyms])             or %rdx, %rax
>           sleep 36660 [016] 1057036.806464725:  ffffffff811fed78 bpf_get_current_pid_tgid+0x28 ([kernel.kallsyms])             retq
>           sleep 36660 [016] 1057036.806464725:  ffffffffa05e8a1c bpf_prog_da4fe6b3d2c29b25_trace_return+0x2d (bpf_prog_da4fe6b3d2c29b25_trace_return)          movq  %rax, -0x8(%rbp)
>           sleep 36660 [016] 1057036.806464725:  ffffffffa05e8a20 bpf_prog_da4fe6b3d2c29b25_trace_return+0x31 (bpf_prog_da4fe6b3d2c29b25_trace_return)          xor %edi, %edi
>           sleep 36660 [016] 1057036.806464725:  ffffffffa05e8a22 bpf_prog_da4fe6b3d2c29b25_trace_return+0x33 (bpf_prog_da4fe6b3d2c29b25_trace_return)          movq  %rdi, -0x10(%rbp)
>           sleep 36660 [016] 1057036.806464725:  ffffffffa05e8a26 bpf_prog_da4fe6b3d2c29b25_trace_return+0x37 (bpf_prog_da4fe6b3d2c29b25_trace_return)          movq  %rdi, -0x18(%rbp)
> 
>  # perf-core/perf-with-kcore script pt --call-trace
>  ...
>           sleep 36660 [016] 1057036.806464404: ([kernel.kallsyms]                       )                kretprobe_perf_func
>           sleep 36660 [016] 1057036.806464404: ([kernel.kallsyms]                       )                    trace_call_bpf
>           sleep 36660 [016] 1057036.806464404: ([kernel.kallsyms]                       )                        __x86_indirect_thunk_rax
>           sleep 36660 [016] 1057036.806464404: ([kernel.kallsyms]                       )                            __x86_indirect_thunk_rax
>           sleep 36660 [016] 1057036.806464725: (bpf_prog_da4fe6b3d2c29b25_trace_return  )                                bpf_get_current_pid_tgid
>           sleep 36660 [016] 1057036.806464725: (bpf_prog_da4fe6b3d2c29b25_trace_return  )                                bpf_ktime_get_ns
>           sleep 36660 [016] 1057036.806464725: ([kernel.kallsyms]                       )                                    __x86_indirect_thunk_rax
>           sleep 36660 [016] 1057036.806464725: ([kernel.kallsyms]                       )                                        __x86_indirect_thunk_rax
>           sleep 36660 [016] 1057036.806465045: (bpf_prog_da4fe6b3d2c29b25_trace_return  )                                __htab_map_lookup_elem
>           sleep 36660 [016] 1057036.806465366: ([kernel.kallsyms]                       )                                    memcmp
>           sleep 36660 [016] 1057036.806465687: (bpf_prog_da4fe6b3d2c29b25_trace_return  )                                bpf_probe_read
>           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                    probe_kernel_read
>           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                        __check_object_size
>           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                            check_stack_object
>           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                        copy_user_enhanced_fast_string
>           sleep 36660 [016] 1057036.806465687: (bpf_prog_da4fe6b3d2c29b25_trace_return  )                                bpf_probe_read
>           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                    probe_kernel_read
>           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                        __check_object_size
>           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                            check_stack_object
>           sleep 36660 [016] 1057036.806465687: ([kernel.kallsyms]                       )                                        copy_user_enhanced_fast_string
>           sleep 36660 [016] 1057036.806466008: (bpf_prog_da4fe6b3d2c29b25_trace_return  )                                bpf_get_current_uid_gid
>           sleep 36660 [016] 1057036.806466008: ([kernel.kallsyms]                       )                                    from_kgid
>           sleep 36660 [016] 1057036.806466008: ([kernel.kallsyms]                       )                                    from_kuid
>           sleep 36660 [016] 1057036.806466008: (bpf_prog_da4fe6b3d2c29b25_trace_return  )                                bpf_perf_event_output
>           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms]                       )                                    perf_event_output
>           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms]                       )                                        perf_prepare_sample
>           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms]                       )                                            perf_misc_flags
>           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms]                       )                                                __x86_indirect_thunk_rax
>           sleep 36660 [016] 1057036.806466328: ([kernel.kallsyms]                       )                                                    __x86_indirect_thunk_rax
> 
> 
> v2 changes:
>  - fix missing pthread_mutex_unlock [Stanislav Fomichev]
>  - removed eBPF dso reusing [Adrian Hunter]
>  - merge eBPF and kcore maps [Adrian Hunter]
>  - few patches already applied
>  - added some perf script helper options
>  - patches are rebased on top of Arnaldo's perf/core with perf/urgent merged in
> 
> It's also available in here:
>  git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
>  perf/fixes
> 
> thanks,
> jirka

Besides minor comments in a few patches, for the series: 

Acked-by: Song Liu <songliubraving@fb.com>


> 
> Cc: Jesper Dangaard Brouer <brouer@redhat.com>
> Cc: Alexei Starovoitov <ast@kernel.org>
> Cc: Daniel Borkmann <daniel@iogearbox.net>
> ---
> Jiri Olsa (12):
>      perf tools: Separate generic code in dso__data_file_size
>      perf tools: Separate generic code in dso_cache__read
>      perf tools: Simplify dso_cache__read function
>      perf tools: Add bpf dso read and size hooks
>      perf tools: Read also the end of the kernel
>      perf tools: Keep zero in pgoff bpf map
>      perf script: Pad dso name for --call-trace
>      perf tools: Preserve eBPF maps when loading kcore
>      perf tests: Add map_groups__merge_in test
>      perf script: Add --show-bpf-events to show eBPF related events
>      perf script: Remove superfluous bpf event titles
>      perf script: Add --show-all-events option
> 
> tools/include/linux/kernel.h             |   1 +
> tools/lib/vsprintf.c                     |  19 +++++++++++++++++++
> tools/perf/Documentation/perf-script.txt |   6 ++++++
> tools/perf/builtin-script.c              |  56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> tools/perf/tests/Build                   |   1 +
> tools/perf/tests/builtin-test.c          |   4 ++++
> tools/perf/tests/map_groups.c            | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> tools/perf/tests/tests.h                 |   1 +
> tools/perf/util/dso.c                    | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------
> tools/perf/util/event.c                  |   4 ++--
> tools/perf/util/machine.c                |  31 ++++++++++++++++++++-----------
> tools/perf/util/map.c                    |   6 ++++++
> tools/perf/util/map_groups.h             |   2 ++
> tools/perf/util/symbol.c                 |  97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
> tools/perf/util/symbol_conf.h            |   1 +
> 15 files changed, 421 insertions(+), 53 deletions(-)
> create mode 100644 tools/perf/tests/map_groups.c


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 07/12] perf script: Pad dso name for --call-trace
  2019-05-06 21:38   ` Song Liu
@ 2019-05-07  8:13     ` Jiri Olsa
  2019-05-07 18:29       ` Song Liu
  0 siblings, 1 reply; 28+ messages in thread
From: Jiri Olsa @ 2019-05-07  8:13 UTC (permalink / raw)
  To: Song Liu
  Cc: Jiri Olsa, Arnaldo Carvalho de Melo, lkml, Ingo Molnar,
	Namhyung Kim, Alexander Shishkin, Peter Zijlstra,
	Stanislav Fomichev, Adrian Hunter, Andi Kleen

On Mon, May 06, 2019 at 09:38:55PM +0000, Song Liu wrote:

SNIP

> > 
> > Link: http://lkml.kernel.org/n/tip-99g9rg4p20a1o99vr0nkjhq8@git.kernel.org
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> > tools/include/linux/kernel.h  |  1 +
> > tools/lib/vsprintf.c          | 19 +++++++++++++++++++
> > tools/perf/builtin-script.c   |  1 +
> > tools/perf/util/map.c         |  6 ++++++
> > tools/perf/util/symbol_conf.h |  1 +
> > 5 files changed, 28 insertions(+)
> > 
> > diff --git a/tools/include/linux/kernel.h b/tools/include/linux/kernel.h
> > index 857d9e22826e..cba226948a0c 100644
> > --- a/tools/include/linux/kernel.h
> > +++ b/tools/include/linux/kernel.h
> > @@ -102,6 +102,7 @@
> > 
> > int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
> > int scnprintf(char * buf, size_t size, const char * fmt, ...);
> > +int scnprintf_pad(char * buf, size_t size, const char * fmt, ...);
> > 
> > #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
> > 
> > diff --git a/tools/lib/vsprintf.c b/tools/lib/vsprintf.c
> > index e08ee147eab4..149a15013b23 100644
> > --- a/tools/lib/vsprintf.c
> > +++ b/tools/lib/vsprintf.c
> > @@ -23,3 +23,22 @@ int scnprintf(char * buf, size_t size, const char * fmt, ...)
> > 
> >        return (i >= ssize) ? (ssize - 1) : i;
> > }
> > +
> > +int scnprintf_pad(char * buf, size_t size, const char * fmt, ...)
> > +{
> > +	ssize_t ssize = size;
> > +	va_list args;
> > +	int i;
> 
> nit: I guess we can avoid mixing int, ssize_t and size_t here?

I copied that from scnprintf ;-)

the thing is that at the end we call vsnprintf, which takes size_t
as size param and returns int, so there will be casting at some
point in any case..

I guess the ssize_t was introduced to compare the size_t value with int

> 
> 
> > +
> > +	va_start(args, fmt);
> > +	i = vsnprintf(buf, size, fmt, args);
> > +	va_end(args);
> > +
> > +	if (i < (int) size) {
> > +		for (; i < (int) size; i++)
> > +			buf[i] = ' ';
> > +		buf[i] = 0x0;
> > +	}
> > +
> > +	return (i >= ssize) ? (ssize - 1) : i;
> > +}
> > diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
> > index 61cfd8f70989..7adaa6c63a0b 100644
> > --- a/tools/perf/builtin-script.c
> > +++ b/tools/perf/builtin-script.c
> > @@ -3297,6 +3297,7 @@ static int parse_call_trace(const struct option *opt __maybe_unused,
> > 	parse_output_fields(NULL, "-ip,-addr,-event,-period,+callindent", 0);
> > 	itrace_parse_synth_opts(opt, "cewp", 0);
> > 	symbol_conf.nanosecs = true;
> > +	symbol_conf.pad_output_len_dso = 50;
> > 	return 0;
> > }
> > 
> > diff --git a/tools/perf/util/map.c b/tools/perf/util/map.c
> > index ee71efb9db62..c3fbd6e556b0 100644
> > --- a/tools/perf/util/map.c
> > +++ b/tools/perf/util/map.c
> > @@ -405,6 +405,7 @@ size_t map__fprintf(struct map *map, FILE *fp)
> > 
> > size_t map__fprintf_dsoname(struct map *map, FILE *fp)
> > {
> > +	char buf[PATH_MAX];
> 
> nit: PATH_MAX vs. 50 is a little weird. 

right, the "staying on the safe side" is too big here, will change 

thanks,
jirka

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 10/12] perf script: Add --show-bpf-events to show eBPF related events
  2019-05-06 21:42   ` Song Liu
@ 2019-05-07  8:18     ` Jiri Olsa
  2019-05-07 18:27       ` Song Liu
  0 siblings, 1 reply; 28+ messages in thread
From: Jiri Olsa @ 2019-05-07  8:18 UTC (permalink / raw)
  To: Song Liu
  Cc: Jiri Olsa, Arnaldo Carvalho de Melo, lkml, Ingo Molnar,
	Namhyung Kim, Alexander Shishkin, Peter Zijlstra,
	Stanislav Fomichev, Adrian Hunter, Andi Kleen

On Mon, May 06, 2019 at 09:42:44PM +0000, Song Liu wrote:

SNIP

> > +static int
> > +process_bpf_events(struct perf_tool *tool __maybe_unused,
> > +		   union perf_event *event,
> > +		   struct perf_sample *sample,
> > +		   struct machine *machine)
> > +{
> > +	struct thread *thread;
> > +	struct perf_script *script = container_of(tool, struct perf_script, tool);
> > +	struct perf_session *session = script->session;
> > +	struct perf_evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id);
> > +
> > +	if (machine__process_ksymbol(machine, event, sample) < 0)
> > +		return -1;
> > +
> > +	if (!evsel->attr.sample_id_all) {
> > +		perf_event__fprintf(event, stdout);
> > +		return 0;
> > +	}
> > +
> > +	thread = machine__findnew_thread(machine, sample->pid, sample->tid);
> > +	if (thread == NULL) {
> > +		pr_debug("problem processing MMAP event, skipping it.\n");
> > +		return -1;
> > +	}
> > +
> > +	if (!filter_cpu(sample)) {
> > +		perf_sample__fprintf_start(sample, thread, evsel,
> > +					   event->header.type, stdout);
> > +		perf_event__fprintf(event, stdout);
> > +	}
> > +
> > +	thread__put(thread);
> > +	return 0;
> > +}
> > +
> > static void sig_handler(int sig __maybe_unused)
> > {
> > 	session_done = 1;
> > @@ -2420,6 +2456,10 @@ static int __cmd_script(struct perf_script *script)
> > 		script->tool.ordered_events = false;
> > 		script->tool.finished_round = process_finished_round_event;
> > 	}
> > +	if (script->show_bpf_events) {
> > +		script->tool.ksymbol   = process_bpf_events;
> > +		script->tool.bpf_event = process_bpf_events;
> 
> Why do we need both set to process_bpf_events?

--show-*-events option is there to display all the related events for given '*'

we want to display both ksymbol and bpf_event in here,
process_bpf_events takes care of it for both of them

thanks,
jirka

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 10/12] perf script: Add --show-bpf-events to show eBPF related events
  2019-05-07  8:18     ` Jiri Olsa
@ 2019-05-07 18:27       ` Song Liu
  0 siblings, 0 replies; 28+ messages in thread
From: Song Liu @ 2019-05-07 18:27 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Jiri Olsa, Arnaldo Carvalho de Melo, lkml, Ingo Molnar,
	Namhyung Kim, Alexander Shishkin, Peter Zijlstra,
	Stanislav Fomichev, Adrian Hunter, Andi Kleen



> On May 7, 2019, at 1:18 AM, Jiri Olsa <jolsa@redhat.com> wrote:
> 
> On Mon, May 06, 2019 at 09:42:44PM +0000, Song Liu wrote:
> 
> SNIP
> 
>>> +static int
>>> +process_bpf_events(struct perf_tool *tool __maybe_unused,
>>> +		   union perf_event *event,
>>> +		   struct perf_sample *sample,
>>> +		   struct machine *machine)
>>> +{
>>> +	struct thread *thread;
>>> +	struct perf_script *script = container_of(tool, struct perf_script, tool);
>>> +	struct perf_session *session = script->session;
>>> +	struct perf_evsel *evsel = perf_evlist__id2evsel(session->evlist, sample->id);
>>> +
>>> +	if (machine__process_ksymbol(machine, event, sample) < 0)
>>> +		return -1;
>>> +
>>> +	if (!evsel->attr.sample_id_all) {
>>> +		perf_event__fprintf(event, stdout);
>>> +		return 0;
>>> +	}
>>> +
>>> +	thread = machine__findnew_thread(machine, sample->pid, sample->tid);
>>> +	if (thread == NULL) {
>>> +		pr_debug("problem processing MMAP event, skipping it.\n");
>>> +		return -1;
>>> +	}
>>> +
>>> +	if (!filter_cpu(sample)) {
>>> +		perf_sample__fprintf_start(sample, thread, evsel,
>>> +					   event->header.type, stdout);
>>> +		perf_event__fprintf(event, stdout);
>>> +	}
>>> +
>>> +	thread__put(thread);
>>> +	return 0;
>>> +}
>>> +
>>> static void sig_handler(int sig __maybe_unused)
>>> {
>>> 	session_done = 1;
>>> @@ -2420,6 +2456,10 @@ static int __cmd_script(struct perf_script *script)
>>> 		script->tool.ordered_events = false;
>>> 		script->tool.finished_round = process_finished_round_event;
>>> 	}
>>> +	if (script->show_bpf_events) {
>>> +		script->tool.ksymbol   = process_bpf_events;
>>> +		script->tool.bpf_event = process_bpf_events;
>> 
>> Why do we need both set to process_bpf_events?
> 
> --show-*-events option is there to display all the related events for given '*'
> 
> we want to display both ksymbol and bpf_event in here,
> process_bpf_events takes care of it for both of them

I see. Thanks for the explanation!

Song


^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 07/12] perf script: Pad dso name for --call-trace
  2019-05-07  8:13     ` Jiri Olsa
@ 2019-05-07 18:29       ` Song Liu
  2019-05-08  7:40         ` Jiri Olsa
  0 siblings, 1 reply; 28+ messages in thread
From: Song Liu @ 2019-05-07 18:29 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Jiri Olsa, Arnaldo Carvalho de Melo, lkml, Ingo Molnar,
	Namhyung Kim, Alexander Shishkin, Peter Zijlstra,
	Stanislav Fomichev, Adrian Hunter, Andi Kleen



> On May 7, 2019, at 1:13 AM, Jiri Olsa <jolsa@redhat.com> wrote:
> 
> On Mon, May 06, 2019 at 09:38:55PM +0000, Song Liu wrote:
> 
> SNIP
> 
>>> 
>>> Link: http://lkml.kernel.org/n/tip-99g9rg4p20a1o99vr0nkjhq8@git.kernel.org
>>> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
>>> ---
>>> tools/include/linux/kernel.h  |  1 +
>>> tools/lib/vsprintf.c          | 19 +++++++++++++++++++
>>> tools/perf/builtin-script.c   |  1 +
>>> tools/perf/util/map.c         |  6 ++++++
>>> tools/perf/util/symbol_conf.h |  1 +
>>> 5 files changed, 28 insertions(+)
>>> 
>>> diff --git a/tools/include/linux/kernel.h b/tools/include/linux/kernel.h
>>> index 857d9e22826e..cba226948a0c 100644
>>> --- a/tools/include/linux/kernel.h
>>> +++ b/tools/include/linux/kernel.h
>>> @@ -102,6 +102,7 @@
>>> 
>>> int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
>>> int scnprintf(char * buf, size_t size, const char * fmt, ...);
>>> +int scnprintf_pad(char * buf, size_t size, const char * fmt, ...);
>>> 
>>> #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
>>> 
>>> diff --git a/tools/lib/vsprintf.c b/tools/lib/vsprintf.c
>>> index e08ee147eab4..149a15013b23 100644
>>> --- a/tools/lib/vsprintf.c
>>> +++ b/tools/lib/vsprintf.c
>>> @@ -23,3 +23,22 @@ int scnprintf(char * buf, size_t size, const char * fmt, ...)
>>> 
>>>       return (i >= ssize) ? (ssize - 1) : i;
>>> }
>>> +
>>> +int scnprintf_pad(char * buf, size_t size, const char * fmt, ...)
>>> +{
>>> +	ssize_t ssize = size;
>>> +	va_list args;
>>> +	int i;
>> 
>> nit: I guess we can avoid mixing int, ssize_t and size_t here?
> 
> I copied that from scnprintf ;-)
> 
> the thing is that at the end we call vsnprintf, which takes size_t
> as size param and returns int, so there will be casting at some
> point in any case..
> 
> I guess the ssize_t was introduced to compare the size_t value with int
> 

Interesting. Given scnprintf works fine, I think we can keep the patch
as-is. 

Thanks,
Song

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 07/12] perf script: Pad dso name for --call-trace
  2019-05-07 18:29       ` Song Liu
@ 2019-05-08  7:40         ` Jiri Olsa
  0 siblings, 0 replies; 28+ messages in thread
From: Jiri Olsa @ 2019-05-08  7:40 UTC (permalink / raw)
  To: Song Liu
  Cc: Jiri Olsa, Arnaldo Carvalho de Melo, lkml, Ingo Molnar,
	Namhyung Kim, Alexander Shishkin, Peter Zijlstra,
	Stanislav Fomichev, Adrian Hunter, Andi Kleen

On Tue, May 07, 2019 at 06:29:07PM +0000, Song Liu wrote:
> 
> 
> > On May 7, 2019, at 1:13 AM, Jiri Olsa <jolsa@redhat.com> wrote:
> > 
> > On Mon, May 06, 2019 at 09:38:55PM +0000, Song Liu wrote:
> > 
> > SNIP
> > 
> >>> 
> >>> Link: http://lkml.kernel.org/n/tip-99g9rg4p20a1o99vr0nkjhq8@git.kernel.org
> >>> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> >>> ---
> >>> tools/include/linux/kernel.h  |  1 +
> >>> tools/lib/vsprintf.c          | 19 +++++++++++++++++++
> >>> tools/perf/builtin-script.c   |  1 +
> >>> tools/perf/util/map.c         |  6 ++++++
> >>> tools/perf/util/symbol_conf.h |  1 +
> >>> 5 files changed, 28 insertions(+)
> >>> 
> >>> diff --git a/tools/include/linux/kernel.h b/tools/include/linux/kernel.h
> >>> index 857d9e22826e..cba226948a0c 100644
> >>> --- a/tools/include/linux/kernel.h
> >>> +++ b/tools/include/linux/kernel.h
> >>> @@ -102,6 +102,7 @@
> >>> 
> >>> int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
> >>> int scnprintf(char * buf, size_t size, const char * fmt, ...);
> >>> +int scnprintf_pad(char * buf, size_t size, const char * fmt, ...);
> >>> 
> >>> #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
> >>> 
> >>> diff --git a/tools/lib/vsprintf.c b/tools/lib/vsprintf.c
> >>> index e08ee147eab4..149a15013b23 100644
> >>> --- a/tools/lib/vsprintf.c
> >>> +++ b/tools/lib/vsprintf.c
> >>> @@ -23,3 +23,22 @@ int scnprintf(char * buf, size_t size, const char * fmt, ...)
> >>> 
> >>>       return (i >= ssize) ? (ssize - 1) : i;
> >>> }
> >>> +
> >>> +int scnprintf_pad(char * buf, size_t size, const char * fmt, ...)
> >>> +{
> >>> +	ssize_t ssize = size;
> >>> +	va_list args;
> >>> +	int i;
> >> 
> >> nit: I guess we can avoid mixing int, ssize_t and size_t here?
> > 
> > I copied that from scnprintf ;-)
> > 
> > the thing is that at the end we call vsnprintf, which takes size_t
> > as size param and returns int, so there will be casting at some
> > point in any case..
> > 
> > I guess the ssize_t was introduced to compare the size_t value with int
> > 
> 
> Interesting. Given scnprintf works fine, I think we can keep the patch
> as-is. 

I actualy found off by one issue in here.. I'll send new version

thanks,
jirka

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 05/12] perf tools: Read also the end of the kernel
  2019-05-24 18:46       ` Arnaldo Carvalho de Melo
@ 2019-05-26 13:09         ` Jiri Olsa
  0 siblings, 0 replies; 28+ messages in thread
From: Jiri Olsa @ 2019-05-26 13:09 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Jiri Olsa, lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
	Peter Zijlstra, Stanislav Fomichev, Song Liu, Adrian Hunter,
	Andi Kleen

On Fri, May 24, 2019 at 03:46:07PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Fri, May 24, 2019 at 03:17:17PM -0300, Arnaldo Carvalho de Melo escreveu:
> > Em Fri, May 24, 2019 at 03:15:06PM -0300, Arnaldo Carvalho de Melo escreveu:
> > > Em Wed, May 08, 2019 at 03:20:03PM +0200, Jiri Olsa escreveu:
> > > > We mark the end of kernel based on the first module,
> > > > but that could cover some bpf program maps. Reading
> > > > _etext symbol if it's present to get precise kernel
> > > > map end.
> > > 
> > > Investigating... Have you run 'perf test' before hitting the send
> > > button? :-)
> > 
> > <SNIP>
> > 
> > > [root@quaco c]# perf test -v 1
> > >  1: vmlinux symtab matches kallsyms                       :
> > <SNIP>
> > > --- start ---
> > > ERR : 0xffffffff8cc00e41: __indirect_thunk_end not on kallsyms
> > <SNIP>
> > > test child finished with -1
> > > ---- end ----
> > > vmlinux symtab matches kallsyms: FAILED!
> > > [root@quaco c]#
> > 
> > So...
> > 
> > [root@quaco c]# grep __indirect_thunk_end /proc/kallsyms
> > ffffffff8cc00e41 T __indirect_thunk_end
> > [root@quaco c]# grep -w _etext /proc/kallsyms
> > ffffffff8cc00e41 T _etext
> > [root@quaco c]#
> > 
> > [root@quaco c]# grep -w ffffffff8cc00e41 /proc/kallsyms
> > ffffffff8cc00e41 T _etext
> > ffffffff8cc00e41 T __indirect_thunk_end
> > [root@quaco c]#
> > 
> > Lemme try to fix this.
> 
> So, I got this right before your patch:
> 
> commit 1d1c54c5bbf55256e691bedb47b0d14745043e80
> Author: Arnaldo Carvalho de Melo <acme@redhat.com>
> Date:   Fri May 24 15:39:00 2019 -0300
> 
>     perf test vmlinux-kallsyms: Ignore aliases to _etext when searching on kallsyms
>     
>     No need to search for aliases for the symbol that marks the end of the
>     kernel text segment, the following patch will make such symbols not to
>     be found when searching in the kallsyms maps causing this test to fail.
>     
>     So as a prep patch to avoid breaking bisection, ignore such symbols.
>     
>     Cc: Adrian Hunter <adrian.hunter@intel.com>
>     Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
>     Cc: Andi Kleen <ak@linux.intel.com>
>     Cc: Jiri Olsa <jolsa@kernel.org>
>     Cc: Namhyung Kim <namhyung@kernel.org>
>     Cc: Peter Zijlstra <peterz@infradead.org>
>     Cc: Song Liu <songliubraving@fb.com>
>     Cc: Stanislav Fomichev <sdf@google.com>
>     Cc: Thomas Richter <tmricht@linux.ibm.com>
>     Link: https://lkml.kernel.org/n/tip-qfwuih8cvmk9doh7k5k244eq@git.kernel.org
>     Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

works for me

Tested-by: Jiri Olsa <jolsa@kernel.org>

thanks,
jirka

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 05/12] perf tools: Read also the end of the kernel
  2019-05-24 18:15   ` Arnaldo Carvalho de Melo
  2019-05-24 18:17     ` Arnaldo Carvalho de Melo
@ 2019-05-24 23:21     ` Jiri Olsa
  1 sibling, 0 replies; 28+ messages in thread
From: Jiri Olsa @ 2019-05-24 23:21 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Jiri Olsa, lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
	Peter Zijlstra, Stanislav Fomichev, Song Liu, Adrian Hunter,
	Andi Kleen

On Fri, May 24, 2019 at 03:15:06PM -0300, Arnaldo Carvalho de Melo wrote:
> Em Wed, May 08, 2019 at 03:20:03PM +0200, Jiri Olsa escreveu:
> > We mark the end of kernel based on the first module,
> > but that could cover some bpf program maps. Reading
> > _etext symbol if it's present to get precise kernel
> > map end.
> 
> Investigating... Have you run 'perf test' before hitting the send
> button? :-)

yea, I got skip test.. for not having the vmlinux in place

[jolsa@krava perf]$ sudo ./perf test 1
 1: vmlinux symtab matches kallsyms                       : Skip

did not realized it would break.. because I have 'Skip' in
this one always :-\ sry

jirka

> 
> - Arnaldo
> 
> [root@quaco c]# perf test 1
>  1: vmlinux symtab matches kallsyms                       : FAILED!
> [root@quaco c]# perf test -v 1
>  1: vmlinux symtab matches kallsyms                       :
> --- start ---
> test child forked, pid 17488
> Looking at the vmlinux_path (8 entries long)
> Using /lib/modules/5.2.0-rc1+/build/vmlinux for symbols
> WARN: 0xffffffff8c001000: diff name v: hypercall_page k: xen_hypercall_set_trap_table
> WARN: 0xffffffff8c0275c0: diff name v: __ia32_sys_rt_sigreturn k: __x64_sys_rt_sigreturn
> WARN: 0xffffffff8c06ac31: diff name v: end_irq_irq_disable k: start_irq_irq_enable
> WARN: 0xffffffff8c06ac32: diff name v: end_irq_irq_enable k: start_irq_restore_fl
> WARN: 0xffffffff8c06ac34: diff name v: end_irq_restore_fl k: start_irq_save_fl
> WARN: 0xffffffff8c06ac36: diff name v: end_irq_save_fl k: start_mmu_read_cr2
> WARN: 0xffffffff8c06ac3c: diff name v: end_mmu_read_cr3 k: start_mmu_write_cr3
> WARN: 0xffffffff8c06ac3f: diff name v: end_mmu_write_cr3 k: start_cpu_wbinvd
> WARN: 0xffffffff8c06ac41: diff name v: end_cpu_wbinvd k: start_cpu_usergs_sysret64
> WARN: 0xffffffff8c06ac47: diff name v: end_cpu_usergs_sysret64 k: start_cpu_swapgs
> WARN: 0xffffffff8c06ac4a: diff name v: end_cpu_swapgs k: start__mov64
> WARN: 0xffffffff8c0814b0: diff end addr for aesni_gcm_dec v: 0xffffffff8c083606 k: 0xffffffff8c0817c7
> WARN: 0xffffffff8c083610: diff end addr for aesni_gcm_enc v: 0xffffffff8c0856f2 k: 0xffffffff8c083927
> WARN: 0xffffffff8c085c00: diff end addr for aesni_gcm_enc_update v: 0xffffffff8c087556 k: 0xffffffff8c085c31
> WARN: 0xffffffff8c087560: diff end addr for aesni_gcm_dec_update v: 0xffffffff8c088f2a k: 0xffffffff8c087591
> WARN: 0xffffffff8c08b7c0: diff end addr for aesni_gcm_enc_update_avx_gen2 v: 0xffffffff8c09b13c k: 0xffffffff8c08b818
> WARN: 0xffffffff8c08fac1: diff name v: _initial_blocks_done2259 k: _initial_blocks_encrypted15
> WARN: 0xffffffff8c094943: diff name v: _initial_blocks_done4447 k: _initial_blocks_encrypted2497
> WARN: 0xffffffff8c09a023: diff name v: _initial_blocks_done7187 k: _initial_blocks_encrypted4649
> WARN: 0xffffffff8c09b140: diff end addr for aesni_gcm_dec_update_avx_gen2 v: 0xffffffff8c0ab05f k: 0xffffffff8c09b198
> WARN: 0xffffffff8c09f5b6: diff name v: _initial_blocks_done9706 k: _initial_blocks_encrypted7462
> WARN: 0xffffffff8c0a4619: diff name v: _initial_blocks_done11894 k: _initial_blocks_encrypted9944
> WARN: 0xffffffff8c0a9eda: diff name v: _initial_blocks_done14634 k: _initial_blocks_encrypted12096
> WARN: 0xffffffff8c0abcd0: diff end addr for aesni_gcm_enc_update_avx_gen4 v: 0xffffffff8c0ba4a6 k: 0xffffffff8c0abd28
> WARN: 0xffffffff8c0afaa5: diff name v: _initial_blocks_done17291 k: _initial_blocks_encrypted15047
> WARN: 0xffffffff8c0b4345: diff name v: _initial_blocks_done19479 k: _initial_blocks_encrypted17529
> WARN: 0xffffffff8c0b9443: diff name v: _initial_blocks_done22219 k: _initial_blocks_encrypted19681
> WARN: 0xffffffff8c0ba4b0: diff end addr for aesni_gcm_dec_update_avx_gen4 v: 0xffffffff8c0c9229 k: 0xffffffff8c0ba508
> WARN: 0xffffffff8c0be3fa: diff name v: _initial_blocks_done24738 k: _initial_blocks_encrypted22494
> WARN: 0xffffffff8c0c2e7b: diff name v: _initial_blocks_done26926 k: _initial_blocks_encrypted24976
> WARN: 0xffffffff8c0c815a: diff name v: _initial_blocks_done29666 k: _initial_blocks_encrypted27128
> WARN: 0xffffffff8c0dc2b0: diff name v: __ia32_sys_fork k: __x64_sys_fork
> WARN: 0xffffffff8c0dc2d0: diff name v: __ia32_sys_vfork k: __x64_sys_vfork
> WARN: 0xffffffff8c0e9eb0: diff name v: __ia32_sys_restart_syscall k: __x64_sys_restart_syscall
> WARN: 0xffffffff8c0e9f30: diff name v: __ia32_sys_sgetmask k: __x64_sys_sgetmask
> WARN: 0xffffffff8c0ea4b0: diff name v: __ia32_sys_pause k: __x64_sys_pause
> WARN: 0xffffffff8c0f1610: diff name v: __ia32_sys_gettid k: __x64_sys_gettid
> WARN: 0xffffffff8c0f1630: diff name v: __ia32_sys_getpid k: __x64_sys_getpid
> WARN: 0xffffffff8c0f1650: diff name v: __ia32_sys_getppid k: __x64_sys_getppid
> WARN: 0xffffffff8c0f1980: diff name v: __ia32_sys_getuid k: __x64_sys_getuid
> WARN: 0xffffffff8c0f19b0: diff name v: __ia32_sys_geteuid k: __x64_sys_geteuid
> WARN: 0xffffffff8c0f1b30: diff name v: __ia32_sys_getgid k: __x64_sys_getgid
> WARN: 0xffffffff8c0f1b60: diff name v: __ia32_sys_getegid k: __x64_sys_getegid
> WARN: 0xffffffff8c0f2130: diff name v: __ia32_sys_getpgrp k: __x64_sys_getpgrp
> WARN: 0xffffffff8c0f52f0: diff name v: __ia32_sys_setsid k: __x64_sys_setsid
> WARN: 0xffffffff8c1016d0: diff name v: sys_ni_syscall k: __x64_sys_vm86old
> WARN: 0xffffffff8c10b400: diff name v: __ia32_sys_sched_yield k: __x64_sys_sched_yield
> WARN: 0xffffffff8c1775a0: diff name v: __ia32_sys_getuid16 k: __x64_sys_getuid16
> WARN: 0xffffffff8c1775f0: diff name v: __ia32_sys_geteuid16 k: __x64_sys_geteuid16
> WARN: 0xffffffff8c177640: diff name v: __ia32_sys_getgid16 k: __x64_sys_getgid16
> WARN: 0xffffffff8c177690: diff name v: __ia32_sys_getegid16 k: __x64_sys_getegid16
> WARN: 0xffffffff8c1fa600: diff name v: mark_reg_not_init.part.48 k: mark_reg_unknown.part.51
> WARN: 0xffffffff8c21c1f0: diff name v: perf_pmu_cancel_txn.part.104 k: perf_pmu_commit_txn.part.105
> WARN: 0xffffffff8c23cad0: diff name v: __probe_kernel_read k: probe_kernel_read
> WARN: 0xffffffff8c23cb50: diff name v: __probe_kernel_write k: probe_kernel_write
> WARN: 0xffffffff8c277720: diff name v: __ia32_sys_munlockall k: __x64_sys_munlockall
> WARN: 0xffffffff8c2e9a70: diff name v: __ia32_sys_vhangup k: __x64_sys_vhangup
> WARN: 0xffffffff8c325d30: diff name v: __ia32_sys_sync k: __x64_sys_sync
> WARN: 0xffffffff8c33c310: diff name v: __ia32_sys_inotify_init k: __x64_sys_inotify_init
> WARN: 0xffffffff8c42be70: diff name v: selinux_msg_queue_msgctl.part.37 k: selinux_shm_shmctl.part.36
> WARN: 0xffffffff8c4574c0: diff name v: _rsa_dec.isra.2 k: _rsa_enc.isra.3
> WARN: 0xffffffff8c4c84e0: diff name v: __crc32c_le_base k: __crc32c_le
> WARN: 0xffffffff8c4c8630: diff name v: crc32_le_base k: crc32_le
> WARN: 0xffffffff8c516041: diff name v: quirk_disable_msi.part.30 k: quirk_msi_ht_cap.part.43
> WARN: 0xffffffff8c596c80: diff name v: clkdev_hw_create k: __clk_register_clkdev
> WARN: 0xffffffff8c844430: diff name v: phys_switch_id_show.part.17 k: speed_show.part.22
> WARN: 0xffffffff8c8578f0: diff name v: devlink_fmsg_arr_pair_nest_end.part.56 k: devlink_fmsg_u8_pair_put.part.60
> WARN: 0xffffffff8c9961d0: diff name v: __memcpy k: memcpy
> WARN: 0xffffffff8c996370: diff name v: __memmove k: memmove
> WARN: 0xffffffff8c996510: diff name v: __memset k: memset
> WARN: 0xffffffff8c996b90: diff end addr for csum_partial_copy_generic v: 0xffffffff8c996cf9 k: 0xffffffff8c999590
> WARN: 0xffffffff8c9a6e50: diff name v: default_idle k: __cpuidle_text_start
> WARN: 0xffffffff8ca00000: diff name v: native_usergs_sysret64 k: __entry_text_start
> WARN: 0xffffffff8ca00a3b: diff name v: restore_regs_and_return_to_kernel k: retint_kernel
> ERR : 0xffffffff8cc00e41: __indirect_thunk_end not on kallsyms
> WARN: Maps only in vmlinux:
>  b000000-b02c000 1c00000 [kernel].data..percpu
>  ffffffff8cc00e44-ffffffff8cc01044 e00e44 [kernel].notes
>  ffffffff8ce00000-ffffffff8d1c9372 1000000 [kernel].rodata
>  ffffffff8d1cbfb0-ffffffff8d1cc028 13cbfb0 [kernel].tracedata
>  ffffffff8d1e04d0-ffffffff8d2123a0 13e04d0 [kernel]__ksymtab_strings
>  ffffffff8d2123a0-ffffffff8d2125d0 14123a0 [kernel]__init_rodata
>  ffffffff8d2125d0-ffffffff8d215bb8 14125d0 [kernel]__param
>  ffffffff8d215bb8-ffffffff8d216000 1415bb8 [kernel]__modver
>  ffffffff8d400000-ffffffff8d5679c0 1600000 [kernel].data
>  ffffffff8d933000-ffffffff8d934000 1b33000 [kernel].vvar
>  ffffffff8d960000-ffffffff8d9dcb2f 1d60000 [kernel].init.text
>  ffffffff8d9de000-ffffffff8db46590 1dde000 [kernel].init.data
>  ffffffff8db46590-ffffffff8db465b0 1f46590 [kernel].x86_cpu_dev.init
>  ffffffff8db5ded0-ffffffff8db5df98 1f5ded0 [kernel].iommu_table
>  ffffffff8db5df98-ffffffff8db5dfd8 1f5df98 [kernel].apicdrivers
>  ffffffff8db5dfd8-ffffffff8db5f85e 1f5dfd8 [kernel].exit.text
>  ffffffff8db69000-ffffffff8db6a000 1f69000 [kernel].data_nosave
>  ffffffff8db6a000-ffffffff8e000000 1f6a000 [kernel].bss
> test child finished with -1
> ---- end ----
> vmlinux symtab matches kallsyms: FAILED!
> [root@quaco c]#
> 
> [acme@quaco perf]$ git bisect good
> 7d98e1a73bd7dae6cb321ec8b0b97b9fed7c0e1b is the first bad commit
> commit 7d98e1a73bd7dae6cb321ec8b0b97b9fed7c0e1b
> Author: Jiri Olsa <jolsa@kernel.org>
> Date:   Wed May 8 15:20:03 2019 +0200
> 
>     perf machine: Read also the end of the kernel
> 
>     We mark the end of kernel based on the first module, but that could
>     cover some bpf program maps. Reading _etext symbol if it's present to
>     get precise kernel map end.
> 
>     Signed-off-by: Jiri Olsa <jolsa@kernel.org>
>     Acked-by: Song Liu <songliubraving@fb.com>
>     Cc: Adrian Hunter <adrian.hunter@intel.com>
>     Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
>     Cc: Andi Kleen <ak@linux.intel.com>
>     Cc: Namhyung Kim <namhyung@kernel.org>
>     Cc: Peter Zijlstra <peterz@infradead.org>
>     Cc: Stanislav Fomichev <sdf@google.com>
>     Cc: Thomas Richter <tmricht@linux.ibm.com>
>     Link: http://lkml.kernel.org/r/20190508132010.14512-6-jolsa@kernel.org
>     Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> 
> :040000 040000 4ca5fa4c6f15fd8cf9a0eee870efbd01e9fe309d 8311b30f94e9cf9a863dc9619b0499863f64960e M	tools
> [acme@quaco perf]$
>  
> > Link: http://lkml.kernel.org/n/tip-ynut991ttyyhvo1sbhlm4c42@git.kernel.org
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> >  tools/perf/util/machine.c | 27 ++++++++++++++++++---------
> >  1 file changed, 18 insertions(+), 9 deletions(-)
> > 
> > diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
> > index 3c520baa198c..ad0205fbb506 100644
> > --- a/tools/perf/util/machine.c
> > +++ b/tools/perf/util/machine.c
> > @@ -924,7 +924,8 @@ const char *ref_reloc_sym_names[] = {"_text", "_stext", NULL};
> >   * symbol_name if it's not that important.
> >   */
> >  static int machine__get_running_kernel_start(struct machine *machine,
> > -					     const char **symbol_name, u64 *start)
> > +					     const char **symbol_name,
> > +					     u64 *start, u64 *end)
> >  {
> >  	char filename[PATH_MAX];
> >  	int i, err = -1;
> > @@ -949,6 +950,11 @@ static int machine__get_running_kernel_start(struct machine *machine,
> >  		*symbol_name = name;
> >  
> >  	*start = addr;
> > +
> > +	err = kallsyms__get_function_start(filename, "_etext", &addr);
> > +	if (!err)
> > +		*end = addr;
> > +
> >  	return 0;
> >  }
> >  
> > @@ -1440,7 +1446,7 @@ int machine__create_kernel_maps(struct machine *machine)
> >  	struct dso *kernel = machine__get_kernel(machine);
> >  	const char *name = NULL;
> >  	struct map *map;
> > -	u64 addr = 0;
> > +	u64 start = 0, end = ~0ULL;
> >  	int ret;
> >  
> >  	if (kernel == NULL)
> > @@ -1459,9 +1465,9 @@ int machine__create_kernel_maps(struct machine *machine)
> >  				 "continuing anyway...\n", machine->pid);
> >  	}
> >  
> > -	if (!machine__get_running_kernel_start(machine, &name, &addr)) {
> > +	if (!machine__get_running_kernel_start(machine, &name, &start, &end)) {
> >  		if (name &&
> > -		    map__set_kallsyms_ref_reloc_sym(machine->vmlinux_map, name, addr)) {
> > +		    map__set_kallsyms_ref_reloc_sym(machine->vmlinux_map, name, start)) {
> >  			machine__destroy_kernel_maps(machine);
> >  			ret = -1;
> >  			goto out_put;
> > @@ -1471,16 +1477,19 @@ int machine__create_kernel_maps(struct machine *machine)
> >  		 * we have a real start address now, so re-order the kmaps
> >  		 * assume it's the last in the kmaps
> >  		 */
> > -		machine__update_kernel_mmap(machine, addr, ~0ULL);
> > +		machine__update_kernel_mmap(machine, start, end);
> >  	}
> >  
> >  	if (machine__create_extra_kernel_maps(machine, kernel))
> >  		pr_debug("Problems creating extra kernel maps, continuing anyway...\n");
> >  
> > -	/* update end address of the kernel map using adjacent module address */
> > -	map = map__next(machine__kernel_map(machine));
> > -	if (map)
> > -		machine__set_kernel_mmap(machine, addr, map->start);
> > +	if (end == ~0ULL) {
> > +		/* update end address of the kernel map using adjacent module address */
> > +		map = map__next(machine__kernel_map(machine));
> > +		if (map)
> > +			machine__set_kernel_mmap(machine, start, map->start);
> > +	}
> > +
> >  out_put:
> >  	dso__put(kernel);
> >  	return ret;
> > -- 
> > 2.20.1
> 
> -- 
> 
> - Arnaldo

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 05/12] perf tools: Read also the end of the kernel
  2019-05-24 18:17     ` Arnaldo Carvalho de Melo
@ 2019-05-24 18:46       ` Arnaldo Carvalho de Melo
  2019-05-26 13:09         ` Jiri Olsa
  0 siblings, 1 reply; 28+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-05-24 18:46 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
	Peter Zijlstra, Stanislav Fomichev, Song Liu, Adrian Hunter,
	Andi Kleen

Em Fri, May 24, 2019 at 03:17:17PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Fri, May 24, 2019 at 03:15:06PM -0300, Arnaldo Carvalho de Melo escreveu:
> > Em Wed, May 08, 2019 at 03:20:03PM +0200, Jiri Olsa escreveu:
> > > We mark the end of kernel based on the first module,
> > > but that could cover some bpf program maps. Reading
> > > _etext symbol if it's present to get precise kernel
> > > map end.
> > 
> > Investigating... Have you run 'perf test' before hitting the send
> > button? :-)
> 
> <SNIP>
> 
> > [root@quaco c]# perf test -v 1
> >  1: vmlinux symtab matches kallsyms                       :
> <SNIP>
> > --- start ---
> > ERR : 0xffffffff8cc00e41: __indirect_thunk_end not on kallsyms
> <SNIP>
> > test child finished with -1
> > ---- end ----
> > vmlinux symtab matches kallsyms: FAILED!
> > [root@quaco c]#
> 
> So...
> 
> [root@quaco c]# grep __indirect_thunk_end /proc/kallsyms
> ffffffff8cc00e41 T __indirect_thunk_end
> [root@quaco c]# grep -w _etext /proc/kallsyms
> ffffffff8cc00e41 T _etext
> [root@quaco c]#
> 
> [root@quaco c]# grep -w ffffffff8cc00e41 /proc/kallsyms
> ffffffff8cc00e41 T _etext
> ffffffff8cc00e41 T __indirect_thunk_end
> [root@quaco c]#
> 
> Lemme try to fix this.

So, I got this right before your patch:

commit 1d1c54c5bbf55256e691bedb47b0d14745043e80
Author: Arnaldo Carvalho de Melo <acme@redhat.com>
Date:   Fri May 24 15:39:00 2019 -0300

    perf test vmlinux-kallsyms: Ignore aliases to _etext when searching on kallsyms
    
    No need to search for aliases for the symbol that marks the end of the
    kernel text segment, the following patch will make such symbols not to
    be found when searching in the kallsyms maps causing this test to fail.
    
    So as a prep patch to avoid breaking bisection, ignore such symbols.
    
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Jiri Olsa <jolsa@kernel.org>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Song Liu <songliubraving@fb.com>
    Cc: Stanislav Fomichev <sdf@google.com>
    Cc: Thomas Richter <tmricht@linux.ibm.com>
    Link: https://lkml.kernel.org/n/tip-qfwuih8cvmk9doh7k5k244eq@git.kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

diff --git a/tools/perf/tests/vmlinux-kallsyms.c b/tools/perf/tests/vmlinux-kallsyms.c
index 7691980b7df1..f101576d1c72 100644
--- a/tools/perf/tests/vmlinux-kallsyms.c
+++ b/tools/perf/tests/vmlinux-kallsyms.c
@@ -161,9 +161,16 @@ int test__vmlinux_matches_kallsyms(struct test *test __maybe_unused, int subtest
 
 				continue;
 			}
-		} else
+		} else if (mem_start == kallsyms.vmlinux_map->end) {
+			/*
+			 * Ignore aliases to _etext, i.e. to the end of the kernel text area,
+			 * such as __indirect_thunk_end.
+			 */
+			continue;
+		} else {
 			pr_debug("ERR : %#" PRIx64 ": %s not on kallsyms\n",
 				 mem_start, sym->name);
+		}
 
 		err = -1;
 	}

^ permalink raw reply related	[flat|nested] 28+ messages in thread

* Re: [PATCH 05/12] perf tools: Read also the end of the kernel
  2019-05-24 18:15   ` Arnaldo Carvalho de Melo
@ 2019-05-24 18:17     ` Arnaldo Carvalho de Melo
  2019-05-24 18:46       ` Arnaldo Carvalho de Melo
  2019-05-24 23:21     ` Jiri Olsa
  1 sibling, 1 reply; 28+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-05-24 18:17 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
	Peter Zijlstra, Stanislav Fomichev, Song Liu, Adrian Hunter,
	Andi Kleen

Em Fri, May 24, 2019 at 03:15:06PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Wed, May 08, 2019 at 03:20:03PM +0200, Jiri Olsa escreveu:
> > We mark the end of kernel based on the first module,
> > but that could cover some bpf program maps. Reading
> > _etext symbol if it's present to get precise kernel
> > map end.
> 
> Investigating... Have you run 'perf test' before hitting the send
> button? :-)

<SNIP>

> [root@quaco c]# perf test -v 1
>  1: vmlinux symtab matches kallsyms                       :
<SNIP>
> --- start ---
> ERR : 0xffffffff8cc00e41: __indirect_thunk_end not on kallsyms
<SNIP>
> test child finished with -1
> ---- end ----
> vmlinux symtab matches kallsyms: FAILED!
> [root@quaco c]#

So...

[root@quaco c]# grep __indirect_thunk_end /proc/kallsyms
ffffffff8cc00e41 T __indirect_thunk_end
[root@quaco c]# grep -w _etext /proc/kallsyms
ffffffff8cc00e41 T _etext
[root@quaco c]#

[root@quaco c]# grep -w ffffffff8cc00e41 /proc/kallsyms
ffffffff8cc00e41 T _etext
ffffffff8cc00e41 T __indirect_thunk_end
[root@quaco c]#

Lemme try to fix this.

- Arnaldo
 
> [acme@quaco perf]$ git bisect good
> 7d98e1a73bd7dae6cb321ec8b0b97b9fed7c0e1b is the first bad commit
> commit 7d98e1a73bd7dae6cb321ec8b0b97b9fed7c0e1b
> Author: Jiri Olsa <jolsa@kernel.org>
> Date:   Wed May 8 15:20:03 2019 +0200
> 
>     perf machine: Read also the end of the kernel
> 
>     We mark the end of kernel based on the first module, but that could
>     cover some bpf program maps. Reading _etext symbol if it's present to
>     get precise kernel map end.
> 
>     Signed-off-by: Jiri Olsa <jolsa@kernel.org>
>     Acked-by: Song Liu <songliubraving@fb.com>
>     Cc: Adrian Hunter <adrian.hunter@intel.com>
>     Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
>     Cc: Andi Kleen <ak@linux.intel.com>
>     Cc: Namhyung Kim <namhyung@kernel.org>
>     Cc: Peter Zijlstra <peterz@infradead.org>
>     Cc: Stanislav Fomichev <sdf@google.com>
>     Cc: Thomas Richter <tmricht@linux.ibm.com>
>     Link: http://lkml.kernel.org/r/20190508132010.14512-6-jolsa@kernel.org
>     Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> 
> :040000 040000 4ca5fa4c6f15fd8cf9a0eee870efbd01e9fe309d 8311b30f94e9cf9a863dc9619b0499863f64960e M	tools
> [acme@quaco perf]$
>  
> > Link: http://lkml.kernel.org/n/tip-ynut991ttyyhvo1sbhlm4c42@git.kernel.org
> > Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> > ---
> >  tools/perf/util/machine.c | 27 ++++++++++++++++++---------
> >  1 file changed, 18 insertions(+), 9 deletions(-)
> > 
> > diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
> > index 3c520baa198c..ad0205fbb506 100644
> > --- a/tools/perf/util/machine.c
> > +++ b/tools/perf/util/machine.c
> > @@ -924,7 +924,8 @@ const char *ref_reloc_sym_names[] = {"_text", "_stext", NULL};
> >   * symbol_name if it's not that important.
> >   */
> >  static int machine__get_running_kernel_start(struct machine *machine,
> > -					     const char **symbol_name, u64 *start)
> > +					     const char **symbol_name,
> > +					     u64 *start, u64 *end)
> >  {
> >  	char filename[PATH_MAX];
> >  	int i, err = -1;
> > @@ -949,6 +950,11 @@ static int machine__get_running_kernel_start(struct machine *machine,
> >  		*symbol_name = name;
> >  
> >  	*start = addr;
> > +
> > +	err = kallsyms__get_function_start(filename, "_etext", &addr);
> > +	if (!err)
> > +		*end = addr;
> > +
> >  	return 0;
> >  }
> >  
> > @@ -1440,7 +1446,7 @@ int machine__create_kernel_maps(struct machine *machine)
> >  	struct dso *kernel = machine__get_kernel(machine);
> >  	const char *name = NULL;
> >  	struct map *map;
> > -	u64 addr = 0;
> > +	u64 start = 0, end = ~0ULL;
> >  	int ret;
> >  
> >  	if (kernel == NULL)
> > @@ -1459,9 +1465,9 @@ int machine__create_kernel_maps(struct machine *machine)
> >  				 "continuing anyway...\n", machine->pid);
> >  	}
> >  
> > -	if (!machine__get_running_kernel_start(machine, &name, &addr)) {
> > +	if (!machine__get_running_kernel_start(machine, &name, &start, &end)) {
> >  		if (name &&
> > -		    map__set_kallsyms_ref_reloc_sym(machine->vmlinux_map, name, addr)) {
> > +		    map__set_kallsyms_ref_reloc_sym(machine->vmlinux_map, name, start)) {
> >  			machine__destroy_kernel_maps(machine);
> >  			ret = -1;
> >  			goto out_put;
> > @@ -1471,16 +1477,19 @@ int machine__create_kernel_maps(struct machine *machine)
> >  		 * we have a real start address now, so re-order the kmaps
> >  		 * assume it's the last in the kmaps
> >  		 */
> > -		machine__update_kernel_mmap(machine, addr, ~0ULL);
> > +		machine__update_kernel_mmap(machine, start, end);
> >  	}
> >  
> >  	if (machine__create_extra_kernel_maps(machine, kernel))
> >  		pr_debug("Problems creating extra kernel maps, continuing anyway...\n");
> >  
> > -	/* update end address of the kernel map using adjacent module address */
> > -	map = map__next(machine__kernel_map(machine));
> > -	if (map)
> > -		machine__set_kernel_mmap(machine, addr, map->start);
> > +	if (end == ~0ULL) {
> > +		/* update end address of the kernel map using adjacent module address */
> > +		map = map__next(machine__kernel_map(machine));
> > +		if (map)
> > +			machine__set_kernel_mmap(machine, start, map->start);
> > +	}
> > +
> >  out_put:
> >  	dso__put(kernel);
> >  	return ret;
> > -- 
> > 2.20.1
> 
> -- 
> 
> - Arnaldo

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 05/12] perf tools: Read also the end of the kernel
  2019-05-08 13:20 ` [PATCH 05/12] perf tools: Read also the end of the kernel Jiri Olsa
@ 2019-05-24 18:15   ` Arnaldo Carvalho de Melo
  2019-05-24 18:17     ` Arnaldo Carvalho de Melo
  2019-05-24 23:21     ` Jiri Olsa
  0 siblings, 2 replies; 28+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-05-24 18:15 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
	Peter Zijlstra, Stanislav Fomichev, Song Liu, Adrian Hunter,
	Andi Kleen

Em Wed, May 08, 2019 at 03:20:03PM +0200, Jiri Olsa escreveu:
> We mark the end of kernel based on the first module,
> but that could cover some bpf program maps. Reading
> _etext symbol if it's present to get precise kernel
> map end.

Investigating... Have you run 'perf test' before hitting the send
button? :-)

- Arnaldo

[root@quaco c]# perf test 1
 1: vmlinux symtab matches kallsyms                       : FAILED!
[root@quaco c]# perf test -v 1
 1: vmlinux symtab matches kallsyms                       :
--- start ---
test child forked, pid 17488
Looking at the vmlinux_path (8 entries long)
Using /lib/modules/5.2.0-rc1+/build/vmlinux for symbols
WARN: 0xffffffff8c001000: diff name v: hypercall_page k: xen_hypercall_set_trap_table
WARN: 0xffffffff8c0275c0: diff name v: __ia32_sys_rt_sigreturn k: __x64_sys_rt_sigreturn
WARN: 0xffffffff8c06ac31: diff name v: end_irq_irq_disable k: start_irq_irq_enable
WARN: 0xffffffff8c06ac32: diff name v: end_irq_irq_enable k: start_irq_restore_fl
WARN: 0xffffffff8c06ac34: diff name v: end_irq_restore_fl k: start_irq_save_fl
WARN: 0xffffffff8c06ac36: diff name v: end_irq_save_fl k: start_mmu_read_cr2
WARN: 0xffffffff8c06ac3c: diff name v: end_mmu_read_cr3 k: start_mmu_write_cr3
WARN: 0xffffffff8c06ac3f: diff name v: end_mmu_write_cr3 k: start_cpu_wbinvd
WARN: 0xffffffff8c06ac41: diff name v: end_cpu_wbinvd k: start_cpu_usergs_sysret64
WARN: 0xffffffff8c06ac47: diff name v: end_cpu_usergs_sysret64 k: start_cpu_swapgs
WARN: 0xffffffff8c06ac4a: diff name v: end_cpu_swapgs k: start__mov64
WARN: 0xffffffff8c0814b0: diff end addr for aesni_gcm_dec v: 0xffffffff8c083606 k: 0xffffffff8c0817c7
WARN: 0xffffffff8c083610: diff end addr for aesni_gcm_enc v: 0xffffffff8c0856f2 k: 0xffffffff8c083927
WARN: 0xffffffff8c085c00: diff end addr for aesni_gcm_enc_update v: 0xffffffff8c087556 k: 0xffffffff8c085c31
WARN: 0xffffffff8c087560: diff end addr for aesni_gcm_dec_update v: 0xffffffff8c088f2a k: 0xffffffff8c087591
WARN: 0xffffffff8c08b7c0: diff end addr for aesni_gcm_enc_update_avx_gen2 v: 0xffffffff8c09b13c k: 0xffffffff8c08b818
WARN: 0xffffffff8c08fac1: diff name v: _initial_blocks_done2259 k: _initial_blocks_encrypted15
WARN: 0xffffffff8c094943: diff name v: _initial_blocks_done4447 k: _initial_blocks_encrypted2497
WARN: 0xffffffff8c09a023: diff name v: _initial_blocks_done7187 k: _initial_blocks_encrypted4649
WARN: 0xffffffff8c09b140: diff end addr for aesni_gcm_dec_update_avx_gen2 v: 0xffffffff8c0ab05f k: 0xffffffff8c09b198
WARN: 0xffffffff8c09f5b6: diff name v: _initial_blocks_done9706 k: _initial_blocks_encrypted7462
WARN: 0xffffffff8c0a4619: diff name v: _initial_blocks_done11894 k: _initial_blocks_encrypted9944
WARN: 0xffffffff8c0a9eda: diff name v: _initial_blocks_done14634 k: _initial_blocks_encrypted12096
WARN: 0xffffffff8c0abcd0: diff end addr for aesni_gcm_enc_update_avx_gen4 v: 0xffffffff8c0ba4a6 k: 0xffffffff8c0abd28
WARN: 0xffffffff8c0afaa5: diff name v: _initial_blocks_done17291 k: _initial_blocks_encrypted15047
WARN: 0xffffffff8c0b4345: diff name v: _initial_blocks_done19479 k: _initial_blocks_encrypted17529
WARN: 0xffffffff8c0b9443: diff name v: _initial_blocks_done22219 k: _initial_blocks_encrypted19681
WARN: 0xffffffff8c0ba4b0: diff end addr for aesni_gcm_dec_update_avx_gen4 v: 0xffffffff8c0c9229 k: 0xffffffff8c0ba508
WARN: 0xffffffff8c0be3fa: diff name v: _initial_blocks_done24738 k: _initial_blocks_encrypted22494
WARN: 0xffffffff8c0c2e7b: diff name v: _initial_blocks_done26926 k: _initial_blocks_encrypted24976
WARN: 0xffffffff8c0c815a: diff name v: _initial_blocks_done29666 k: _initial_blocks_encrypted27128
WARN: 0xffffffff8c0dc2b0: diff name v: __ia32_sys_fork k: __x64_sys_fork
WARN: 0xffffffff8c0dc2d0: diff name v: __ia32_sys_vfork k: __x64_sys_vfork
WARN: 0xffffffff8c0e9eb0: diff name v: __ia32_sys_restart_syscall k: __x64_sys_restart_syscall
WARN: 0xffffffff8c0e9f30: diff name v: __ia32_sys_sgetmask k: __x64_sys_sgetmask
WARN: 0xffffffff8c0ea4b0: diff name v: __ia32_sys_pause k: __x64_sys_pause
WARN: 0xffffffff8c0f1610: diff name v: __ia32_sys_gettid k: __x64_sys_gettid
WARN: 0xffffffff8c0f1630: diff name v: __ia32_sys_getpid k: __x64_sys_getpid
WARN: 0xffffffff8c0f1650: diff name v: __ia32_sys_getppid k: __x64_sys_getppid
WARN: 0xffffffff8c0f1980: diff name v: __ia32_sys_getuid k: __x64_sys_getuid
WARN: 0xffffffff8c0f19b0: diff name v: __ia32_sys_geteuid k: __x64_sys_geteuid
WARN: 0xffffffff8c0f1b30: diff name v: __ia32_sys_getgid k: __x64_sys_getgid
WARN: 0xffffffff8c0f1b60: diff name v: __ia32_sys_getegid k: __x64_sys_getegid
WARN: 0xffffffff8c0f2130: diff name v: __ia32_sys_getpgrp k: __x64_sys_getpgrp
WARN: 0xffffffff8c0f52f0: diff name v: __ia32_sys_setsid k: __x64_sys_setsid
WARN: 0xffffffff8c1016d0: diff name v: sys_ni_syscall k: __x64_sys_vm86old
WARN: 0xffffffff8c10b400: diff name v: __ia32_sys_sched_yield k: __x64_sys_sched_yield
WARN: 0xffffffff8c1775a0: diff name v: __ia32_sys_getuid16 k: __x64_sys_getuid16
WARN: 0xffffffff8c1775f0: diff name v: __ia32_sys_geteuid16 k: __x64_sys_geteuid16
WARN: 0xffffffff8c177640: diff name v: __ia32_sys_getgid16 k: __x64_sys_getgid16
WARN: 0xffffffff8c177690: diff name v: __ia32_sys_getegid16 k: __x64_sys_getegid16
WARN: 0xffffffff8c1fa600: diff name v: mark_reg_not_init.part.48 k: mark_reg_unknown.part.51
WARN: 0xffffffff8c21c1f0: diff name v: perf_pmu_cancel_txn.part.104 k: perf_pmu_commit_txn.part.105
WARN: 0xffffffff8c23cad0: diff name v: __probe_kernel_read k: probe_kernel_read
WARN: 0xffffffff8c23cb50: diff name v: __probe_kernel_write k: probe_kernel_write
WARN: 0xffffffff8c277720: diff name v: __ia32_sys_munlockall k: __x64_sys_munlockall
WARN: 0xffffffff8c2e9a70: diff name v: __ia32_sys_vhangup k: __x64_sys_vhangup
WARN: 0xffffffff8c325d30: diff name v: __ia32_sys_sync k: __x64_sys_sync
WARN: 0xffffffff8c33c310: diff name v: __ia32_sys_inotify_init k: __x64_sys_inotify_init
WARN: 0xffffffff8c42be70: diff name v: selinux_msg_queue_msgctl.part.37 k: selinux_shm_shmctl.part.36
WARN: 0xffffffff8c4574c0: diff name v: _rsa_dec.isra.2 k: _rsa_enc.isra.3
WARN: 0xffffffff8c4c84e0: diff name v: __crc32c_le_base k: __crc32c_le
WARN: 0xffffffff8c4c8630: diff name v: crc32_le_base k: crc32_le
WARN: 0xffffffff8c516041: diff name v: quirk_disable_msi.part.30 k: quirk_msi_ht_cap.part.43
WARN: 0xffffffff8c596c80: diff name v: clkdev_hw_create k: __clk_register_clkdev
WARN: 0xffffffff8c844430: diff name v: phys_switch_id_show.part.17 k: speed_show.part.22
WARN: 0xffffffff8c8578f0: diff name v: devlink_fmsg_arr_pair_nest_end.part.56 k: devlink_fmsg_u8_pair_put.part.60
WARN: 0xffffffff8c9961d0: diff name v: __memcpy k: memcpy
WARN: 0xffffffff8c996370: diff name v: __memmove k: memmove
WARN: 0xffffffff8c996510: diff name v: __memset k: memset
WARN: 0xffffffff8c996b90: diff end addr for csum_partial_copy_generic v: 0xffffffff8c996cf9 k: 0xffffffff8c999590
WARN: 0xffffffff8c9a6e50: diff name v: default_idle k: __cpuidle_text_start
WARN: 0xffffffff8ca00000: diff name v: native_usergs_sysret64 k: __entry_text_start
WARN: 0xffffffff8ca00a3b: diff name v: restore_regs_and_return_to_kernel k: retint_kernel
ERR : 0xffffffff8cc00e41: __indirect_thunk_end not on kallsyms
WARN: Maps only in vmlinux:
 b000000-b02c000 1c00000 [kernel].data..percpu
 ffffffff8cc00e44-ffffffff8cc01044 e00e44 [kernel].notes
 ffffffff8ce00000-ffffffff8d1c9372 1000000 [kernel].rodata
 ffffffff8d1cbfb0-ffffffff8d1cc028 13cbfb0 [kernel].tracedata
 ffffffff8d1e04d0-ffffffff8d2123a0 13e04d0 [kernel]__ksymtab_strings
 ffffffff8d2123a0-ffffffff8d2125d0 14123a0 [kernel]__init_rodata
 ffffffff8d2125d0-ffffffff8d215bb8 14125d0 [kernel]__param
 ffffffff8d215bb8-ffffffff8d216000 1415bb8 [kernel]__modver
 ffffffff8d400000-ffffffff8d5679c0 1600000 [kernel].data
 ffffffff8d933000-ffffffff8d934000 1b33000 [kernel].vvar
 ffffffff8d960000-ffffffff8d9dcb2f 1d60000 [kernel].init.text
 ffffffff8d9de000-ffffffff8db46590 1dde000 [kernel].init.data
 ffffffff8db46590-ffffffff8db465b0 1f46590 [kernel].x86_cpu_dev.init
 ffffffff8db5ded0-ffffffff8db5df98 1f5ded0 [kernel].iommu_table
 ffffffff8db5df98-ffffffff8db5dfd8 1f5df98 [kernel].apicdrivers
 ffffffff8db5dfd8-ffffffff8db5f85e 1f5dfd8 [kernel].exit.text
 ffffffff8db69000-ffffffff8db6a000 1f69000 [kernel].data_nosave
 ffffffff8db6a000-ffffffff8e000000 1f6a000 [kernel].bss
test child finished with -1
---- end ----
vmlinux symtab matches kallsyms: FAILED!
[root@quaco c]#

[acme@quaco perf]$ git bisect good
7d98e1a73bd7dae6cb321ec8b0b97b9fed7c0e1b is the first bad commit
commit 7d98e1a73bd7dae6cb321ec8b0b97b9fed7c0e1b
Author: Jiri Olsa <jolsa@kernel.org>
Date:   Wed May 8 15:20:03 2019 +0200

    perf machine: Read also the end of the kernel

    We mark the end of kernel based on the first module, but that could
    cover some bpf program maps. Reading _etext symbol if it's present to
    get precise kernel map end.

    Signed-off-by: Jiri Olsa <jolsa@kernel.org>
    Acked-by: Song Liu <songliubraving@fb.com>
    Cc: Adrian Hunter <adrian.hunter@intel.com>
    Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
    Cc: Andi Kleen <ak@linux.intel.com>
    Cc: Namhyung Kim <namhyung@kernel.org>
    Cc: Peter Zijlstra <peterz@infradead.org>
    Cc: Stanislav Fomichev <sdf@google.com>
    Cc: Thomas Richter <tmricht@linux.ibm.com>
    Link: http://lkml.kernel.org/r/20190508132010.14512-6-jolsa@kernel.org
    Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

:040000 040000 4ca5fa4c6f15fd8cf9a0eee870efbd01e9fe309d 8311b30f94e9cf9a863dc9619b0499863f64960e M	tools
[acme@quaco perf]$
 
> Link: http://lkml.kernel.org/n/tip-ynut991ttyyhvo1sbhlm4c42@git.kernel.org
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  tools/perf/util/machine.c | 27 ++++++++++++++++++---------
>  1 file changed, 18 insertions(+), 9 deletions(-)
> 
> diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
> index 3c520baa198c..ad0205fbb506 100644
> --- a/tools/perf/util/machine.c
> +++ b/tools/perf/util/machine.c
> @@ -924,7 +924,8 @@ const char *ref_reloc_sym_names[] = {"_text", "_stext", NULL};
>   * symbol_name if it's not that important.
>   */
>  static int machine__get_running_kernel_start(struct machine *machine,
> -					     const char **symbol_name, u64 *start)
> +					     const char **symbol_name,
> +					     u64 *start, u64 *end)
>  {
>  	char filename[PATH_MAX];
>  	int i, err = -1;
> @@ -949,6 +950,11 @@ static int machine__get_running_kernel_start(struct machine *machine,
>  		*symbol_name = name;
>  
>  	*start = addr;
> +
> +	err = kallsyms__get_function_start(filename, "_etext", &addr);
> +	if (!err)
> +		*end = addr;
> +
>  	return 0;
>  }
>  
> @@ -1440,7 +1446,7 @@ int machine__create_kernel_maps(struct machine *machine)
>  	struct dso *kernel = machine__get_kernel(machine);
>  	const char *name = NULL;
>  	struct map *map;
> -	u64 addr = 0;
> +	u64 start = 0, end = ~0ULL;
>  	int ret;
>  
>  	if (kernel == NULL)
> @@ -1459,9 +1465,9 @@ int machine__create_kernel_maps(struct machine *machine)
>  				 "continuing anyway...\n", machine->pid);
>  	}
>  
> -	if (!machine__get_running_kernel_start(machine, &name, &addr)) {
> +	if (!machine__get_running_kernel_start(machine, &name, &start, &end)) {
>  		if (name &&
> -		    map__set_kallsyms_ref_reloc_sym(machine->vmlinux_map, name, addr)) {
> +		    map__set_kallsyms_ref_reloc_sym(machine->vmlinux_map, name, start)) {
>  			machine__destroy_kernel_maps(machine);
>  			ret = -1;
>  			goto out_put;
> @@ -1471,16 +1477,19 @@ int machine__create_kernel_maps(struct machine *machine)
>  		 * we have a real start address now, so re-order the kmaps
>  		 * assume it's the last in the kmaps
>  		 */
> -		machine__update_kernel_mmap(machine, addr, ~0ULL);
> +		machine__update_kernel_mmap(machine, start, end);
>  	}
>  
>  	if (machine__create_extra_kernel_maps(machine, kernel))
>  		pr_debug("Problems creating extra kernel maps, continuing anyway...\n");
>  
> -	/* update end address of the kernel map using adjacent module address */
> -	map = map__next(machine__kernel_map(machine));
> -	if (map)
> -		machine__set_kernel_mmap(machine, addr, map->start);
> +	if (end == ~0ULL) {
> +		/* update end address of the kernel map using adjacent module address */
> +		map = map__next(machine__kernel_map(machine));
> +		if (map)
> +			machine__set_kernel_mmap(machine, start, map->start);
> +	}
> +
>  out_put:
>  	dso__put(kernel);
>  	return ret;
> -- 
> 2.20.1

-- 

- Arnaldo

^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 05/12] perf tools: Read also the end of the kernel
  2019-05-08 13:19 [PATCHv3 " Jiri Olsa
@ 2019-05-08 13:20 ` Jiri Olsa
  2019-05-24 18:15   ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 28+ messages in thread
From: Jiri Olsa @ 2019-05-08 13:20 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
	Peter Zijlstra, Stanislav Fomichev, Song Liu, Adrian Hunter,
	Andi Kleen

We mark the end of kernel based on the first module,
but that could cover some bpf program maps. Reading
_etext symbol if it's present to get precise kernel
map end.

Link: http://lkml.kernel.org/n/tip-ynut991ttyyhvo1sbhlm4c42@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/machine.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 3c520baa198c..ad0205fbb506 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -924,7 +924,8 @@ const char *ref_reloc_sym_names[] = {"_text", "_stext", NULL};
  * symbol_name if it's not that important.
  */
 static int machine__get_running_kernel_start(struct machine *machine,
-					     const char **symbol_name, u64 *start)
+					     const char **symbol_name,
+					     u64 *start, u64 *end)
 {
 	char filename[PATH_MAX];
 	int i, err = -1;
@@ -949,6 +950,11 @@ static int machine__get_running_kernel_start(struct machine *machine,
 		*symbol_name = name;
 
 	*start = addr;
+
+	err = kallsyms__get_function_start(filename, "_etext", &addr);
+	if (!err)
+		*end = addr;
+
 	return 0;
 }
 
@@ -1440,7 +1446,7 @@ int machine__create_kernel_maps(struct machine *machine)
 	struct dso *kernel = machine__get_kernel(machine);
 	const char *name = NULL;
 	struct map *map;
-	u64 addr = 0;
+	u64 start = 0, end = ~0ULL;
 	int ret;
 
 	if (kernel == NULL)
@@ -1459,9 +1465,9 @@ int machine__create_kernel_maps(struct machine *machine)
 				 "continuing anyway...\n", machine->pid);
 	}
 
-	if (!machine__get_running_kernel_start(machine, &name, &addr)) {
+	if (!machine__get_running_kernel_start(machine, &name, &start, &end)) {
 		if (name &&
-		    map__set_kallsyms_ref_reloc_sym(machine->vmlinux_map, name, addr)) {
+		    map__set_kallsyms_ref_reloc_sym(machine->vmlinux_map, name, start)) {
 			machine__destroy_kernel_maps(machine);
 			ret = -1;
 			goto out_put;
@@ -1471,16 +1477,19 @@ int machine__create_kernel_maps(struct machine *machine)
 		 * we have a real start address now, so re-order the kmaps
 		 * assume it's the last in the kmaps
 		 */
-		machine__update_kernel_mmap(machine, addr, ~0ULL);
+		machine__update_kernel_mmap(machine, start, end);
 	}
 
 	if (machine__create_extra_kernel_maps(machine, kernel))
 		pr_debug("Problems creating extra kernel maps, continuing anyway...\n");
 
-	/* update end address of the kernel map using adjacent module address */
-	map = map__next(machine__kernel_map(machine));
-	if (map)
-		machine__set_kernel_mmap(machine, addr, map->start);
+	if (end == ~0ULL) {
+		/* update end address of the kernel map using adjacent module address */
+		map = map__next(machine__kernel_map(machine));
+		if (map)
+			machine__set_kernel_mmap(machine, start, map->start);
+	}
+
 out_put:
 	dso__put(kernel);
 	return ret;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 05/12] perf tools: Read also the end of the kernel
  2019-04-16 16:01 [PATCH 00/12] perf tools: Display eBPF code in intel_pt trace Jiri Olsa
@ 2019-04-16 16:01 ` Jiri Olsa
  0 siblings, 0 replies; 28+ messages in thread
From: Jiri Olsa @ 2019-04-16 16:01 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: lkml, Ingo Molnar, Namhyung Kim, Alexander Shishkin,
	Peter Zijlstra, Andi Kleen, Adrian Hunter, Song Liu,
	Alexei Starovoitov, Daniel Borkmann

We mark the end of kernel based on the first module,
but that could cover some bpf program maps. Reading
_etext symbol if it's present to get precise kernel
map end.

Link: http://lkml.kernel.org/n/tip-ynut991ttyyhvo1sbhlm4c42@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/util/machine.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 3c520baa198c..ad0205fbb506 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -924,7 +924,8 @@ const char *ref_reloc_sym_names[] = {"_text", "_stext", NULL};
  * symbol_name if it's not that important.
  */
 static int machine__get_running_kernel_start(struct machine *machine,
-					     const char **symbol_name, u64 *start)
+					     const char **symbol_name,
+					     u64 *start, u64 *end)
 {
 	char filename[PATH_MAX];
 	int i, err = -1;
@@ -949,6 +950,11 @@ static int machine__get_running_kernel_start(struct machine *machine,
 		*symbol_name = name;
 
 	*start = addr;
+
+	err = kallsyms__get_function_start(filename, "_etext", &addr);
+	if (!err)
+		*end = addr;
+
 	return 0;
 }
 
@@ -1440,7 +1446,7 @@ int machine__create_kernel_maps(struct machine *machine)
 	struct dso *kernel = machine__get_kernel(machine);
 	const char *name = NULL;
 	struct map *map;
-	u64 addr = 0;
+	u64 start = 0, end = ~0ULL;
 	int ret;
 
 	if (kernel == NULL)
@@ -1459,9 +1465,9 @@ int machine__create_kernel_maps(struct machine *machine)
 				 "continuing anyway...\n", machine->pid);
 	}
 
-	if (!machine__get_running_kernel_start(machine, &name, &addr)) {
+	if (!machine__get_running_kernel_start(machine, &name, &start, &end)) {
 		if (name &&
-		    map__set_kallsyms_ref_reloc_sym(machine->vmlinux_map, name, addr)) {
+		    map__set_kallsyms_ref_reloc_sym(machine->vmlinux_map, name, start)) {
 			machine__destroy_kernel_maps(machine);
 			ret = -1;
 			goto out_put;
@@ -1471,16 +1477,19 @@ int machine__create_kernel_maps(struct machine *machine)
 		 * we have a real start address now, so re-order the kmaps
 		 * assume it's the last in the kmaps
 		 */
-		machine__update_kernel_mmap(machine, addr, ~0ULL);
+		machine__update_kernel_mmap(machine, start, end);
 	}
 
 	if (machine__create_extra_kernel_maps(machine, kernel))
 		pr_debug("Problems creating extra kernel maps, continuing anyway...\n");
 
-	/* update end address of the kernel map using adjacent module address */
-	map = map__next(machine__kernel_map(machine));
-	if (map)
-		machine__set_kernel_mmap(machine, addr, map->start);
+	if (end == ~0ULL) {
+		/* update end address of the kernel map using adjacent module address */
+		map = map__next(machine__kernel_map(machine));
+		if (map)
+			machine__set_kernel_mmap(machine, start, map->start);
+	}
+
 out_put:
 	dso__put(kernel);
 	return ret;
-- 
2.17.2


^ permalink raw reply related	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2019-05-26 13:11 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-03  8:18 [PATCHv2 00/12] perf tools: Display eBPF code in intel_pt trace Jiri Olsa
2019-05-03  8:18 ` [PATCH 01/12] perf tools: Separate generic code in dso__data_file_size Jiri Olsa
2019-05-03  8:18 ` [PATCH 02/12] perf tools: Separate generic code in dso_cache__read Jiri Olsa
2019-05-03  8:18 ` [PATCH 03/12] perf tools: Simplify dso_cache__read function Jiri Olsa
2019-05-03  8:18 ` [PATCH 04/12] perf tools: Add bpf dso read and size hooks Jiri Olsa
2019-05-03  8:18 ` [PATCH 05/12] perf tools: Read also the end of the kernel Jiri Olsa
2019-05-03  8:18 ` [PATCH 06/12] perf tools: Keep zero in pgoff bpf map Jiri Olsa
2019-05-03  8:18 ` [PATCH 07/12] perf script: Pad dso name for --call-trace Jiri Olsa
2019-05-06 21:38   ` Song Liu
2019-05-07  8:13     ` Jiri Olsa
2019-05-07 18:29       ` Song Liu
2019-05-08  7:40         ` Jiri Olsa
2019-05-03  8:18 ` [PATCH 08/12] perf tools: Preserve eBPF maps when loading kcore Jiri Olsa
2019-05-03  8:18 ` [PATCH 09/12] perf tests: Add map_groups__merge_in test Jiri Olsa
2019-05-03  8:18 ` [PATCH 10/12] perf script: Add --show-bpf-events to show eBPF related events Jiri Olsa
2019-05-06 21:42   ` Song Liu
2019-05-07  8:18     ` Jiri Olsa
2019-05-07 18:27       ` Song Liu
2019-05-03  8:18 ` [PATCH 11/12] perf script: Remove superfluous bpf event titles Jiri Olsa
2019-05-03  8:18 ` [PATCH 12/12] perf script: Add --show-all-events option Jiri Olsa
2019-05-06 21:46 ` [PATCHv2 00/12] perf tools: Display eBPF code in intel_pt trace Song Liu
  -- strict thread matches above, loose matches on Subject: below --
2019-05-08 13:19 [PATCHv3 " Jiri Olsa
2019-05-08 13:20 ` [PATCH 05/12] perf tools: Read also the end of the kernel Jiri Olsa
2019-05-24 18:15   ` Arnaldo Carvalho de Melo
2019-05-24 18:17     ` Arnaldo Carvalho de Melo
2019-05-24 18:46       ` Arnaldo Carvalho de Melo
2019-05-26 13:09         ` Jiri Olsa
2019-05-24 23:21     ` Jiri Olsa
2019-04-16 16:01 [PATCH 00/12] perf tools: Display eBPF code in intel_pt trace Jiri Olsa
2019-04-16 16:01 ` [PATCH 05/12] perf tools: Read also the end of the kernel Jiri Olsa

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.