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/linux (2 of 6 files). Show all
Unified · Split
| @@ -951,6 +951,7 @@ bpf_address_lookup(unsigned long addr, unsigned long *size, · 950 unmodified lines | |||
| 951 | 951 | ||
| 952 | void bpf_prog_kallsyms_add(struct bpf_prog *fp); | 952 | void bpf_prog_kallsyms_add(struct bpf_prog *fp); |
| 953 | void bpf_prog_kallsyms_del(struct bpf_prog *fp); | 953 | void bpf_prog_kallsyms_del(struct bpf_prog *fp); |
| 954 | void bpf_get_prog_name(const struct bpf_prog *prog, char *sym); | ||
| 954 | 955 | ||
| 955 | #else /* CONFIG_BPF_JIT */ | 956 | #else /* CONFIG_BPF_JIT */ |
| 956 | 957 | ||
| @@ -1006,6 +1007,12 @@ static inline void bpf_prog_kallsyms_add(struct bpf_prog *fp) · 49 unmodified lines | |||
| 1006 | static inline void bpf_prog_kallsyms_del(struct bpf_prog *fp) | 1007 | static inline void bpf_prog_kallsyms_del(struct bpf_prog *fp) |
| 1007 | { | 1008 | { |
| 1008 | } | 1009 | } |
| 1010 | |||
| 1011 | static inline void bpf_get_prog_name(const struct bpf_prog *prog, char *sym) | ||
| 1012 | { | ||
| 1013 | sym[0] = '\0'; | ||
| 1014 | } | ||
| 1015 | |||
| 1009 | #endif /* CONFIG_BPF_JIT */ | 1016 | #endif /* CONFIG_BPF_JIT */ |
| 1010 | 1017 | ||
| 1011 | void bpf_prog_kallsyms_del_subprogs(struct bpf_prog *fp); | 1018 | void bpf_prog_kallsyms_del_subprogs(struct bpf_prog *fp); |
| @@ -1125,6 +1125,9 @@ extern void perf_event_mmap(struct vm_area_struct *vma); · 1124 unmodified lines | |||
| 1125 | 1125 | ||
| 1126 | extern void perf_event_ksymbol(u16 ksym_type, u64 addr, u32 len, | 1126 | extern void perf_event_ksymbol(u16 ksym_type, u64 addr, u32 len, |
| 1127 | bool unregister, const char *sym); | 1127 | bool unregister, const char *sym); |
| 1128 | extern void perf_event_bpf_event(struct bpf_prog *prog, | ||
| 1129 | enum perf_bpf_event_type type, | ||
| 1130 | u16 flags); | ||
| 1128 | 1131 | ||
| 1129 | extern struct perf_guest_info_callbacks *perf_guest_cbs; | 1132 | extern struct perf_guest_info_callbacks *perf_guest_cbs; |
| 1130 | extern int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks); | 1133 | extern int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks); |
| @@ -1350,6 +1353,9 @@ static inline void perf_event_mmap(struct vm_area_struct *vma) { } · 219 unmodified lines | |||
| 1350 | typedef int (perf_ksymbol_get_name_f)(char *name, int name_len, void *data); | 1353 | typedef int (perf_ksymbol_get_name_f)(char *name, int name_len, void *data); |
| 1351 | static inline void perf_event_ksymbol(u16 ksym_type, u64 addr, u32 len, | 1354 | static inline void perf_event_ksymbol(u16 ksym_type, u64 addr, u32 len, |
| 1352 | bool unregister, const char *sym) { } | 1355 | bool unregister, const char *sym) { } |
| 1356 | static inline void perf_event_bpf_event(struct bpf_prog *prog, | ||
| 1357 | enum perf_bpf_event_type type, | ||
| 1358 | u16 flags) { } | ||
| 1353 | static inline void perf_event_exec(void) { } | 1359 | static inline void perf_event_exec(void) { } |
| 1354 | static inline void perf_event_comm(struct task_struct *tsk, bool exec) { } | 1360 | static inline void perf_event_comm(struct task_struct *tsk, bool exec) { } |
| 1355 | static inline void perf_event_namespaces(struct task_struct *tsk) { } | 1361 | static inline void perf_event_namespaces(struct task_struct *tsk) { } |