perf intel-pt: Fix 'CPU too large' error
Adrian Hunter
reviewerPATCH 1/1 perf intel-pt: Fix 'CPU too large' error
In some cases, the number of cpus (nr_cpus_online) is confused with the maximum cpu number (nr_cpus_avail), which results in the error in the example below:
Example on system with 8 cpus:
Before:
# echo 0 > /sys/devices/system/cpu/cpu2/online # ./perf record --kcore -e intel_pt// taskset --cpu-list 7 uname Linux [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.147 MB perf.data ] # ./perf script --itrace=e Requested CPU 7 too large. Consider raising MAX_NR_CPUS 0x25908 [0x8]: failed to process type: 68 [Invalid argument]
After:
# ./perf script --itrace=e #
--- tools/perf/util/machine.c | 4 ++-- tools/perf/util/session.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
tools/perf/util/machine.c +2 -2
@@ -2977,7 +2977,7 @@ int machines__for_each_thread(struct machines *machines,pid_t machine__get_current_tid (struct machine *machine,int cpu) { -int nr_cpus =min (machine->env->nr_cpus_online,MAX_NR_CPUS ); +int nr_cpus =min (machine->env->nr_cpus_avail,MAX_NR_CPUS );if (cpu <0 || cpu >= nr_cpus || !machine->current_tid)return -1 ;
@@ -2989,7 +2989,7 @@ int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid, pid_t tid) {struct thread *thread; -int nr_cpus =min (machine->env->nr_cpus_online,MAX_NR_CPUS ); +int nr_cpus =min (machine->env->nr_cpus_avail,MAX_NR_CPUS );if (cpu <0 )return -EINVAL ;
tools/perf/util/session.c +1 -1
@@ -2391,7 +2391,7 @@ int perf_session__cpu_bitmap(struct perf_session *session, {int i, err =-1 ;struct perf_cpu_map *map; -int nr_cpus =min (session->header.env.nr_cpus_online,MAX_NR_CPUS ); +int nr_cpus =min (session->header.env.nr_cpus_avail,MAX_NR_CPUS );for (i =0 ; i <PERF_TYPE_MAX ; ++i) {struct evsel *evsel;
Signature · 1 line
2.17.1
Quoted 16 lines · Adrian Hunter
In some cases, the number of cpus (
nr_cpus_online) is confused with the maximum cpu number (nr_cpus_avail), which results in the error in the example below:Example on system with 8 cpus:
Before:
# echo 0 > /sys/devices/system/cpu/cpu2/online # ./perf record --kcore -e intel_pt// taskset --cpu-list 7 uname Linux [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.147 MB perf.data ] # ./perf script --itrace=e Requested CPU 7 too large. Consider raising MAX_NR_CPUS 0x25908 [0x8]: failed to process type: 68 [Invalid argument]
Quoted 8 lines
After:
# ./perf script --itrace=e #Fixes 8c7274691f0d ("perf machine: Replace MAX_NR_CPUS with perf_env::nr_cpus_online")Fixes 7df4e36a4785 ("perf session: Replace MAX_NR_CPUS with perf_env::nr_cpus_online")Signed-off-by Adrian Hunter <[email protected]>
Thanks,
Kan
Quoted 41 lines
--- tools/perf/util/machine.c | 4 ++-- tools/perf/util/session.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)tools/perf/util/machine.c +2
-2@@ -2977,7 +2977,7 @@ int machines__for_each_thread(struct machines *machines,pid_t machine__get_current_tid (struct machine *machine,int cpu) { -int nr_cpus =min (machine->env->nr_cpus_online,MAX_NR_CPUS ); +int nr_cpus =min (machine->env->nr_cpus_avail,MAX_NR_CPUS );if (cpu <0 || cpu >= nr_cpus || !machine->current_tid)return -1 ;@@ -2989,7 +2989,7 @@ int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid, pid_t tid) {struct thread *thread; -int nr_cpus =min (machine->env->nr_cpus_online,MAX_NR_CPUS ); +int nr_cpus =min (machine->env->nr_cpus_avail,MAX_NR_CPUS );if (cpu <0 )return -EINVAL ;tools/perf/util/session.c +1
-1@@ -2391,7 +2391,7 @@ int perf_session__cpu_bitmap(struct perf_session *session, {int i, err =-1 ;struct perf_cpu_map *map; -int nr_cpus =min (session->header.env.nr_cpus_online,MAX_NR_CPUS ); +int nr_cpus =min (session->header.env.nr_cpus_avail,MAX_NR_CPUS );for (i =0 ; i <PERF_TYPE_MAX ; ++i) {struct evsel *evsel;
Em Thu, Jan 07, 2021 at 03:46:03PM -0500, Liang, Kan escreveu:
Quoted 23 lines · Adrian Hunter
Quoted 20 lines
In some cases, the number of cpus (
nr_cpus_online) is confused with the maximum cpu number (nr_cpus_avail), which results in the error in the example below:Example on system with 8 cpus:
Before:
# echo 0 > /sys/devices/system/cpu/cpu2/online # ./perf record --kcore -e intel_pt// taskset --cpu-list 7 uname Linux [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.147 MB perf.data ] # ./perf script --itrace=e Requested CPU 7 too large. Consider raising MAX_NR_CPUS 0x25908 [0x8]: failed to process type: 68 [Invalid argument]After:
# ./perf script --itrace=e #
Quoted 7 lines
Quoted 4 lines
Fixes 8c7274691f0d ("perf machine: Replace MAX_NR_CPUS with perf_env::nr_cpus_online")Fixes 7df4e36a4785 ("perf session: Replace MAX_NR_CPUS with perf_env::nr_cpus_online")Signed-off-by Adrian Hunter <[email protected]>Tested-by Kan Liang <[email protected]>
Thanks, applied.
- Arnaldo
Quoted 40 lines
Thanks,
KanQuoted 37 lines
--- tools/perf/util/machine.c | 4 ++-- tools/perf/util/session.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)tools/perf/util/machine.c +2
-2@@ -2977,7 +2977,7 @@ int machines__for_each_thread(struct machines *machines,pid_t machine__get_current_tid (struct machine *machine,int cpu) { -int nr_cpus =min (machine->env->nr_cpus_online,MAX_NR_CPUS ); +int nr_cpus =min (machine->env->nr_cpus_avail,MAX_NR_CPUS );if (cpu <0 || cpu >= nr_cpus || !machine->current_tid)return -1 ;@@ -2989,7 +2989,7 @@ int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid, pid_t tid) {struct thread *thread; -int nr_cpus =min (machine->env->nr_cpus_online,MAX_NR_CPUS ); +int nr_cpus =min (machine->env->nr_cpus_avail,MAX_NR_CPUS );if (cpu <0 )return -EINVAL ;tools/perf/util/session.c +1
-1@@ -2391,7 +2391,7 @@ int perf_session__cpu_bitmap(struct perf_session *session, {int i, err =-1 ;struct perf_cpu_map *map; -int nr_cpus =min (session->header.env.nr_cpus_online,MAX_NR_CPUS ); +int nr_cpus =min (session->header.env.nr_cpus_avail,MAX_NR_CPUS );for (i =0 ; i <PERF_TYPE_MAX ; ++i) {struct evsel *evsel;
Signature · 1 line
- Arnaldo