]> granicus.if.org Git - strace/commitdiff
bpf: add support for new fields in struct bpf_prog_info
authorDmitry V. Levin <ldv@altlinux.org>
Tue, 21 May 2019 23:30:35 +0000 (23:30 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 21 May 2019 23:30:35 +0000 (23:30 +0000)
* 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.

NEWS
bpf.c
bpf_attr.h
tests/bpf-obj_get_info_by_fd.c

diff --git a/NEWS b/NEWS
index 667571f6a6a931966c3614105365bd8c6b573ba0..ad5e838092842ad90d703ce6621a55ae97f63f2d 100644 (file)
--- 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 cd13167b88029cca3e31bb62f0bdf78f4e5877da..1eeb0e440a7f417df81444f4e1e85e2a595eea55 100644 (file)
--- 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:
index 5d888dd8b8f19fb349238031710129fcbdaca180..5c5eee410c8a037d304af5b0f4a166f5ca028e57 100644 (file)
@@ -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 */
index 6444ff8136782e1c58ce5b6c4100d88551839974..243a62a092c1f1dedeb252fc598c70f37e39c0d4 100644 (file)
@@ -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 */