Skip to content

Pass external callchain entry to get_perf_callchain

Tao Chen bpf linux-perf-users lkml 10 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v8 Latest3 patches 23 repliesIn review
  2. v7 posting 2/22 patches 7 repliesSuperseded
  3. v7 posting 1/22 patches 2 repliesSuperseded
Earlier versions · 7
VersionPostedPatchesRepliesStatus
v62 patches4 repliesSuperseded
v53 patches3 repliesSuperseded
v4 posting 2/22 patches7 repliesSuperseded
v4 posting 1/22 patches2 repliesSuperseded
v3 RFC2 patches5 repliesSuperseded
v2 RFC2 patches7 repliesSuperseded
v1 RFC2 patches3 repliesSuperseded

Patches in v8 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3perf: Add rctx in perf_callchain_entryinclude/linux/perf_event.h kernel/bpf/stackmap.c kernel/events/callchain.c+21 -167 replies
2/3perf: Refactor get_perf_callchaininclude/linux/perf_event.h kernel/events/callchain.c+27 -1213 replies
3/3bpf: Hold ther perf callchain entry until used completelykernel/bpf/stackmap.c+47 -83 replies

Reviews trailers per patch

1 of 3 patches has a Reviewed-by or Acked-by.

PatchYonghong Song
1/3
2/3
3/3A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v8 thread

Cover letter [PATCH bpf-next v8 0/3] Pass external callchain entry to get_perf_callchain

Background
==========
Alexei noted we should use preempt_disable to protect get_perf_callchain in bpf stackmap.
https://lore.kernel.org/bpf/CAADnVQ+s8B7-fvR1TNO-bniSyKv57cH_ihRszmZV7pQDyV=VDQ@mail.gmail.com

A previous patch was submitted to attempt fixing this issue. And Andrii suggested teach get_perf_callchain to let us pass that buffer directly to avoid that unnecessary copy.
https://lore.kernel.org/bpf/[email protected]

Proposed Solution
=================
Add external perf_callchain_entry parameter for get_perf_callchain to allow us to use external buffer from BPF side. The biggest advantage is that it can reduce unnecessary copies.

Todo
====
But I'm not sure if this modification is appropriate. After all, the implementation of get_callchain_entry in the perf subsystem seems much more complex than directly using an external buffer.

Comments and suggestions are always welcome.

Change list:
- v1 -> v2
From Jiri
- rebase code, fix conflict
- v1: https://lore.kernel.org/bpf/[email protected]

- v2 -> v3:
From Andrii
- entries per CPU used in a stack-like fashion
- v2: https://lore.kernel.org/bpf/[email protected]

- v3 -> v4:
From Peter
- refactor get_perf_callchain and add three new APIs to use perf callchain easily.
From Andrii
- reuse the perf callchain management.

- rename patch1 and patch2.
- v3: https://lore.kernel.org/bpf/[email protected]

- v4 -> v5:
From Yonghong
- keep add_mark false in stackmap when refactor get_perf_callchain in

     patch1.
   - add atomic operation in get_recursion_context in patch2.
   - rename bpf_put_callchain_entry with bpf_put_perf_callchain in
     patch3.

- rebase bpf-next master.
- v4: https://lore.kernel.org/bpf/[email protected]

- v5 -> v6:
From Peter
- disable preemption from BPF side in patch2.
From AI
- use ctx->entry->nr instead of ctx->nr in patch1.
- v5: https://lore.kernel.org/bpf/[email protected]

- v6 -> v7:
From yonghong
- Add ack in patch2
From AI
- resolve conflict
- v6: https://lore.kernel.org/bpf/[email protected]

- v7 -> v8:
From Andrii
- Record rctx in perf_callchain_entry in patch1
- Export __get_perf_callchain in patch2
- v7: https://lore.kernel.org/bpf/[email protected]

Tao Chen (3):
perf: Add rctx in perf_callchain_entry
perf: Refactor get_perf_callchain
bpf: Hold ther perf callchain entry until used completely

 include/linux/perf_event.h | 10 +++++--
 kernel/bpf/stackmap.c      | 58 ++++++++++++++++++++++++++++++-------
 kernel/events/callchain.c  | 59 ++++++++++++++++++++++++--------------
 3 files changed, 93 insertions(+), 34 deletions(-)
Signature · 1 line
2.48.1