History

bpf: expose program stats via bpf_prog_info

Return bpf program run_time_ns and run_cnt via bpf_prog_info

Alexei Starovoitov committed 7 years ago

Commit 5f8f8b91 parent 492ecee2 files · +7 −0Browse files

Unified · Split

2 files
  1. include/uapi/linux/bpf.h +2 −0
  2. kernel/bpf/syscall.c +5 −0
include/uapi/linux/bpf.h+2−0
@@ -2813,6 +2813,8 @@ struct bpf_prog_info { · 2812 unmodified lines
28132813 __u32 jited_line_info_rec_size;
28142814 __u32 nr_prog_tags;
28152815 __aligned_u64 prog_tags;
2816+ __u64 run_time_ns;
2817+ __u64 run_cnt;
28162818 } __attribute__((aligned(8)));
28172819
28182820 struct bpf_map_info {
kernel/bpf/syscall.c+5−0
@@ -2152,6 +2152,7 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog, · 2151 unmodified lines
21522152 struct bpf_prog_info __user *uinfo = u64_to_user_ptr(attr->info.info);
21532153 struct bpf_prog_info info = {};
21542154 u32 info_len = attr->info.info_len;
2155+ struct bpf_prog_stats stats;
21552156 char __user *uinsns;
21562157 u32 ulen;
21572158 int err;
@@ -2191,6 +2192,10 @@ static int bpf_prog_get_info_by_fd(struct bpf_prog *prog, · 33 unmodified lines
21912192 if (err)
21922193 return err;
21932194
2195+ bpf_prog_get_stats(prog, &stats);
2196+ info.run_time_ns = stats.nsecs;
2197+ info.run_cnt = stats.cnt;
2198+
21942199 if (!capable(CAP_SYS_ADMIN)) {
21952200 info.jited_prog_len = 0;
21962201 info.xlated_prog_len = 0;