Commit 1a734efe authored by Toke Høiland-Jørgensen's avatar Toke Høiland-Jørgensen Committed by Alexei Starovoitov

libbpf: Add getter for program size

This adds a new getter for the BPF program size (in bytes). This is useful
for a caller that is trying to predict how much memory will be locked by
loading a BPF object into the kernel.
Signed-off-by: default avatarToke Høiland-Jørgensen <toke@redhat.com>
Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
Acked-by: default avatarAndrii Nakryiko <andriin@fb.com>
Acked-by: default avatarDavid S. Miller <davem@davemloft.net>
Acked-by: default avatarSong Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/157333185272.88376.10996937115395724683.stgit@toke.dk
parent 473f4e13
...@@ -4782,6 +4782,11 @@ int bpf_program__fd(const struct bpf_program *prog) ...@@ -4782,6 +4782,11 @@ int bpf_program__fd(const struct bpf_program *prog)
return bpf_program__nth_fd(prog, 0); return bpf_program__nth_fd(prog, 0);
} }
size_t bpf_program__size(const struct bpf_program *prog)
{
return prog->insns_cnt * sizeof(struct bpf_insn);
}
int bpf_program__set_prep(struct bpf_program *prog, int nr_instances, int bpf_program__set_prep(struct bpf_program *prog, int nr_instances,
bpf_program_prep_t prep) bpf_program_prep_t prep)
{ {
......
...@@ -214,6 +214,9 @@ LIBBPF_API void bpf_program__set_ifindex(struct bpf_program *prog, ...@@ -214,6 +214,9 @@ LIBBPF_API void bpf_program__set_ifindex(struct bpf_program *prog,
LIBBPF_API const char *bpf_program__title(const struct bpf_program *prog, LIBBPF_API const char *bpf_program__title(const struct bpf_program *prog,
bool needs_copy); bool needs_copy);
/* returns program size in bytes */
LIBBPF_API size_t bpf_program__size(const struct bpf_program *prog);
LIBBPF_API int bpf_program__load(struct bpf_program *prog, char *license, LIBBPF_API int bpf_program__load(struct bpf_program *prog, char *license,
__u32 kern_version); __u32 kern_version);
LIBBPF_API int bpf_program__fd(const struct bpf_program *prog); LIBBPF_API int bpf_program__fd(const struct bpf_program *prog);
......
...@@ -203,4 +203,5 @@ LIBBPF_0.0.6 { ...@@ -203,4 +203,5 @@ LIBBPF_0.0.6 {
bpf_program__get_type; bpf_program__get_type;
bpf_program__is_tracing; bpf_program__is_tracing;
bpf_program__set_tracing; bpf_program__set_tracing;
bpf_program__size;
} LIBBPF_0.0.5; } LIBBPF_0.0.5;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment