From: Dmitry V. Levin Date: Tue, 21 May 2019 23:30:35 +0000 (+0000) Subject: bpf: add support for new fields in struct bpf_prog_info X-Git-Tag: v5.1~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2962a8b02d9ead052d21c02c120ffbcc3fdcfaf7;p=strace bpf: add support for new fields in struct bpf_prog_info * bpf_attr.h (struct bpf_prog_info_struct): Add run_time_ns and run_cnt fields. * bpf.c (print_bpf_prog_info): Decode run_time_ns and run_cnt fields introduced by Linux kernel commit v5.1-rc1~178^2~17^2~15^2~2. * NEWS: Mention it. * tests/bpf-obj_get_info_by_fd.c (main): Update expected output. --- diff --git a/NEWS b/NEWS index 667571f6..ad5e8380 100644 --- a/NEWS +++ b/NEWS @@ -15,6 +15,7 @@ Noteworthy changes in release ?.? (????-??-??) rt_sigtimedwait_time64, futex_time64, sched_rr_get_interval_time64, pidfd_send_signal, io_uring_setup, io_uring_enter, and io_uring_register syscalls. + * Enhanced decoding of bpf syscall. * Wired up getegid, geteuid, getppid, io_pgetevents, statfs64, and fstatfs64 syscalls on alpha. * Wired up kexec_file_load and migrate_pages syscalls on arm. diff --git a/bpf.c b/bpf.c index cd13167b..1eeb0e44 100644 --- a/bpf.c +++ b/bpf.c @@ -691,6 +691,16 @@ print_bpf_prog_info(struct tcb * const tcp, uint32_t bpf_fd, PRINT_FIELD_ADDR64(", ", info, prog_tags); + /* + * run_time_ns and run_cnt fields were introduced + * by Linux commit v5.1-rc1~178^2~17^2~15^2~2. + */ + if (len <= offsetof(struct bpf_prog_info_struct, run_time_ns)) + goto print_bpf_prog_info_end; + + PRINT_FIELD_U(", ", info, run_time_ns); + PRINT_FIELD_U(", ", info, run_cnt); + decode_attr_extra_data(tcp, info_buf, size, bpf_prog_info_struct_size); print_bpf_prog_info_end: diff --git a/bpf_attr.h b/bpf_attr.h index 5d888dd8..5c5eee41 100644 --- a/bpf_attr.h +++ b/bpf_attr.h @@ -332,10 +332,12 @@ struct bpf_prog_info_struct { uint32_t jited_line_info_rec_size; uint32_t nr_prog_tags; uint64_t ATTRIBUTE_ALIGNED(8) prog_tags; + uint64_t ATTRIBUTE_ALIGNED(8) run_time_ns; + uint64_t ATTRIBUTE_ALIGNED(8) run_cnt; }; # define bpf_prog_info_struct_size \ sizeof(struct bpf_prog_info_struct) -# define expected_bpf_prog_info_struct_size 192 +# define expected_bpf_prog_info_struct_size 208 #endif /* !STRACE_BPF_ATTR_H */ diff --git a/tests/bpf-obj_get_info_by_fd.c b/tests/bpf-obj_get_info_by_fd.c index 6444ff81..243a62a0 100644 --- a/tests/bpf-obj_get_info_by_fd.c +++ b/tests/bpf-obj_get_info_by_fd.c @@ -585,6 +585,14 @@ main(void) if (bpf_prog_get_info_attr.info_len > offsetof(struct bpf_prog_info_struct, prog_tags)) printf(", prog_tags=NULL"); + if (bpf_prog_get_info_attr.info_len > + offsetof(struct bpf_prog_info_struct, run_time_ns)) + printf(", run_time_ns=%llu", + (unsigned long long) prog_info->run_time_ns); + if (bpf_prog_get_info_attr.info_len > + offsetof(struct bpf_prog_info_struct, run_cnt)) + printf(", run_cnt=%llu", + (unsigned long long) prog_info->run_cnt); printf("}"); # else /* !VERBOSE */