For better performance analysis of BPF programs, this patch introduces PERF_RECORD_BPF_EVENT, a new perf_event_type that exposes BPF program load/unload information to user space. Each BPF program may contain up to BPF_MAX_SUBPROGS (256) sub programs. The following example shows kernel symbols for a BPF program with 7 sub programs: ffffffffa0257cf9 t bpf_prog_b07ccb89267cf242_F ffffffffa02592e1 t bpf_prog_2dcecc18072623fc_F ffffffffa025b0e9 t bpf_prog_bb7a405ebaec5d5c_F ffffffffa025dd2c t bpf_prog_a7540d4a39ec1fc7_F ffffffffa025fcca t bpf_prog_05762d4ade0e3737_F ffffffffa026108f t bpf_prog_db4bd11e35df90d4_F ffffffffa0263f00 t bpf_prog_89d64e4abf0f0126_F ffffffffa0257cf9 t bpf_prog_ae31629322c4b018__dummy_tracepoi When a bpf program is loaded, PERF_RECORD_KSYMBOL is generated for each of these sub programs. Therefore, PERF_RECORD_BPF_EVENT is not needed for simple profiling. For annotation, user space need to listen to PERF_RECORD_BPF_EVENT and gather more information about these (sub) programs via sys_bpf.
Showing the changes to include/uapi/linux (1 of 6 files). Show all
Unified · Split
| @@ -373,7 +373,8 @@ struct perf_event_attr { · 372 unmodified lines | |||
| 373 | write_backward : 1, /* Write ring buffer from end to beginning */ | 373 | write_backward : 1, /* Write ring buffer from end to beginning */ |
| 374 | namespaces : 1, /* include namespaces data */ | 374 | namespaces : 1, /* include namespaces data */ |
| 375 | ksymbol : 1, /* include ksymbol events */ | 375 | ksymbol : 1, /* include ksymbol events */ |
| 376 | __reserved_1 : 34; | 376 | bpf_event : 1, /* include bpf events */ |
| 377 | __reserved_1 : 33; | ||
| 377 | 378 | ||
| 378 | union { | 379 | union { |
| 379 | __u32 wakeup_events; /* wakeup every n events */ | 380 | __u32 wakeup_events; /* wakeup every n events */ |
| @@ -979,6 +980,25 @@ enum perf_event_type { · 599 unmodified lines | |||
| 979 | */ | 980 | */ |
| 980 | PERF_RECORD_KSYMBOL = 17, | 981 | PERF_RECORD_KSYMBOL = 17, |
| 981 | 982 | ||
| 983 | /* | ||
| 984 | * Record bpf events: | ||
| 985 | * enum perf_bpf_event_type { | ||
| 986 | * PERF_BPF_EVENT_UNKNOWN = 0, | ||
| 987 | * PERF_BPF_EVENT_PROG_LOAD = 1, | ||
| 988 | * PERF_BPF_EVENT_PROG_UNLOAD = 2, | ||
| 989 | * }; | ||
| 990 | * | ||
| 991 | * struct { | ||
| 992 | * struct perf_event_header header; | ||
| 993 | * u16 type; | ||
| 994 | * u16 flags; | ||
| 995 | * u32 id; | ||
| 996 | * u8 tag[BPF_TAG_SIZE]; | ||
| 997 | * struct sample_id sample_id; | ||
| 998 | * }; | ||
| 999 | */ | ||
| 1000 | PERF_RECORD_BPF_EVENT = 18, | ||
| 1001 | |||
| 982 | PERF_RECORD_MAX, /* non-ABI */ | 1002 | PERF_RECORD_MAX, /* non-ABI */ |
| 983 | }; | 1003 | }; |
| 984 | 1004 | ||
| @@ -990,6 +1010,13 @@ enum perf_record_ksymbol_type { · 5 unmodified lines | |||
| 990 | 1010 | ||
| 991 | #define PERF_RECORD_KSYMBOL_FLAGS_UNREGISTER (1 << 0) | 1011 | #define PERF_RECORD_KSYMBOL_FLAGS_UNREGISTER (1 << 0) |
| 992 | 1012 | ||
| 1013 | enum perf_bpf_event_type { | ||
| 1014 | PERF_BPF_EVENT_UNKNOWN = 0, | ||
| 1015 | PERF_BPF_EVENT_PROG_LOAD = 1, | ||
| 1016 | PERF_BPF_EVENT_PROG_UNLOAD = 2, | ||
| 1017 | PERF_BPF_EVENT_MAX, /* non-ABI */ | ||
| 1018 | }; | ||
| 1019 | |||
| 993 | #define PERF_MAX_STACK_DEPTH 127 | 1020 | #define PERF_MAX_STACK_DEPTH 127 |
| 994 | #define PERF_MAX_CONTEXTS_PER_STACK 8 | 1021 | #define PERF_MAX_CONTEXTS_PER_STACK 8 |
| 995 | 1022 | ||