mirror of
https://github.com/netdata/libbpf.git
synced 2026-04-05 08:09:07 +08:00
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>
This commit is contained in:
committed by
Andrii Nakryiko
parent
4f260bccf5
commit
49967c1f5a
16
src/libbpf.h
16
src/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
|
||||
|
||||
Reference in New Issue
Block a user