kernel/bpf/syscall.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
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.
Signed-off-by: Tao Chen <chen.dylane@linux.dev>
---
kernel/bpf/syscall.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
index 51ba1a7aa43..407841ea296 100644
--- a/kernel/bpf/syscall.c
+++ b/kernel/bpf/syscall.c
@@ -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
--
2.48.1
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/202506221641.xWzKiW3U-lkp@intel.com/config) compiler: m68k-linux-gcc (GCC) 8.5.0 reproduce: (https://download.01.org/0day-ci/archive/20250622/202506221641.xWzKiW3U-lkp@intel.com/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 <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202506221641.xWzKiW3U-lkp@intel.com/ 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' -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
On Thu, Jun 19, 2025 at 10:10 PM Tao Chen <chen.dylane@linux.dev> wrote:
>
> 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.
>
> Signed-off-by: Tao Chen <chen.dylane@linux.dev>
> ---
> kernel/bpf/syscall.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> index 51ba1a7aa43..407841ea296 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c
> @@ -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);
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".
在 2025/6/21 02:27, Alexei Starovoitov 写道:
> On Thu, Jun 19, 2025 at 10:10 PM Tao Chen <chen.dylane@linux.dev> wrote:
>>
>> 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.
>>
>> Signed-off-by: Tao Chen <chen.dylane@linux.dev>
>> ---
>> kernel/bpf/syscall.c | 7 +++++--
>> 1 file changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
>> index 51ba1a7aa43..407841ea296 100644
>> --- a/kernel/bpf/syscall.c
>> +++ b/kernel/bpf/syscall.c
>> @@ -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);
>
> 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.
--
Best Regards
Tao Chen
© 2016 - 2026 Red Hat, Inc.