linux/tools/bpf/bpftool
Tonghao Zhang 9d786d1a1c bpftool: profile online CPUs instead of possible
[ Upstream commit 377c16fa3f ]

The number of online cpu may be not equal to possible cpu.
"bpftool prog profile" can not create pmu event on possible
but on online cpu.

$ dmidecode -s system-product-name
PowerEdge R620
$ cat /sys/devices/system/cpu/possible
0-47
$ cat /sys/devices/system/cpu/online
0-31

Disable cpu dynamically:
$ echo 0 > /sys/devices/system/cpu/cpuX/online

If one cpu is offline, perf_event_open will return ENODEV.
To fix this issue:
* check value returned and skip offline cpu.
* close pmu_fd immediately on error path, avoid fd leaking.

Fixes: 47c09d6a9f ("bpftool: Introduce "prog profile" command")
Signed-off-by: Tonghao Zhang <tong@infragraf.org>
Cc: Quentin Monnet <quentin@isovalent.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Martin KaFai Lau <martin.lau@linux.dev>
Cc: Song Liu <song@kernel.org>
Cc: Yonghong Song <yhs@fb.com>
Cc: John Fastabend <john.fastabend@gmail.com>
Cc: KP Singh <kpsingh@kernel.org>
Cc: Stanislav Fomichev <sdf@google.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Link: https://lore.kernel.org/r/20230202131701.29519-1-tong@infragraf.org
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2023-03-10 09:32:58 +01:00
..
bash-completion
Documentation bpf: Define new BPF_MAP_TYPE_USER_RINGBUF map type 2022-09-21 16:24:17 -07:00
skeleton
.gitignore
btf_dumper.c
btf.c bpftool: Fix error message of strerror 2022-09-30 15:40:46 -07:00
cfg.c
cfg.h
cgroup.c bpftool: Fix wrong cgroup attach flags being assigned to effective progs 2022-09-21 10:57:12 -07:00
common.c bpftool: Fix memory leak in do_build_table_cb 2022-12-31 13:32:23 +01:00
feature.c
gen.c bpftool: Fix error message of strerror 2022-09-30 15:40:46 -07:00
iter.c
jit_disasm.c
json_writer.c
json_writer.h
link.c bpftool: Show parameters of BPF task iterators. 2022-09-28 16:30:08 -07:00
main.c
main.h
Makefile
map_perf_ring.c bpftool: Fix error message of strerror 2022-09-30 15:40:46 -07:00
map.c bpf: Define new BPF_MAP_TYPE_USER_RINGBUF map type 2022-09-21 16:24:17 -07:00
net.c
netlink_dumper.c
netlink_dumper.h
perf.c
pids.c
prog.c bpftool: profile online CPUs instead of possible 2023-03-10 09:32:58 +01:00
struct_ops.c
tracelog.c
xlated_dumper.c
xlated_dumper.h