bpf: make perf_event_read_output accessible from BPF core when available
Subsystems (5)
Emil Tsalapatis
reviewerPATCH v2 1/1 bpf: make perf_event_read_output accessible from BPF core when available
The perf_event_read_event_output helper is currently only available to tracing protrams, but is useful for other BPF programs like sched_ext schedulers. When the helper is available, provide its bpf_func_proto directly from the bpf core.
--- include/linux/bpf.h | 2 ++ kernel/bpf/core.c | 5 +++++ kernel/bpf/helpers.c | 2 ++ kernel/trace/bpf_trace.c | 5 +++++ 4 files changed, 14 insertions(+)
include/linux/bpf.h +2 -0
@@ -2059,6 +2059,8 @@ int bpf_prog_calc_tag(struct bpf_prog *fp);const struct bpf_func_proto *bpf_get_trace_printk_proto (void );const struct bpf_func_proto *bpf_get_trace_vprintk_proto (void ); +const struct bpf_func_proto *bpf_get_perf_event_read_value_proto (void ); +typedef unsigned long (*bpf_ctx_copy_t )(void *dst,const void *src,unsigned long off,unsigned long len); typedef u32 (*bpf_convert_ctx_access_t)(enum bpf_access_type type,
kernel/bpf/core.c +5 -0
@@ -2972,6 +2972,11 @@ const struct bpf_func_proto * __weak bpf_get_trace_vprintk_proto(void)return NULL ; } +const struct bpf_func_proto *__weak bpf_get_perf_event_read_value_proto (void ) +{ +return NULL ; +} +u64 __weak bpf_event_output (struct bpf_map *map,u64 flags,void *meta,u64 meta_size,void *ctx,u64 ctx_size,bpf_ctx_copy_t ctx_copy)
kernel/bpf/helpers.c +2 -0
@@ -2056,6 +2056,8 @@ bpf_base_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)return &bpf_task_pt_regs_proto;case BPF_FUNC_trace_vprintk:return bpf_get_trace_vprintk_proto (); +case BPF_FUNC_perf_event_read_value: +return bpf_get_perf_event_read_value_proto ();default :return NULL ; }
kernel/trace/bpf_trace.c +5 -0
@@ -607,6 +607,11 @@ static const struct bpf_func_proto bpf_perf_event_read_value_proto = { .arg4_type = ARG_CONST_SIZE, }; +const struct bpf_func_proto *bpf_get_perf_event_read_value_proto (void ) +{ +return &bpf_perf_event_read_value_proto; +} + static __always_inline u64 __bpf_perf_event_output(struct pt_regs *regs, struct bpf_map *map, u64 flags, struct perf_raw_record *raw,
Signature · 1 line
2.47.1
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:
Quoted 9 lines · On Mon, 17 Mar 2025 23:07:53 -0400 you wrote:
The
perf_event_read_event_outputhelper is currently only available to tracing protrams, but is useful for other BPF programs likesched_extschedulers. When the helper is available, provide itsbpf_func_protodirectly from the bpf core.Signed-off-by Emil Tsalapatis (Meta) <[email protected]>Acked-by Jiri Olsa <[email protected]>[...]
Here is the summary with links:
- [bpf-next,v2] bpf: make perf_event_read_output accessible from BPF core when available
https://git.kernel.org/bpf/bpf-next/c/ae0a457f5d33
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html