Skip to content

Commit 4402869

Browse files
captain5050acmel
authored andcommitted
perf cpumap: Migrate to libperf cpumap api
Switch from directly accessing the perf_cpu_map to using the appropriate libperf API when possible. Using the API simplifies the job of refactoring use of perf_cpu_map. Signed-off-by: Ian Rogers <irogers@google.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Alexey Bayduraev <alexey.v.bayduraev@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: André Almeida <andrealmeid@collabora.com> Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Cc: Darren Hart <dvhart@infradead.org> Cc: Davidlohr Bueso <dave@stgolabs.net> Cc: Dmitriy Vyukov <dvyukov@google.com> Cc: Eric Dumazet <edumazet@google.com> Cc: German Gomez <german.gomez@arm.com> Cc: James Clark <james.clark@arm.com> Cc: Jin Yao <yao.jin@linux.intel.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: John Garry <john.garry@huawei.com> Cc: Kajol Jain <kjain@linux.ibm.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Leo Yan <leo.yan@linaro.org> Cc: Madhavan Srinivasan <maddy@linux.ibm.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Masami Hiramatsu <mhiramat@kernel.org> Cc: Miaoqian Lin <linmq006@gmail.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Riccardo Mancini <rickyman7@gmail.com> Cc: Shunsuke Nakamura <nakamura.shun@fujitsu.com> Cc: Song Liu <song@kernel.org> Cc: Stephane Eranian <eranian@google.com> Cc: Stephen Brennan <stephen.s.brennan@oracle.com> Cc: Steven Rostedt (VMware) <rostedt@goodmis.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Thomas Richter <tmricht@linux.ibm.com> Cc: Yury Norov <yury.norov@gmail.com> Link: http://lore.kernel.org/lkml/20220122045811.3402706-3-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 1d1d9af commit 4402869

31 files changed

+99
-87
lines changed

tools/lib/perf/evsel.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus,
141141
}
142142

143143
if (evsel->fd == NULL &&
144-
perf_evsel__alloc_fd(evsel, cpus->nr, threads->nr) < 0)
144+
perf_evsel__alloc_fd(evsel, perf_cpu_map__nr(cpus), threads->nr) < 0)
145145
return -ENOMEM;
146146

147147
perf_cpu_map__for_each_cpu(cpu, idx, cpus) {
@@ -384,7 +384,7 @@ int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter)
384384
{
385385
int err = 0, i;
386386

387-
for (i = 0; i < evsel->cpus->nr && !err; i++)
387+
for (i = 0; i < perf_cpu_map__nr(evsel->cpus) && !err; i++)
388388
err = perf_evsel__run_ioctl(evsel,
389389
PERF_EVENT_IOC_SET_FILTER,
390390
(void *)filter, i);

tools/perf/bench/epoll-ctl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ int bench_epoll_ctl(int argc, const char **argv)
333333

334334
/* default to the number of CPUs */
335335
if (!nthreads)
336-
nthreads = cpu->nr;
336+
nthreads = perf_cpu_map__nr(cpu);
337337

338338
worker = calloc(nthreads, sizeof(*worker));
339339
if (!worker)

tools/perf/bench/epoll-wait.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ int bench_epoll_wait(int argc, const char **argv)
452452

453453
/* default to the number of CPUs and leave one for the writer pthread */
454454
if (!nthreads)
455-
nthreads = cpu->nr - 1;
455+
nthreads = perf_cpu_map__nr(cpu) - 1;
456456

457457
worker = calloc(nthreads, sizeof(*worker));
458458
if (!worker) {

tools/perf/bench/evlist-open-close.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static int evlist__count_evsel_fds(struct evlist *evlist)
7171
int cnt = 0;
7272

7373
evlist__for_each_entry(evlist, evsel)
74-
cnt += evsel->core.threads->nr * evsel->core.cpus->nr;
74+
cnt += evsel->core.threads->nr * perf_cpu_map__nr(evsel->core.cpus);
7575

7676
return cnt;
7777
}
@@ -151,7 +151,7 @@ static int bench_evlist_open_close__run(char *evstr)
151151

152152
init_stats(&time_stats);
153153

154-
printf(" Number of cpus:\t%d\n", evlist->core.cpus->nr);
154+
printf(" Number of cpus:\t%d\n", perf_cpu_map__nr(evlist->core.cpus));
155155
printf(" Number of threads:\t%d\n", evlist->core.threads->nr);
156156
printf(" Number of events:\t%d (%d fds)\n",
157157
evlist->core.nr_entries, evlist__count_evsel_fds(evlist));

tools/perf/bench/futex-hash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ int bench_futex_hash(int argc, const char **argv)
150150
}
151151

152152
if (!params.nthreads) /* default to the number of CPUs */
153-
params.nthreads = cpu->nr;
153+
params.nthreads = perf_cpu_map__nr(cpu);
154154

155155
worker = calloc(params.nthreads, sizeof(*worker));
156156
if (!worker)

tools/perf/bench/futex-lock-pi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ int bench_futex_lock_pi(int argc, const char **argv)
173173
}
174174

175175
if (!params.nthreads)
176-
params.nthreads = cpu->nr;
176+
params.nthreads = perf_cpu_map__nr(cpu);
177177

178178
worker = calloc(params.nthreads, sizeof(*worker));
179179
if (!worker)

tools/perf/bench/futex-requeue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ int bench_futex_requeue(int argc, const char **argv)
175175
}
176176

177177
if (!params.nthreads)
178-
params.nthreads = cpu->nr;
178+
params.nthreads = perf_cpu_map__nr(cpu);
179179

180180
worker = calloc(params.nthreads, sizeof(*worker));
181181
if (!worker)

tools/perf/bench/futex-wake-parallel.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ int bench_futex_wake_parallel(int argc, const char **argv)
252252
err(EXIT_FAILURE, "calloc");
253253

254254
if (!params.nthreads)
255-
params.nthreads = cpu->nr;
255+
params.nthreads = perf_cpu_map__nr(cpu);
256256

257257
/* some sanity checks */
258258
if (params.nwakes > params.nthreads ||

tools/perf/bench/futex-wake.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ int bench_futex_wake(int argc, const char **argv)
151151
}
152152

153153
if (!params.nthreads)
154-
params.nthreads = cpu->nr;
154+
params.nthreads = perf_cpu_map__nr(cpu);
155155

156156
worker = calloc(params.nthreads, sizeof(*worker));
157157
if (!worker)

tools/perf/builtin-ftrace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ static int set_tracing_cpumask(struct perf_cpu_map *cpumap)
281281
int ret;
282282
int last_cpu;
283283

284-
last_cpu = perf_cpu_map__cpu(cpumap, cpumap->nr - 1).cpu;
284+
last_cpu = perf_cpu_map__cpu(cpumap, perf_cpu_map__nr(cpumap) - 1).cpu;
285285
mask_size = last_cpu / 4 + 2; /* one more byte for EOS */
286286
mask_size += last_cpu / 32; /* ',' is needed for every 32th cpus */
287287

0 commit comments

Comments
 (0)