Skip to contentSkip to conversation

perf record: collect user registers set jointly with dwarf stacks

PATCH Applied Alexey Budankov 3 participants 7 messages May 30, 2019 – Jun 17, 2019 perf events

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 perf record: collect user registers set jointly with dwarf stacks

When dwarf stacks are collected jointly with user specified register set using --user-regs option like below the full register context is captured on a sample:

  $ perf record -g --call-graph dwarf,1024 --user-regs=IP,SP,BP -- stack_test2.g.O3

188143843893585 0x6b48 [0x4f8]: PERF_RECORD_SAMPLE(IP, 0x4002): 23828/23828: 0x401236 period: 1363819 addr: 0x7ffedbdd51ac ... FP chain: nr:0
... user regs: mask 0xff0fff ABI 64-bit

  .... AX    0x53b
  .... BX    0x7ffedbdd3cc0
  .... CX    0xffffffff
  .... DX    0x33d3a
  .... SI    0x7f09b74c38d0
  .... DI    0x0
  .... BP    0x401260
  .... SP    0x7ffedbdd3cc0
  .... IP    0x401236
  .... FLAGS 0x20a
  .... CS    0x33
  .... SS    0x2b
  .... R8    0x7f09b74c3800
  .... R9    0x7f09b74c2da0
  .... R10   0xfffffffffffff3ce
  .... R11   0x246
  .... R12   0x401070
  .... R13   0x7ffedbdd5db0
  .... R14   0x0
  .... R15   0x0

... ustack: size 1024, offset 0xe0
. data_src: 0x5080021
... thread: stack_test2.g.O:23828
...... dso: /root/abudanko/stacks/stack_test2.g.O3

After applying the change suggested in the patch the sample data contain only user specified register values. IP and SP registers (DWARF_MINIMAL_REGS) are collected anyways regardless of the --user-regs value provided from the command line:

  -g call-graph dwarf,K                         full_regs
  --user-regs=user_regs                         user_regs
  -g call-graph dwarf,K --user-regs=user_regs	user_regs + DWARF_MINIMAL_REGS
  $ perf record -g --call-graph dwarf,1024 --user-regs=BP -- ls
  WARNING: The use of --call-graph=dwarf may require all the user registers, specifying a subset with --user-regs may render DWARF unwinding unreliable, so the minimal registers set (IP, SP) is explicitly forced.
  arch   COPYING	Documentation  include	Kbuild	 lbuild    MAINTAINERS	modules.builtin		 Module.symvers  perf.data.old	scripts   System.map  virt
  block  CREDITS	drivers        init	Kconfig  lib	   Makefile	modules.builtin.modinfo  net		 README		security  tools       vmlinux
  certs  crypto	fs	       ipc	kernel	 LICENSES  mm		modules.order		 perf.data	 samples	sound	  usr	      vmlinux.o
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.030 MB perf.data (10 samples) ]

188368474305373 0x5e40 [0x470]: PERF_RECORD_SAMPLE(IP, 0x4002): 23839/23839: 0x401236 period: 1260507 addr: 0x7ffd3d85e96c ... FP chain: nr:0
... user regs: mask 0x1c0 ABI 64-bit

  .... BP    0x401260
  .... SP    0x7ffd3d85cc20
  .... IP    0x401236

... ustack: size 1024, offset 0x58
. data_src: 0x5080021

---
Changes in v5:
- renamed minimal dwarf regs set macro to DWARF_MINIMAL_REGS
- edited warning message

Changes in v4:
- added warning message about dwarf registers unconditionally included into the collected registers set

Changes in v3:
- avoid changes in platform specific header files

Changes in v2:
- implemented dwarf register set to avoid corrupted trace when --user-regs option value omits IP,SP

---
 tools/perf/util/evsel.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
tools/perf/util/evsel.c +10 -1
index a6f572a40deb..375ab4eb7560 100644
@@ -669,6 +669,8 @@ int perf_evsel__group_desc(struct perf_evsel *evsel, char *buf, size_t size)
 	return ret;
 }
 
+#define DWARF_MINIMAL_REGS ((1ULL << PERF_REG_IP) | (1ULL << PERF_REG_SP))
+
 static void __perf_evsel__config_callchain(struct perf_evsel *evsel,
 					   struct record_opts *opts,
 					   struct callchain_param *param)
@@ -702,7 +704,14 @@ static void __perf_evsel__config_callchain(struct perf_evsel *evsel,
 		if (!function) {
 			perf_evsel__set_sample_bit(evsel, REGS_USER);
 			perf_evsel__set_sample_bit(evsel, STACK_USER);
-			attr->sample_regs_user |= PERF_REGS_MASK;
+			if (opts->sample_user_regs) {
+				attr->sample_regs_user |= DWARF_MINIMAL_REGS;
+				pr_warning("WARNING: The use of --call-graph=dwarf may require all the user registers, "
+					   "specifying a subset with --user-regs may render DWARF unwinding unreliable, "
+					   "so the minimal registers set (IP, SP) is explicitly forced.\n");
+			} else {
+				attr->sample_regs_user |= PERF_REGS_MASK;
+			}
 			attr->sample_stack_user = param->dump_size;
 			attr->exclude_callchain_user = 1;
 		} else {
Signature · 1 line
2.20.1
#1 lore raw

Em Thu, May 30, 2019 at 10:03:36PM +0300, Alexey Budankov escreveu:

Quoted 35 lines

When dwarf stacks are collected jointly with user specified register set using --user-regs option like below the full register context is captured on a sample:

  $ perf record -g --call-graph dwarf,1024 --user-regs=IP,SP,BP -- stack_test2.g.O3

188143843893585 0x6b48 [0x4f8]: PERF_RECORD_SAMPLE(IP, 0x4002): 23828/23828: 0x401236 period: 1363819 addr: 0x7ffedbdd51ac ... FP chain: nr:0
... user regs: mask 0xff0fff ABI 64-bit

  .... AX    0x53b
  .... BX    0x7ffedbdd3cc0
  .... CX    0xffffffff
  .... DX    0x33d3a
  .... SI    0x7f09b74c38d0
  .... DI    0x0
  .... BP    0x401260
  .... SP    0x7ffedbdd3cc0
  .... IP    0x401236
  .... FLAGS 0x20a
  .... CS    0x33
  .... SS    0x2b
  .... R8    0x7f09b74c3800
  .... R9    0x7f09b74c2da0
  .... R10   0xfffffffffffff3ce
  .... R11   0x246
  .... R12   0x401070
  .... R13   0x7ffedbdd5db0
  .... R14   0x0
  .... R15   0x0

... ustack: size 1024, offset 0xe0
. data_src: 0x5080021
... thread: stack_test2.g.O:23828
...... dso: /root/abudanko/stacks/stack_test2.g.O3

Quoted 4 lines

After applying the change suggested in the patch the sample data contain only user specified register values. IP and SP registers (DWARF_MINIMAL_REGS) are collected anyways regardless of the --user-regs value provided from the command line:

Applied, changed the subject and description to:

perf record: Allow mixing --user-regs with --call-graph=dwarf

When DWARF stacks were requested and at the same time that the user specifies a register set using the --user-regs option the full register context was being captured on samples:

  $ perf record -g --call-graph dwarf,1024 --user-regs=IP,SP,BP -- stack_test2.g.O3

188143843893585 0x6b48 [0x4f8]: PERF_RECORD_SAMPLE(IP, 0x4002): 23828/23828: 0x401236 period: 1363819 addr: 0x7ffedbdd51ac ... FP chain: nr:0
... user regs: mask 0xff0fff ABI 64-bit

  .... AX    0x53b
  .... BX    0x7ffedbdd3cc0
  .... CX    0xffffffff
  .... DX    0x33d3a
  .... SI    0x7f09b74c38d0
  .... DI    0x0
  .... BP    0x401260
  .... SP    0x7ffedbdd3cc0
  .... IP    0x401236
  .... FLAGS 0x20a
  .... CS    0x33
  .... SS    0x2b
  .... R8    0x7f09b74c3800
  .... R9    0x7f09b74c2da0
  .... R10   0xfffffffffffff3ce
  .... R11   0x246
  .... R12   0x401070
  .... R13   0x7ffedbdd5db0
  .... R14   0x0
  .... R15   0x0

... ustack: size 1024, offset 0xe0
. data_src: 0x5080021
... thread: stack_test2.g.O:23828
...... dso: /root/abudanko/stacks/stack_test2.g.O3

I.e. the --user-regs=IP,SP,BP was being ignored, being overridden by the needs of --call-graph=dwarf.

After applying the change in this patch the sample data contains the user specified register, but making sure that at least the minimal set of register needed for DWARF unwinding (DWARF_MINIMAL_REGS) is requested.

The user is warned that DWARF unwinding may not work if extra registers end up being needed.

  -g call-graph dwarf,K                         full_regs
  --user-regs=user_regs                         user_regs
  -g call-graph dwarf,K --user-regs=user_regs   user_regs + DWARF_MINIMAL_REGS

<REST remains the same>

#2 lore raw
Quoted 87 lines · Arnaldo Carvalho de Melo

Em Thu, May 30, 2019 at 10:03:36PM +0300, Alexey Budankov escreveu:

Quoted 35 lines

When dwarf stacks are collected jointly with user specified register set using --user-regs option like below the full register context is captured on a sample:

  $ perf record -g --call-graph dwarf,1024 --user-regs=IP,SP,BP -- stack_test2.g.O3

188143843893585 0x6b48 [0x4f8]: PERF_RECORD_SAMPLE(IP, 0x4002): 23828/23828: 0x401236 period: 1363819 addr: 0x7ffedbdd51ac ... FP chain: nr:0
... user regs: mask 0xff0fff ABI 64-bit

  .... AX    0x53b
  .... BX    0x7ffedbdd3cc0
  .... CX    0xffffffff
  .... DX    0x33d3a
  .... SI    0x7f09b74c38d0
  .... DI    0x0
  .... BP    0x401260
  .... SP    0x7ffedbdd3cc0
  .... IP    0x401236
  .... FLAGS 0x20a
  .... CS    0x33
  .... SS    0x2b
  .... R8    0x7f09b74c3800
  .... R9    0x7f09b74c2da0
  .... R10   0xfffffffffffff3ce
  .... R11   0x246
  .... R12   0x401070
  .... R13   0x7ffedbdd5db0
  .... R14   0x0
  .... R15   0x0

... ustack: size 1024, offset 0xe0
. data_src: 0x5080021
... thread: stack_test2.g.O:23828
...... dso: /root/abudanko/stacks/stack_test2.g.O3

Quoted 4 lines

After applying the change suggested in the patch the sample data contain only user specified register values. IP and SP registers (DWARF_MINIMAL_REGS) are collected anyways regardless of the --user-regs value provided from the command line:

Applied, changed the subject and description to:

perf record: Allow mixing --user-regs with --call-graph=dwarf

When DWARF stacks were requested and at the same time that the user specifies a register set using the --user-regs option the full register context was being captured on samples:

  $ perf record -g --call-graph dwarf,1024 --user-regs=IP,SP,BP -- stack_test2.g.O3

188143843893585 0x6b48 [0x4f8]: PERF_RECORD_SAMPLE(IP, 0x4002): 23828/23828: 0x401236 period: 1363819 addr: 0x7ffedbdd51ac ... FP chain: nr:0
... user regs: mask 0xff0fff ABI 64-bit

  .... AX    0x53b
  .... BX    0x7ffedbdd3cc0
  .... CX    0xffffffff
  .... DX    0x33d3a
  .... SI    0x7f09b74c38d0
  .... DI    0x0
  .... BP    0x401260
  .... SP    0x7ffedbdd3cc0
  .... IP    0x401236
  .... FLAGS 0x20a
  .... CS    0x33
  .... SS    0x2b
  .... R8    0x7f09b74c3800
  .... R9    0x7f09b74c2da0
  .... R10   0xfffffffffffff3ce
  .... R11   0x246
  .... R12   0x401070
  .... R13   0x7ffedbdd5db0
  .... R14   0x0
  .... R15   0x0

... ustack: size 1024, offset 0xe0
. data_src: 0x5080021
... thread: stack_test2.g.O:23828
...... dso: /root/abudanko/stacks/stack_test2.g.O3

I.e. the --user-regs=IP,SP,BP was being ignored, being overridden by the needs of --call-graph=dwarf.

After applying the change in this patch the sample data contains the user specified register, but making sure that at least the minimal set of register needed for DWARF unwinding (DWARF_MINIMAL_REGS) is requested.

Quoted 8 lines

The user is warned that DWARF unwinding may not work if extra registers end up being needed.

  -g call-graph dwarf,K                         full_regs
  --user-regs=user_regs                         user_regs
  -g call-graph dwarf,K --user-regs=user_regs   user_regs + DWARF_MINIMAL_REGS

<REST remains the same>

Sounds better. Thanks!

~Alexey

#3 lore raw

Em Fri, May 31, 2019 at 09:27:38AM +0300, Alexey Budankov escreveu:

Quoted 96 lines · Arnaldo Carvalho de Melo
Quoted 86 lines

Em Thu, May 30, 2019 at 10:03:36PM +0300, Alexey Budankov escreveu:

Quoted 34 lines

When dwarf stacks are collected jointly with user specified register set using --user-regs option like below the full register context is captured on a sample:

  $ perf record -g --call-graph dwarf,1024 --user-regs=IP,SP,BP -- stack_test2.g.O3

188143843893585 0x6b48 [0x4f8]: PERF_RECORD_SAMPLE(IP, 0x4002): 23828/23828: 0x401236 period: 1363819 addr: 0x7ffedbdd51ac ... FP chain: nr:0
... user regs: mask 0xff0fff ABI 64-bit

  .... AX    0x53b
  .... BX    0x7ffedbdd3cc0
  .... CX    0xffffffff
  .... DX    0x33d3a
  .... SI    0x7f09b74c38d0
  .... DI    0x0
  .... BP    0x401260
  .... SP    0x7ffedbdd3cc0
  .... IP    0x401236
  .... FLAGS 0x20a
  .... CS    0x33
  .... SS    0x2b
  .... R8    0x7f09b74c3800
  .... R9    0x7f09b74c2da0
  .... R10   0xfffffffffffff3ce
  .... R11   0x246
  .... R12   0x401070
  .... R13   0x7ffedbdd5db0
  .... R14   0x0
  .... R15   0x0

... ustack: size 1024, offset 0xe0
. data_src: 0x5080021
... thread: stack_test2.g.O:23828
...... dso: /root/abudanko/stacks/stack_test2.g.O3

Quoted 4 lines

After applying the change suggested in the patch the sample data contain only user specified register values. IP and SP registers (DWARF_MINIMAL_REGS) are collected anyways regardless of the --user-regs value provided from the command line:

Applied, changed the subject and description to:

perf record: Allow mixing --user-regs with --call-graph=dwarf

When DWARF stacks were requested and at the same time that the user specifies a register set using the --user-regs option the full register context was being captured on samples:

  $ perf record -g --call-graph dwarf,1024 --user-regs=IP,SP,BP -- stack_test2.g.O3

188143843893585 0x6b48 [0x4f8]: PERF_RECORD_SAMPLE(IP, 0x4002): 23828/23828: 0x401236 period: 1363819 addr: 0x7ffedbdd51ac ... FP chain: nr:0
... user regs: mask 0xff0fff ABI 64-bit

  .... AX    0x53b
  .... BX    0x7ffedbdd3cc0
  .... CX    0xffffffff
  .... DX    0x33d3a
  .... SI    0x7f09b74c38d0
  .... DI    0x0
  .... BP    0x401260
  .... SP    0x7ffedbdd3cc0
  .... IP    0x401236
  .... FLAGS 0x20a
  .... CS    0x33
  .... SS    0x2b
  .... R8    0x7f09b74c3800
  .... R9    0x7f09b74c2da0
  .... R10   0xfffffffffffff3ce
  .... R11   0x246
  .... R12   0x401070
  .... R13   0x7ffedbdd5db0
  .... R14   0x0
  .... R15   0x0

... ustack: size 1024, offset 0xe0
. data_src: 0x5080021
... thread: stack_test2.g.O:23828
...... dso: /root/abudanko/stacks/stack_test2.g.O3

I.e. the --user-regs=IP,SP,BP was being ignored, being overridden by the needs of --call-graph=dwarf.

After applying the change in this patch the sample data contains the user specified register, but making sure that at least the minimal set of register needed for DWARF unwinding (DWARF_MINIMAL_REGS) is requested.

Quoted 8 lines

The user is warned that DWARF unwinding may not work if extra registers end up being needed.

  -g call-graph dwarf,K                         full_regs
  --user-regs=user_regs                         user_regs
  -g call-graph dwarf,K --user-regs=user_regs   user_regs + DWARF_MINIMAL_REGS

<REST remains the same>

Quoted 3 lines

Sounds better. Thanks!

~Alexey

Now cross building to a few arches is failing, so far:

[perfbuilder@quaco ~]$ cat /tmp/dm.log/summary
alpine:3.4: Ok
alpine:3.5: Ok
alpine:3.6: Ok
alpine:3.7: Ok
alpine:3.8: Ok
alpine:3.9: Ok
alpine:edge: Ok
amazonlinux:1: Ok
amazonlinux:2: Ok
android-ndk:r12b-arm: Ok
android-ndk:r15c-arm: Ok
centos:5: Ok
centos:6: Ok
centos:7: Ok
clearlinux:latest: Ok
debian:8: Ok
debian:9: Ok
debian:experimental: Ok
debian:experimental-x-arm64: Ok
debian:experimental-x-mips: FAIL
debian:experimental-x-mips64: FAIL
debian:experimental-x-mipsel: FAIL
fedora:20: Ok
fedora:22: Ok
fedora:23: Ok
fedora:24: Ok
fedora:24-x-ARC-uClibc: FAIL
fedora:25: Ok
fedora:26: Ok
fedora:27: Ok
[perfbuilder@quaco ~]$

For instance:

[perfbuilder@quaco ~]$ cat /tmp/dm.log/debian\:experimental-x-mips64
<SNIP>
CC /tmp/build/perf/tests/pmu.o
util/evsel.c: In function '__perf_evsel__config_callchain':
util/evsel.c:672:38: error: 'PERF_REG_IP' undeclared (first use in this function); did you mean 'PERF_REGS_MAX'?

 #define DWARF_MINIMAL_REGS ((1ULL << PERF_REG_IP) | (1ULL << PERF_REG_SP))
                                      ^~~~~~~~~~~
util/evsel.c:708:31: note: in expansion of macro 'DWARF_MINIMAL_REGS'
     attr->sample_regs_user |= DWARF_MINIMAL_REGS;
                               ^~~~~~~~~~~~~~~~~~
util/evsel.c:672:38: note: each undeclared identifier is reported only once for each function it appears in
 #define DWARF_MINIMAL_REGS ((1ULL << PERF_REG_IP) | (1ULL << PERF_REG_SP))
                                      ^~~~~~~~~~~
util/evsel.c:708:31: note: in expansion of macro 'DWARF_MINIMAL_REGS'
     attr->sample_regs_user |= DWARF_MINIMAL_REGS;
                               ^~~~~~~~~~~~~~~~~~
util/evsel.c:672:62: error: 'PERF_REG_SP' undeclared (first use in this function); did you mean 'PERF_MEM_S'?
 #define DWARF_MINIMAL_REGS ((1ULL << PERF_REG_IP) | (1ULL << PERF_REG_SP))
                                                              ^~~~~~~~~~~
util/evsel.c:708:31: note: in expansion of macro 'DWARF_MINIMAL_REGS'
     attr->sample_regs_user |= DWARF_MINIMAL_REGS;
                               ^~~~~~~~~~~~~~~~~~

LD /tmp/build/perf/bench/perf-in.o
CC /tmp/build/perf/tests/hists_common.o
mv: cannot stat '/tmp/build/perf/util/.evsel.o.tmp': No such file or directory make[4]: *** [/git/linux/tools/build/Makefile.build:97: /tmp/build/perf/util/evsel.o] Error 1 make[4]: *** Waiting for unfinished jobs....
<SNIP>

[perfbuilder@quaco ~]$ cat /tmp/dm.log/fedora\:24-x-ARC-uClibc

<SNIP>
CC /tmp/build/perf/tests/mmap-basic.o
CC /tmp/build/perf/ui/hist.o
util/evsel.c: In function '__perf_evsel__config_callchain':
util/evsel.c:672:38: error: 'PERF_REG_IP' undeclared (first use in this function); did you mean 'PERF_MEM_S'?

 #define DWARF_MINIMAL_REGS ((1ULL << PERF_REG_IP) | (1ULL << PERF_REG_SP))
                                      ^
util/evsel.c:708:31: note: in expansion of macro 'DWARF_MINIMAL_REGS'
     attr->sample_regs_user |= DWARF_MINIMAL_REGS;
                               ^~~~~~~~~~~~~~~~~~
util/evsel.c:672:38: note: each undeclared identifier is reported only once for each function it appears in
 #define DWARF_MINIMAL_REGS ((1ULL << PERF_REG_IP) | (1ULL << PERF_REG_SP))
                                      ^
util/evsel.c:708:31: note: in expansion of macro 'DWARF_MINIMAL_REGS'
     attr->sample_regs_user |= DWARF_MINIMAL_REGS;
                               ^~~~~~~~~~~~~~~~~~
util/evsel.c:672:62: error: 'PERF_REG_SP' undeclared (first use in this function); did you mean 'PERF_REG_IP'?
 #define DWARF_MINIMAL_REGS ((1ULL << PERF_REG_IP) | (1ULL << PERF_REG_SP))
                                                              ^
util/evsel.c:708:31: note: in expansion of macro 'DWARF_MINIMAL_REGS'
     attr->sample_regs_user |= DWARF_MINIMAL_REGS;
                               ^~~~~~~~~~~~~~~~~~

MKDIR /tmp/build/perf/ui/stdio/
mv: cannot stat '/tmp/build/perf/util/.evsel.o.tmp': No such file or directory /git/linux/tools/build/Makefile.build:96: recipe for target '/tmp/build/perf/util/evsel.o' failed make[4]: *** [/tmp/build/perf/util/evsel.o] Error 1

#4 lore raw
Quoted 1 line · Arnaldo Carvalho de Melo

Em Fri, May 31, 2019 at 09:27:38AM +0300, Alexey Budankov escreveu:

<SNIP>

Quoted 27 lines

Now cross building to a few arches is failing, so far:

[perfbuilder@quaco ~]$ cat /tmp/dm.log/summary
alpine:3.4: Ok
alpine:3.5: Ok
alpine:3.6: Ok
alpine:3.7: Ok
alpine:3.8: Ok
alpine:3.9: Ok
alpine:edge: Ok
amazonlinux:1: Ok
amazonlinux:2: Ok
android-ndk:r12b-arm: Ok
android-ndk:r15c-arm: Ok
centos:5: Ok
centos:6: Ok
centos:7: Ok
clearlinux:latest: Ok
debian:8: Ok
debian:9: Ok
debian:experimental: Ok
debian:experimental-x-arm64: Ok
debian:experimental-x-mips: FAIL
debian:experimental-x-mips64: FAIL
debian:experimental-x-mipsel: FAIL
fedora:20: Ok

Quoted 8 lines

fedora:22: Ok
fedora:23: Ok
fedora:24: Ok
fedora:24-x-ARC-uClibc: FAIL
fedora:25: Ok
fedora:26: Ok
fedora:27: Ok
[perfbuilder@quaco ~]$

That below can fix it. Unfortunately can't test in advance on that architectures.

Thanks,
Alexey

---
 tools/perf/util/evsel.c     | 4 +---
 tools/perf/util/perf_regs.h | 4 ++++
 2 files changed, 5 insertions(+), 3 deletions(-)
tools/perf/util/evsel.c +1 -3
index 375ab4eb7560..cc6e7a0dda92 100644
@@ -669,8 +669,6 @@ int perf_evsel__group_desc(struct perf_evsel *evsel, char *buf, size_t size)
 	return ret;
 }
 
-#define DWARF_MINIMAL_REGS ((1ULL << PERF_REG_IP) | (1ULL << PERF_REG_SP))
-
 static void __perf_evsel__config_callchain(struct perf_evsel *evsel,
 					   struct record_opts *opts,
 					   struct callchain_param *param)
@@ -704,7 +702,7 @@ static void __perf_evsel__config_callchain(struct perf_evsel *evsel,
 		if (!function) {
 			perf_evsel__set_sample_bit(evsel, REGS_USER);
 			perf_evsel__set_sample_bit(evsel, STACK_USER);
-			if (opts->sample_user_regs) {
+			if (opts->sample_user_regs && DWARF_MINIMAL_REGS != PERF_REGS_MASK) {
 				attr->sample_regs_user |= DWARF_MINIMAL_REGS;
 				pr_warning("WARNING: The use of --call-graph=dwarf may require all the user registers, "
 					   "specifying a subset with --user-regs may render DWARF unwinding unreliable, "
tools/perf/util/perf_regs.h +4 -0
index cb9c246c8962..47fe34e5f7d5 100644
@@ -29,12 +29,16 @@ uint64_t arch__user_reg_mask(void);
 #ifdef HAVE_PERF_REGS_SUPPORT
 #include <perf_regs.h>
 
+#define DWARF_MINIMAL_REGS ((1ULL << PERF_REG_IP) | (1ULL << PERF_REG_SP))
+
 int perf_reg_value(u64 *valp, struct regs_dump *regs, int id);
 
 #else
 #define PERF_REGS_MASK	0
 #define PERF_REGS_MAX	0
 
+#define DWARF_MINIMAL_REGS PERF_REGS_MASK
+
 static inline const char *perf_reg_name(int id __maybe_unused)
 {
 	return NULL;

---

Quoted 64 lines

For instance:

[perfbuilder@quaco ~]$ cat /tmp/dm.log/debian\:experimental-x-mips64
<SNIP>
CC /tmp/build/perf/tests/pmu.o
util/evsel.c: In function '__perf_evsel__config_callchain':
util/evsel.c:672:38: error: 'PERF_REG_IP' undeclared (first use in this function); did you mean 'PERF_REGS_MAX'?

 #define DWARF_MINIMAL_REGS ((1ULL << PERF_REG_IP) | (1ULL << PERF_REG_SP))
                                      ^~~~~~~~~~~
util/evsel.c:708:31: note: in expansion of macro 'DWARF_MINIMAL_REGS'
     attr->sample_regs_user |= DWARF_MINIMAL_REGS;
                               ^~~~~~~~~~~~~~~~~~
util/evsel.c:672:38: note: each undeclared identifier is reported only once for each function it appears in
 #define DWARF_MINIMAL_REGS ((1ULL << PERF_REG_IP) | (1ULL << PERF_REG_SP))
                                      ^~~~~~~~~~~
util/evsel.c:708:31: note: in expansion of macro 'DWARF_MINIMAL_REGS'
     attr->sample_regs_user |= DWARF_MINIMAL_REGS;
                               ^~~~~~~~~~~~~~~~~~
util/evsel.c:672:62: error: 'PERF_REG_SP' undeclared (first use in this function); did you mean 'PERF_MEM_S'?
 #define DWARF_MINIMAL_REGS ((1ULL << PERF_REG_IP) | (1ULL << PERF_REG_SP))
                                                              ^~~~~~~~~~~
util/evsel.c:708:31: note: in expansion of macro 'DWARF_MINIMAL_REGS'
     attr->sample_regs_user |= DWARF_MINIMAL_REGS;
                               ^~~~~~~~~~~~~~~~~~

LD /tmp/build/perf/bench/perf-in.o
CC /tmp/build/perf/tests/hists_common.o
mv: cannot stat '/tmp/build/perf/util/.evsel.o.tmp': No such file or directory make[4]: *** [/git/linux/tools/build/Makefile.build:97: /tmp/build/perf/util/evsel.o] Error 1 make[4]: *** Waiting for unfinished jobs....
<SNIP>

[perfbuilder@quaco ~]$ cat /tmp/dm.log/fedora\:24-x-ARC-uClibc

<SNIP>
CC /tmp/build/perf/tests/mmap-basic.o
CC /tmp/build/perf/ui/hist.o
util/evsel.c: In function '__perf_evsel__config_callchain':
util/evsel.c:672:38: error: 'PERF_REG_IP' undeclared (first use in this function); did you mean 'PERF_MEM_S'?

 #define DWARF_MINIMAL_REGS ((1ULL << PERF_REG_IP) | (1ULL << PERF_REG_SP))
                                      ^
util/evsel.c:708:31: note: in expansion of macro 'DWARF_MINIMAL_REGS'
     attr->sample_regs_user |= DWARF_MINIMAL_REGS;
                               ^~~~~~~~~~~~~~~~~~
util/evsel.c:672:38: note: each undeclared identifier is reported only once for each function it appears in
 #define DWARF_MINIMAL_REGS ((1ULL << PERF_REG_IP) | (1ULL << PERF_REG_SP))
                                      ^
util/evsel.c:708:31: note: in expansion of macro 'DWARF_MINIMAL_REGS'
     attr->sample_regs_user |= DWARF_MINIMAL_REGS;
                               ^~~~~~~~~~~~~~~~~~
util/evsel.c:672:62: error: 'PERF_REG_SP' undeclared (first use in this function); did you mean 'PERF_REG_IP'?
 #define DWARF_MINIMAL_REGS ((1ULL << PERF_REG_IP) | (1ULL << PERF_REG_SP))
                                                              ^
util/evsel.c:708:31: note: in expansion of macro 'DWARF_MINIMAL_REGS'
     attr->sample_regs_user |= DWARF_MINIMAL_REGS;
                               ^~~~~~~~~~~~~~~~~~

MKDIR /tmp/build/perf/ui/stdio/
mv: cannot stat '/tmp/build/perf/util/.evsel.o.tmp': No such file or directory /git/linux/tools/build/Makefile.build:96: recipe for target '/tmp/build/perf/util/evsel.o' failed make[4]: *** [/tmp/build/perf/util/evsel.o] Error 1

#5 lore raw

Em Tue, Jun 04, 2019 at 05:56:30PM +0300, Alexey Budankov escreveu:

Quoted 40 lines · Arnaldo Carvalho de Melo
Quoted 1 line

Em Fri, May 31, 2019 at 09:27:38AM +0300, Alexey Budankov escreveu:

<SNIP>

Quoted 27 lines

Now cross building to a few arches is failing, so far:

[perfbuilder@quaco ~]$ cat /tmp/dm.log/summary
alpine:3.4: Ok
alpine:3.5: Ok
alpine:3.6: Ok
alpine:3.7: Ok
alpine:3.8: Ok
alpine:3.9: Ok
alpine:edge: Ok
amazonlinux:1: Ok
amazonlinux:2: Ok
android-ndk:r12b-arm: Ok
android-ndk:r15c-arm: Ok
centos:5: Ok
centos:6: Ok
centos:7: Ok
clearlinux:latest: Ok
debian:8: Ok
debian:9: Ok
debian:experimental: Ok
debian:experimental-x-arm64: Ok
debian:experimental-x-mips: FAIL
debian:experimental-x-mips64: FAIL
debian:experimental-x-mipsel: FAIL
fedora:20: Ok

Quoted 8 lines

fedora:22: Ok
fedora:23: Ok
fedora:24: Ok
fedora:24-x-ARC-uClibc: FAIL
fedora:25: Ok
fedora:26: Ok
fedora:27: Ok
[perfbuilder@quaco ~]$

Quoted 1 line

That below can fix it. Unfortunately can't test in advance on that architectures.

Thanks for the prompt fix, just from visual inspection it looks good, but just in case:

[perfbuilder@quaco ~]$ dm debian:experimental-x-{arm64,mips,mips64,mipsel} fedora:{24-x-ARC-uClibc,30-x-ARC-{g,uC}libc}

   1   debian:experimental-x-arm64   : Ok   aarch64-linux-gnu-gcc (Debian 8.3.0-7) 8.3.0
   2   debian:experimental-x-mips    : Ok   mips-linux-gnu-gcc (Debian 8.3.0-7) 8.3.0
   3   debian:experimental-x-mips64  : Ok   mips64-linux-gnuabi64-gcc (Debian 8.3.0-7) 8.3.0
   4   debian:experimental-x-mipsel  : Ok   mipsel-linux-gnu-gcc (Debian 8.3.0-7) 8.3.0
   5   fedora:24-x-ARC-uClibc        : Ok   arc-linux-gcc (ARCompact ISA Linux uClibc toolchain 2017.09-rc2) 7.1.1 20170710
   6   fedora:30-x-ARC-glibc         : Ok   arc-linux-gcc (ARC HS GNU/Linux glibc toolchain 2019.03-rc1) 8.3.1 20190225
   7   fedora:30-x-ARC-uClibc        : Ok   arc-linux-gcc (ARCv2 ISA Linux uClibc toolchain 2019.03-rc1) 8.3.1 20190225

[perfbuilder@quaco ~]$

So I merged this fix with your v5 so as to keep the tree bisectable,

- Arnaldo

#6 lore raw

[tip:perf/core] perf record: Allow mixing --user-regs with --call-graph=dwarf

In reply to Alexey Budankov
perf record: Allow mixing --user-regs with --call-graph=dwarf
Commit-ID:  d194d8fccf610a3f5cdfa94f2bbbe6b89e11a295
Gitweb:     https://git.kernel.org/tip/d194d8fccf610a3f5cdfa94f2bbbe6b89e11a295
Author:     Alexey Budankov <[email protected]>
AuthorDate: Thu, 30 May 2019 22:03:36 +0300
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 5 Jun 2019 09:47:54 -0300

perf record: Allow mixing --user-regs with --call-graph=dwarf

When DWARF stacks were requested and at the same time that the user specifies a register set using the --user-regs option the full register context was being captured on samples:

  $ perf record -g --call-graph dwarf,1024 --user-regs=IP,SP,BP -- stack_test2.g.O3

188143843893585 0x6b48 [0x4f8]: PERF_RECORD_SAMPLE(IP, 0x4002): 23828/23828: 0x401236 period: 1363819 addr: 0x7ffedbdd51ac ... FP chain: nr:0
... user regs: mask 0xff0fff ABI 64-bit

  .... AX    0x53b
  .... BX    0x7ffedbdd3cc0
  .... CX    0xffffffff
  .... DX    0x33d3a
  .... SI    0x7f09b74c38d0
  .... DI    0x0
  .... BP    0x401260
  .... SP    0x7ffedbdd3cc0
  .... IP    0x401236
  .... FLAGS 0x20a
  .... CS    0x33
  .... SS    0x2b
  .... R8    0x7f09b74c3800
  .... R9    0x7f09b74c2da0
  .... R10   0xfffffffffffff3ce
  .... R11   0x246
  .... R12   0x401070
  .... R13   0x7ffedbdd5db0
  .... R14   0x0
  .... R15   0x0

... ustack: size 1024, offset 0xe0
. data_src: 0x5080021
... thread: stack_test2.g.O:23828
...... dso: /root/abudanko/stacks/stack_test2.g.O3

I.e. the --user-regs=IP,SP,BP was being ignored, being overridden by the needs of --call-graph=dwarf.

After applying the change in this patch the sample data contains the user specified register, but making sure that at least the minimal set of register needed for DWARF unwinding (DWARF_MINIMAL_REGS) is requested.

The user is warned that DWARF unwinding may not work if extra registers end up being needed.

  -g call-graph dwarf,K                         full_regs
  --user-regs=user_regs                         user_regs
  -g call-graph dwarf,K --user-regs=user_regs	user_regs + DWARF_MINIMAL_REGS
  $ perf record -g --call-graph dwarf,1024 --user-regs=BP -- ls
  WARNING: The use of --call-graph=dwarf may require all the user registers, specifying a subset with --user-regs may render DWARF unwinding unreliable, so the minimal registers set (IP, SP) is explicitly forced.
  arch   COPYING	Documentation  include	Kbuild	 lbuild    MAINTAINERS	modules.builtin		 Module.symvers  perf.data.old	scripts   System.map  virt
  block  CREDITS	drivers        init	Kconfig  lib	   Makefile	modules.builtin.modinfo  net		 README		security  tools       vmlinux
  certs  crypto	fs	       ipc	kernel	 LICENSES  mm		modules.order		 perf.data	 samples	sound	  usr	      vmlinux.o
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 0.030 MB perf.data (10 samples) ]

188368474305373 0x5e40 [0x470]: PERF_RECORD_SAMPLE(IP, 0x4002): 23839/23839: 0x401236 period: 1260507 addr: 0x7ffd3d85e96c ... FP chain: nr:0
... user regs: mask 0x1c0 ABI 64-bit

  .... BP    0x401260
  .... SP    0x7ffd3d85cc20
  .... IP    0x401236

... ustack: size 1024, offset 0x58
. data_src: 0x5080021

Committer notes:

Detected build failures on arches where PERF_REGS_ is not available, such as debian:experimental-x-{mips,mips64,mipsel}, fedora 24 and 30 for ARC uClibc and glibc, reported to Alexey that provided a patch moving the DWARF_MINIMAL_REGS from evsel.c to util/perf_regs.h, where it is guarded by an HAVE_PERF_REGS_SUPPORT ifdef.

Committer testing:

  # perf record --user-regs=bp,ax -a sleep 1
  [ perf record: Woken up 1 times to write data ]
  [ perf record: Captured and wrote 1.955 MB perf.data (1773 samples) ]
  # perf script -F+uregs | grep AX: | head -5
     perf 1719 [000] 181.272398:    1 cycles: ffffffffba06a7c4 native_write_msr+0x4 (/lib/modules/5.2.0-rc1+/build/vmlinux) ABI:2 AX:0xffffffffffffffda BP:0x7ffef828fb00
     perf 1719 [000] 181.272402:    1 cycles: ffffffffba06a7c4 native_write_msr+0x4 (/lib/modules/5.2.0-rc1+/build/vmlinux) ABI:2 AX:0xffffffffffffffda BP:0x7ffef828fb00
     perf 1719 [000] 181.272403:    8 cycles: ffffffffba06a7c4 native_write_msr+0x4 (/lib/modules/5.2.0-rc1+/build/vmlinux) ABI:2 AX:0xffffffffffffffda BP:0x7ffef828fb00
     perf 1719 [000] 181.272405:  181 cycles: ffffffffba06a7c6 native_write_msr+0x6 (/lib/modules/5.2.0-rc1+/build/vmlinux) ABI:2 AX:0xffffffffffffffda BP:0x7ffef828fb00
     perf 1719 [000] 181.272406: 4405 cycles: ffffffffba06a7c4 native_write_msr+0x4 (/lib/modules/5.2.0-rc1+/build/vmlinux) ABI:2 AX:0xffffffffffffffda BP:0x7ffef828fb00
  # perf record --call-graph=dwarf --user-regs=bp,ax -a sleep 1
  WARNING: The use of --call-graph=dwarf may require all the user registers, specifying a subset with --user-regs may render DWARF unwinding unreliable, so the minimal registers set (IP, SP) is explicitly forced.
  [ perf record: Woken up 55 times to write data ]
  [ perf record: Captured and wrote 24.184 MB perf.data (2841 samples) ]
  [root@quaco ~]# perf script --hide-call-graph -F+uregs | grep AX: | head -5
     perf 1729 [000] 211.268006:    1 cycles: ffffffffba06a7c4 native_write_msr+0x4 (/lib/modules/5.2.0-rc1+/build/vmlinux) ABI:2 AX:0xffffffffffffffda BP:0x7ffc8679abb0 SP:0x7ffc8679ab78 IP:0x7fa75223a0db
     perf 1729 [000] 211.268014:    1 cycles: ffffffffba06a7c4 native_write_msr+0x4 (/lib/modules/5.2.0-rc1+/build/vmlinux) ABI:2 AX:0xffffffffffffffda BP:0x7ffc8679abb0 SP:0x7ffc8679ab78 IP:0x7fa75223a0db
     perf 1729 [000] 211.268017:    5 cycles: ffffffffba06a7c4 native_write_msr+0x4 (/lib/modules/5.2.0-rc1+/build/vmlinux) ABI:2 AX:0xffffffffffffffda BP:0x7ffc8679abb0 SP:0x7ffc8679ab78 IP:0x7fa75223a0db
     perf 1729 [000] 211.268020:   48 cycles: ffffffffba06a7c6 native_write_msr+0x6 (/lib/modules/5.2.0-rc1+/build/vmlinux) ABI:2 AX:0xffffffffffffffda BP:0x7ffc8679abb0 SP:0x7ffc8679ab78 IP:0x7fa75223a0db
     perf 1729 [000] 211.268024:  490 cycles: ffffffffba00e471 intel_bts_enable_local+0x21 (/lib/modules/5.2.0-rc1+/build/vmlinux) ABI:2 AX:0xffffffffffffffda BP:0x7ffc8679abb0 SP:0x7ffc8679ab78 IP:0x7fa75223a0db
  #
---
 tools/perf/util/evsel.c     | 9 ++++++++-
 tools/perf/util/perf_regs.h | 4 ++++
 2 files changed, 12 insertions(+), 1 deletion(-)
tools/perf/util/evsel.c +8 -1
index a6f572a40deb..cc6e7a0dda92 100644
@@ -702,7 +702,14 @@ static void __perf_evsel__config_callchain(struct perf_evsel *evsel,
 		if (!function) {
 			perf_evsel__set_sample_bit(evsel, REGS_USER);
 			perf_evsel__set_sample_bit(evsel, STACK_USER);
-			attr->sample_regs_user |= PERF_REGS_MASK;
+			if (opts->sample_user_regs && DWARF_MINIMAL_REGS != PERF_REGS_MASK) {
+				attr->sample_regs_user |= DWARF_MINIMAL_REGS;
+				pr_warning("WARNING: The use of --call-graph=dwarf may require all the user registers, "
+					   "specifying a subset with --user-regs may render DWARF unwinding unreliable, "
+					   "so the minimal registers set (IP, SP) is explicitly forced.\n");
+			} else {
+				attr->sample_regs_user |= PERF_REGS_MASK;
+			}
 			attr->sample_stack_user = param->dump_size;
 			attr->exclude_callchain_user = 1;
 		} else {
tools/perf/util/perf_regs.h +4 -0
index cb9c246c8962..47fe34e5f7d5 100644
@@ -29,12 +29,16 @@ uint64_t arch__user_reg_mask(void);
 #ifdef HAVE_PERF_REGS_SUPPORT
 #include <perf_regs.h>
 
+#define DWARF_MINIMAL_REGS ((1ULL << PERF_REG_IP) | (1ULL << PERF_REG_SP))
+
 int perf_reg_value(u64 *valp, struct regs_dump *regs, int id);
 
 #else
 #define PERF_REGS_MASK	0
 #define PERF_REGS_MAX	0
 
+#define DWARF_MINIMAL_REGS PERF_REGS_MASK
+
 static inline const char *perf_reg_name(int id __maybe_unused)
 {
 	return NULL;