bpf: Add load_time in bpf_prog fdinfo
PATCH 1/1 bpf: Add load_time in bpf_prog fdinfo
The field run_time_ns can tell us the run time of the bpf_prog, and load_time_s can tell us how long the bpf_prog loaded on the machine.
--- kernel/bpf/syscall.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
kernel/bpf/syscall.c +5 -2
@@ -2438,6 +2438,7 @@ static void bpf_prog_show_fdinfo(struct seq_file *m, struct file *filp)const struct bpf_prog *prog = filp->private_data;char prog_tag[sizeof (prog->tag) *2 +1 ] = { };struct bpf_prog_kstats stats; +u64 now =ktime_get_boottime_ns ();bpf_prog_get_stats (prog, &stats);bin2hex (prog_tag, prog->tag,sizeof (prog->tag));
@@ -2450,7 +2451,8 @@ static void bpf_prog_show_fdinfo(struct seq_file *m, struct file *filp)"run_time_ns:\t%llu\n" "run_cnt:\t%llu\n" "recursion_misses:\t%llu\n" -"verified_insns:\t%u\n" , +"verified_insns:\t%u\n" +"load_time_s:\t%llu\n" , prog->type, prog->jited, prog_tag,
@@ -2459,7 +2461,8 @@ static void bpf_prog_show_fdinfo(struct seq_file *m, struct file *filp) stats.nsecs, stats.cnt, stats.misses, - prog->aux->verified_insns); + prog->aux->verified_insns, + (now - prog->aux->load_time) / NSEC_PER_SEC); }#endif
Signature · 1 line
2.48.1
Quoted 33 lines · Tao Chen
The field
run_time_nscan tell us the run time of thebpf_prog, andload_time_scan tell us how long thebpf_progloaded on the machine.Signed-off-by Tao Chen <[email protected]>--- kernel/bpf/syscall.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)kernel/bpf/syscall.c +3
-1@@ -2438,6 +2438,7 @@ static void bpf_prog_show_fdinfo(struct seq_file *m, struct file *filp)const struct bpf_prog *prog = filp->private_data;char prog_tag[sizeof (prog->tag) *2 +1 ] = { };struct bpf_prog_kstats stats; +u64 now =ktime_get_boottime_ns ();bpf_prog_get_stats (prog, &stats);bin2hex (prog_tag, prog->tag,sizeof (prog->tag));@@ -2450,7 +2451,8 @@ static void bpf_prog_show_fdinfo(struct seq_file *m, struct file *filp)"run_time_ns:\t%llu\n" "run_cnt:\t%llu\n" "recursion_misses:\t%llu\n" -"verified_insns:\t%u\n" , +"verified_insns:\t%u\n" +"load_time_s:\t%llu\n" , prog->type, prog->jited, prog_tag,
kernel/bpf/syscall.c static void bpf_prog_show_fdinfo(struct seq_file *m, struct file *filp) · line 2465
Quoted 6 lines
kernel/bpf/syscall.c +2
-1@@ -2459,7 +2461,8 @@ static void bpf_prog_show_fdinfo(struct seq_file *m, struct file *filp) stats.nsecs, stats.cnt, stats.misses, - prog->aux->verified_insns); + prog->aux->verified_insns, + (now - prog->aux->load_time) / NSEC_PER_SEC);
I don't like where it's going.
Soon fdinfo will be printing the xlated insns of the prog too, since why not?
Let's stop here. We have syscall query api-s for that and bpftool to print such things.
No more fdinfo "improvements".
Quoted 39 lines · Alexei Starovoitov
Quoted 38 lines · Tao Chen
The field
run_time_nscan tell us the run time of thebpf_prog, andload_time_scan tell us how long thebpf_progloaded on the machine.Signed-off-by Tao Chen <[email protected]>--- kernel/bpf/syscall.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)kernel/bpf/syscall.c +4
-2@@ -2438,6 +2438,7 @@ static void bpf_prog_show_fdinfo(struct seq_file *m, struct file *filp)const struct bpf_prog *prog = filp->private_data;char prog_tag[sizeof (prog->tag) *2 +1 ] = { };struct bpf_prog_kstats stats; +u64 now =ktime_get_boottime_ns ();bpf_prog_get_stats (prog, &stats);bin2hex (prog_tag, prog->tag,sizeof (prog->tag));@@ -2450,7 +2451,8 @@ static void bpf_prog_show_fdinfo(struct seq_file *m, struct file *filp)"run_time_ns:\t%llu\n" "run_cnt:\t%llu\n" "recursion_misses:\t%llu\n" -"verified_insns:\t%u\n" , +"verified_insns:\t%u\n" +"load_time_s:\t%llu\n" , prog->type, prog->jited, prog_tag,@@ -2459,7 +2461,8 @@ static void bpf_prog_show_fdinfo(struct seq_file *m, struct file *filp) stats.nsecs, stats.cnt, stats.misses, - prog->aux->verified_insns); + prog->aux->verified_insns,
Quoted 8 lines
kernel/bpf/syscall.c static void bpf_prog_show_fdinfo(struct seq_file *m, struct file *filp) · line 2465
Quoted 1 line
kernel/bpf/syscall.c +1
-0+ (now - prog->aux->load_time) / NSEC_PER_SEC);I don't like where it's going.
Soon fdinfo will be printing the xlated insns of the prog too, since why not?
Let's stop here. We have syscall query api-s for that and bpftool to print such things.
No more fdinfo "improvements".
Got it, Alexei, thanks for your patient explanation.
Signature · 2 lines
Best Regards Tao Chen
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Tao,
kernel test robot noticed the following build errors:
[auto build test ERROR on bpf-next/master]
url: https://github.com/intel-lab-lkp/linux/commits/Tao-Chen/bpf-Add-load_time-in-bpf_prog-fdinfo/20250620-131249 base: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master patch link: https://lore.kernel.org/r/20250620051017.111559-1-chen.dylane%40linux.dev patch subject: [PATCH bpf-next] bpf: Add load_time in bpf_prog fdinfo config: m68k-randconfig-r123-20250622 (https://download.01.org/0day-ci/archive/20250622/[email protected]/config) compiler: m68k-linux-gcc (GCC) 8.5.0 reproduce: (https://download.01.org/0day-ci/archive/20250622/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
m68k-linux-ld: kernel/bpf/syscall.o: in function `bpf_prog_show_fdinfo':
>> syscall.c:(.text+0x1088): undefined reference to `__udivdi3'
m68k-linux-ld: drivers/clocksource/timer-tegra186.o: in function `tegra186_wdt_get_timeleft':
timer-tegra186.c:(.text+0x130): undefined reference to `__udivdi3'
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki