]> www.infradead.org Git - users/jedix/linux-maple.git/commit
veristat: Load struct_ops programs only once
authorEduard Zingerman <eddyz87@gmail.com>
Wed, 15 Jan 2025 22:38:35 +0000 (14:38 -0800)
committerAndrii Nakryiko <andrii@kernel.org>
Thu, 16 Jan 2025 23:33:58 +0000 (15:33 -0800)
commit7c311b7cb3c7d84c5c342e803c5cb1b2fabbc438
tree44672c606fd07d5cc8011029851b96d8d0ed0caa
parenta8d1c48d0720140b53063ff23507845bb2078e92
veristat: Load struct_ops programs only once

libbpf automatically adjusts autoload for struct_ops programs,
see libbpf.c:bpf_object_adjust_struct_ops_autoload.

For example, if there is a map:

    SEC(".struct_ops.link")
    struct sched_ext_ops ops = {
     .enqueue = foo,
        .tick = bar,
    };

Both 'foo' and 'bar' would be loaded if 'ops' autocreate is true,
both 'foo' and 'bar' would be skipped if 'ops' autocreate is false.

This means that when veristat processes object file with 'ops',
it would load 4 programs in total: two programs per each
'process_prog' call.

The adjustment occurs at object load time, and libbpf remembers
association between 'ops' and 'foo'/'bar' at object open time.
The only way to persuade libbpf to load one of two is to adjust map
initial value, such that only one program is referenced.
This patch does exactly that, significantly reducing time to process
object files with big number of struct_ops programs.

Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20250115223835.919989-1-eddyz87@gmail.com
tools/testing/selftests/bpf/veristat.c