Skip to content

Commit

Permalink
perf machine: Replace MAX_NR_CPUS with perf_env::nr_cpus_online
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Kyle Meyer authored and Arnaldo Carvalho de Melo committed Aug 29, 2019
1 parent 7df4e36 commit 8c72746
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions tools/perf/util/machine.c
Original file line number Diff line number Diff line change
Expand Up @@ -2619,7 +2619,9 @@ int __machine__synthesize_threads(struct machine *machine, struct perf_tool *too

pid_t machine__get_current_tid(struct machine *machine, int cpu)
{
if (cpu < 0 || cpu >= MAX_NR_CPUS || !machine->current_tid)
int nr_cpus = min(machine->env->nr_cpus_online, MAX_NR_CPUS);

if (cpu < 0 || cpu >= nr_cpus || !machine->current_tid)
return -1;

return machine->current_tid[cpu];
Expand All @@ -2629,21 +2631,22 @@ 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);

if (cpu < 0)
return -EINVAL;

if (!machine->current_tid) {
int i;

machine->current_tid = calloc(MAX_NR_CPUS, sizeof(pid_t));
machine->current_tid = calloc(nr_cpus, sizeof(pid_t));
if (!machine->current_tid)
return -ENOMEM;
for (i = 0; i < MAX_NR_CPUS; i++)
for (i = 0; i < nr_cpus; i++)
machine->current_tid[i] = -1;
}

if (cpu >= MAX_NR_CPUS) {
if (cpu >= nr_cpus) {
pr_err("Requested CPU %d too large. ", cpu);
pr_err("Consider raising MAX_NR_CPUS\n");
return -EINVAL;
Expand Down

0 comments on commit 8c72746

Please sign in to comment.