perf: New conditional branch filter
Subsystems (3)
v6 cover perf: New conditional branch filter
This patchset is the re-spin of the original branch stack sampling
patchset which introduced new PERF_SAMPLE_BRANCH_COND branch filter. This patchset also enables SW based branch filtering support for book3s powerpc platforms which have PMU HW backed branch stack sampling support.
Summary of code changes in this patchset:
(1) Introduces a new PERF_SAMPLE_BRANCH_COND branch filter
(2) Add the "cond" branch filter options in the "perf record" tool
(3) Enable PERF_SAMPLE_BRANCH_COND in X86 platforms
(4) Enable PERF_SAMPLE_BRANCH_COND in POWER8 platform
(5) Update the documentation regarding "perf record" tool
(6) Add some new powerpc instruction analysis functions in code-patching library
(7) Enable SW based branch filter support for powerpc book3s
(8) Changed BHRB configuration in POWER8 to accommodate SW branch filters
With this new SW enablement, the branch filter support for book3s platforms have been extended to include all these combinations discussed below with a sample test application program (included here).
Changes in V2
=============
(1) Enabled PPC64 SW branch filtering support
(2) Incorporated changes required for all previous comments
Changes in V3
=============
(1) Split the SW branch filter enablement into multiple patches
(2) Added PMU neutral SW branch filtering code, PMU specific HW branch filtering code
(3) Added new instruction analysis functionality into powerpc code-patching library
(4) Changed name for some of the functions
(5) Fixed couple of spelling mistakes
(6) Changed code documentation in multiple places
Changes in V4
=============
(1) Changed the commit message for patch (01/10)
(2) Changed the patch (02/10) to accommodate review comments from Michael Ellerman
(3) Rebased the patchset against latest Linus's tree
Changes in V5
=============
(1) Added a precursor patch to cleanup the indentation problem in power_pmu_bhrb_read
(2) Added a precursor patch to re-arrange P8 PMU BHRB filter config which improved the clarity
(3) Merged the previous 10th patch into the 8th patch
(4) Moved SW based branch analysis code from core perf into code-patching library as suggested by Michael
(5) Simplified the logic in branch analysis library
(6) Fixed some ambiguities in documentation at various places
(7) Added some more in-code documentation blocks at various places
(8) Renamed some local variable and function names
(9) Fixed some indentation and white space errors in the code
(10) Implemented almost all the review comments and suggestions made by Michael Ellerman on V4 patchset
(11) Enabled privilege mode SW branch filter
(12) Simplified and generalized the SW implemented conditional branch filter
(13) PERF_SAMPLE_BRANCH_COND filter is now supported only through SW implementation
(14) Adjusted other patches to deal with the above changes
Changes in V6
=============
(1) Rebased the patchset against the master
(2) Added "Reviewed-by: Andi Kleen" in the first four patches in the series which changes the
generic or X86 perf code. [https://lkml.org/lkml/2014/4/7/130]
HW implemented branch filters
=============================
(1) perf record -j any_call -e branch-misses:u ./cprog
# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol
# ........ ....... .................... ....................... .................... ....................
#
7.85% cprog cprog [.] sw_3_1 cprog [.] success_3_1_2
5.66% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_2
5.65% cprog cprog [.] hw_1_1 cprog [.] symbol1
5.42% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_3
5.40% cprog cprog [.] callme cprog [.] hw_1_1
5.40% cprog cprog [.] sw_3_1 cprog [.] success_3_1_1
5.40% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_1
5.39% cprog cprog [.] sw_4_2 cprog [.] lr_addr
5.39% cprog cprog [.] callme cprog [.] sw_4_2
5.39% cprog [unknown] [.] 00000000 cprog [.] ctr_addr
5.38% cprog cprog [.] hw_1_2 cprog [.] symbol2
5.38% cprog cprog [.] callme cprog [.] hw_1_2
5.16% cprog cprog [.] sw_3_1 cprog [.] success_3_1_3
5.15% cprog cprog [.] callme cprog [.] sw_3_2
5.14% cprog cprog [.] callme cprog [.] hw_2_2
2.96% cprog cprog [.] callme cprog [.] sw_3_1
2.94% cprog cprog [.] callme cprog [.] hw_2_1
2.71% cprog cprog [.] main cprog [.] callme
2.71% cprog [unknown] [.] 00000000 cprog [.] lr_addr
2.70% cprog cprog [.] sw_4_1 cprog [.] ctr_addr
2.70% cprog cprog [.] callme cprog [.] sw_4_1
0.09% cprog [unknown] [.] 0xf7ad76c4 [unknown] [.] 0xf7ac22c0
0.00% cprog libc-2.11.2.so [.] vfprintf libc-2.11.2.so [.] __errno_location
0.00% cprog libc-2.11.2.so [.] printf libc-2.11.2.so [.] vfprintf
0.00% cprog libc-2.11.2.so [.] _IO_file_doallocate libc-2.11.2.so [.] isatty
0.00% cprog libc-2.11.2.so [.] _IO_file_doallocate libc-2.11.2.so [.] mmap
0.00% cprog libc-2.11.2.so [.] isatty libc-2.11.2.so [.] tcgetattr
0.00% cprog cprog [.] main [unknown] [.] 0x10000950
0.00% cprog [unknown] [.] 00000000 libc-2.11.2.so [.] _IO_file_stat
0.00% cprog [unknown] [.] 0xf7acfca4 cprog [.] _fini
0.00% cprog [unknown] [k] 00000000 cprog [k] ctr_addr
0.00% cprog [unknown] [k] 00000000 cprog [k] lr_addr SW implemented branch filters
=============================
(2) perf record -j cond -e branch-misses:u ./cprog
# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol
# ........ ....... .................... ...................... .................... ......................
#
25.82% cprog [unknown] [.] 00000000 cprog [.] sw_3_1
12.66% cprog cprog [.] sw_4_2 cprog [.] lr_addr
12.63% cprog [unknown] [.] 00000000 cprog [.] callme
9.42% cprog cprog [.] hw_2_2 cprog [.] address2
9.39% cprog cprog [.] sw_3_1 cprog [.] success_3_1_2
4.91% cprog cprog [.] sw_3_1 cprog [.] success_3_1_1
4.91% cprog cprog [.] sw_3_1 cprog [.] success_3_1_3
3.35% cprog cprog [.] sw_3_1_3 cprog [.] sw_3_1
3.34% cprog cprog [.] sw_3_1_1 cprog [.] sw_3_1
3.31% cprog cprog [.] hw_1_2 cprog [.] symbol2
3.31% cprog cprog [.] sw_4_1 cprog [.] ctr_addr
3.29% cprog cprog [.] hw_2_1 cprog [.] address1
3.27% cprog cprog [.] sw_3_1_2 cprog [.] sw_3_1
0.32% cprog [unknown] [.] 0xf7c62328 [unknown] [.] 0xf7c62320
0.01% cprog libc-2.11.2.so [.] vfprintf libc-2.11.2.so [.] vfprintf
0.01% cprog libc-2.11.2.so [.] _IO_file_xsputn libc-2.11.2.so [.] _IO_file_xsputn
0.01% cprog libc-2.11.2.so [.] _IO_default_xsputn libc-2.11.2.so [.] _IO_default_xsputn
0.01% cprog libc-2.11.2.so [.] strchrnul libc-2.11.2.so [.] strchrnul
0.01% cprog [unknown] [.] 00000000 libc-2.11.2.so [.] _IO_file_xsputn
0.01% cprog [unknown] [k] 00000000 cprog [k] callme (3) perf record -j any_ret -e branch-misses:u ./cprog
# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol
# ........ ....... .................... ..................... .................... .....................
#
15.61% cprog [unknown] [.] 00000000 cprog [.] sw_3_1
6.28% cprog cprog [.] symbol2 cprog [.] hw_1_2
6.28% cprog cprog [.] ctr_addr cprog [.] sw_4_1
6.26% cprog cprog [.] success_3_1_3 cprog [.] sw_3_1
6.24% cprog cprog [.] symbol1 cprog [.] hw_1_1
6.24% cprog cprog [.] sw_4_2 cprog [.] callme
6.21% cprog [unknown] [.] 00000000 cprog [.] callme
6.19% cprog cprog [.] lr_addr cprog [.] sw_4_2
3.16% cprog cprog [.] hw_1_2 cprog [.] callme
3.15% cprog cprog [.] success_3_1_1 cprog [.] sw_3_1
3.15% cprog cprog [.] sw_4_1 cprog [.] callme
3.14% cprog cprog [.] callme cprog [.] main
3.13% cprog cprog [.] hw_1_1 cprog [.] callme
3.13% cprog cprog [.] sw_3_1_1 cprog [.] sw_3_1
3.12% cprog cprog [.] back2 cprog [.] callme
3.12% cprog cprog [.] sw_3_1 cprog [.] callme
3.11% cprog cprog [.] back1 cprog [.] callme
3.11% cprog cprog [.] sw_3_1_2 cprog [.] sw_3_1
3.11% cprog cprog [.] sw_3_1_3 cprog [.] sw_3_1
3.10% cprog cprog [.] sw_3_2 cprog [.] callme
3.09% cprog cprog [.] success_3_1_2 cprog [.] sw_3_1
0.03% cprog [unknown] [.] 0x100009b0 [unknown] [.] 0xf7d5581c
0.01% cprog libc-2.11.2.so [.] _IO_file_overflow libc-2.11.2.so [.] _IO_file_xsputn
0.01% cprog libc-2.11.2.so [.] _IO_file_setbuf [unknown] [.] 0x0fee1084
0.01% cprog [unknown] [.] 0xf7d5589c libc-2.11.2.so [.] printf
0.01% cprog [unknown] [.] 00000000 libc-2.11.2.so [.] _IO_file_overflow
0.01% cprog [unknown] [.] 00000000 libc-2.11.2.so [.] _IO_file_setbuf
0.01% cprog [unknown] [k] 00000000 cprog [k] callme (4) perf record -j ind_call -e branch-misses:u ./cprog
# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol
# ........ ....... .................... .............. .................... .....................
#
42.59% cprog [unknown] [.] 00000000 cprog [.] sw_3_1
25.88% cprog cprog [.] sw_4_2 cprog [.] lr_addr
25.65% cprog [unknown] [.] 00000000 cprog [.] callme
5.58% cprog cprog [.] sw_4_1 cprog [.] ctr_addr
0.23% cprog [unknown] [k] 00000000 cprog [k] callme
0.05% cprog [unknown] [.] 00000000 [unknown] [.] 0xf79fd740
0.03% cprog [unknown] [.] 00000000 libc-2.11.2.so [.] _IO_file_overflow(5) perf record -j any_call,any_ret -e branch-misses:u ./cprog
# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol
# ........ ....... .................... ......................... .................... .....................
#
10.00% cprog [unknown] [.] 00000000 cprog [.] sw_3_1
4.20% cprog cprog [.] sw_4_2 cprog [.] lr_addr
4.17% cprog cprog [.] lr_addr cprog [.] sw_4_2
4.16% cprog cprog [.] symbol1 cprog [.] hw_1_1
4.12% cprog [unknown] [.] 00000000 cprog [.] callme
4.12% cprog cprog [.] symbol2 cprog [.] hw_1_2
4.11% cprog cprog [.] success_3_1_3 cprog [.] sw_3_1
4.11% cprog cprog [.] ctr_addr cprog [.] sw_4_1
4.10% cprog cprog [.] sw_4_2 cprog [.] callme
2.42% cprog cprog [.] callme cprog [.] sw_4_2
2.40% cprog cprog [.] sw_3_1_3 cprog [.] sw_3_1
2.40% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_3
2.39% cprog cprog [.] hw_1_2 cprog [.] symbol2
2.39% cprog cprog [.] back1 cprog [.] callme
2.39% cprog cprog [.] sw_3_1_1 cprog [.] sw_3_1
2.39% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_1
2.39% cprog cprog [.] sw_3_1 cprog [.] callme
2.39% cprog cprog [.] sw_4_1 cprog [.] ctr_addr
2.39% cprog cprog [.] callme cprog [.] hw_1_2
2.39% cprog cprog [.] callme cprog [.] sw_3_1
2.39% cprog cprog [.] sw_3_1_2 cprog [.] sw_3_1
2.39% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_2
2.38% cprog cprog [.] hw_1_1 cprog [.] symbol1
2.38% cprog cprog [.] callme cprog [.] hw_1_1
1.78% cprog cprog [.] back2 cprog [.] callme
1.78% cprog cprog [.] hw_1_1 cprog [.] callme
1.76% cprog cprog [.] success_3_1_2 cprog [.] sw_3_1
1.76% cprog cprog [.] sw_3_1 cprog [.] success_3_1_2
1.76% cprog cprog [.] sw_3_2 cprog [.] callme
1.76% cprog cprog [.] callme cprog [.] sw_3_2
1.73% cprog cprog [.] success_3_1_1 cprog [.] sw_3_1
1.73% cprog cprog [.] sw_3_1 cprog [.] success_3_1_1
1.73% cprog cprog [.] hw_1_2 cprog [.] callme
1.71% cprog cprog [.] sw_3_1 cprog [.] success_3_1_3
1.71% cprog cprog [.] sw_4_1 cprog [.] callme
1.71% cprog cprog [.] callme cprog [.] main
0.05% cprog [unknown] [k] 00000000 cprog [k] callme
0.03% cprog [unknown] [.] 0xf7aa9d4c [unknown] [.] 0xf7aa5f80
0.01% cprog libc-2.11.2.so [.] __errno_location libc-2.11.2.so [.] vfprintf
0.01% cprog libc-2.11.2.so [.] vfprintf libc-2.11.2.so [.] __errno_location
0.01% cprog libc-2.11.2.so [.] _IO_doallocbuf libc-2.11.2.so [.] _IO_file_overflow
0.01% cprog cprog [.] __do_global_dtors_aux [unknown] [.] 0xf7a9fc74
0.01% cprog [unknown] [.] 0xf7a9fca4 cprog [.] _fini (6) perf record -j any_call,ind_call -e branch-misses:u ./cprog
# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol
# ........ ....... .................... ...................... .................... ......................
#
17.38% cprog [unknown] [.] 00000000 cprog [.] sw_3_1
7.76% cprog cprog [.] sw_4_2 cprog [.] lr_addr
7.64% cprog [unknown] [.] 00000000 cprog [.] callme
6.00% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_1
6.00% cprog cprog [.] callme cprog [.] sw_3_1
5.98% cprog cprog [.] sw_4_1 cprog [.] ctr_addr
5.97% cprog cprog [.] hw_1_1 cprog [.] symbol1
5.97% cprog cprog [.] hw_1_2 cprog [.] symbol2
5.97% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_3
5.97% cprog cprog [.] callme cprog [.] hw_1_1
5.97% cprog cprog [.] callme cprog [.] hw_1_2
5.96% cprog cprog [.] callme cprog [.] sw_4_2
5.95% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_2
1.83% cprog cprog [.] sw_3_1 cprog [.] success_3_1_2
1.82% cprog cprog [.] sw_3_1 cprog [.] success_3_1_1
1.82% cprog cprog [.] sw_3_1 cprog [.] success_3_1_3
1.82% cprog cprog [.] callme cprog [.] sw_3_2
0.14% cprog [unknown] [k] 00000000 cprog [k] callme
0.01% cprog libc-2.11.2.so [.] vfprintf libc-2.11.2.so [.] strchrnul
0.01% cprog libc-2.11.2.so [.] _IO_file_xsputn libc-2.11.2.so [.] _IO_default_xsputn
0.01% cprog libc-2.11.2.so [.] _IO_default_xsputn libc-2.11.2.so [.] _IO_file_overflow
0.01% cprog ld-2.11.2.so [.] calloc [unknown] [.] 0xf795b390
0.01% cprog [unknown] [.] 0x0fee00fc libc-2.11.2.so [.] _IO_file_overflow
0.01% cprog [unknown] [.] 00000000 ld-2.11.2.so [.] calloc
0.01% cprog [unknown] [.] 0xf794b41c [unknown] [.] 0xf794ab70 (7) perf record -j cond,any_ret -e branch-misses:u ./cprog
# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol
# ........ ....... .................... ...................... .................... ......................
#
12.43% cprog [unknown] [.] 00000000 cprog [.] sw_3_1
4.91% cprog cprog [.] lr_addr cprog [.] sw_4_2
4.89% cprog [unknown] [.] 00000000 cprog [.] callme
4.87% cprog cprog [.] sw_4_2 cprog [.] lr_addr
4.87% cprog cprog [.] symbol1 cprog [.] hw_1_1
4.19% cprog cprog [.] hw_2_2 cprog [.] address2
4.19% cprog cprog [.] back2 cprog [.] callme
4.19% cprog cprog [.] sw_3_2 cprog [.] callme
4.18% cprog cprog [.] hw_1_1 cprog [.] callme
4.18% cprog cprog [.] success_3_1_2 cprog [.] sw_3_1
4.18% cprog cprog [.] sw_3_1 cprog [.] success_3_1_2
4.16% cprog cprog [.] sw_4_2 cprog [.] callme
4.13% cprog cprog [.] ctr_addr cprog [.] sw_4_1
4.12% cprog cprog [.] symbol2 cprog [.] hw_1_2
4.12% cprog cprog [.] success_3_1_3 cprog [.] sw_3_1
3.43% cprog cprog [.] callme cprog [.] main
3.42% cprog cprog [.] sw_3_1 cprog [.] success_3_1_3
3.41% cprog cprog [.] success_3_1_1 cprog [.] sw_3_1
3.41% cprog cprog [.] sw_3_1 cprog [.] success_3_1_1
3.41% cprog cprog [.] sw_4_1 cprog [.] callme
3.40% cprog cprog [.] hw_1_2 cprog [.] callme
0.73% cprog cprog [.] sw_3_1_3 cprog [.] sw_3_1
0.73% cprog cprog [.] sw_4_1 cprog [.] ctr_addr
0.72% cprog cprog [.] hw_1_2 cprog [.] symbol2
0.72% cprog cprog [.] sw_3_1_1 cprog [.] sw_3_1
0.70% cprog cprog [.] hw_2_1 cprog [.] address1
0.70% cprog cprog [.] back1 cprog [.] callme
0.70% cprog cprog [.] sw_3_1_2 cprog [.] sw_3_1
0.70% cprog cprog [.] sw_3_1 cprog [.] callme
0.19% cprog [unknown] [.] 0xf7c12328 [unknown] [.] 0xf7c12320
0.01% cprog libc-2.11.2.so [.] __errno_location libc-2.11.2.so [.] vfprintf
0.01% cprog libc-2.11.2.so [.] vfprintf libc-2.11.2.so [.] vfprintf
0.01% cprog libc-2.11.2.so [.] _IO_file_overflow [unknown] [.] 0x0fee0100
0.01% cprog libc-2.11.2.so [.] _IO_default_xsputn libc-2.11.2.so [.] _IO_default_xsputn
0.01% cprog [unknown] [.] 00000000 libc-2.11.2.so [.] _IO_file_overflow (8) perf record -j cond,ind_call -e branch-misses:u ./cprog
# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol
# ........ ....... .................... .............. .................... .................
#
20.70% cprog [unknown] [.] 00000000 cprog [.] sw_3_1
9.99% cprog cprog [.] sw_4_2 cprog [.] lr_addr
9.91% cprog [unknown] [.] 00000000 cprog [.] callme
9.45% cprog cprog [.] sw_3_1_3 cprog [.] sw_3_1
9.44% cprog cprog [.] hw_2_1 cprog [.] address1
9.43% cprog cprog [.] sw_3_1_1 cprog [.] sw_3_1
9.42% cprog cprog [.] hw_1_2 cprog [.] symbol2
9.42% cprog cprog [.] sw_3_1_2 cprog [.] sw_3_1
9.42% cprog cprog [.] sw_4_1 cprog [.] ctr_addr
0.65% cprog cprog [.] sw_3_1 cprog [.] success_3_1_1
0.62% cprog cprog [.] sw_3_1 cprog [.] success_3_1_3
0.56% cprog cprog [.] hw_2_2 cprog [.] address2
0.55% cprog cprog [.] sw_3_1 cprog [.] success_3_1_2
0.29% cprog [unknown] [.] 0xf7f72328 [unknown] [.] 0xf7f72320
0.10% cprog [unknown] [k] 00000000 cprog [k] callme
0.02% cprog libc-2.11.2.so [.] _IO_setb libc-2.11.2.so [.] _IO_setb (9) perf record -e branch-misses:u -j any_call,any_ret,ind_call,cond ./cprog
# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol
# ........ ....... .................... .................. .................... .......................
#
9.31% cprog [unknown] [.] 00000000 cprog [.] sw_3_1
4.04% cprog cprog [.] symbol1 cprog [.] hw_1_1
4.03% cprog cprog [.] lr_addr cprog [.] sw_4_2
4.03% cprog cprog [.] sw_4_2 cprog [.] lr_addr
4.00% cprog [unknown] [.] 00000000 cprog [.] callme
3.88% cprog cprog [.] ctr_addr cprog [.] sw_4_1
3.87% cprog cprog [.] sw_4_2 cprog [.] callme
3.86% cprog cprog [.] symbol2 cprog [.] hw_1_2
3.86% cprog cprog [.] success_3_1_3 cprog [.] sw_3_1
2.49% cprog cprog [.] sw_4_1 cprog [.] ctr_addr
2.47% cprog cprog [.] hw_1_1 cprog [.] symbol1
2.47% cprog cprog [.] sw_3_1_1 cprog [.] sw_3_1
2.47% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_1
2.47% cprog cprog [.] callme cprog [.] hw_1_1
2.47% cprog cprog [.] callme cprog [.] sw_3_1
2.47% cprog cprog [.] hw_1_2 cprog [.] symbol2
2.47% cprog cprog [.] hw_2_1 cprog [.] address1
2.47% cprog cprog [.] back1 cprog [.] callme
2.47% cprog cprog [.] sw_3_1_3 cprog [.] sw_3_1
2.47% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_3
2.47% cprog cprog [.] sw_3_1 cprog [.] callme
2.47% cprog cprog [.] callme cprog [.] hw_1_2
2.47% cprog cprog [.] callme cprog [.] sw_4_2
2.46% cprog cprog [.] sw_3_1_2 cprog [.] sw_3_1
2.46% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_2
1.57% cprog cprog [.] success_3_1_2 cprog [.] sw_3_1
1.57% cprog cprog [.] sw_3_1 cprog [.] success_3_1_2
1.57% cprog cprog [.] hw_1_1 cprog [.] callme
1.56% cprog cprog [.] hw_2_2 cprog [.] address2
1.56% cprog cprog [.] back2 cprog [.] callme
1.56% cprog cprog [.] sw_3_2 cprog [.] callme
1.56% cprog cprog [.] callme cprog [.] sw_3_2
1.41% cprog cprog [.] success_3_1_1 cprog [.] sw_3_1
1.41% cprog cprog [.] sw_3_1 cprog [.] success_3_1_1
1.40% cprog cprog [.] sw_4_1 cprog [.] callme
1.39% cprog cprog [.] hw_1_2 cprog [.] callme
1.39% cprog cprog [.] sw_3_1 cprog [.] success_3_1_3
1.39% cprog cprog [.] callme cprog [.] main
0.14% cprog [unknown] [.] 0xf7d72328 [unknown] [.] 0xf7d72320
0.03% cprog [unknown] [k] 00000000 cprog [k] callme
0.01% cprog libc-2.11.2.so [.] _IO_doallocbuf libc-2.11.2.so [.] _IO_doallocbuf
0.01% cprog libc-2.11.2.so [.] printf cprog [.] main
0.01% cprog libc-2.11.2.so [.] _IO_doallocbuf libc-2.11.2.so [.] _IO_file_doallocate
0.01% cprog ld-2.11.2.so [.] malloc [unknown] [.] 0xf7d8b380
0.01% cprog cprog [.] main [unknown] [.] 0x0fe7f63c
0.01% cprog [unknown] [.] 0xf7d8b388 ld-2.11.2.so [.] __libc_memalign
0.01% cprog [unknown] [.] 00000000 ld-2.11.2.so [.] malloc Please refer to the V4 version of the patchset to learn about the sample test case and it's makefile.
Anshuman Khandual (11):
perf: Add PERF_SAMPLE_BRANCH_COND
perf, tool: Conditional branch filter 'cond' added to perf record x86, perf: Add conditional branch filtering support
perf, documentation: Description for conditional branch filter powerpc, perf: Re-arrange BHRB processing
powerpc, perf: Re-arrange PMU based branch filter processing in POWER8 powerpc, perf: Change the name of HW PMU branch filter tracking variable powerpc, lib: Add new branch analysis support functions powerpc, perf: Enable SW filtering in branch stack sampling framework power8, perf: Adapt BHRB PMU configuration to work with SW filters powerpc, perf: Enable privilege mode SW branch filters
arch/powerpc/include/asm/code-patching.h | 16 ++ arch/powerpc/include/asm/perf_event_server.h | 6 +- arch/powerpc/lib/code-patching.c | 80 +++++++ arch/powerpc/perf/core-book3s.c | 323 ++++++++++++++++++++++----- arch/powerpc/perf/power8-pmu.c | 70 ++++-- arch/x86/kernel/cpu/perf_event_intel_lbr.c | 5 + include/uapi/linux/perf_event.h | 3 +- tools/perf/Documentation/perf-record.txt | 3 +- tools/perf/builtin-record.c | 1 + 9 files changed, 429 insertions(+), 78 deletions(-)
Signature · 1 line
1.7.11.7
PATCH v6 1/11 perf: Add PERF_SAMPLE_BRANCH_COND
This patch introduces new branch filter PERF_SAMPLE_BRANCH_COND which will extend the existing perf ABI. Various architectures can provide this functionality with either with HW filtering support (if present) or with SW filtering of captured branch instructions.
--- include/uapi/linux/perf_event.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
include/uapi/linux/perf_event.h +2 -1
@@ -163,8 +163,9 @@ enum perf_branch_sample_type {PERF_SAMPLE_BRANCH_ABORT_TX =1U <<7 ,/* transaction aborts */ PERF_SAMPLE_BRANCH_IN_TX =1U <<8 ,/* in transaction */ PERF_SAMPLE_BRANCH_NO_TX =1U <<9 ,/* not in transaction */ +PERF_SAMPLE_BRANCH_COND =1U <<10 ,/* conditional branches */ - PERF_SAMPLE_BRANCH_MAX = 1U << 10, /* non-ABI */ + PERF_SAMPLE_BRANCH_MAX = 1U << 11, /* non-ABI */ };#define PERF_SAMPLE_BRANCH_PLM_ALL \
Signature · 1 line
1.7.11.7
PATCH v6 2/11 perf, tool: Conditional branch filter 'cond' added to perf record
In reply to Anshuman KhandualAdding perf record support for new branch stack filter criteria PERF_SAMPLE_BRANCH_COND.
--- tools/perf/builtin-record.c | 1 + 1 file changed, 1 insertion(+)
tools/perf/builtin-record.c +1 -0
@@ -583,6 +583,7 @@ static const struct branch_mode branch_modes[] = {BRANCH_OPT ("abort_tx" ,PERF_SAMPLE_BRANCH_ABORT_TX ),BRANCH_OPT ("in_tx" ,PERF_SAMPLE_BRANCH_IN_TX ),BRANCH_OPT ("no_tx" ,PERF_SAMPLE_BRANCH_NO_TX ), +BRANCH_OPT ("cond" ,PERF_SAMPLE_BRANCH_COND ), BRANCH_END };
Signature · 1 line
1.7.11.7
PATCH v6 3/11 x86, perf: Add conditional branch filtering support
In reply to Anshuman KhandualThis patch adds conditional branch filtering support, enabling it for PERF_SAMPLE_BRANCH_COND in perf branch stack sampling framework by utilizing an available software filter X86_BR_JCC.
--- arch/x86/kernel/cpu/perf_event_intel_lbr.c | 5 +++++ 1 file changed, 5 insertions(+)
arch/x86/kernel/cpu/perf_event_intel_lbr.c +5 -0
@@ -384,6 +384,9 @@ static void intel_pmu_setup_sw_lbr_filter(struct perf_event *event)if (br_type &PERF_SAMPLE_BRANCH_NO_TX ) mask |=X86_BR_NO_TX ; +if (br_type &PERF_SAMPLE_BRANCH_COND ) + mask |=X86_BR_JCC ; +/* * stash actual user request into reg, it may * be used by fixup code for some CPU
@@ -678,6 +681,7 @@ static const int nhm_lbr_sel_map[PERF_SAMPLE_BRANCH_MAX] = {* NHM/WSM erratum: must include IND_JMP to capture IND_CALL */ [PERF_SAMPLE_BRANCH_IND_CALL] = LBR_IND_CALL | LBR_IND_JMP, + [PERF_SAMPLE_BRANCH_COND] = LBR_JCC, };static const int snb_lbr_sel_map[PERF_SAMPLE_BRANCH_MAX ] = {
@@ -689,6 +693,7 @@ static const int snb_lbr_sel_map[PERF_SAMPLE_BRANCH_MAX] = { [PERF_SAMPLE_BRANCH_ANY_CALL ] =LBR_REL_CALL |LBR_IND_CALL | LBR_FAR, [PERF_SAMPLE_BRANCH_IND_CALL] = LBR_IND_CALL, + [PERF_SAMPLE_BRANCH_COND] = LBR_JCC, };/* core */
Signature · 1 line
1.7.11.7
PATCH v6 4/11 perf, documentation: Description for conditional branch filter
In reply to Anshuman KhandualAdding documentation support for conditional branch filter.
--- tools/perf/Documentation/perf-record.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tools/perf/Documentation/perf-record.txt +2 -1
@@ -184,9 +184,10 @@ following filters are defined: - in_tx: only when the target is in a hardware transaction - no_tx: only when the target is not in a hardware transaction - abort_tx: only when the target is a hardware transaction abort + - cond: conditional branches + -The option requires at least one branch type among any, any_call, any_ret, ind_call. +The option requires at least one branch type among any, any_call, any_ret, ind_call, cond. The privilege levels may be omitted, in which case, the privilege levels of the associated event are applied to the branch filter. Both kernel (k) and hypervisor (hv) privilege levels are subject to permissions. When sampling on multiple events, branch stack sampling
Signature · 1 line
1.7.11.7
PATCH v6 5/11 powerpc, perf: Re-arrange BHRB processing
In reply to Anshuman KhandualThis patch cleans up some existing indentation problem and re-organizes the BHRB processing code with an helper function named update_branch_entry making it more readable. This patch does not change any functionality.
--- arch/powerpc/perf/core-book3s.c | 102 ++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 50 deletions(-)
arch/powerpc/perf/core-book3s.c +52 -50
@@ -402,11 +402,21 @@ static __u64 power_pmu_bhrb_to(u64 addr)return target - (unsigned long )&instr + addr; } +/* Update individual branch entry */ +void update_branch_entry (struct cpu_hw_events *cpuhw,int u_index,u64 from,u64 to,int pred) +{ + cpuhw->bhrb_entries[u_index].from = from; + cpuhw->bhrb_entries[u_index].to = to; + cpuhw->bhrb_entries[u_index].mispred = pred; + cpuhw->bhrb_entries[u_index].predicted = ~pred; +return ; +} +/* Processing BHRB entries */ void power_pmu_bhrb_read (struct cpu_hw_events *cpuhw) {u64 val; -u64 addr; +u64 addr, tmp;int r_index, u_index, pred; r_index =0 ;
@@ -417,62 +427,54 @@ void power_pmu_bhrb_read(struct cpu_hw_events *cpuhw)if (!val)/* Terminal marker: End of valid BHRB entries */ break ; -else { - addr = val &BHRB_EA ; - pred = val &BHRB_PREDICTION ; -if (!addr) -/* invalid entry */ -continue ; + addr = val &BHRB_EA ; + pred = val &BHRB_PREDICTION ; -/* Branches are read most recent first (ie. mfbhrb 0 is -* the most recent branch). -* There are two types of valid entries: -* 1) a target entry which is the to address of a -* computed goto like a blr,bctr,btar. The next -* entry read from the bhrb will be branch -* corresponding to this target (ie. the actual -* blr/bctr/btar instruction). -* 2) a from address which is an actual branch. If a -* target entry proceeds this, then this is the -* matching branch for that target. If this is not -* following a target entry, then this is a branch -* where the target is given as an immediate field -* in the instruction (ie. an i or b form branch). -* In this case we need to read the instruction from -* memory to determine the target/to address. +if (!addr) +/* invalid entry */ +continue ; + +/* Branches are read most recent first (ie. mfbhrb 0 is +* the most recent branch). +* There are two types of valid entries: +* 1) a target entry which is the to address of a +* computed goto like a blr,bctr,btar. The next +* entry read from the bhrb will be branch +* corresponding to this target (ie. the actual +* blr/bctr/btar instruction). +* 2) a from address which is an actual branch. If a +* target entry proceeds this, then this is the +* matching branch for that target. If this is not +* following a target entry, then this is a branch +* where the target is given as an immediate field +* in the instruction (ie. an i or b form branch). +* In this case we need to read the instruction from +* memory to determine the target/to address. +*/ +if (val &BHRB_TARGET ) { +/* Target branches use two entries +* (ie. computed gotos/XL form) */ + tmp = addr; +/* Get from address in next entry */ + val =read_bhrb (r_index++); + addr = val &BHRB_EA ;if (val &BHRB_TARGET ) { -/* Target branches use two entries -* (ie. computed gotos/XL form) -*/ - cpuhw->bhrb_entries[u_index].to = addr; - cpuhw->bhrb_entries[u_index].mispred = pred; - cpuhw->bhrb_entries[u_index].predicted = ~pred; - -/* Get from address in next entry */ - val =read_bhrb (r_index++); - addr = val &BHRB_EA ; -if (val &BHRB_TARGET ) { -/* Shouldn't have two targets in a -row.. Reset index and try again */ - r_index--; - addr =0 ; - } - cpuhw->bhrb_entries[u_index].from = addr; - }else { -/* Branches to immediate field -(ie I or B form) */ - cpuhw->bhrb_entries[u_index].from = addr; - cpuhw->bhrb_entries[u_index].to = -power_pmu_bhrb_to (addr); - cpuhw->bhrb_entries[u_index].mispred = pred; - cpuhw->bhrb_entries[u_index].predicted = ~pred; +/* Shouldn't have two targets in a +row.. Reset index and try again */ + r_index--; + addr =0 ; } - u_index++; - +update_branch_entry (cpuhw, u_index, addr, tmp, pred); + }else { +/* Branches to immediate field +(ie I or B form) */ + tmp =power_pmu_bhrb_to (addr); +update_branch_entry (cpuhw, u_index, addr, tmp, pred); } + u_index++; } cpuhw->bhrb_stack.nr = u_index;return ;
Signature · 1 line
1.7.11.7
PATCH v6 6/11 powerpc, perf: Re-arrange PMU based branch filter processing in POWER8
In reply to Anshuman KhandualThis patch does some code re-arrangements to make it clear that it ignores any separate privilege level branch filter request and does not support any combinations of HW PMU branch filters.
--- arch/powerpc/perf/power8-pmu.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-)
arch/powerpc/perf/power8-pmu.c +7 -14
@@ -635,8 +635,6 @@ static int power8_generic_events[] = {static u64 power8_bhrb_filter_map (u64 branch_sample_type) { -u64 pmu_bhrb_filter =0 ; -/* BHRB and regular PMU events share the same privilege state * filter configuration. BHRB is always recorded along with a * regular PMU event. As the privilege state filter is handled
@@ -644,20 +642,15 @@ static u64 power8_bhrb_filter_map(u64 branch_sample_type)* PMU event, we ignore any separate BHRB specific request. */ -/* No branch filter requested */ -if (branch_sample_type &PERF_SAMPLE_BRANCH_ANY ) -return pmu_bhrb_filter; - -/* Invalid branch filter options - HW does not support */ -if (branch_sample_type &PERF_SAMPLE_BRANCH_ANY_RETURN ) -return -1 ; +/* Ignore user, kernel, hv bits */ + branch_sample_type &= ~PERF_SAMPLE_BRANCH_PLM_ALL ; -if (branch_sample_type &PERF_SAMPLE_BRANCH_IND_CALL ) -return -1 ; +/* No branch filter requested */ +if (branch_sample_type ==PERF_SAMPLE_BRANCH_ANY ) +return 0 ; -if (branch_sample_type &PERF_SAMPLE_BRANCH_ANY_CALL ) { - pmu_bhrb_filter |=POWER8_MMCRA_IFM1 ; -return pmu_bhrb_filter; +if (branch_sample_type ==PERF_SAMPLE_BRANCH_ANY_CALL ) { +return POWER8_MMCRA_IFM1 ; }/* Every thing else is unsupported */
Signature · 1 line
1.7.11.7
PATCH v6 7/11 powerpc, perf: Change the name of HW PMU branch filter tracking variable
In reply to Anshuman KhandualThis patch simply changes the name of the variable from 'bhrb_filter' to 'bhrb_hw_filter' in order to add one more variable which will track SW filters in generic powerpc book3s code which will be implemented in the subsequent patch. This patch does not change any functionality.
--- arch/powerpc/perf/core-book3s.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
arch/powerpc/perf/core-book3s.c +5 -5
@@ -47,7 +47,7 @@ struct cpu_hw_events {int n_txn_start;/* BHRB bits */ -u64 bhrb_filter;/* BHRB HW branch filter */ +u64 bhrb_hw_filter;/* BHRB HW branch filter */ int bhrb_users;void *bhrb_context;struct perf_branch_stack bhrb_stack;
@@ -1298,7 +1298,7 @@ static void power_pmu_enable(struct pmu *pmu)mb ();if (cpuhw->bhrb_users) - ppmu->config_bhrb (cpuhw->bhrb_filter); + ppmu->config_bhrb (cpuhw->bhrb_hw_filter);write_mmcr0 (cpuhw, mmcr0);
@@ -1405,7 +1405,7 @@ nocheck: out:if (has_branch_stack (event)) {power_pmu_bhrb_enable (event); - cpuhw->bhrb_filter = ppmu->bhrb_filter_map ( + cpuhw->bhrb_hw_filter = ppmu->bhrb_filter_map ( event->attr.branch_sample_type); }
@@ -1788,10 +1788,10 @@ static int power_pmu_event_init(struct perf_event *event) err =power_check_constraints (cpuhw, events, cflags, n +1 );if (has_branch_stack (event)) { - cpuhw->bhrb_filter = ppmu->bhrb_filter_map ( + cpuhw->bhrb_hw_filter = ppmu->bhrb_filter_map ( event->attr.branch_sample_type); -if (cpuhw->bhrb_filter ==-1 ) +if (cpuhw->bhrb_hw_filter ==-1 )return -EOPNOTSUPP ; }
Signature · 1 line
1.7.11.7
PATCH v6 8/11 powerpc, lib: Add new branch analysis support functions
In reply to Anshuman KhandualGeneric powerpc branch analysis support added in the code patching library which will help the subsequent patch on SW based filtering of branch records in perf.
--- arch/powerpc/include/asm/code-patching.h | 16 +++++++ arch/powerpc/lib/code-patching.c | 80 ++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+)
arch/powerpc/include/asm/code-patching.h +16 -0
@@ -22,6 +22,16 @@#define BRANCH_SET_LINK 0x1#define BRANCH_ABSOLUTE 0x2 +#define XL_FORM_LR 0x4C000020 +#define XL_FORM_CTR 0x4C000420 +#define XL_FORM_TAR 0x4C000460 + +#define BO_ALWAYS 0x02800000 +#define BO_CTR 0x02000000 +#define BO_CRBI_OFF 0x00800000 +#define BO_CRBI_ON 0x01800000 +#define BO_CRBI_HINT 0x00400000 +unsigned int create_branch (const unsigned int *addr,unsigned long target,int flags); unsigned int create_cond_branch(const unsigned int *addr,
@@ -56,4 +66,10 @@ static inline unsigned long ppc_function_entry(void *func) #endif } +/* Perf branch filters */ +bool instr_is_return_branch (unsigned int instr); +bool instr_is_conditional_branch (unsigned int instr); +bool instr_is_func_call (unsigned int instr); +bool instr_is_indirect_func_call (unsigned int instr); +#endif /* _ASM_POWERPC_CODE_PATCHING_H */
arch/powerpc/lib/code-patching.c +80 -0
92 lines not on this page · raw message
Signature · 1 line
1.7.11.7
PATCH v6 9/11 powerpc, perf: Enable SW filtering in branch stack sampling framework
In reply to Anshuman KhandualThis patch enables SW based post processing of BHRB captured branches to be able to meet more user defined branch filtration criteria in perf branch stack sampling framework. These changes increase the number of branch filters and their valid combinations on any powerpc64 server platform with BHRB support. Find the summary of code changes here.
(1) struct cpu_hw_events
Introduced two new variables track various filter values and mask
(a) bhrb_sw_filter Tracks SW implemented branch filter flags
(b) bhrb_filter Tracks both (SW and HW) branch filter flags
(2) Event creation
Kernel will figure out supported BHRB branch filters through a PMU call back 'bhrb_filter_map'. This function will find out how many of the requested branch filters can be supported in the PMU HW. It will not try to invalidate any branch filter combinations. Event creation will not error out because of lack of HW based branch filters. Meanwhile it will track the overall supported branch filters in the 'bhrb_filter' variable.
Once the PMU call back returns kernel will process the user branch filter request against available SW filters (bhrb_sw_filter_map) while looking at the 'bhrb_filter'. During this phase all the branch filters which are still pending from the user requested list will have to be supported in SW failing which the event creation will error out.
(3) SW branch filter
During the BHRB data capture inside the PMU interrupt context, each of the captured 'perf_branch_entry.from' will be checked for compliance with applicable SW branch filters. If the entry does not conform to the filter requirements, it will be discarded from the final perf branch stack buffer.
(4) Supported SW based branch filters
(a) PERF_SAMPLE_BRANCH_ANY_RETURN
(b) PERF_SAMPLE_BRANCH_IND_CALL
(c) PERF_SAMPLE_BRANCH_ANY_CALL
(d) PERF_SAMPLE_BRANCH_COND
Please refer the patch to understand the classification of instructions into these branch filter categories.
(5) Multiple branch filter semantics
Book3 sever implementation follows the same OR semantics (as implemented in x86) while dealing with multiple branch filters at any point of time. SW branch filter analysis is carried on the data set captured in the PMU HW. So the resulting set of data (after applying the SW filters) will inherently be an AND with the HW captured set. Hence any combination of HW and SW branch filters will be invalid. HW based branch filters are more efficient and faster compared to SW implemented branch filters. So at first the PMU should decide whether it can support all the requested branch filters itself or not. In case it can support all the branch filters in an OR manner, we dont apply any SW branch filter on top of the HW captured set (which is the final set). This preserves the OR semantic of multiple branch filters as required. But in case where the PMU cannot support all the requested branch filters in an OR manner, it should not apply any it's filters and leave it upto the SW to handle them all. Its the PMU code's responsibility to uphold this protocol to be able to conform to the overall OR semantic of perf branch stack sampling framework.
--- arch/powerpc/include/asm/perf_event_server.h | 6 +- arch/powerpc/perf/core-book3s.c | 188 ++++++++++++++++++++++++++- arch/powerpc/perf/power8-pmu.c | 2 +- 3 files changed, 187 insertions(+), 9 deletions(-)
arch/powerpc/include/asm/perf_event_server.h +5 -1
@@ -19,6 +19,10 @@#define MAX_EVENT_ALTERNATIVES 8#define MAX_LIMITED_HWCOUNTERS 2 +#define for_each_branch_sample_type (x) \ + for ((x) = PERF_SAMPLE_BRANCH_USER; \ + (x) < PERF_SAMPLE_BRANCH_MAX; (x) <<= 1) +/* * This struct provides the constants and functions needed to * describe the PMU on a particular POWER-family CPU.
@@ -35,7 +39,7 @@ struct power_pmu { unsigned long *valp);int (*get_alternatives)(u64 event_id,unsigned int flags,u64 alt[]); -u64 (*bhrb_filter_map)(u64 branch_sample_type); +u64 (*bhrb_filter_map)(u64 branch_sample_type,u64 *bhrb_filter);void (*config_bhrb)(u64 pmu_bhrb_filter);void (*disable_pmc)(unsigned int pmc,unsigned long mmcr[]);int (*limited_pmc_event)(u64 event_id);
arch/powerpc/perf/core-book3s.c +181 -7
226 lines not on this page · raw message
arch/powerpc/perf/power8-pmu.c +1 -1
@@ -633,7 +633,7 @@ static int power8_generic_events[] = { [PERF_COUNT_HW_CACHE_MISSES] = PM_LD_MISS_L1, }; -static u64 power8_bhrb_filter_map (u64 branch_sample_type) +static u64 power8_bhrb_filter_map (u64 branch_sample_type,u64 *bhrb_filter) {/* BHRB and regular PMU events share the same privilege state * filter configuration. BHRB is always recorded along with a
Signature · 1 line
1.7.11.7
PATCH v6 10/11 power8, perf: Adapt BHRB PMU configuration to work with SW filters
In reply to Anshuman KhandualPowerpc kernel now supports SW based branch filters for book3s systems with some specifc requirements while dealing with HW supported branch filters in order to achieve overall OR semantics prevailing in perf branch stack sampling framework. This patch adapts the BHRB branch filter configuration to meet those protocols. POWER8 PMU can only handle one HW based branch filter request at any point of time. For all other combinations PMU will pass it on to the SW.
--- arch/powerpc/perf/power8-pmu.c | 50 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 7 deletions(-)
arch/powerpc/perf/power8-pmu.c +43 -7
@@ -635,6 +635,16 @@ static int power8_generic_events[] = {static u64 power8_bhrb_filter_map (u64 branch_sample_type,u64 *bhrb_filter) { +u64 x, pmu_bhrb_filter; + pmu_bhrb_filter =0 ; + *bhrb_filter =0 ; + +/* No branch filter requested */ +if (branch_sample_type &PERF_SAMPLE_BRANCH_ANY ) { + *bhrb_filter =PERF_SAMPLE_BRANCH_ANY ; +return pmu_bhrb_filter; + } +/* BHRB and regular PMU events share the same privilege state * filter configuration. BHRB is always recorded along with a * regular PMU event. As the privilege state filter is handled
@@ -645,16 +655,42 @@ static u64 power8_bhrb_filter_map(u64 branch_sample_type, u64 *bhrb_filter)/* Ignore user, kernel, hv bits */ branch_sample_type &= ~PERF_SAMPLE_BRANCH_PLM_ALL ; -/* No branch filter requested */ -if (branch_sample_type ==PERF_SAMPLE_BRANCH_ANY ) -return 0 ; +/* +* P8 does not support oring of PMU HW branch filters. Hence +* if multiple branch filters are requested which includes filters +* supported in PMU, still go ahead and clear the PMU based HW branch +* filter component as in this case all the filters will be processed +* in SW. +*/ -if (branch_sample_type ==PERF_SAMPLE_BRANCH_ANY_CALL ) { -return POWER8_MMCRA_IFM1 ; +for_each_branch_sample_type (x) { +/* Ignore privilege branch filters */ +if ((x ==PERF_SAMPLE_BRANCH_USER ) + || (x ==PERF_SAMPLE_BRANCH_KERNEL ) + || (x ==PERF_SAMPLE_BRANCH_HV )) +continue ; + +if (!(branch_sample_type & x)) +continue ; + +/* Supported individual PMU branch filters */ +if (branch_sample_type &PERF_SAMPLE_BRANCH_ANY_CALL ) { + branch_sample_type &= ~PERF_SAMPLE_BRANCH_ANY_CALL ; +if (branch_sample_type) { +/* Multiple branch filters will be processed in SW */ + pmu_bhrb_filter =0 ; + *bhrb_filter =0 ; +return pmu_bhrb_filter; + }else { +/* Individual branch filter will be processed in PMU */ + pmu_bhrb_filter |=POWER8_MMCRA_IFM1 ; + *bhrb_filter |=PERF_SAMPLE_BRANCH_ANY_CALL ; +return pmu_bhrb_filter; + } + } } -/* Every thing else is unsupported */ -return -1 ; +return pmu_bhrb_filter; }static void power8_config_bhrb (u64 pmu_bhrb_filter)
Signature · 1 line
1.7.11.7
PATCH v6 11/11 powerpc, perf: Enable privilege mode SW branch filters
In reply to Anshuman KhandualThis patch enables privilege mode SW branch filters. Also modifies POWER8 PMU branch filter configuration so that the privilege mode branch filter implemented as part of base PMU event configuration is reflected in bhrb filter mask. As a result, the SW will skip and not try to process the privilege mode branch filters itself.
--- arch/powerpc/perf/core-book3s.c | 53 +++++++++++++++++++++++++++++++---------- arch/powerpc/perf/power8-pmu.c | 13 ++++++++-- 2 files changed, 52 insertions(+), 14 deletions(-)
arch/powerpc/perf/core-book3s.c +41 -12
@@ -26,6 +26,9 @@#define BHRB_PREDICTION 0x0000000000000001#define BHRB_EA 0xFFFFFFFFFFFFFFFCUL +#define POWER_ADDR_USER 0 +#define POWER_ADDR_KERNEL 1 +struct cpu_hw_events {int n_events;int n_percpu;
@@ -450,10 +453,10 @@ static bool check_instruction(unsigned int *addr, u64 sw_filter)* Access the instruction contained in the address and check * whether it complies with the applicable SW branch filters. */ -static bool keep_branch (u64 from,u64 sw_filter) +static bool keep_branch (u64 from,u64 to,u64 sw_filter) {unsigned int instr; -bool ret; +bool to_plm, ret, flag;/* * The "from" branch for every branch record has to go
@@ -463,6 +466,37 @@ static bool keep_branch(u64 from, u64 sw_filter)if (sw_filter ==0 )return true; + to_plm =is_kernel_addr (to) ?POWER_ADDR_KERNEL :POWER_ADDR_USER ; + +/* +* Applying privilege mode SW branch filters first on the +* 'to' address makes an AND semantic with the SW generic +* branch filters (OR with each other) being applied on the +* from address there after. +*/ + +/* Ignore PERF_SAMPLE_BRANCH_HV */ + sw_filter &= ~PERF_SAMPLE_BRANCH_HV ; + +/* Privilege mode branch filters for "TO" address */ +if (sw_filter &PERF_SAMPLE_BRANCH_PLM_ALL ) { + flag = false; + +if (sw_filter &PERF_SAMPLE_BRANCH_USER ) { +if (to_plm ==POWER_ADDR_USER ) + flag = true; + } + +if (sw_filter &PERF_SAMPLE_BRANCH_KERNEL ) { +if (to_plm ==POWER_ADDR_KERNEL ) + flag = true; + } + +if (!flag) +return false; + } + +/* Generic branch filters for "FROM" address */ if (is_kernel_addr (from)) {return check_instruction ((unsigned int *) from, sw_filter); }else {
@@ -501,15 +535,6 @@ static int all_filters_covered(u64 branch_sample_type, u64 bhrb_filter)if (!(branch_sample_type & x))continue ;/* -* Privilege filter requests have been already -* taken care during the base PMU configuration. -*/ -if ((x ==PERF_SAMPLE_BRANCH_USER ) - || (x ==PERF_SAMPLE_BRANCH_KERNEL ) - || (x ==PERF_SAMPLE_BRANCH_HV )) -continue ; - -/* * Requested filter not available either * in PMU or in SW. */
@@ -520,7 +545,10 @@ static int all_filters_covered(u64 branch_sample_type, u64 bhrb_filter) }/* SW implemented branch filters */ -static unsigned int power_sw_filter[] = {PERF_SAMPLE_BRANCH_ANY_CALL , +static unsigned int power_sw_filter[] = {PERF_SAMPLE_BRANCH_USER , +PERF_SAMPLE_BRANCH_KERNEL , +PERF_SAMPLE_BRANCH_HV , +PERF_SAMPLE_BRANCH_ANY_CALL ,PERF_SAMPLE_BRANCH_COND ,PERF_SAMPLE_BRANCH_ANY_RETURN ,PERF_SAMPLE_BRANCH_IND_CALL };
@@ -624,6 +652,7 @@ void power_pmu_bhrb_read(struct cpu_hw_events *cpuhw)/* Apply SW branch filters and drop the entry if required */ if (!keep_branch (cpuhw->bhrb_entries[u_index].from, + cpuhw->bhrb_entries[u_index].to, cpuhw->bhrb_sw_filter)) u_index--; u_index++;
arch/powerpc/perf/power8-pmu.c +11 -2
@@ -649,9 +649,19 @@ static u64 power8_bhrb_filter_map(u64 branch_sample_type, u64 *bhrb_filter)* filter configuration. BHRB is always recorded along with a * regular PMU event. As the privilege state filter is handled * in the basic PMC configuration of the accompanying regular -* PMU event, we ignore any separate BHRB specific request. +* PMU event, we ignore any separate BHRB specific request. But +* this needs to be communicated with the branch filter mask. */ +if (branch_sample_type &PERF_SAMPLE_BRANCH_USER ) + *bhrb_filter |=PERF_SAMPLE_BRANCH_USER ; + +if (branch_sample_type &PERF_SAMPLE_BRANCH_KERNEL ) + *bhrb_filter |=PERF_SAMPLE_BRANCH_KERNEL ; + +if (branch_sample_type &PERF_SAMPLE_BRANCH_HV ) + *bhrb_filter |=PERF_SAMPLE_BRANCH_HV ; +/* Ignore user, kernel, hv bits */ branch_sample_type &= ~PERF_SAMPLE_BRANCH_PLM_ALL ;
@@ -679,7 +689,6 @@ static u64 power8_bhrb_filter_map(u64 branch_sample_type, u64 *bhrb_filter)if (branch_sample_type) {/* Multiple branch filters will be processed in SW */ pmu_bhrb_filter =0 ; - *bhrb_filter =0 ;return pmu_bhrb_filter; }else {/* Individual branch filter will be processed in PMU */
Signature · 1 line
1.7.11.7
v6 cover perf: New conditional branch filter
In reply to Anshuman KhandualHello Peter/Ingo,
Would you please consider reviewing the first four patches in this patch series which changes the generic perf kernel and perf tools code. Andi Kleen and Stephane Eranian have already reviewed these changes. The rest of the patch series is related to powerpc and being reviewed by Michael Ellerman/Ben.
Regards
Anshuman
-------- Original Message --------
Subject: [V6 00/11] perf: New conditional branch filter
Date: Mon, 5 May 2014 14:39:02 +0530
From: Anshuman Khandual <[email protected]>
To: [email protected], [email protected]
CC: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
This patchset is the re-spin of the original branch stack sampling
patchset which introduced new PERF_SAMPLE_BRANCH_COND branch filter. This patchset also enables SW based branch filtering support for book3s powerpc platforms which have PMU HW backed branch stack sampling support.
Summary of code changes in this patchset:
(1) Introduces a new PERF_SAMPLE_BRANCH_COND branch filter
(2) Add the "cond" branch filter options in the "perf record" tool
(3) Enable PERF_SAMPLE_BRANCH_COND in X86 platforms
(4) Enable PERF_SAMPLE_BRANCH_COND in POWER8 platform
(5) Update the documentation regarding "perf record" tool
(6) Add some new powerpc instruction analysis functions in code-patching library
(7) Enable SW based branch filter support for powerpc book3s
(8) Changed BHRB configuration in POWER8 to accommodate SW branch filters
With this new SW enablement, the branch filter support for book3s platforms have been extended to include all these combinations discussed below with a sample test application program (included here).
Changes in V2
=============
(1) Enabled PPC64 SW branch filtering support
(2) Incorporated changes required for all previous comments
Changes in V3
=============
(1) Split the SW branch filter enablement into multiple patches
(2) Added PMU neutral SW branch filtering code, PMU specific HW branch filtering code
(3) Added new instruction analysis functionality into powerpc code-patching library
(4) Changed name for some of the functions
(5) Fixed couple of spelling mistakes
(6) Changed code documentation in multiple places
Changes in V4
=============
(1) Changed the commit message for patch (01/10)
(2) Changed the patch (02/10) to accommodate review comments from Michael Ellerman
(3) Rebased the patchset against latest Linus's tree
Changes in V5
=============
(1) Added a precursor patch to cleanup the indentation problem in power_pmu_bhrb_read
(2) Added a precursor patch to re-arrange P8 PMU BHRB filter config which improved the clarity
(3) Merged the previous 10th patch into the 8th patch
(4) Moved SW based branch analysis code from core perf into code-patching library as suggested by Michael
(5) Simplified the logic in branch analysis library
(6) Fixed some ambiguities in documentation at various places
(7) Added some more in-code documentation blocks at various places
(8) Renamed some local variable and function names
(9) Fixed some indentation and white space errors in the code
(10) Implemented almost all the review comments and suggestions made by Michael Ellerman on V4 patchset
(11) Enabled privilege mode SW branch filter
(12) Simplified and generalized the SW implemented conditional branch filter
(13) PERF_SAMPLE_BRANCH_COND filter is now supported only through SW implementation
(14) Adjusted other patches to deal with the above changes
Changes in V6
=============
(1) Rebased the patchset against the master
(2) Added "Reviewed-by: Andi Kleen" in the first four patches in the series which changes the
generic or X86 perf code. [https://lkml.org/lkml/2014/4/7/130]
HW implemented branch filters
=============================
(1) perf record -j any_call -e branch-misses:u ./cprog
# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol
# ........ ....... .................... ....................... .................... ....................
#
7.85% cprog cprog [.] sw_3_1 cprog [.] success_3_1_2
5.66% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_2
5.65% cprog cprog [.] hw_1_1 cprog [.] symbol1
5.42% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_3
5.40% cprog cprog [.] callme cprog [.] hw_1_1
5.40% cprog cprog [.] sw_3_1 cprog [.] success_3_1_1
5.40% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_1
5.39% cprog cprog [.] sw_4_2 cprog [.] lr_addr
5.39% cprog cprog [.] callme cprog [.] sw_4_2
5.39% cprog [unknown] [.] 00000000 cprog [.] ctr_addr
5.38% cprog cprog [.] hw_1_2 cprog [.] symbol2
5.38% cprog cprog [.] callme cprog [.] hw_1_2
5.16% cprog cprog [.] sw_3_1 cprog [.] success_3_1_3
5.15% cprog cprog [.] callme cprog [.] sw_3_2
5.14% cprog cprog [.] callme cprog [.] hw_2_2
2.96% cprog cprog [.] callme cprog [.] sw_3_1
2.94% cprog cprog [.] callme cprog [.] hw_2_1
2.71% cprog cprog [.] main cprog [.] callme
2.71% cprog [unknown] [.] 00000000 cprog [.] lr_addr
2.70% cprog cprog [.] sw_4_1 cprog [.] ctr_addr
2.70% cprog cprog [.] callme cprog [.] sw_4_1
0.09% cprog [unknown] [.] 0xf7ad76c4 [unknown] [.] 0xf7ac22c0
0.00% cprog libc-2.11.2.so [.] vfprintf libc-2.11.2.so [.] __errno_location
0.00% cprog libc-2.11.2.so [.] printf libc-2.11.2.so [.] vfprintf
0.00% cprog libc-2.11.2.so [.] _IO_file_doallocate libc-2.11.2.so [.] isatty
0.00% cprog libc-2.11.2.so [.] _IO_file_doallocate libc-2.11.2.so [.] mmap
0.00% cprog libc-2.11.2.so [.] isatty libc-2.11.2.so [.] tcgetattr
0.00% cprog cprog [.] main [unknown] [.] 0x10000950
0.00% cprog [unknown] [.] 00000000 libc-2.11.2.so [.] _IO_file_stat
0.00% cprog [unknown] [.] 0xf7acfca4 cprog [.] _fini
0.00% cprog [unknown] [k] 00000000 cprog [k] ctr_addr
0.00% cprog [unknown] [k] 00000000 cprog [k] lr_addr SW implemented branch filters
=============================
(2) perf record -j cond -e branch-misses:u ./cprog
# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol
# ........ ....... .................... ...................... .................... ......................
#
25.82% cprog [unknown] [.] 00000000 cprog [.] sw_3_1
12.66% cprog cprog [.] sw_4_2 cprog [.] lr_addr
12.63% cprog [unknown] [.] 00000000 cprog [.] callme
9.42% cprog cprog [.] hw_2_2 cprog [.] address2
9.39% cprog cprog [.] sw_3_1 cprog [.] success_3_1_2
4.91% cprog cprog [.] sw_3_1 cprog [.] success_3_1_1
4.91% cprog cprog [.] sw_3_1 cprog [.] success_3_1_3
3.35% cprog cprog [.] sw_3_1_3 cprog [.] sw_3_1
3.34% cprog cprog [.] sw_3_1_1 cprog [.] sw_3_1
3.31% cprog cprog [.] hw_1_2 cprog [.] symbol2
3.31% cprog cprog [.] sw_4_1 cprog [.] ctr_addr
3.29% cprog cprog [.] hw_2_1 cprog [.] address1
3.27% cprog cprog [.] sw_3_1_2 cprog [.] sw_3_1
0.32% cprog [unknown] [.] 0xf7c62328 [unknown] [.] 0xf7c62320
0.01% cprog libc-2.11.2.so [.] vfprintf libc-2.11.2.so [.] vfprintf
0.01% cprog libc-2.11.2.so [.] _IO_file_xsputn libc-2.11.2.so [.] _IO_file_xsputn
0.01% cprog libc-2.11.2.so [.] _IO_default_xsputn libc-2.11.2.so [.] _IO_default_xsputn
0.01% cprog libc-2.11.2.so [.] strchrnul libc-2.11.2.so [.] strchrnul
0.01% cprog [unknown] [.] 00000000 libc-2.11.2.so [.] _IO_file_xsputn
0.01% cprog [unknown] [k] 00000000 cprog [k] callme (3) perf record -j any_ret -e branch-misses:u ./cprog
# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol
# ........ ....... .................... ..................... .................... .....................
#
15.61% cprog [unknown] [.] 00000000 cprog [.] sw_3_1
6.28% cprog cprog [.] symbol2 cprog [.] hw_1_2
6.28% cprog cprog [.] ctr_addr cprog [.] sw_4_1
6.26% cprog cprog [.] success_3_1_3 cprog [.] sw_3_1
6.24% cprog cprog [.] symbol1 cprog [.] hw_1_1
6.24% cprog cprog [.] sw_4_2 cprog [.] callme
6.21% cprog [unknown] [.] 00000000 cprog [.] callme
6.19% cprog cprog [.] lr_addr cprog [.] sw_4_2
3.16% cprog cprog [.] hw_1_2 cprog [.] callme
3.15% cprog cprog [.] success_3_1_1 cprog [.] sw_3_1
3.15% cprog cprog [.] sw_4_1 cprog [.] callme
3.14% cprog cprog [.] callme cprog [.] main
3.13% cprog cprog [.] hw_1_1 cprog [.] callme
3.13% cprog cprog [.] sw_3_1_1 cprog [.] sw_3_1
3.12% cprog cprog [.] back2 cprog [.] callme
3.12% cprog cprog [.] sw_3_1 cprog [.] callme
3.11% cprog cprog [.] back1 cprog [.] callme
3.11% cprog cprog [.] sw_3_1_2 cprog [.] sw_3_1
3.11% cprog cprog [.] sw_3_1_3 cprog [.] sw_3_1
3.10% cprog cprog [.] sw_3_2 cprog [.] callme
3.09% cprog cprog [.] success_3_1_2 cprog [.] sw_3_1
0.03% cprog [unknown] [.] 0x100009b0 [unknown] [.] 0xf7d5581c
0.01% cprog libc-2.11.2.so [.] _IO_file_overflow libc-2.11.2.so [.] _IO_file_xsputn
0.01% cprog libc-2.11.2.so [.] _IO_file_setbuf [unknown] [.] 0x0fee1084
0.01% cprog [unknown] [.] 0xf7d5589c libc-2.11.2.so [.] printf
0.01% cprog [unknown] [.] 00000000 libc-2.11.2.so [.] _IO_file_overflow
0.01% cprog [unknown] [.] 00000000 libc-2.11.2.so [.] _IO_file_setbuf
0.01% cprog [unknown] [k] 00000000 cprog [k] callme (4) perf record -j ind_call -e branch-misses:u ./cprog
# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol
# ........ ....... .................... .............. .................... .....................
#
42.59% cprog [unknown] [.] 00000000 cprog [.] sw_3_1
25.88% cprog cprog [.] sw_4_2 cprog [.] lr_addr
25.65% cprog [unknown] [.] 00000000 cprog [.] callme
5.58% cprog cprog [.] sw_4_1 cprog [.] ctr_addr
0.23% cprog [unknown] [k] 00000000 cprog [k] callme
0.05% cprog [unknown] [.] 00000000 [unknown] [.] 0xf79fd740
0.03% cprog [unknown] [.] 00000000 libc-2.11.2.so [.] _IO_file_overflow(5) perf record -j any_call,any_ret -e branch-misses:u ./cprog
# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol
# ........ ....... .................... ......................... .................... .....................
#
10.00% cprog [unknown] [.] 00000000 cprog [.] sw_3_1
4.20% cprog cprog [.] sw_4_2 cprog [.] lr_addr
4.17% cprog cprog [.] lr_addr cprog [.] sw_4_2
4.16% cprog cprog [.] symbol1 cprog [.] hw_1_1
4.12% cprog [unknown] [.] 00000000 cprog [.] callme
4.12% cprog cprog [.] symbol2 cprog [.] hw_1_2
4.11% cprog cprog [.] success_3_1_3 cprog [.] sw_3_1
4.11% cprog cprog [.] ctr_addr cprog [.] sw_4_1
4.10% cprog cprog [.] sw_4_2 cprog [.] callme
2.42% cprog cprog [.] callme cprog [.] sw_4_2
2.40% cprog cprog [.] sw_3_1_3 cprog [.] sw_3_1
2.40% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_3
2.39% cprog cprog [.] hw_1_2 cprog [.] symbol2
2.39% cprog cprog [.] back1 cprog [.] callme
2.39% cprog cprog [.] sw_3_1_1 cprog [.] sw_3_1
2.39% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_1
2.39% cprog cprog [.] sw_3_1 cprog [.] callme
2.39% cprog cprog [.] sw_4_1 cprog [.] ctr_addr
2.39% cprog cprog [.] callme cprog [.] hw_1_2
2.39% cprog cprog [.] callme cprog [.] sw_3_1
2.39% cprog cprog [.] sw_3_1_2 cprog [.] sw_3_1
2.39% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_2
2.38% cprog cprog [.] hw_1_1 cprog [.] symbol1
2.38% cprog cprog [.] callme cprog [.] hw_1_1
1.78% cprog cprog [.] back2 cprog [.] callme
1.78% cprog cprog [.] hw_1_1 cprog [.] callme
1.76% cprog cprog [.] success_3_1_2 cprog [.] sw_3_1
1.76% cprog cprog [.] sw_3_1 cprog [.] success_3_1_2
1.76% cprog cprog [.] sw_3_2 cprog [.] callme
1.76% cprog cprog [.] callme cprog [.] sw_3_2
1.73% cprog cprog [.] success_3_1_1 cprog [.] sw_3_1
1.73% cprog cprog [.] sw_3_1 cprog [.] success_3_1_1
1.73% cprog cprog [.] hw_1_2 cprog [.] callme
1.71% cprog cprog [.] sw_3_1 cprog [.] success_3_1_3
1.71% cprog cprog [.] sw_4_1 cprog [.] callme
1.71% cprog cprog [.] callme cprog [.] main
0.05% cprog [unknown] [k] 00000000 cprog [k] callme
0.03% cprog [unknown] [.] 0xf7aa9d4c [unknown] [.] 0xf7aa5f80
0.01% cprog libc-2.11.2.so [.] __errno_location libc-2.11.2.so [.] vfprintf
0.01% cprog libc-2.11.2.so [.] vfprintf libc-2.11.2.so [.] __errno_location
0.01% cprog libc-2.11.2.so [.] _IO_doallocbuf libc-2.11.2.so [.] _IO_file_overflow
0.01% cprog cprog [.] __do_global_dtors_aux [unknown] [.] 0xf7a9fc74
0.01% cprog [unknown] [.] 0xf7a9fca4 cprog [.] _fini (6) perf record -j any_call,ind_call -e branch-misses:u ./cprog
# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol
# ........ ....... .................... ...................... .................... ......................
#
17.38% cprog [unknown] [.] 00000000 cprog [.] sw_3_1
7.76% cprog cprog [.] sw_4_2 cprog [.] lr_addr
7.64% cprog [unknown] [.] 00000000 cprog [.] callme
6.00% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_1
6.00% cprog cprog [.] callme cprog [.] sw_3_1
5.98% cprog cprog [.] sw_4_1 cprog [.] ctr_addr
5.97% cprog cprog [.] hw_1_1 cprog [.] symbol1
5.97% cprog cprog [.] hw_1_2 cprog [.] symbol2
5.97% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_3
5.97% cprog cprog [.] callme cprog [.] hw_1_1
5.97% cprog cprog [.] callme cprog [.] hw_1_2
5.96% cprog cprog [.] callme cprog [.] sw_4_2
5.95% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_2
1.83% cprog cprog [.] sw_3_1 cprog [.] success_3_1_2
1.82% cprog cprog [.] sw_3_1 cprog [.] success_3_1_1
1.82% cprog cprog [.] sw_3_1 cprog [.] success_3_1_3
1.82% cprog cprog [.] callme cprog [.] sw_3_2
0.14% cprog [unknown] [k] 00000000 cprog [k] callme
0.01% cprog libc-2.11.2.so [.] vfprintf libc-2.11.2.so [.] strchrnul
0.01% cprog libc-2.11.2.so [.] _IO_file_xsputn libc-2.11.2.so [.] _IO_default_xsputn
0.01% cprog libc-2.11.2.so [.] _IO_default_xsputn libc-2.11.2.so [.] _IO_file_overflow
0.01% cprog ld-2.11.2.so [.] calloc [unknown] [.] 0xf795b390
0.01% cprog [unknown] [.] 0x0fee00fc libc-2.11.2.so [.] _IO_file_overflow
0.01% cprog [unknown] [.] 00000000 ld-2.11.2.so [.] calloc
0.01% cprog [unknown] [.] 0xf794b41c [unknown] [.] 0xf794ab70 (7) perf record -j cond,any_ret -e branch-misses:u ./cprog
# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol
# ........ ....... .................... ...................... .................... ......................
#
12.43% cprog [unknown] [.] 00000000 cprog [.] sw_3_1
4.91% cprog cprog [.] lr_addr cprog [.] sw_4_2
4.89% cprog [unknown] [.] 00000000 cprog [.] callme
4.87% cprog cprog [.] sw_4_2 cprog [.] lr_addr
4.87% cprog cprog [.] symbol1 cprog [.] hw_1_1
4.19% cprog cprog [.] hw_2_2 cprog [.] address2
4.19% cprog cprog [.] back2 cprog [.] callme
4.19% cprog cprog [.] sw_3_2 cprog [.] callme
4.18% cprog cprog [.] hw_1_1 cprog [.] callme
4.18% cprog cprog [.] success_3_1_2 cprog [.] sw_3_1
4.18% cprog cprog [.] sw_3_1 cprog [.] success_3_1_2
4.16% cprog cprog [.] sw_4_2 cprog [.] callme
4.13% cprog cprog [.] ctr_addr cprog [.] sw_4_1
4.12% cprog cprog [.] symbol2 cprog [.] hw_1_2
4.12% cprog cprog [.] success_3_1_3 cprog [.] sw_3_1
3.43% cprog cprog [.] callme cprog [.] main
3.42% cprog cprog [.] sw_3_1 cprog [.] success_3_1_3
3.41% cprog cprog [.] success_3_1_1 cprog [.] sw_3_1
3.41% cprog cprog [.] sw_3_1 cprog [.] success_3_1_1
3.41% cprog cprog [.] sw_4_1 cprog [.] callme
3.40% cprog cprog [.] hw_1_2 cprog [.] callme
0.73% cprog cprog [.] sw_3_1_3 cprog [.] sw_3_1
0.73% cprog cprog [.] sw_4_1 cprog [.] ctr_addr
0.72% cprog cprog [.] hw_1_2 cprog [.] symbol2
0.72% cprog cprog [.] sw_3_1_1 cprog [.] sw_3_1
0.70% cprog cprog [.] hw_2_1 cprog [.] address1
0.70% cprog cprog [.] back1 cprog [.] callme
0.70% cprog cprog [.] sw_3_1_2 cprog [.] sw_3_1
0.70% cprog cprog [.] sw_3_1 cprog [.] callme
0.19% cprog [unknown] [.] 0xf7c12328 [unknown] [.] 0xf7c12320
0.01% cprog libc-2.11.2.so [.] __errno_location libc-2.11.2.so [.] vfprintf
0.01% cprog libc-2.11.2.so [.] vfprintf libc-2.11.2.so [.] vfprintf
0.01% cprog libc-2.11.2.so [.] _IO_file_overflow [unknown] [.] 0x0fee0100
0.01% cprog libc-2.11.2.so [.] _IO_default_xsputn libc-2.11.2.so [.] _IO_default_xsputn
0.01% cprog [unknown] [.] 00000000 libc-2.11.2.so [.] _IO_file_overflow (8) perf record -j cond,ind_call -e branch-misses:u ./cprog
# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol
# ........ ....... .................... .............. .................... .................
#
20.70% cprog [unknown] [.] 00000000 cprog [.] sw_3_1
9.99% cprog cprog [.] sw_4_2 cprog [.] lr_addr
9.91% cprog [unknown] [.] 00000000 cprog [.] callme
9.45% cprog cprog [.] sw_3_1_3 cprog [.] sw_3_1
9.44% cprog cprog [.] hw_2_1 cprog [.] address1
9.43% cprog cprog [.] sw_3_1_1 cprog [.] sw_3_1
9.42% cprog cprog [.] hw_1_2 cprog [.] symbol2
9.42% cprog cprog [.] sw_3_1_2 cprog [.] sw_3_1
9.42% cprog cprog [.] sw_4_1 cprog [.] ctr_addr
0.65% cprog cprog [.] sw_3_1 cprog [.] success_3_1_1
0.62% cprog cprog [.] sw_3_1 cprog [.] success_3_1_3
0.56% cprog cprog [.] hw_2_2 cprog [.] address2
0.55% cprog cprog [.] sw_3_1 cprog [.] success_3_1_2
0.29% cprog [unknown] [.] 0xf7f72328 [unknown] [.] 0xf7f72320
0.10% cprog [unknown] [k] 00000000 cprog [k] callme
0.02% cprog libc-2.11.2.so [.] _IO_setb libc-2.11.2.so [.] _IO_setb (9) perf record -e branch-misses:u -j any_call,any_ret,ind_call,cond ./cprog
# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol
# ........ ....... .................... .................. .................... .......................
#
9.31% cprog [unknown] [.] 00000000 cprog [.] sw_3_1
4.04% cprog cprog [.] symbol1 cprog [.] hw_1_1
4.03% cprog cprog [.] lr_addr cprog [.] sw_4_2
4.03% cprog cprog [.] sw_4_2 cprog [.] lr_addr
4.00% cprog [unknown] [.] 00000000 cprog [.] callme
3.88% cprog cprog [.] ctr_addr cprog [.] sw_4_1
3.87% cprog cprog [.] sw_4_2 cprog [.] callme
3.86% cprog cprog [.] symbol2 cprog [.] hw_1_2
3.86% cprog cprog [.] success_3_1_3 cprog [.] sw_3_1
2.49% cprog cprog [.] sw_4_1 cprog [.] ctr_addr
2.47% cprog cprog [.] hw_1_1 cprog [.] symbol1
2.47% cprog cprog [.] sw_3_1_1 cprog [.] sw_3_1
2.47% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_1
2.47% cprog cprog [.] callme cprog [.] hw_1_1
2.47% cprog cprog [.] callme cprog [.] sw_3_1
2.47% cprog cprog [.] hw_1_2 cprog [.] symbol2
2.47% cprog cprog [.] hw_2_1 cprog [.] address1
2.47% cprog cprog [.] back1 cprog [.] callme
2.47% cprog cprog [.] sw_3_1_3 cprog [.] sw_3_1
2.47% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_3
2.47% cprog cprog [.] sw_3_1 cprog [.] callme
2.47% cprog cprog [.] callme cprog [.] hw_1_2
2.47% cprog cprog [.] callme cprog [.] sw_4_2
2.46% cprog cprog [.] sw_3_1_2 cprog [.] sw_3_1
2.46% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_2
1.57% cprog cprog [.] success_3_1_2 cprog [.] sw_3_1
1.57% cprog cprog [.] sw_3_1 cprog [.] success_3_1_2
1.57% cprog cprog [.] hw_1_1 cprog [.] callme
1.56% cprog cprog [.] hw_2_2 cprog [.] address2
1.56% cprog cprog [.] back2 cprog [.] callme
1.56% cprog cprog [.] sw_3_2 cprog [.] callme
1.56% cprog cprog [.] callme cprog [.] sw_3_2
1.41% cprog cprog [.] success_3_1_1 cprog [.] sw_3_1
1.41% cprog cprog [.] sw_3_1 cprog [.] success_3_1_1
1.40% cprog cprog [.] sw_4_1 cprog [.] callme
1.39% cprog cprog [.] hw_1_2 cprog [.] callme
1.39% cprog cprog [.] sw_3_1 cprog [.] success_3_1_3
1.39% cprog cprog [.] callme cprog [.] main
0.14% cprog [unknown] [.] 0xf7d72328 [unknown] [.] 0xf7d72320
0.03% cprog [unknown] [k] 00000000 cprog [k] callme
0.01% cprog libc-2.11.2.so [.] _IO_doallocbuf libc-2.11.2.so [.] _IO_doallocbuf
0.01% cprog libc-2.11.2.so [.] printf cprog [.] main
0.01% cprog libc-2.11.2.so [.] _IO_doallocbuf libc-2.11.2.so [.] _IO_file_doallocate
0.01% cprog ld-2.11.2.so [.] malloc [unknown] [.] 0xf7d8b380
0.01% cprog cprog [.] main [unknown] [.] 0x0fe7f63c
0.01% cprog [unknown] [.] 0xf7d8b388 ld-2.11.2.so [.] __libc_memalign
0.01% cprog [unknown] [.] 00000000 ld-2.11.2.so [.] malloc Please refer to the V4 version of the patchset to learn about the sample test case and it's makefile.
Anshuman Khandual (11):
perf: Add PERF_SAMPLE_BRANCH_COND
perf, tool: Conditional branch filter 'cond' added to perf record x86, perf: Add conditional branch filtering support
perf, documentation: Description for conditional branch filter powerpc, perf: Re-arrange BHRB processing
powerpc, perf: Re-arrange PMU based branch filter processing in POWER8 powerpc, perf: Change the name of HW PMU branch filter tracking variable powerpc, lib: Add new branch analysis support functions powerpc, perf: Enable SW filtering in branch stack sampling framework power8, perf: Adapt BHRB PMU configuration to work with SW filters powerpc, perf: Enable privilege mode SW branch filters
arch/powerpc/include/asm/code-patching.h | 16 ++ arch/powerpc/include/asm/perf_event_server.h | 6 +- arch/powerpc/lib/code-patching.c | 80 +++++++ arch/powerpc/perf/core-book3s.c | 323 ++++++++++++++++++++++----- arch/powerpc/perf/power8-pmu.c | 70 ++++-- arch/x86/kernel/cpu/perf_event_intel_lbr.c | 5 + include/uapi/linux/perf_event.h | 3 +- tools/perf/Documentation/perf-record.txt | 3 +- tools/perf/builtin-record.c | 1 + 9 files changed, 429 insertions(+), 78 deletions(-)
Signature · 6 lines
1.7.11.7 _______________________________________________ Linuxppc-dev mailing list [email protected] https://lists.ozlabs.org/listinfo/linuxppc-dev
Peter Zijlstra
maintainerQuoted 7 lines · Anshuman Khandual
Hello Peter/Ingo,
Would you please consider reviewing the first four patches in this patch series which changes the generic perf kernel and perf tools code. Andi Kleen and Stephane Eranian have already reviewed these changes. The rest of the patch series is related to powerpc and being reviewed by Michael Ellerman/Ben.
If they land in my inbox I might have a look.
Quoted 11 lines · Peter Zijlstra
Quoted 7 lines · Anshuman Khandual
Hello Peter/Ingo,
Would you please consider reviewing the first four patches in this patch series which changes the generic perf kernel and perf tools code. Andi Kleen and Stephane Eranian have already reviewed these changes. The rest of the patch series is related to powerpc and being reviewed by Michael Ellerman/Ben.
If they land in my inbox I might have a look.
Sent.
Peter Zijlstra
maintainerQuoted 10 lines · Anshuman Khandual
Quoted 9 lines · Peter Zijlstra
Quoted 7 lines · Anshuman Khandual
Hello Peter/Ingo,
Would you please consider reviewing the first four patches in this patch series which changes the generic perf kernel and perf tools code. Andi Kleen and Stephane Eranian have already reviewed these changes. The rest of the patch series is related to powerpc and being reviewed by Michael Ellerman/Ben.
Quoted 4 lines
Quoted 2 lines
If they land in my inbox I might have a look.
Sent.
Thanks, they look fine to me, although 1/x can use a lightly longer changelog, making it explicit its a filter for conditional branches.
How do people want this routed? Should I take all patches through tip, or do I ask Ingo to create a special perf/cond branch which includes the first 4 patches which can be merged into whatever ppc branch and the rest then go on top in the ppc tree?
Quoted 16 lines · Peter Zijlstra
Quoted 10 lines · Anshuman Khandual
Quoted 9 lines · Peter Zijlstra
Quoted 7 lines · Anshuman Khandual
Hello Peter/Ingo,
Would you please consider reviewing the first four patches in this patch series which changes the generic perf kernel and perf tools code. Andi Kleen and Stephane Eranian have already reviewed these changes. The rest of the patch series is related to powerpc and being reviewed by Michael Ellerman/Ben.
Quoted 4 lines
Quoted 2 lines
If they land in my inbox I might have a look.
Sent.
Quoted 8 lines
Thanks, they look fine to me, although 1/x can use a lightly longer changelog, making it explicit its a filter for conditional branches.
How do people want this routed? Should I take all patches through tip, or do I ask Ingo to create a special perf/cond branch which includes the first 4 patches which can be merged into whatever ppc branch and the rest then go on top in the ppc tree?
Peter,
Thanks for considering the patchset.
Michael Ellerman
reviewerQuoted 16 lines · Peter Zijlstra
Quoted 10 lines · Anshuman Khandual
Quoted 9 lines · Peter Zijlstra
Quoted 7 lines · Anshuman Khandual
Hello Peter/Ingo,
Would you please consider reviewing the first four patches in this patch series which changes the generic perf kernel and perf tools code. Andi Kleen and Stephane Eranian have already reviewed these changes. The rest of the patch series is related to powerpc and being reviewed by Michael Ellerman/Ben.
Quoted 4 lines
Quoted 2 lines
If they land in my inbox I might have a look.
Sent.
Quoted 7 lines
Thanks, they look fine to me, although 1/x can use a lightly longer changelog, making it explicit its a filter for conditional branches.
How do people want this routed? Should I take all patches through tip, or do I ask Ingo to create a special perf/cond branch which includes the first 4 patches which can be merged into whatever ppc branch and the rest then go on top in the ppc tree?
Hi Peter,
Can you take just the first 4 in your tree please. I asked Anshuman to just send those 4 but he & I seem to have miscommunicated on that.
We only depend on patch 1 in order for the powerpc parts to build, so I think we'll just merge that into the powerpc tree and it should merge fine when it hits next.
cheers
Peter Zijlstra
maintainerQuoted 7 lines · Michael Ellerman
Can you take just the first 4 in your tree please. I asked Anshuman to just send those 4 but he & I seem to have miscommunicated on that.
We only depend on patch 1 in order for the powerpc parts to build, so I think we'll just merge that into the powerpc tree and it should merge fine when it hits next.
OK, will do. Thanks!
Hi,
Quoted 8 lines · Anshuman Khandual
This patchset is the re-spin of the original branch stack sampling
patchset which introduced newPERF_SAMPLE_BRANCH_CONDbranch filter. This patchset also enables SW based branch filtering support for book3s powerpc platforms which have PMU HW backed branch stack sampling support.Summary of code changes in this patchset:
Quoted 9 lines
(1) Introduces a new
PERF_SAMPLE_BRANCH_CONDbranch filter
(2) Add the "cond" branch filter options in the "perf record" tool
(3) EnablePERF_SAMPLE_BRANCH_CONDin X86 platforms
(4) EnablePERF_SAMPLE_BRANCH_CONDin POWER8 platform
(5) Update the documentation regarding "perf record" tool
(6) Add some new powerpc instruction analysis functions in code-patching library
(7) Enable SW based branch filter support for powerpc book3s
(8) Changed BHRB configuration in POWER8 to accommodate SW branch filters
I have been looking at those patches and ran some tests. And I found a few issues so far.
I am running:
$ perf record -j any_ret -e cycles:u test_program $ perf report -D
Most entries are okay and match the filter, however some do not make sense:
3642586996762 0x15d0 [0x108]: PERF_RECORD_SAMPLE(IP, 2): 17921/17921:0x10001170 period: 613678 addr: 0
.... branch stack: nr:9
..... 0: 00000000100011cc -> 0000000010000e38 ..... 1: 0000000010001150 -> 00000000100011bc ..... 2: 0000000010001208 -> 0000000010000e38 ..... 3: 0000000010001160 -> 00000000100011f8 ..... 4: 00000000100011cc -> 0000000010000e38 ..... 5: 0000000010001150 -> 00000000100011bc ..... 6: 0000000010001208 -> 0000000010000e38 ..... 7: 0000000010001160 -> 00000000100011f8 ..... 8: 0000000000000000 -> 0000000010001160
^^^^^^
Entry 8 does not make sense, unless 0x0 is a valid return branch instruction address.
If an address is invalid, the whole entry needs to be eliminated. It is okay to have
less than the max number of entries supported by HW.
I also had cases where monitoring only at the user level, got me branch addresses in the0xc0000000...... range. My test program is linked statically.
when eliminating the bogus entries, my tests yielded only return branch instruction addresses
which is good. Will run more tests.
Quoted 391 lines
With this new SW enablement, the branch filter support for book3s platforms have been extended to include all these combinations discussed below with a sample test application program (included here).
Changes in V2
=============
(1) Enabled PPC64 SW branch filtering support
(2) Incorporated changes required for all previous commentsChanges in V3
=============
(1) Split the SW branch filter enablement into multiple patches
(2) Added PMU neutral SW branch filtering code, PMU specific HW branch filtering code
(3) Added new instruction analysis functionality into powerpc code-patching library
(4) Changed name for some of the functions
(5) Fixed couple of spelling mistakes
(6) Changed code documentation in multiple placesChanges in V4
=============
(1) Changed the commit message for patch (01/10)
(2) Changed the patch (02/10) to accommodate review comments from Michael Ellerman
(3) Rebased the patchset against latest Linus's treeChanges in V5
=============
(1) Added a precursor patch to cleanup the indentation problem inpower_pmu_bhrb_read
(2) Added a precursor patch to re-arrange P8 PMU BHRB filter config which improved the clarity
(3) Merged the previous 10th patch into the 8th patch
(4) Moved SW based branch analysis code from core perf into code-patching library as suggested by Michael
(5) Simplified the logic in branch analysis library
(6) Fixed some ambiguities in documentation at various places
(7) Added some more in-code documentation blocks at various places
(8) Renamed some local variable and function names
(9) Fixed some indentation and white space errors in the code
(10) Implemented almost all the review comments and suggestions made by Michael Ellerman on V4 patchset
(11) Enabled privilege mode SW branch filter
(12) Simplified and generalized the SW implemented conditional branch filter
(13)PERF_SAMPLE_BRANCH_CONDfilter is now supported only through SW implementation
(14) Adjusted other patches to deal with the above changesChanges in V6
=============
(1) Rebased the patchset against the master
(2) Added "Reviewed-by: Andi Kleen" in the first four patches in the series which changes thegeneric or X86 perf code. [https://lkml.org/lkml/2014/4/7/130]HW implemented branch filters
=============================(1) perf record -j
any_call-e branch-misses:u ./cprog# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol # ........ ....... .................... ....................... .................... .................... # 7.85% cprog cprog [.] sw_3_1 cprog [.] success_3_1_2 5.66% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_2 5.65% cprog cprog [.] hw_1_1 cprog [.] symbol1 5.42% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_3 5.40% cprog cprog [.] callme cprog [.] hw_1_1 5.40% cprog cprog [.] sw_3_1 cprog [.] success_3_1_1 5.40% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_1 5.39% cprog cprog [.] sw_4_2 cprog [.] lr_addr 5.39% cprog cprog [.] callme cprog [.] sw_4_2 5.39% cprog [unknown] [.] 00000000 cprog [.] ctr_addr 5.38% cprog cprog [.] hw_1_2 cprog [.] symbol2 5.38% cprog cprog [.] callme cprog [.] hw_1_2 5.16% cprog cprog [.] sw_3_1 cprog [.] success_3_1_3 5.15% cprog cprog [.] callme cprog [.] sw_3_2 5.14% cprog cprog [.] callme cprog [.] hw_2_2 2.96% cprog cprog [.] callme cprog [.] sw_3_1 2.94% cprog cprog [.] callme cprog [.] hw_2_1 2.71% cprog cprog [.] main cprog [.] callme 2.71% cprog [unknown] [.] 00000000 cprog [.] lr_addr 2.70% cprog cprog [.] sw_4_1 cprog [.] ctr_addr 2.70% cprog cprog [.] callme cprog [.] sw_4_1 0.09% cprog [unknown] [.] 0xf7ad76c4 [unknown] [.] 0xf7ac22c0 0.00% cprog libc-2.11.2.so [.] vfprintf libc-2.11.2.so [.] __errno_location 0.00% cprog libc-2.11.2.so [.] printf libc-2.11.2.so [.] vfprintf 0.00% cprog libc-2.11.2.so [.] _IO_file_doallocate libc-2.11.2.so [.] isatty 0.00% cprog libc-2.11.2.so [.] _IO_file_doallocate libc-2.11.2.so [.] mmap 0.00% cprog libc-2.11.2.so [.] isatty libc-2.11.2.so [.] tcgetattr 0.00% cprog cprog [.] main [unknown] [.] 0x10000950 0.00% cprog [unknown] [.] 00000000 libc-2.11.2.so [.] _IO_file_stat 0.00% cprog [unknown] [.] 0xf7acfca4 cprog [.] _fini 0.00% cprog [unknown] [k] 00000000 cprog [k] ctr_addr 0.00% cprog [unknown] [k] 00000000 cprog [k] lr_addrSW implemented branch filters
=============================(2) perf record -j cond -e branch-misses:u ./cprog
# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol # ........ ....... .................... ...................... .................... ...................... # 25.82% cprog [unknown] [.] 00000000 cprog [.] sw_3_1 12.66% cprog cprog [.] sw_4_2 cprog [.] lr_addr 12.63% cprog [unknown] [.] 00000000 cprog [.] callme 9.42% cprog cprog [.] hw_2_2 cprog [.] address2 9.39% cprog cprog [.] sw_3_1 cprog [.] success_3_1_2 4.91% cprog cprog [.] sw_3_1 cprog [.] success_3_1_1 4.91% cprog cprog [.] sw_3_1 cprog [.] success_3_1_3 3.35% cprog cprog [.] sw_3_1_3 cprog [.] sw_3_1 3.34% cprog cprog [.] sw_3_1_1 cprog [.] sw_3_1 3.31% cprog cprog [.] hw_1_2 cprog [.] symbol2 3.31% cprog cprog [.] sw_4_1 cprog [.] ctr_addr 3.29% cprog cprog [.] hw_2_1 cprog [.] address1 3.27% cprog cprog [.] sw_3_1_2 cprog [.] sw_3_1 0.32% cprog [unknown] [.] 0xf7c62328 [unknown] [.] 0xf7c62320 0.01% cprog libc-2.11.2.so [.] vfprintf libc-2.11.2.so [.] vfprintf 0.01% cprog libc-2.11.2.so [.] _IO_file_xsputn libc-2.11.2.so [.] _IO_file_xsputn 0.01% cprog libc-2.11.2.so [.] _IO_default_xsputn libc-2.11.2.so [.] _IO_default_xsputn 0.01% cprog libc-2.11.2.so [.] strchrnul libc-2.11.2.so [.] strchrnul 0.01% cprog [unknown] [.] 00000000 libc-2.11.2.so [.] _IO_file_xsputn 0.01% cprog [unknown] [k] 00000000 cprog [k] callme(3) perf record -j
any_ret-e branch-misses:u ./cprog# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol # ........ ....... .................... ..................... .................... ..................... # 15.61% cprog [unknown] [.] 00000000 cprog [.] sw_3_1 6.28% cprog cprog [.] symbol2 cprog [.] hw_1_2 6.28% cprog cprog [.] ctr_addr cprog [.] sw_4_1 6.26% cprog cprog [.] success_3_1_3 cprog [.] sw_3_1 6.24% cprog cprog [.] symbol1 cprog [.] hw_1_1 6.24% cprog cprog [.] sw_4_2 cprog [.] callme 6.21% cprog [unknown] [.] 00000000 cprog [.] callme 6.19% cprog cprog [.] lr_addr cprog [.] sw_4_2 3.16% cprog cprog [.] hw_1_2 cprog [.] callme 3.15% cprog cprog [.] success_3_1_1 cprog [.] sw_3_1 3.15% cprog cprog [.] sw_4_1 cprog [.] callme 3.14% cprog cprog [.] callme cprog [.] main 3.13% cprog cprog [.] hw_1_1 cprog [.] callme 3.13% cprog cprog [.] sw_3_1_1 cprog [.] sw_3_1 3.12% cprog cprog [.] back2 cprog [.] callme 3.12% cprog cprog [.] sw_3_1 cprog [.] callme 3.11% cprog cprog [.] back1 cprog [.] callme 3.11% cprog cprog [.] sw_3_1_2 cprog [.] sw_3_1 3.11% cprog cprog [.] sw_3_1_3 cprog [.] sw_3_1 3.10% cprog cprog [.] sw_3_2 cprog [.] callme 3.09% cprog cprog [.] success_3_1_2 cprog [.] sw_3_1 0.03% cprog [unknown] [.] 0x100009b0 [unknown] [.] 0xf7d5581c 0.01% cprog libc-2.11.2.so [.] _IO_file_overflow libc-2.11.2.so [.] _IO_file_xsputn 0.01% cprog libc-2.11.2.so [.] _IO_file_setbuf [unknown] [.] 0x0fee1084 0.01% cprog [unknown] [.] 0xf7d5589c libc-2.11.2.so [.] printf 0.01% cprog [unknown] [.] 00000000 libc-2.11.2.so [.] _IO_file_overflow 0.01% cprog [unknown] [.] 00000000 libc-2.11.2.so [.] _IO_file_setbuf 0.01% cprog [unknown] [k] 00000000 cprog [k] callme(4) perf record -j
ind_call-e branch-misses:u ./cprog# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol # ........ ....... .................... .............. .................... ..................... # 42.59% cprog [unknown] [.] 00000000 cprog [.] sw_3_1 25.88% cprog cprog [.] sw_4_2 cprog [.] lr_addr 25.65% cprog [unknown] [.] 00000000 cprog [.] callme 5.58% cprog cprog [.] sw_4_1 cprog [.] ctr_addr 0.23% cprog [unknown] [k] 00000000 cprog [k] callme 0.05% cprog [unknown] [.] 00000000 [unknown] [.] 0xf79fd740 0.03% cprog [unknown] [.] 00000000 libc-2.11.2.so [.] _IO_file_overflow(5) perf record -j any_call,any_ret -e branch-misses:u ./cprog
# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol # ........ ....... .................... ......................... .................... ..................... # 10.00% cprog [unknown] [.] 00000000 cprog [.] sw_3_1 4.20% cprog cprog [.] sw_4_2 cprog [.] lr_addr 4.17% cprog cprog [.] lr_addr cprog [.] sw_4_2 4.16% cprog cprog [.] symbol1 cprog [.] hw_1_1 4.12% cprog [unknown] [.] 00000000 cprog [.] callme 4.12% cprog cprog [.] symbol2 cprog [.] hw_1_2 4.11% cprog cprog [.] success_3_1_3 cprog [.] sw_3_1 4.11% cprog cprog [.] ctr_addr cprog [.] sw_4_1 4.10% cprog cprog [.] sw_4_2 cprog [.] callme 2.42% cprog cprog [.] callme cprog [.] sw_4_2 2.40% cprog cprog [.] sw_3_1_3 cprog [.] sw_3_1 2.40% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_3 2.39% cprog cprog [.] hw_1_2 cprog [.] symbol2 2.39% cprog cprog [.] back1 cprog [.] callme 2.39% cprog cprog [.] sw_3_1_1 cprog [.] sw_3_1 2.39% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_1 2.39% cprog cprog [.] sw_3_1 cprog [.] callme 2.39% cprog cprog [.] sw_4_1 cprog [.] ctr_addr 2.39% cprog cprog [.] callme cprog [.] hw_1_2 2.39% cprog cprog [.] callme cprog [.] sw_3_1 2.39% cprog cprog [.] sw_3_1_2 cprog [.] sw_3_1 2.39% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_2 2.38% cprog cprog [.] hw_1_1 cprog [.] symbol1 2.38% cprog cprog [.] callme cprog [.] hw_1_1 1.78% cprog cprog [.] back2 cprog [.] callme 1.78% cprog cprog [.] hw_1_1 cprog [.] callme 1.76% cprog cprog [.] success_3_1_2 cprog [.] sw_3_1 1.76% cprog cprog [.] sw_3_1 cprog [.] success_3_1_2 1.76% cprog cprog [.] sw_3_2 cprog [.] callme 1.76% cprog cprog [.] callme cprog [.] sw_3_2 1.73% cprog cprog [.] success_3_1_1 cprog [.] sw_3_1 1.73% cprog cprog [.] sw_3_1 cprog [.] success_3_1_1 1.73% cprog cprog [.] hw_1_2 cprog [.] callme 1.71% cprog cprog [.] sw_3_1 cprog [.] success_3_1_3 1.71% cprog cprog [.] sw_4_1 cprog [.] callme 1.71% cprog cprog [.] callme cprog [.] main 0.05% cprog [unknown] [k] 00000000 cprog [k] callme 0.03% cprog [unknown] [.] 0xf7aa9d4c [unknown] [.] 0xf7aa5f80 0.01% cprog libc-2.11.2.so [.] __errno_location libc-2.11.2.so [.] vfprintf 0.01% cprog libc-2.11.2.so [.] vfprintf libc-2.11.2.so [.] __errno_location 0.01% cprog libc-2.11.2.so [.] _IO_doallocbuf libc-2.11.2.so [.] _IO_file_overflow 0.01% cprog cprog [.] __do_global_dtors_aux [unknown] [.] 0xf7a9fc74 0.01% cprog [unknown] [.] 0xf7a9fca4 cprog [.] _fini(6) perf record -j any_call,ind_call -e branch-misses:u ./cprog
# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol # ........ ....... .................... ...................... .................... ...................... # 17.38% cprog [unknown] [.] 00000000 cprog [.] sw_3_1 7.76% cprog cprog [.] sw_4_2 cprog [.] lr_addr 7.64% cprog [unknown] [.] 00000000 cprog [.] callme 6.00% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_1 6.00% cprog cprog [.] callme cprog [.] sw_3_1 5.98% cprog cprog [.] sw_4_1 cprog [.] ctr_addr 5.97% cprog cprog [.] hw_1_1 cprog [.] symbol1 5.97% cprog cprog [.] hw_1_2 cprog [.] symbol2 5.97% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_3 5.97% cprog cprog [.] callme cprog [.] hw_1_1 5.97% cprog cprog [.] callme cprog [.] hw_1_2 5.96% cprog cprog [.] callme cprog [.] sw_4_2 5.95% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_2 1.83% cprog cprog [.] sw_3_1 cprog [.] success_3_1_2 1.82% cprog cprog [.] sw_3_1 cprog [.] success_3_1_1 1.82% cprog cprog [.] sw_3_1 cprog [.] success_3_1_3 1.82% cprog cprog [.] callme cprog [.] sw_3_2 0.14% cprog [unknown] [k] 00000000 cprog [k] callme 0.01% cprog libc-2.11.2.so [.] vfprintf libc-2.11.2.so [.] strchrnul 0.01% cprog libc-2.11.2.so [.] _IO_file_xsputn libc-2.11.2.so [.] _IO_default_xsputn 0.01% cprog libc-2.11.2.so [.] _IO_default_xsputn libc-2.11.2.so [.] _IO_file_overflow 0.01% cprog ld-2.11.2.so [.] calloc [unknown] [.] 0xf795b390 0.01% cprog [unknown] [.] 0x0fee00fc libc-2.11.2.so [.] _IO_file_overflow 0.01% cprog [unknown] [.] 00000000 ld-2.11.2.so [.] calloc 0.01% cprog [unknown] [.] 0xf794b41c [unknown] [.] 0xf794ab70(7) perf record -j cond,any_ret -e branch-misses:u ./cprog
# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol # ........ ....... .................... ...................... .................... ...................... # 12.43% cprog [unknown] [.] 00000000 cprog [.] sw_3_1 4.91% cprog cprog [.] lr_addr cprog [.] sw_4_2 4.89% cprog [unknown] [.] 00000000 cprog [.] callme 4.87% cprog cprog [.] sw_4_2 cprog [.] lr_addr 4.87% cprog cprog [.] symbol1 cprog [.] hw_1_1 4.19% cprog cprog [.] hw_2_2 cprog [.] address2 4.19% cprog cprog [.] back2 cprog [.] callme 4.19% cprog cprog [.] sw_3_2 cprog [.] callme 4.18% cprog cprog [.] hw_1_1 cprog [.] callme 4.18% cprog cprog [.] success_3_1_2 cprog [.] sw_3_1 4.18% cprog cprog [.] sw_3_1 cprog [.] success_3_1_2 4.16% cprog cprog [.] sw_4_2 cprog [.] callme 4.13% cprog cprog [.] ctr_addr cprog [.] sw_4_1 4.12% cprog cprog [.] symbol2 cprog [.] hw_1_2 4.12% cprog cprog [.] success_3_1_3 cprog [.] sw_3_1 3.43% cprog cprog [.] callme cprog [.] main 3.42% cprog cprog [.] sw_3_1 cprog [.] success_3_1_3 3.41% cprog cprog [.] success_3_1_1 cprog [.] sw_3_1 3.41% cprog cprog [.] sw_3_1 cprog [.] success_3_1_1 3.41% cprog cprog [.] sw_4_1 cprog [.] callme 3.40% cprog cprog [.] hw_1_2 cprog [.] callme 0.73% cprog cprog [.] sw_3_1_3 cprog [.] sw_3_1 0.73% cprog cprog [.] sw_4_1 cprog [.] ctr_addr 0.72% cprog cprog [.] hw_1_2 cprog [.] symbol2 0.72% cprog cprog [.] sw_3_1_1 cprog [.] sw_3_1 0.70% cprog cprog [.] hw_2_1 cprog [.] address1 0.70% cprog cprog [.] back1 cprog [.] callme 0.70% cprog cprog [.] sw_3_1_2 cprog [.] sw_3_1 0.70% cprog cprog [.] sw_3_1 cprog [.] callme 0.19% cprog [unknown] [.] 0xf7c12328 [unknown] [.] 0xf7c12320 0.01% cprog libc-2.11.2.so [.] __errno_location libc-2.11.2.so [.] vfprintf 0.01% cprog libc-2.11.2.so [.] vfprintf libc-2.11.2.so [.] vfprintf 0.01% cprog libc-2.11.2.so [.] _IO_file_overflow [unknown] [.] 0x0fee0100 0.01% cprog libc-2.11.2.so [.] _IO_default_xsputn libc-2.11.2.so [.] _IO_default_xsputn 0.01% cprog [unknown] [.] 00000000 libc-2.11.2.so [.] _IO_file_overflow(8) perf record -j cond,ind_call -e branch-misses:u ./cprog
# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol # ........ ....... .................... .............. .................... ................. # 20.70% cprog [unknown] [.] 00000000 cprog [.] sw_3_1 9.99% cprog cprog [.] sw_4_2 cprog [.] lr_addr 9.91% cprog [unknown] [.] 00000000 cprog [.] callme 9.45% cprog cprog [.] sw_3_1_3 cprog [.] sw_3_1 9.44% cprog cprog [.] hw_2_1 cprog [.] address1 9.43% cprog cprog [.] sw_3_1_1 cprog [.] sw_3_1 9.42% cprog cprog [.] hw_1_2 cprog [.] symbol2 9.42% cprog cprog [.] sw_3_1_2 cprog [.] sw_3_1 9.42% cprog cprog [.] sw_4_1 cprog [.] ctr_addr 0.65% cprog cprog [.] sw_3_1 cprog [.] success_3_1_1 0.62% cprog cprog [.] sw_3_1 cprog [.] success_3_1_3 0.56% cprog cprog [.] hw_2_2 cprog [.] address2 0.55% cprog cprog [.] sw_3_1 cprog [.] success_3_1_2 0.29% cprog [unknown] [.] 0xf7f72328 [unknown] [.] 0xf7f72320 0.10% cprog [unknown] [k] 00000000 cprog [k] callme 0.02% cprog libc-2.11.2.so [.] _IO_setb libc-2.11.2.so [.] _IO_setb(9) perf record -e branch-misses:u -j any_call,any_ret,ind_call,cond ./cprog
# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol # ........ ....... .................... .................. .................... ....................... # 9.31% cprog [unknown] [.] 00000000 cprog [.] sw_3_1 4.04% cprog cprog [.] symbol1 cprog [.] hw_1_1 4.03% cprog cprog [.] lr_addr cprog [.] sw_4_2 4.03% cprog cprog [.] sw_4_2 cprog [.] lr_addr 4.00% cprog [unknown] [.] 00000000 cprog [.] callme 3.88% cprog cprog [.] ctr_addr cprog [.] sw_4_1 3.87% cprog cprog [.] sw_4_2 cprog [.] callme 3.86% cprog cprog [.] symbol2 cprog [.] hw_1_2 3.86% cprog cprog [.] success_3_1_3 cprog [.] sw_3_1 2.49% cprog cprog [.] sw_4_1 cprog [.] ctr_addr 2.47% cprog cprog [.] hw_1_1 cprog [.] symbol1 2.47% cprog cprog [.] sw_3_1_1 cprog [.] sw_3_1 2.47% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_1 2.47% cprog cprog [.] callme cprog [.] hw_1_1 2.47% cprog cprog [.] callme cprog [.] sw_3_1 2.47% cprog cprog [.] hw_1_2 cprog [.] symbol2 2.47% cprog cprog [.] hw_2_1 cprog [.] address1 2.47% cprog cprog [.] back1 cprog [.] callme 2.47% cprog cprog [.] sw_3_1_3 cprog [.] sw_3_1 2.47% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_3 2.47% cprog cprog [.] sw_3_1 cprog [.] callme 2.47% cprog cprog [.] callme cprog [.] hw_1_2 2.47% cprog cprog [.] callme cprog [.] sw_4_2 2.46% cprog cprog [.] sw_3_1_2 cprog [.] sw_3_1 2.46% cprog cprog [.] sw_3_1 cprog [.] sw_3_1_2 1.57% cprog cprog [.] success_3_1_2 cprog [.] sw_3_1 1.57% cprog cprog [.] sw_3_1 cprog [.] success_3_1_2 1.57% cprog cprog [.] hw_1_1 cprog [.] callme 1.56% cprog cprog [.] hw_2_2 cprog [.] address2 1.56% cprog cprog [.] back2 cprog [.] callme 1.56% cprog cprog [.] sw_3_2 cprog [.] callme 1.56% cprog cprog [.] callme cprog [.] sw_3_2 1.41% cprog cprog [.] success_3_1_1 cprog [.] sw_3_1 1.41% cprog cprog [.] sw_3_1 cprog [.] success_3_1_1 1.40% cprog cprog [.] sw_4_1 cprog [.] callme 1.39% cprog cprog [.] hw_1_2 cprog [.] callme 1.39% cprog cprog [.] sw_3_1 cprog [.] success_3_1_3 1.39% cprog cprog [.] callme cprog [.] main 0.14% cprog [unknown] [.] 0xf7d72328 [unknown] [.] 0xf7d72320 0.03% cprog [unknown] [k] 00000000 cprog [k] callme 0.01% cprog libc-2.11.2.so [.] _IO_doallocbuf libc-2.11.2.so [.] _IO_doallocbuf 0.01% cprog libc-2.11.2.so [.] printf cprog [.] main 0.01% cprog libc-2.11.2.so [.] _IO_doallocbuf libc-2.11.2.so [.] _IO_file_doallocate 0.01% cprog ld-2.11.2.so [.] malloc [unknown] [.] 0xf7d8b380 0.01% cprog cprog [.] main [unknown] [.] 0x0fe7f63c 0.01% cprog [unknown] [.] 0xf7d8b388 ld-2.11.2.so [.] __libc_memalign 0.01% cprog [unknown] [.] 00000000 ld-2.11.2.so [.] mallocPlease refer to the V4 version of the patchset to learn about the sample test case and it's makefile.
Anshuman Khandual (11):
perf: AddPERF_SAMPLE_BRANCH_COND
perf, tool: Conditional branch filter 'cond' added to perf record x86, perf: Add conditional branch filtering support
perf, documentation: Description for conditional branch filter powerpc, perf: Re-arrange BHRB processing
powerpc, perf: Re-arrange PMU based branch filter processing in POWER8 powerpc, perf: Change the name of HW PMU branch filter tracking variable powerpc, lib: Add new branch analysis support functions powerpc, perf: Enable SW filtering in branch stack sampling framework power8, perf: Adapt BHRB PMU configuration to work with SW filters powerpc, perf: Enable privilege mode SW branch filtersarch/powerpc/include/asm/code-patching.h | 16 ++ arch/powerpc/include/asm/perf_event_server.h | 6 +- arch/powerpc/lib/code-patching.c | 80 +++++++ arch/powerpc/perf/core-book3s.c | 323 ++++++++++++++++++++++----- arch/powerpc/perf/power8-pmu.c | 70 ++++-- arch/x86/kernel/cpu/perf_event_intel_lbr.c | 5 + include/uapi/linux/perf_event.h | 3 +- tools/perf/Documentation/perf-record.txt | 3 +- tools/perf/builtin-record.c | 1 + 9 files changed, 429 insertions(+), 78 deletions(-)--
1.7.11.7
Quoted 21 lines · Stephane Eranian
I have been looking at those patches and ran some tests. And I found a few issues so far.
I am running:
$ perf record -j any_ret -e cycles:u test_program $ perf report -DMost entries are okay and match the filter, however some do not make sense:
3642586996762
0x15d0[0x108]:PERF_RECORD_SAMPLE(IP, 2): 17921/17921:0x10001170period: 613678 addr: 0
.... branch stack: nr:9..... 0: 00000000100011cc -> 0000000010000e38 ..... 1: 0000000010001150 -> 00000000100011bc ..... 2: 0000000010001208 -> 0000000010000e38 ..... 3: 0000000010001160 -> 00000000100011f8 ..... 4: 00000000100011cc -> 0000000010000e38 ..... 5: 0000000010001150 -> 00000000100011bc ..... 6: 0000000010001208 -> 0000000010000e38 ..... 7: 0000000010001160 -> 00000000100011f8 ..... 8: 0000000000000000 -> 0000000010001160
Quoted 6 lines
^^^^^^
Entry 8 does not make sense, unless0x0is a valid return branch instruction address.
If an address is invalid, the whole entry needs to be eliminated. It is okay to have
less than the max number of entries supported by HW.
Hey Stephane,
Okay. The same behaviour is also reflected in the test results what I have shared in the patchset. Here is that section.
(3) perf record -j any_ret -e branch-misses:u ./cprog
# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol
# ........ ....... .................... ..................... .................... .....................
#
15.61% cprog [unknown] [.] 00000000 cprog [.] sw_3_1
6.28% cprog cprog [.] symbol2 cprog [.] hw_1_2
6.28% cprog cprog [.] ctr_addr cprog [.] sw_4_1
6.26% cprog cprog [.] success_3_1_3 cprog [.] sw_3_1
6.24% cprog cprog [.] symbol1 cprog [.] hw_1_1
6.24% cprog cprog [.] sw_4_2 cprog [.] callme
6.21% cprog [unknown] [.] 00000000 cprog [.] callme
6.19% cprog cprog [.] lr_addr cprog [.] sw_4_2
3.16% cprog cprog [.] hw_1_2 cprog [.] callme
3.15% cprog cprog [.] success_3_1_1 cprog [.] sw_3_1
3.15% cprog cprog [.] sw_4_1 cprog [.] callme
3.14% cprog cprog [.] callme cprog [.] main
3.13% cprog cprog [.] hw_1_1 cprog [.] callmeSo a lot of samples above have 0x0 as the "from" address. This originates from the code section here inside the function "power_pmu_bhrb_read", where we hit two back to back target addresses. So we zero out the from address for the first target address and re-read the second address over again. So thats how we get zero as the from address. This is how the HW capture the samples. I was reluctant to drop these samples but I agree that these kind of samples can be dropped if we need to.
if (val & BHRB_TARGET) {
/* Shouldn't have two targets in a
row.. Reset index and try again */
r_index--;
addr = 0;
}Quoted 4 lines
I also had cases where monitoring only at the user level, got me branch addresses in the
0xc0000000...... range. My test program is linked statically.
Thats weird. I would need more information and details on this. BTW what is the system you are running on ? Could you please share the /proc/cpuinfo details of the same ?
Quoted 3 lines
when eliminating the bogus entries, my tests yielded only return branch instruction addresses
which is good. Will run more tests.
Sure. Thanks for the tests and comments.
Quoted 53 lines · Anshuman Khandual
Quoted 21 lines · Stephane Eranian
I have been looking at those patches and ran some tests. And I found a few issues so far.
I am running:
$ perf record -j any_ret -e cycles:u test_program $ perf report -DMost entries are okay and match the filter, however some do not make sense:
3642586996762
0x15d0[0x108]:PERF_RECORD_SAMPLE(IP, 2): 17921/17921:0x10001170period: 613678 addr: 0
.... branch stack: nr:9..... 0: 00000000100011cc -> 0000000010000e38 ..... 1: 0000000010001150 -> 00000000100011bc ..... 2: 0000000010001208 -> 0000000010000e38 ..... 3: 0000000010001160 -> 00000000100011f8 ..... 4: 00000000100011cc -> 0000000010000e38 ..... 5: 0000000010001150 -> 00000000100011bc ..... 6: 0000000010001208 -> 0000000010000e38 ..... 7: 0000000010001160 -> 00000000100011f8 ..... 8: 0000000000000000 -> 0000000010001160Quoted 6 lines
^^^^^^
Entry 8 does not make sense, unless0x0is a valid return branch instruction address.
If an address is invalid, the whole entry needs to be eliminated. It is okay to have
less than the max number of entries supported by HW.Hey Stephane,
Okay. The same behaviour is also reflected in the test results what I have shared in the patchset. Here is that section.
(3) perf record -j
any_ret-e branch-misses:u ./cprog# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol # ........ ....... .................... ..................... .................... ..................... # 15.61% cprog [unknown] [.] 00000000 cprog [.] sw_3_1 6.28% cprog cprog [.] symbol2 cprog [.] hw_1_2 6.28% cprog cprog [.] ctr_addr cprog [.] sw_4_1 6.26% cprog cprog [.] success_3_1_3 cprog [.] sw_3_1 6.24% cprog cprog [.] symbol1 cprog [.] hw_1_1 6.24% cprog cprog [.] sw_4_2 cprog [.] callme 6.21% cprog [unknown] [.] 00000000 cprog [.] callme 6.19% cprog cprog [.] lr_addr cprog [.] sw_4_2 3.16% cprog cprog [.] hw_1_2 cprog [.] callme 3.15% cprog cprog [.] success_3_1_1 cprog [.] sw_3_1 3.15% cprog cprog [.] sw_4_1 cprog [.] callme 3.14% cprog cprog [.] callme cprog [.] main 3.13% cprog cprog [.] hw_1_1 cprog [.] callme
Quoted 2 lines
So a lot of samples above have
0x0as the "from" address. This originates from the code section here inside the function "power_pmu_bhrb_read", where we hit two back to back
Could you explain the back-to-back case a bit more here? Back-to-back returns to me means something like:
int foo()
{
...
return bar();
}
int bar()
{
return 0;
}
Not counting the leaf optimization here, bar return to foo which immediately returns: 2 back-2-back returns.
Is that the case you're talking about here?
Quoted 5 lines
target addresses. So we zero out the from address for the first target address and re-read the second address over again. So thats how we get zero as the from address. This is how the HW capture the samples. I was reluctant to drop these samples but I agree that these kind of samples can be dropped if we need to.
I think we need to make it as simple as possible for tools, i.e., avoid having to decode the
disassembly to figure out what happened. Here address 0 is not exploitable.
Quoted 6 lines
if (val & BHRB_TARGET) {
/* Shouldn't have two targets in a
row.. Reset index and try again */
r_index--;
addr = 0;
}Quoted 67 lines · Stephane Eranian
Quoted 53 lines · Anshuman Khandual
Quoted 21 lines · Stephane Eranian
I have been looking at those patches and ran some tests. And I found a few issues so far.
I am running:
$ perf record -j any_ret -e cycles:u test_program $ perf report -DMost entries are okay and match the filter, however some do not make sense:
3642586996762
0x15d0[0x108]:PERF_RECORD_SAMPLE(IP, 2): 17921/17921:0x10001170period: 613678 addr: 0
.... branch stack: nr:9..... 0: 00000000100011cc -> 0000000010000e38 ..... 1: 0000000010001150 -> 00000000100011bc ..... 2: 0000000010001208 -> 0000000010000e38 ..... 3: 0000000010001160 -> 00000000100011f8 ..... 4: 00000000100011cc -> 0000000010000e38 ..... 5: 0000000010001150 -> 00000000100011bc ..... 6: 0000000010001208 -> 0000000010000e38 ..... 7: 0000000010001160 -> 00000000100011f8 ..... 8: 0000000000000000 -> 0000000010001160Quoted 6 lines
^^^^^^
Entry 8 does not make sense, unless0x0is a valid return branch instruction address.
If an address is invalid, the whole entry needs to be eliminated. It is okay to have
less than the max number of entries supported by HW.Hey Stephane,
Okay. The same behaviour is also reflected in the test results what I have shared in the patchset. Here is that section.
(3) perf record -j
any_ret-e branch-misses:u ./cprog# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol # ........ ....... .................... ..................... .................... ..................... # 15.61% cprog [unknown] [.] 00000000 cprog [.] sw_3_1 6.28% cprog cprog [.] symbol2 cprog [.] hw_1_2 6.28% cprog cprog [.] ctr_addr cprog [.] sw_4_1 6.26% cprog cprog [.] success_3_1_3 cprog [.] sw_3_1 6.24% cprog cprog [.] symbol1 cprog [.] hw_1_1 6.24% cprog cprog [.] sw_4_2 cprog [.] callme 6.21% cprog [unknown] [.] 00000000 cprog [.] callme 6.19% cprog cprog [.] lr_addr cprog [.] sw_4_2 3.16% cprog cprog [.] hw_1_2 cprog [.] callme 3.15% cprog cprog [.] success_3_1_1 cprog [.] sw_3_1 3.15% cprog cprog [.] sw_4_1 cprog [.] callme 3.14% cprog cprog [.] callme cprog [.] main 3.13% cprog cprog [.] hw_1_1 cprog [.] callmeQuoted 2 lines
So a lot of samples above have
0x0as the "from" address. This originates from the code section here inside the function "power_pmu_bhrb_read", where we hit two back to backCould you explain the back-to-back case a bit more here? Back-to-back returns to me means something like:
int
foo()
{
...
returnbar();
}
Quoted 9 lines
int
bar()
{
return 0;
}Not counting the leaf optimization here, bar return to foo which immediately returns: 2 back-2-back returns.
Is that the case you're talking about here?
No. Filtering of return branches has been implemented in SW only. So PMU as such does not capture return only branches. It captures all the branches what it encounters. During the capture process PMU might *record* two back to back "target addresses" (without capturing the from address for the first one) for which we are unable to figure out the "from address". This leaves us with one branch record where we have the target address not from address and so we make it zero. With the current logic all branch records with "from address" as zero get filtered through and become the part of the final set. I was not too sure how to deal with these cases.
Quoted 8 lines
Quoted 5 lines
target addresses. So we zero out the from address for the first target address and re-read the second address over again. So thats how we get zero as the from address. This is how the HW capture the samples. I was reluctant to drop these samples but I agree that these kind of samples can be dropped if we need to.
I think we need to make it as simple as possible for tools, i.e., avoid having to decode the
disassembly to figure out what happened. Here address 0 is not exploitable.
Thats right. Dropping the branch record where we have only the target address not the from address might just solve this problem.
Quoted 78 lines · Anshuman Khandual
Quoted 67 lines · Stephane Eranian
Quoted 53 lines · Anshuman Khandual
Quoted 21 lines · Stephane Eranian
I have been looking at those patches and ran some tests. And I found a few issues so far.
I am running:
$ perf record -j any_ret -e cycles:u test_program $ perf report -DMost entries are okay and match the filter, however some do not make sense:
3642586996762
0x15d0[0x108]:PERF_RECORD_SAMPLE(IP, 2): 17921/17921:0x10001170period: 613678 addr: 0
.... branch stack: nr:9..... 0: 00000000100011cc -> 0000000010000e38 ..... 1: 0000000010001150 -> 00000000100011bc ..... 2: 0000000010001208 -> 0000000010000e38 ..... 3: 0000000010001160 -> 00000000100011f8 ..... 4: 00000000100011cc -> 0000000010000e38 ..... 5: 0000000010001150 -> 00000000100011bc ..... 6: 0000000010001208 -> 0000000010000e38 ..... 7: 0000000010001160 -> 00000000100011f8 ..... 8: 0000000000000000 -> 0000000010001160Quoted 6 lines
^^^^^^
Entry 8 does not make sense, unless0x0is a valid return branch instruction address.
If an address is invalid, the whole entry needs to be eliminated. It is okay to have
less than the max number of entries supported by HW.Hey Stephane,
Okay. The same behaviour is also reflected in the test results what I have shared in the patchset. Here is that section.
(3) perf record -j
any_ret-e branch-misses:u ./cprog# Overhead Command Source Shared Object Source Symbol Target Shared Object Target Symbol # ........ ....... .................... ..................... .................... ..................... # 15.61% cprog [unknown] [.] 00000000 cprog [.] sw_3_1 6.28% cprog cprog [.] symbol2 cprog [.] hw_1_2 6.28% cprog cprog [.] ctr_addr cprog [.] sw_4_1 6.26% cprog cprog [.] success_3_1_3 cprog [.] sw_3_1 6.24% cprog cprog [.] symbol1 cprog [.] hw_1_1 6.24% cprog cprog [.] sw_4_2 cprog [.] callme 6.21% cprog [unknown] [.] 00000000 cprog [.] callme 6.19% cprog cprog [.] lr_addr cprog [.] sw_4_2 3.16% cprog cprog [.] hw_1_2 cprog [.] callme 3.15% cprog cprog [.] success_3_1_1 cprog [.] sw_3_1 3.15% cprog cprog [.] sw_4_1 cprog [.] callme 3.14% cprog cprog [.] callme cprog [.] main 3.13% cprog cprog [.] hw_1_1 cprog [.] callmeQuoted 2 lines
So a lot of samples above have
0x0as the "from" address. This originates from the code section here inside the function "power_pmu_bhrb_read", where we hit two back to backCould you explain the back-to-back case a bit more here? Back-to-back returns to me means something like:
int
foo()
{
...
returnbar();
}Quoted 9 lines
int
bar()
{
return 0;
}Not counting the leaf optimization here, bar return to foo which immediately returns: 2 back-2-back returns.
Is that the case you're talking about here?
Quoted 8 lines
No. Filtering of return branches has been implemented in SW only. So PMU as such does not capture return only branches. It captures all the branches what it encounters. During the capture process PMU might *record* two back to back "target addresses" (without capturing the from address for the first one) for which we are unable to figure out the "from address". This leaves us with one branch record where we have the target address not from address and so we make it zero. With the current logic all branch records with "from address" as zero get filtered through and become the part of the final set. I was not too sure how to deal with these cases.
So PPC8 captures all branches, no HW filter. But then in SW you filter out non return branches.
Given you're description, I have to believe that sometimes the HW does not even capture the
from address. If so, then in that case, I think it is best to drop the sample. Because the target
address may be the target of an indirect branch for which there is no way to find the source.
In other words, the record cannot be exploited.
But why does the HW not capture some from addresses? I am worried this might create some bias in the samples.
Quoted 12 lines
Quoted 8 lines
Quoted 5 lines
target addresses. So we zero out the from address for the first target address and re-read the second address over again. So thats how we get zero as the from address. This is how the HW capture the samples. I was reluctant to drop these samples but I agree that these kind of samples can be dropped if we need to.
I think we need to make it as simple as possible for tools, i.e., avoid having to decode the
disassembly to figure out what happened. Here address 0 is not exploitable.Thats right. Dropping the branch record where we have only the target address not the from address might just solve this problem.
Quoted 11 lines · Stephane Eranian
Quoted 9 lines · Anshuman Khandual
Quoted 8 lines · Stephane Eranian
I have been looking at those patches and ran some tests. And I found a few issues so far.
I am running:
$ perf record -j any_ret -e cycles:u test_program $ perf report -DMost entries are okay and match the filter, however some do not make s=
ense:
Quoted 20 lines
Quoted 20 lines
Quoted 19 lines
3642586996762
0x15d0[0x108]:PERF_RECORD_SAMPLE(IP, 2): 17921/17921:0x10001170period: 613678 addr: 0
.... branch stack: nr:9..... 0: 00000000100011cc -> 0000000010000e38 ..... 1: 0000000010001150 -> 00000000100011bc ..... 2: 0000000010001208 -> 0000000010000e38 ..... 3: 0000000010001160 -> 00000000100011f8 ..... 4: 00000000100011cc -> 0000000010000e38 ..... 5: 0000000010001150 -> 00000000100011bc ..... 6: 0000000010001208 -> 0000000010000e38 ..... 7: 0000000010001160 -> 00000000100011f8 ..... 8: 0000000000000000 -> 0000000010001160^^^^^^
Entry 8 does not make sense, unless0x0is a valid return branch instruction address.
If an address is invalid, the whole entry needs to be eliminated. It is okay to have
less than the max number of entries supported by HW.
Quoted 3 lines
Quoted 3 lines
Hey Stephane,
Okay. The same behaviour is also reflected in the test results what I h=
ave
Quoted 5 lines
Quoted 5 lines
shared in the patchset. Here is that section.
(3) perf record -j
any_ret-e branch-misses:u ./cprog# Overhead Command Source Shared Object Source Symbol Targe=
t Shared Object Target Symbol
Quoted 1 line
Quoted 1 line
# ........ ....... .................... ..................... .....=
............... .....................
Quoted 2 lines
Quoted 2 lines
#
15.61% cprog [unknown] [.] 00000000 cprog=
[.] sw_3_1
Quoted 1 line
Quoted 1 line
6.28% cprog cprog [.] symbol2 cprog=
[.] hw_1_2
Quoted 1 line
Quoted 1 line
6.28% cprog cprog [.]
ctr_addrcprog=
[.] sw_4_1
Quoted 1 line
Quoted 1 line
6.26% cprog cprog [.]
success_3_1_3cprog=
[.] sw_3_1
Quoted 1 line
Quoted 1 line
6.24% cprog cprog [.] symbol1 cprog=
[.] hw_1_1
Quoted 1 line
Quoted 1 line
6.24% cprog cprog [.]
sw_4_2cprog=
[.] callme
Quoted 1 line
Quoted 1 line
6.21% cprog [unknown] [.] 00000000 cprog=
[.] callme
Quoted 1 line
Quoted 1 line
6.19% cprog cprog [.]
lr_addrcprog=
[.] sw_4_2
Quoted 1 line
Quoted 1 line
3.16% cprog cprog [.]
hw_1_2cprog=
[.] callme
Quoted 1 line
Quoted 1 line
3.15% cprog cprog [.]
success_3_1_1cprog=
[.] sw_3_1
Quoted 1 line
Quoted 1 line
3.15% cprog cprog [.]
sw_4_1cprog=
[.] callme
Quoted 1 line
Quoted 1 line
3.14% cprog cprog [.] callme cprog=
[.] main
Quoted 1 line
Quoted 1 line
3.13% cprog cprog [.]
hw_1_1cprog=
[.] callme
Quoted 2 lines
Quoted 2 lines
So a lot of samples above have
0x0as the "from" address. This originat=
es from the code
Quoted 1 line
Quoted 1 line
section here inside the function "
power_pmu_bhrb_read", where we hit tw=
o back to back
Quoted 11 lines
=20
Could you explain the back-to-back case a bit more here? Back-to-back returns to me means something like:
=20
intfoo()
{
...
returnbar();
}
=20
intbar()
Quoted 9 lines
{
return 0;
}
=20
Not counting the leaf optimization here, bar return to foo which immediately returns: 2 back-2-back returns.
Is that the case you're talking about here?
=20Quoted 1 line
target addresses. So we zero out the from address for the first target =
address and re-read
Quoted 1 line
Quoted 1 line
the second address over again. So thats how we get zero as the from add=
ress. This is how the
Quoted 1 line
Quoted 1 line
HW capture the samples. I was reluctant to drop these samples but I agr=
ee that these kind of
Quoted 5 lines
Quoted 2 lines
samples can be dropped if we need to.
I think we need to make it as simple as possible for tools, i.e., avoid having to decode the
disassembly to figure out what happened. Here address 0 is not exploitabl=
e.
This was my fault. I figured if we only had partial information from the hardware, it was best to at least export that to the tools. If you disagree then we can we remove them. There was a discussion a while back on this here:
https://lkml.org/lkml/2013/5/8/543
Because of the way the branch buffer is structured, we can certainly lose the from address of the oldest branch in the buffer. I've not seen the hardware lose the from branches in the middle of the buffer but I guess it's possible. We'll have to get back to you on how or why this would occur (and associated bias) after talking to some hardware folk.
FWIW, there was some discussion on how the POWER8 branch buffer works a while back here (same thread as before):
https://lkml.org/lkml/2013/5/8/541
Mikey