kernel icon indicating copy to clipboard operation
kernel copied to clipboard

[5.15-velinux] Backported perf consider phase 2 patches for velinux-5.15 kernel

Open PvsNarasimha opened this issue 1 year ago • 6 comments

perf support :

Add support perf script: Add missing fields in usage hint Add support 'brstackinsnlen' for branch stacks s390/pai: add support for cryptography counters Add support for PAI Extension 1 NNPA counters Add Zen 4 core/uncore and mapping, memory controller and cache latency events perf: Rewrite core context handling perf: Optimize perf_cgroup_switch() perf evsel amd: Fix IBS error message perf evsel: Improve AMD IBS (Instruction-Based Sampling) error handling message

  • perf: Rewrite core context handling
Current design:

    Currently we have a per task and per cpu perf_event_contexts:

      task_struct::perf_events_ctxp[] <-> perf_event_context <-> perf_cpu_context
           ^                                 |    ^     |           ^
           `---------------------------------'    |     `--> pmu ---'
                                                  v           ^
                                             perf_event ------'
  Proposed design:

    New design proposed by this patch reduce to a single task context and
    a single CPU context but adds some intermediate data-structures:

      task_struct::perf_event_ctxp -> perf_event_context <- perf_cpu_context
           ^                           |   ^ ^
           `---------------------------'   | |
                                           | |    perf_cpu_pmu_context <--.
                                           | `----.    ^                  |
                                           |      |    |                  |
                                           |      v    v                  |
                                           | ,--> perf_event_pmu_context  |
                                           | |                            |
                                           | |                            |
                                           v v                            |
                                      perf_event ---> pmu ----------------'

Run Test cases

#cd /kernel/tools/perf/
#sudo make perf
#cp perf /usr/bin/
  • Add support 'brstackinsnlen' for branch stacks
./perf script -F ip,brstackinsn,brstackinsnlen
root@volcano9b5e-os:/home/amd/ukernel/kernel/tools/perf# ./perf script -F ip,brstackinsn,brstackinsnlen
ffffffff88b42f4b
        amd_pmu_lbr_read+113:
        ffffffff88a0a4d1        insn: e8 ba ad 06 00            ilen: 5 # PRED
        native_read_msr:
        ffffffff88a75290        insn: 53        ilen: 1
        ffffffff88a75291        insn: 89 f9     ilen: 2
        ffffffff88a75293        insn: 0f 32     ilen: 2
        ffffffff88a75295        insn: 48 c1 e2 20       ilen: 4
        ffffffff88a75299        insn: 48 89 d3  ilen: 3
        ffffffff88a7529c        insn: 48 09 c3  ilen: 3
        ffffffff88a7529f        insn: 66 90     ilen: 2
        ffffffff88a752a1        insn: 48 89 d8  ilen: 3
        ffffffff88a752a4        insn: 5b        ilen: 1
        ffffffff88a752a5        insn: c3                        ilen: 1 # PRED
  • perf vendor events amd: Fix Zen 4 cache latency events
$ sudo perf stat -e l3_xi_sampled_latency.all,l3_xi_sampled_latency_requests.all -a sleep 1
amd@volcano9dee-os:~/Narasimha/kernel/tools/perf$ sudo ./perf stat -e l3_xi_sampled_latency.all,l3_xi_sampled_latency_requests.all -a sleep 1
 
Performance counter stats for 'system wide':
 
          1,07,000      l3_xi_sampled_latency.all
             6,069      l3_xi_sampled_latency_requests.all
 
       1.001188417 seconds time elapsed
  • perf/amd/ibs: Make IBS a core pmu
./perf record -e cycles:pp ls
[ perf record: Woken up 3 times to write data ]
[ perf record: Captured and wrote 0.024 MB perf.data (11 samples) ]
  • perf: Optimize perf_cgroup_switch()
$ taskset -c 0 ./perf bench sched pipe -l 10000 -T AAA,BBB
root@volcano9b5e-os:/home/amd/Narasimha/Linux_Backport/tools/perf# taskset -c 0 ./perf bench sched pipe -l 10000 -T AAA,BBB
# Running 'sched/pipe' benchmark:
# Executed 10000 pipe operations between two threads
 
     Total time: 0.029 [sec]
 
       2.982400 usecs/op
         335300 ops/sec
$ taskset -c 0 ./perf bench sched pipe -l 10000 -l 100
  root@volcano9b5e-os:/home/amd/Narasimha/Linux_Backport/tools/perf# taskset -c 0 ./perf bench sched pipe -l 10000 -l 100
# Running 'sched/pipe' benchmark:
# Executed 100 pipe operations between two processes
 
     Total time: 0.000 [sec]
 
       6.170000 usecs/op
         162074 ops/sec
  • perf evsel amd: Fix IBS error message
$ ./perf record -e ibs_op//k -C 0
root@volcano9b5e-os:/home/amd/Narasimha/Linux_Backport/tools/perf# ./perf record -e ibs_op//k -C 0
Error:
AMD IBS doesn't support privilege filtering. Try again without the privilege modifiers (like 'k') at the end.
  • perf evsel: Improve AMD IBS (Instruction-Based Sampling) error handling message
$ ./perf record -e ibs_op// true
root@volcano9b5e-os:/home/amd/Narasimha/Linux_Backport/tools/perf# ./perf record -e ibs_op// true
[ perf record: Woken up 4 times to write data ]
[ perf record: Captured and wrote 0.021 MB perf.data (11 samples) ]
root@volcano9b5e-os:/home/amd/Narasimha/Linux_Backport/tools/perf# ./perf record -a -e ibs_op// true
[ perf record: Woken up 0 times to write data ]
[ perf record: Captured and wrote 0.896 MB perf.data (3557 samples) ]
  • perf events test suite
git clone https://github.com/deater/perf_event_tests.git

[sudo sysctl kernel.perf_event_paranoid=2]

./fuzzer/perf_fuzzer -t OC -s 100
....
....
Close:  5/5 Successful
Read:   0/0 Successful
Write:  0/0 Successful
Ioctl:  0/0 Successful

PvsNarasimha avatar Feb 11 '25 11:02 PvsNarasimha

Thanks for the PR. 1)Seems some commit messages have more period in commit xxx upstream line. Like below "commit 6ea5d1a3e301a3d1f0364dfd481210aa6aa3cf17 upstream.." 2)We have some search fix erros on this PR. I'm not sure whether we can remove 559a40f2080b and 7ba92beaefc6 commits and fix 81368318b874? Thanks!

ERROR:root:559a40f2080bc833b90ce82fa30ac7a3a9813e0a Downstream commit 559a40f2080b (arm64: perf: Enable PMU counter userspace access for perf event) needs upstream fix 0c2f9acf6ae7 (KVM: arm64: PMU: Don't overwrite PMUSERENR with vcpu loaded) which is not backported ERROR:root:559a40f2080bc833b90ce82fa30ac7a3a9813e0a Downstream commit 559a40f2080b (arm64: perf: Enable PMU counter userspace access for perf event) needs upstream fix 8681f7175901 (KVM: arm64: PMU: Restore the host's PMUSERENR_EL0) which is not backported ERROR:root:7ba92beaefc602e4606a506144f6c872026fe1b2 Downstream commit 7ba92beaefc6 (s390/pai: add support for cryptography counters) needs upstream fix 225d09d6e5f3 (s390/pai: fix attr_event_free upper limit for pai device drivers) which is not backported ERROR:root:7ba92beaefc602e4606a506144f6c872026fe1b2 Downstream commit 7ba92beaefc6 (s390/pai: add support for cryptography counters) needs upstream fix 541a49664451 (s390/pai: Prevent invalid event number for pai_crypto PMU) which is not backported ERROR:root:7ba92beaefc602e4606a506144f6c872026fe1b2 Downstream commit 7ba92beaefc6 (s390/pai: add support for cryptography counters) needs upstream fix e9f3af02f639 (s390/pai: fix sampling event removal for PMU device driver) which is not backported ERROR:root:7ba92beaefc602e4606a506144f6c872026fe1b2 Downstream commit 7ba92beaefc6 (s390/pai: add support for cryptography counters) needs upstream fix 21e876448792 (s390/pai: Fix multiple concurrent event installation) which is not backported ERROR:root:81368318b874f3802b42677232f04c25cd16ddf9 Downstream commit 81368318b874 (perf: Rewrite core context handling) needs upstream fix 889c58b3155f (perf/core: Fix cpuctx refcounting) which is not backported ERROR:root:81368318b874f3802b42677232f04c25cd16ddf9 Downstream commit 81368318b874 (perf: Rewrite core context handling) needs upstream fix f06cc667f799 (perf: Optimize perf_cgroup_switch()) which is not backported ERROR:root:81368318b874f3802b42677232f04c25cd16ddf9 Downstream commit 81368318b874 (perf: Rewrite core context handling) needs upstream fix 853e2dac25c1 (arm64: perf: reject CHAIN events at creation time) which is not backported ERROR:root:81368318b874f3802b42677232f04c25cd16ddf9 Downstream commit 81368318b874 (perf: Rewrite core context handling) needs upstream fix 61d038627343 (arm_pmu: fix event CPU filtering) which is not backported

Liangyan-bd avatar Feb 14 '25 08:02 Liangyan-bd

FYI, search fix script can refer here: https://github.com/openvelinux/kernel/tree/5.4.143-velinux/.github/code/scripts/

Liangyan-bd avatar Feb 14 '25 09:02 Liangyan-bd

Thanks Liangyan for Review I will check and update the PR

PvsNarasimha avatar Feb 14 '25 09:02 PvsNarasimha

Thanks for the update. I'm sorry there are some search fix errors left. Please help to check it.

ERROR:root:e7304ea93878a59ada0b31c2b6e54150144d97b8 Downstream commit e7304ea93878 (s390/pai: add support for cryptography counters) needs upstream fix 225d09d6e5f3 (s390/pai: fix attr_event_free upper limit for pai device drivers) which is not backported ERROR:root:86006ba0e8b6ba9b755f3347f2eca98a4bb74539 Downstream commit 86006ba0e8b6 (arm64: perf: Move PMUv3 driver to drivers/perf) needs upstream fix b50f26a44887 (perf/core: Drop __weak attribute from arch_perf_update_userpage() prototype) which is not backported ERROR:root:86006ba0e8b6ba9b755f3347f2eca98a4bb74539 Downstream commit 86006ba0e8b6 (arm64: perf: Move PMUv3 driver to drivers/perf) needs upstream fix 87727ba2bb05 (KVM: arm64: Ensure CPU PMU probes before pKVM host de-privilege) which is not backported ERROR:root:86006ba0e8b6ba9b755f3347f2eca98a4bb74539 Downstream commit 86006ba0e8b6 (arm64: perf: Move PMUv3 driver to drivers/perf) needs upstream fix fa729bc7c9c8 (KVM: arm64: Handle kvm_arm_init failure correctly in finalize_pkvm) which is not backported ERROR:root:8a605be6529a5426306e0fffca705c4bd86b3086 Downstream commit 8a605be6529a (arm64: perf: Abstract system register accesses away) needs upstream fix 3bc879e355da (arm64: perf: Mark all accessor functions inline) which is not backported ERROR:root:8a605be6529a5426306e0fffca705c4bd86b3086 Downstream commit 8a605be6529a (arm64: perf: Abstract system register accesses away) needs upstream fix 403edfa43628 (arm64/arm: arm_pmuv3: perf: Don't truncate 64-bit registers) which is not backported ERROR:root:90c258711a47f2c385cfe9ed401d6768023f3666 Downstream commit 90c258711a47 (ARM: perf: Allow the use of the PMUv3 driver on 32bit ARM) needs upstream fix 68e3f61eb9f5 (ARM: perf: Mark all accessor functions inline) which is not backported.

You can try to use search fix script like this in your local repo dir: git remote add upstream https://github.com/torvalds/linux.git git fetch upstream master -ap ./git-check-backports -s -r origin/5.15-velinux..HEAD -u upstream/master // git-check-backports script can copy from https://github.com/openvelinux/kernel/blob/5.4.143-velinux/.github/code/scripts/git-check-backports

Liangyan-bd avatar Feb 18 '25 11:02 Liangyan-bd

Thanks for the effort, we have much progress, currently there are only two search fix errrors. Can we fix them?

ERROR:root:29c01c8543c83a960fa6c4af42282b68ec1cd65d Downstream commit 29c01c8543c8 (KVM: arm64: PMU: Don't overwrite PMUSERENR with vcpu loaded) needs upstream fix 403edfa43628 (arm64/arm: arm_pmuv3: perf: Don't truncate 64-bit registers) which is not backported ERROR:root:29c01c8543c83a960fa6c4af42282b68ec1cd65d Downstream commit 29c01c8543c8 (KVM: arm64: PMU: Don't overwrite PMUSERENR with vcpu loaded) needs upstream fix 3bc879e355da (arm64: perf: Mark all accessor functions inline) which is not backported

Liangyan-bd avatar Feb 19 '25 10:02 Liangyan-bd

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 18 committers have signed the CLA.

:white_check_mark: PvsNarasimha
:x: ahunter6
:x: svens-s390
:x: robherring
:x: rafaelmsoares
:x: sean-jc
:x: sandip4n
:x: huangrui
:x: gscui
:x: namhyung
:x: captain5050
:x: willdeacon
:x: reijiw-kvm
:x: sudeep-holla
:x: geertu
:x: ilkka-koskinen
:x: kimphillamd
:x: James-A-Clark
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Feb 20 '25 11:02 CLAassistant

/retest

amalathi2 avatar Apr 03 '25 04:04 amalathi2

Looks good to me. Thanks! cc @guojinhui-liam

Liangyan-bd avatar Apr 29 '25 06:04 Liangyan-bd