From: Tonghao Zhang <tong@xxxxxxxxxxxxx> The number of online cpu may be not equal to possible cpu. bpftool prog profile, can not create pmu event on possible but not online cpu. $ dmidecode -s system-product-name PowerEdge R620 $ cat /sys/devices/system/cpu/online 0-31 $ cat /sys/devices/system/cpu/possible 0-47 To fix this issue, use online cpu instead of possible, to create perf event and other resource. Signed-off-by: Tonghao Zhang <tong@xxxxxxxxxxxxx> Cc: Quentin Monnet <quentin@xxxxxxxxxxxxx> Cc: Alexei Starovoitov <ast@xxxxxxxxxx> Cc: Daniel Borkmann <daniel@xxxxxxxxxxxxx> Cc: Andrii Nakryiko <andrii@xxxxxxxxxx> Cc: Martin KaFai Lau <martin.lau@xxxxxxxxx> Cc: Song Liu <song@xxxxxxxxxx> Cc: Yonghong Song <yhs@xxxxxx> Cc: John Fastabend <john.fastabend@xxxxxxxxx> Cc: KP Singh <kpsingh@xxxxxxxxxx> Cc: Stanislav Fomichev <sdf@xxxxxxxxxx> Cc: Hao Luo <haoluo@xxxxxxxxxx> Cc: Jiri Olsa <jolsa@xxxxxxxxxx> --- tools/bpf/bpftool/prog.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c index cfc9fdc1e863..08b352dd799e 100644 --- a/tools/bpf/bpftool/prog.c +++ b/tools/bpf/bpftool/prog.c @@ -2056,6 +2056,7 @@ static int profile_parse_metrics(int argc, char **argv) static void profile_read_values(struct profiler_bpf *obj) { + __u32 possible_cpus = libbpf_num_possible_cpus(); __u32 m, cpu, num_cpu = obj->rodata->num_cpu; int reading_map_fd, count_map_fd; __u64 counts[num_cpu]; @@ -2080,7 +2081,7 @@ static void profile_read_values(struct profiler_bpf *obj) profile_total_count += counts[cpu]; for (m = 0; m < ARRAY_SIZE(metrics); m++) { - struct bpf_perf_event_value values[num_cpu]; + struct bpf_perf_event_value values[possible_cpus]; if (!metrics[m].selected) continue; @@ -2321,7 +2322,7 @@ static int do_profile(int argc, char **argv) if (num_metric <= 0) goto out; - num_cpu = libbpf_num_possible_cpus(); + num_cpu = libbpf_num_online_cpus(); if (num_cpu <= 0) { p_err("failed to identify number of CPUs"); goto out; -- 2.27.0