Re: [PATCH v3] perf: map pages in advance

David Hildenbrand
2024-12-20T21:30:00Z

On 20.12.24 20:36, Chen, Zide wrote:
>
>
> On 12/20/2024 1:56 AM, David Hildenbrand wrote:
>> On 20.12.24 10:31, Lorenzo Stoakes wrote:
>>> On Thu, Dec 19, 2024 at 01:17:44PM -0800, Chen, Zide wrote:
>>>
>>>> With this patch, it seems perf tool has some problems in capturing the
>>>> kernel data with Intel PT.
>>>>
>>>> Running the following commands, the size of perf.data is very small, and
>>>> perf script can't find any valid records.
>>>>
>>>> perf record -e intel_pt//u -- /bin/ls
>>>> perf script --insn-trace
>>>>
>>>>
>>>
>>> Hi,
>>>
>>> I'm on leave (and should really go back to relaxing :>), returning on 2nd
>>> Jan so can't really dig into this.
>>>
>>> But I tried it on my intel box and it 'works on my machine' with and
>>> without patch with commands provided, so I'm not sure this is actually a
>>> product of this change (which shouldn't impact this).
>>
>> Zide Chen, can you try with and without this patch to see if it
>> introduces the issue?
>
> Yes, I re-did the test on a SPR server, and the result is same. Without
> the patch, it went well; But with it, "perf script --insn-trace" doesn't
> show valid records.
>
> This time I tested it on the clean 6.13-rc1 tag, base commit
> 40384c840ea1944d7c5a392e8975ed088ecf0b37
>
> Also, with this patch, running tools/perf/tests/shell/test_intel_pt.sh:
>
> Error:
> The - data has no samples!

I just tested it on 6.13-rc1 vs. 6.13-rc1 with this patch.

Indeed, there is quite difference. Below are the main parts that changed, only.

We seem to be recording data, but maybe what we record gets corrupted somehow?

Looks like

Before:

--- Test tracing self-modifying code that uses jitdump ---
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.019 MB /tmp/perf-test-intel-pt-sh.pSYRjy9UUy/tmp-perf.data ]
/root/linux/tools/perf/tests/shell
OK
--- Test with MTC and TSC disabled ---
Linux
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.050 MB /tmp/perf-test-intel-pt-sh.pSYRjy9UUy/test-perf.data ]
OK
--- Test with branches disabled ---
Linux
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.012 MB /tmp/perf-test-intel-pt-sh.pSYRjy9UUy/test-perf.data ]
OK
--- Test with/without CYC ---
Linux
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.095 MB /tmp/perf-test-intel-pt-sh.pSYRjy9UUy/test-perf.data ]
Linux
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.061 MB /tmp/perf-test-intel-pt-sh.pSYRjy9UUy/test-perf.data ]
OK
--- Test recording with sample mode ---
Linux
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.077 MB /tmp/perf-test-intel-pt-sh.pSYRjy9UUy/test-perf.data ]
Linux
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.002 MB /tmp/perf-test-intel-pt-sh.pSYRjy9UUy/test-perf.data ]
Linux
[ perf record: Woken up 3 times to write data ]
[ perf record: Captured and wrote 0.006 MB /tmp/perf-test-intel-pt-sh.pSYRjy9UUy/test-perf.data ]
OK
--- Test with kernel trace ---
Linux
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.060 MB /tmp/perf-test-intel-pt-sh.pSYRjy9UUy/test-perf.data ]
OK
--- Test virtual LBR ---
Linux
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.053 MB /tmp/perf-test-intel-pt-sh.pSYRjy9UUy/test-perf.data ]
OK
--- Test power events ---
SKIP: power_event_trace is not supported
--- Test with TNT packets disabled ---
SKIP: tnt_disable is not supported
--- Test with event_trace ---
SKIP: event_trace is not supported
--- Test with pipe mode ---
Linux
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.075 MB - ]
14.20% uname libc.so.6 [.] _int_malloc
10.39% uname ld-linux-x86-64.so.2 [.] _dl_relocate_object
9.68% uname libc.so.6 [.] __strcmp_evex
8.04% uname libc.so.6 [.] __stpcpy_evex
7.89% uname libc.so.6 [.] __memmove_chk_evex_unaligned_erms
5.71% uname libc.so.6 [.] __memmove_evex_unaligned_erms
5.68% uname ld-linux-x86-64.so.2 [.] __GI___tunables_init
5.46% uname ld-linux-x86-64.so.2 [.] _dl_lookup_symbol_x
4.95% uname libc.so.6 [.] getenv
4.37% uname ld-linux-x86-64.so.2 [.] do_lookup_x
4.21% uname libc.so.6 [.] __strchr_evex
3.56% uname libc.so.6 [.] strlen@plt
2.71% uname libc.so.6 [.] _nl_make_l10nflist.localalias
2.34% uname ld-linux-x86-64.so.2 [.] mprotect
2.22% uname libc.so.6 [.] memchr
1.82% uname libc.so.6 [.] find_module_idx
1.61% uname libc.so.6 [.] _nl_intern_locale_data
1.55% uname ld-linux-x86-64.so.2 [.] __minimal_malloc
0.98% uname ld-linux-x86-64.so.2 [.] _dl_start_user
0.96% uname ld-linux-x86-64.so.2 [.] intel_check_word.constprop.0
0.61% uname ld-linux-x86-64.so.2 [.] check_match
0.57% uname ld-linux-x86-64.so.2 [.] update_active.constprop.0
0.50% uname ld-linux-x86-64.so.2 [.] get_common_cache_info.constprop.0

Linux
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.074 MB - ]
OK
--- Cleaning up ---
--- Done ---

After:

--- Test tracing self-modifying code that uses jitdump ---
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.019 MB /tmp/perf-test-intel-pt-sh.SvCUtQzSAe/tmp-perf.data ]
/root/linux/tools/perf/tests/shell
Decode failed, only 0 branches
--- Test with MTC and TSC disabled ---
Linux
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.051 MB /tmp/perf-test-intel-pt-sh.SvCUtQzSAe/test-perf.data ]
Failed to filter with tsc=0
--- Test with branches disabled ---
Linux
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.013 MB /tmp/perf-test-intel-pt-sh.SvCUtQzSAe/test-perf.data ]
Failed to disable branches
--- Test with/without CYC ---
Linux
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.097 MB /tmp/perf-test-intel-pt-sh.SvCUtQzSAe/test-perf.data ]
Linux
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.061 MB /tmp/perf-test-intel-pt-sh.SvCUtQzSAe/test-perf.data ]
Still get CYC packet without cyc
--- Test recording with sample mode ---
Linux
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.076 MB /tmp/perf-test-intel-pt-sh.SvCUtQzSAe/test-perf.data ]
Linux
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.002 MB /tmp/perf-test-intel-pt-sh.SvCUtQzSAe/test-perf.data ]
Linux
[ perf record: Woken up 3 times to write data ]
[ perf record: Captured and wrote 0.006 MB /tmp/perf-test-intel-pt-sh.SvCUtQzSAe/test-perf.data ]
OK
--- Test with kernel trace ---
Linux
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.061 MB /tmp/perf-test-intel-pt-sh.SvCUtQzSAe/test-perf.data ]
OK
--- Test virtual LBR ---
Linux
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.054 MB /tmp/perf-test-intel-pt-sh.SvCUtQzSAe/test-perf.data ]
OK
--- Test power events ---
SKIP: power_event_trace is not supported
--- Test with TNT packets disabled ---
SKIP: tnt_disable is not supported
--- Test with event_trace ---
SKIP: event_trace is not supported
--- Test with pipe mode ---
Linux
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.073 MB - ]
Error:
The - data has no samples!
Linux
[ perf record: Woken up 1 times to write data ]
[ perf record: Captured and wrote 0.077 MB - ]
OK
--- Cleaning up ---
--- Done ---

--
Cheers,

David / dhildenb