History

perf, bpf: Introduce PERF_RECORD_BPF_EVENT

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.

Song Liu committed 7 years ago

Commit 6ee52e21 parent d764ac66 files · +159 −2Browse files

Showing the changes to include/linux (2 of 6 files). Show all

Unified · Split

2 files
  1. include/linux/filter.h +7 −0
  2. include/linux/perf_event.h +6 −0
include/linux/filter.h+7−0
@@ -951,6 +951,7 @@ bpf_address_lookup(unsigned long addr, unsigned long *size, · 950 unmodified lines
951 951
952void bpf_prog_kallsyms_add(struct bpf_prog *fp);952void bpf_prog_kallsyms_add(struct bpf_prog *fp);
953void bpf_prog_kallsyms_del(struct bpf_prog *fp);953void bpf_prog_kallsyms_del(struct bpf_prog *fp);
954void 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
1006static inline void bpf_prog_kallsyms_del(struct bpf_prog *fp)1007static inline void bpf_prog_kallsyms_del(struct bpf_prog *fp)
1007{1008{
1008}1009}
1010
1011static 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
1011void bpf_prog_kallsyms_del_subprogs(struct bpf_prog *fp);1018void bpf_prog_kallsyms_del_subprogs(struct bpf_prog *fp);
include/linux/perf_event.h+6−0
@@ -1125,6 +1125,9 @@ extern void perf_event_mmap(struct vm_area_struct *vma); · 1124 unmodified lines
1125 1125
1126extern void perf_event_ksymbol(u16 ksym_type, u64 addr, u32 len,1126extern void perf_event_ksymbol(u16 ksym_type, u64 addr, u32 len,
1127 bool unregister, const char *sym);1127 bool unregister, const char *sym);
1128extern void perf_event_bpf_event(struct bpf_prog *prog,
1129 enum perf_bpf_event_type type,
1130 u16 flags);
1128 1131
1129extern struct perf_guest_info_callbacks *perf_guest_cbs;1132extern struct perf_guest_info_callbacks *perf_guest_cbs;
1130extern int perf_register_guest_info_callbacks(struct perf_guest_info_callbacks *callbacks);1133extern 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
1350typedef int (perf_ksymbol_get_name_f)(char *name, int name_len, void *data);1353typedef int (perf_ksymbol_get_name_f)(char *name, int name_len, void *data);
1351static inline void perf_event_ksymbol(u16 ksym_type, u64 addr, u32 len,1354static inline void perf_event_ksymbol(u16 ksym_type, u64 addr, u32 len,
1352 bool unregister, const char *sym) { }1355 bool unregister, const char *sym) { }
1356static inline void perf_event_bpf_event(struct bpf_prog *prog,
1357 enum perf_bpf_event_type type,
1358 u16 flags) { }
1353static inline void perf_event_exec(void) { }1359static inline void perf_event_exec(void) { }
1354static inline void perf_event_comm(struct task_struct *tsk, bool exec) { }1360static inline void perf_event_comm(struct task_struct *tsk, bool exec) { }
1355static inline void perf_event_namespaces(struct task_struct *tsk) { }1361static inline void perf_event_namespaces(struct task_struct *tsk) { }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t