Skip to content

Commit 07480cb

Browse files
Jakub Kicinskiborkmann
authored andcommitted
tools: bpftool: improve accuracy of load time
BPF program load time is reported from the kernel relative to boot time. If conversion to wall clock does not take nanosecond parts into account, the load time reported by bpftool may differ by one second from run to run. This means JSON object reported by bpftool for a program will randomly change. Fixes: 71bb428 ("tools: bpf: add bpftool") Signed-off-by: Jakub Kicinski <[email protected]> Reviewed-by: Quentin Monnet <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent 3bce593 commit 07480cb

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

tools/bpf/bpftool/prog.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ static void print_boot_time(__u64 nsecs, char *buf, unsigned int size)
9090
}
9191

9292
wallclock_secs = (real_time_ts.tv_sec - boot_time_ts.tv_sec) +
93-
nsecs / 1000000000;
93+
(real_time_ts.tv_nsec - boot_time_ts.tv_nsec + nsecs) /
94+
1000000000;
95+
9496

9597
if (!localtime_r(&wallclock_secs, &load_tm)) {
9698
snprintf(buf, size, "%llu", nsecs / 1000000000);

0 commit comments

Comments
 (0)