OSDN Git Service

libbpf: Don't attach perf_buffer to offline/missing CPUs
authorAndrii Nakryiko <andriin@fb.com>
Thu, 12 Dec 2019 01:36:09 +0000 (17:36 -0800)
committerAlexei Starovoitov <ast@kernel.org>
Fri, 13 Dec 2019 21:00:09 +0000 (13:00 -0800)
commit783b8f01f5942a786998f5577bd9ff3992f22a1a
tree0015cd8dd301c2b5fb8d1224713a4c3c97b42017
parent65bc4c4063ae36223375a920b7d116e54d7def34
libbpf: Don't attach perf_buffer to offline/missing CPUs

It's quite common on some systems to have more CPUs enlisted as "possible",
than there are (and could ever be) present/online CPUs. In such cases,
perf_buffer creationg will fail due to inability to create perf event on
missing CPU with error like this:

libbpf: failed to open perf buffer event on cpu #16: No such device

This patch fixes the logic of perf_buffer__new() to ignore CPUs that are
missing or currently offline. In rare cases where user explicitly listed
specific CPUs to connect to, behavior is unchanged: libbpf will try to open
perf event buffer on specified CPU(s) anyways.

Fixes: fb84b8224655 ("libbpf: add perf buffer API")
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20191212013609.1691168-1-andriin@fb.com
tools/lib/bpf/libbpf.c