Re: [PATCH 1/2] perf tools powerpc: Fix callchain ip filtering

From: Ravi Bangoria
Date: Tue Apr 17 2018 - 02:59:40 EST




On 04/12/2018 10:41 PM, Sandipan Das wrote:
> For powerpc64, if a probe is added for a function without specifying
> a line number, the corresponding trap instruction is placed at offset
> 0 (for big endian) or 8 (for little endian) from the start address of
> the function. This address is in the function prologue and the trap
> instruction preceeds the instructions to set up the stack frame.
>
> Therefore, at this point during execution, the return address for the
> function is yet to be written to its caller's stack frame. So, the LR
> value at index 2 of the callchain ips provided by the kernel is still
> valid and must not be skipped.
>
> This can be observed on a powerpc64le system running Fedora 27 as
> shown below.
>
> # perf probe -x /usr/lib64/libc-2.26.so -a inet_pton
> # perf record -e probe_libc:inet_pton/max-stack=3/ ping -6 -c 1 ::1
> # perf script
>
> Without this patch, the output is:
>
> ping 27909 [007] 532219.943481: probe_libc:inet_pton: (7fff99b0af28)
> 15af28 __GI___inet_pton (/usr/lib64/libc-2.26.so)
> 1105b4 getaddrinfo (/usr/lib64/libc-2.26.so)
>
> With this patch applied, the output is:
>
> ping 27909 [007] 532219.943481: probe_libc:inet_pton: (7fff99b0af28)
> 15af28 __GI___inet_pton (/usr/lib64/libc-2.26.so)
> 10fa54 gaih_inet.constprop.7 (/usr/lib64/libc-2.26.so)
> 1105b4 getaddrinfo (/usr/lib64/libc-2.26.so)
>
> Fixes: a60335ba3298 ("perf tools powerpc: Adjust callchain based on DWARF debug info")
> Signed-off-by: Sandipan Das <sandipan@xxxxxxxxxxxxxxxxxx>
> ---

This change looks good to me but seems it fixed the issue
partially.Ex,

ÂÂÂ # readelf --debug-dump=frames-interp /lib64/libc-2.26.so | less
ÂÂÂ ...
ÂÂÂ 00005778 0000000000000024 0000577c FDE cie=00000000 pc=0000000000048b30..0000000000048c64
ÂÂÂÂÂÂ LOCÂÂÂÂÂÂÂÂÂÂ CFAÂÂÂÂÂ r31ÂÂ raÂÂÂ
ÂÂÂ 0000000000048b30 r1+0ÂÂÂÂ uÂÂÂÂ uÂÂÂÂ
ÂÂÂ 0000000000048b40 r1+0ÂÂÂÂ c-8ÂÂ r0ÂÂÂ
ÂÂÂ 0000000000048b58 r1+64ÂÂÂ c-8ÂÂ c+16Â
ÂÂÂ 0000000000048bd8 r1+0ÂÂÂÂ c-8ÂÂ c+16Â
ÂÂÂ 0000000000048be4 r1+0ÂÂÂÂ uÂÂÂÂ
ÂÂÂ 0000000000048bf0 r1+64ÂÂÂ c-8ÂÂ c+16Â

0000000000048b30..0000000000048c64 is arandom() function from libc:

ÂÂÂ 0000000000048b30 <random>:
ÂÂÂÂÂÂ 48b30:ÂÂÂÂÂÂ 1c 00 4c 3cÂÂÂÂ addisÂÂ r2,r12,28
ÂÂÂÂÂÂ 48b34:ÂÂÂÂÂÂ d0 e5 42 38ÂÂÂÂ addiÂÂÂ r2,r2,-6704
ÂÂÂÂÂÂ 48b38:ÂÂÂÂÂÂ a6 02 08 7cÂÂÂÂ mflrÂÂÂ r0
ÂÂÂÂÂÂ 48b3c:ÂÂÂÂÂÂ f8 ff e1 fbÂÂÂÂ stdÂÂÂÂ r31,-8(r1)
ÂÂÂÂÂÂ 48b40:ÂÂÂÂÂÂ 00 00 00 60ÂÂÂÂ nop
ÂÂÂÂÂÂ 48b44:ÂÂÂÂÂÂ 00 00 20 39ÂÂÂÂ liÂÂÂÂÂ r9,0
ÂÂÂÂÂÂ 48b48:ÂÂÂÂÂÂ 80 b5 e2 3bÂÂÂÂ addiÂÂÂ r31,r2,-19072
ÂÂÂÂÂÂ 48b4c:ÂÂÂÂÂÂ 01 00 00 39ÂÂÂÂ liÂÂÂÂÂ r8,1
ÂÂÂÂÂÂ 48b50:ÂÂÂÂÂÂ 10 00 01 f8ÂÂÂÂ stdÂÂÂÂ r0,16(r1)
ÂÂÂÂÂÂ 48b54:ÂÂÂÂÂÂ c1 ff 21 f8ÂÂÂÂ stduÂÂÂ r1,-64(r1)
ÂÂÂÂÂÂ 48b58:ÂÂÂÂÂÂ f0 8f 4d e9ÂÂÂÂ ldÂÂÂÂÂ r10,-28688(r13)
  Â ...

Your change fixed the issue for 48b30..48b40. But not for
48b40..48b58.

I probed at 0x48b40.

ÂÂÂ # ./perf record -g -e probe_libc:abs_48b40 ~/rand

perf report without Suka's and your change:

 # Children Self Trace outputÂ
 # ........ ........ ..............
ÂÂÂ #
ÂÂÂÂÂÂ 100.00%ÂÂ 100.00%Â (7fffb7d28b40)
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ |
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ---0
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ __libc_start_main
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ generic_start_main.isra.0
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ main
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ rand
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ __random

perf report with only Suka's change:

 # Children Self Trace outputÂ
 # ........ ........ ..............
ÂÂÂ #
ÂÂÂÂÂÂ 100.00%ÂÂ 100.00%Â (7fffb7d28b40)
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ |
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ---0
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ __libc_start_main
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ generic_start_main.isra.0
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ main
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ __random

perf report with Suka's and your change:

 # Children Self Trace outputÂ
 # ........ ........ ..............
ÂÂÂ #
ÂÂÂÂÂÂ 100.00%ÂÂ 100.00%Â (7fffb7d28b40)
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ |
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ ---0
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ __libc_start_main
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ generic_start_main.isra.0
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ main
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ __random

I think rand() is a valid entry which is missing in last two cases.