diff options
author | Hechao Li <hechaol@fb.com> | 2019-06-10 17:56:50 -0700 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2019-06-11 10:36:02 +0200 |
commit | 6446b3155521aab37f5a2b99ac264803ea7dced8 (patch) | |
tree | 76c48512b43d492676d778e6b1d18fe1bef58b1c /tools/lib/bpf/libbpf.h | |
parent | 89cceaa939171fafa153d4bf637b39e396bbd785 (diff) | |
download | linux-6446b3155521aab37f5a2b99ac264803ea7dced8.tar.gz linux-6446b3155521aab37f5a2b99ac264803ea7dced8.tar.bz2 linux-6446b3155521aab37f5a2b99ac264803ea7dced8.zip |
bpf: add a new API libbpf_num_possible_cpus()
Adding a new API libbpf_num_possible_cpus() that helps user with
per-CPU map operations.
Signed-off-by: Hechao Li <hechaol@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'tools/lib/bpf/libbpf.h')
-rw-r--r-- | tools/lib/bpf/libbpf.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tools/lib/bpf/libbpf.h b/tools/lib/bpf/libbpf.h index 1af0d48178c8..2e594a0fa961 100644 --- a/tools/lib/bpf/libbpf.h +++ b/tools/lib/bpf/libbpf.h @@ -454,6 +454,22 @@ bpf_program__bpil_addr_to_offs(struct bpf_prog_info_linear *info_linear); LIBBPF_API void bpf_program__bpil_offs_to_addr(struct bpf_prog_info_linear *info_linear); +/* + * A helper function to get the number of possible CPUs before looking up + * per-CPU maps. Negative errno is returned on failure. + * + * Example usage: + * + * int ncpus = libbpf_num_possible_cpus(); + * if (ncpus < 0) { + * // error handling + * } + * long values[ncpus]; + * bpf_map_lookup_elem(per_cpu_map_fd, key, values); + * + */ +LIBBPF_API int libbpf_num_possible_cpus(void); + #ifdef __cplusplus } /* extern "C" */ #endif |