perf evsel: Use {cpu,thread}_map to shorten list of parameters

Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
LKML-Reference: <new-submission>
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 5c98d466
...@@ -166,7 +166,7 @@ static int create_perf_stat_counter(struct perf_evsel *evsel) ...@@ -166,7 +166,7 @@ static int create_perf_stat_counter(struct perf_evsel *evsel)
PERF_FORMAT_TOTAL_TIME_RUNNING; PERF_FORMAT_TOTAL_TIME_RUNNING;
if (system_wide) if (system_wide)
return perf_evsel__open_per_cpu(evsel, cpus->nr, cpus->map); return perf_evsel__open_per_cpu(evsel, cpus);
attr->inherit = !no_inherit; attr->inherit = !no_inherit;
if (target_pid == -1 && target_tid == -1) { if (target_pid == -1 && target_tid == -1) {
...@@ -174,7 +174,7 @@ static int create_perf_stat_counter(struct perf_evsel *evsel) ...@@ -174,7 +174,7 @@ static int create_perf_stat_counter(struct perf_evsel *evsel)
attr->enable_on_exec = 1; attr->enable_on_exec = 1;
} }
return perf_evsel__open_per_thread(evsel, threads->nr, threads->map); return perf_evsel__open_per_thread(evsel, threads);
} }
/* /*
......
#include "evsel.h" #include "evsel.h"
#include "../perf.h" #include "../perf.h"
#include "util.h" #include "util.h"
#include "cpumap.h"
#include "thread.h"
#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y)) #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
...@@ -123,13 +125,13 @@ int __perf_evsel__read(struct perf_evsel *evsel, ...@@ -123,13 +125,13 @@ int __perf_evsel__read(struct perf_evsel *evsel,
return 0; return 0;
} }
int perf_evsel__open_per_cpu(struct perf_evsel *evsel, int ncpus, int *cpu_map) int perf_evsel__open_per_cpu(struct perf_evsel *evsel, struct cpu_map *cpus)
{ {
int cpu; int cpu;
for (cpu = 0; cpu < ncpus; cpu++) { for (cpu = 0; cpu < cpus->nr; cpu++) {
FD(evsel, cpu, 0) = sys_perf_event_open(&evsel->attr, -1, FD(evsel, cpu, 0) = sys_perf_event_open(&evsel->attr, -1,
cpu_map[cpu], -1, 0); cpus->map[cpu], -1, 0);
if (FD(evsel, cpu, 0) < 0) if (FD(evsel, cpu, 0) < 0)
goto out_close; goto out_close;
} }
...@@ -144,13 +146,13 @@ int perf_evsel__open_per_cpu(struct perf_evsel *evsel, int ncpus, int *cpu_map) ...@@ -144,13 +146,13 @@ int perf_evsel__open_per_cpu(struct perf_evsel *evsel, int ncpus, int *cpu_map)
return -1; return -1;
} }
int perf_evsel__open_per_thread(struct perf_evsel *evsel, int nthreads, int *thread_map) int perf_evsel__open_per_thread(struct perf_evsel *evsel, struct thread_map *threads)
{ {
int thread; int thread;
for (thread = 0; thread < nthreads; thread++) { for (thread = 0; thread < threads->nr; thread++) {
FD(evsel, 0, thread) = sys_perf_event_open(&evsel->attr, FD(evsel, 0, thread) = sys_perf_event_open(&evsel->attr,
thread_map[thread], -1, -1, 0); threads->map[thread], -1, -1, 0);
if (FD(evsel, 0, thread) < 0) if (FD(evsel, 0, thread) < 0)
goto out_close; goto out_close;
} }
...@@ -165,11 +167,11 @@ int perf_evsel__open_per_thread(struct perf_evsel *evsel, int nthreads, int *thr ...@@ -165,11 +167,11 @@ int perf_evsel__open_per_thread(struct perf_evsel *evsel, int nthreads, int *thr
return -1; return -1;
} }
int perf_evsel__open(struct perf_evsel *evsel, int ncpus, int nthreads, int perf_evsel__open(struct perf_evsel *evsel,
int *cpu_map, int *thread_map) struct cpu_map *cpus, struct thread_map *threads)
{ {
if (nthreads < 0) if (threads == NULL)
return perf_evsel__open_per_cpu(evsel, ncpus, cpu_map); return perf_evsel__open_per_cpu(evsel, cpus);
return perf_evsel__open_per_thread(evsel, nthreads, thread_map); return perf_evsel__open_per_thread(evsel, threads);
} }
...@@ -34,6 +34,9 @@ struct perf_evsel { ...@@ -34,6 +34,9 @@ struct perf_evsel {
void *priv; void *priv;
}; };
struct cpu_map;
struct thread_map;
struct perf_evsel *perf_evsel__new(u32 type, u64 config, int idx); struct perf_evsel *perf_evsel__new(u32 type, u64 config, int idx);
void perf_evsel__delete(struct perf_evsel *evsel); void perf_evsel__delete(struct perf_evsel *evsel);
...@@ -42,10 +45,10 @@ int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus); ...@@ -42,10 +45,10 @@ int perf_evsel__alloc_counts(struct perf_evsel *evsel, int ncpus);
void perf_evsel__free_fd(struct perf_evsel *evsel); void perf_evsel__free_fd(struct perf_evsel *evsel);
void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads); void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
int perf_evsel__open_per_cpu(struct perf_evsel *evsel, int ncpus, int *cpu_map); int perf_evsel__open_per_cpu(struct perf_evsel *evsel, struct cpu_map *cpus);
int perf_evsel__open_per_thread(struct perf_evsel *evsel, int nthreads, int *thread_map); int perf_evsel__open_per_thread(struct perf_evsel *evsel, struct thread_map *threads);
int perf_evsel__open(struct perf_evsel *evsel, int ncpus, int nthreads, int perf_evsel__open(struct perf_evsel *evsel,
int *cpu_map, int *thread_map); struct cpu_map *cpus, struct thread_map *threads);
#define perf_evsel__match(evsel, t, c) \ #define perf_evsel__match(evsel, t, c) \
(evsel->attr.type == PERF_TYPE_##t && \ (evsel->attr.type == PERF_TYPE_##t && \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment