diff options
author | Kyle Meyer <meyerk@hpe.com> | 2019-08-27 17:43:50 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2019-08-29 16:38:32 -0400 |
commit | 8c7274691f0de5fb56f3b9fe9208ce7e515a2d2c (patch) | |
tree | 69b70673aee9326752297bfdbaad7c52be9ec685 | |
parent | 7df4e36a4785618f0c63f3dc2bacb164780ab0f6 (diff) |
perf machine: Replace MAX_NR_CPUS with perf_env::nr_cpus_online
nr_cpus, the number of CPUs online during a record session bound by
MAX_NR_CPUS, can be used as a dynamic alternative for MAX_NR_CPUS in
__machine__synthesize_threads and machine__set_current_tid.
Signed-off-by: Kyle Meyer <kyle.meyer@hpe.com>
Reviewed-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Russ Anderson <russ.anderson@hpe.com>
Link: http://lore.kernel.org/lkml/20190827214352.94272-6-meyerk@stormcage.eag.rdlabs.hpecorp.net
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r-- | tools/perf/util/machine.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c index 93483f1764d3..a1542b4c047b 100644 --- a/tools/perf/util/machine.c +++ b/tools/perf/util/machine.c | |||
@@ -2619,7 +2619,9 @@ int __machine__synthesize_threads(struct machine *machine, struct perf_tool *too | |||
2619 | 2619 | ||
2620 | pid_t machine__get_current_tid(struct machine *machine, int cpu) | 2620 | pid_t machine__get_current_tid(struct machine *machine, int cpu) |
2621 | { | 2621 | { |
2622 | if (cpu < 0 || cpu >= MAX_NR_CPUS || !machine->current_tid) | 2622 | int nr_cpus = min(machine->env->nr_cpus_online, MAX_NR_CPUS); |
2623 | |||
2624 | if (cpu < 0 || cpu >= nr_cpus || !machine->current_tid) | ||
2623 | return -1; | 2625 | return -1; |
2624 | 2626 | ||
2625 | return machine->current_tid[cpu]; | 2627 | return machine->current_tid[cpu]; |
@@ -2629,6 +2631,7 @@ int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid, | |||
2629 | pid_t tid) | 2631 | pid_t tid) |
2630 | { | 2632 | { |
2631 | struct thread *thread; | 2633 | struct thread *thread; |
2634 | int nr_cpus = min(machine->env->nr_cpus_online, MAX_NR_CPUS); | ||
2632 | 2635 | ||
2633 | if (cpu < 0) | 2636 | if (cpu < 0) |
2634 | return -EINVAL; | 2637 | return -EINVAL; |
@@ -2636,14 +2639,14 @@ int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid, | |||
2636 | if (!machine->current_tid) { | 2639 | if (!machine->current_tid) { |
2637 | int i; | 2640 | int i; |
2638 | 2641 | ||
2639 | machine->current_tid = calloc(MAX_NR_CPUS, sizeof(pid_t)); | 2642 | machine->current_tid = calloc(nr_cpus, sizeof(pid_t)); |
2640 | if (!machine->current_tid) | 2643 | if (!machine->current_tid) |
2641 | return -ENOMEM; | 2644 | return -ENOMEM; |
2642 | for (i = 0; i < MAX_NR_CPUS; i++) | 2645 | for (i = 0; i < nr_cpus; i++) |
2643 | machine->current_tid[i] = -1; | 2646 | machine->current_tid[i] = -1; |
2644 | } | 2647 | } |
2645 | 2648 | ||
2646 | if (cpu >= MAX_NR_CPUS) { | 2649 | if (cpu >= nr_cpus) { |
2647 | pr_err("Requested CPU %d too large. ", cpu); | 2650 | pr_err("Requested CPU %d too large. ", cpu); |
2648 | pr_err("Consider raising MAX_NR_CPUS\n"); | 2651 | pr_err("Consider raising MAX_NR_CPUS\n"); |
2649 | return -EINVAL; | 2652 | return -EINVAL; |