提交 a8a8f3eb 编写于 作者: A Adrian Hunter 提交者: Arnaldo Carvalho de Melo

perf evlist: Pass mmap parameters in a struct

In preparation for adding more mmap parameters, pass existing parameters
in a struct.
Signed-off-by: NAdrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1405332185-4050-29-git-send-email-adrian.hunter@intel.comSigned-off-by: NArnaldo Carvalho de Melo <acme@redhat.com>
上级 919d86d3
...@@ -606,12 +606,17 @@ static int perf_evlist__alloc_mmap(struct perf_evlist *evlist) ...@@ -606,12 +606,17 @@ static int perf_evlist__alloc_mmap(struct perf_evlist *evlist)
return evlist->mmap != NULL ? 0 : -ENOMEM; return evlist->mmap != NULL ? 0 : -ENOMEM;
} }
static int __perf_evlist__mmap(struct perf_evlist *evlist, struct mmap_params {
int idx, int prot, int mask, int fd) int prot;
int mask;
};
static int __perf_evlist__mmap(struct perf_evlist *evlist, int idx,
struct mmap_params *mp, int fd)
{ {
evlist->mmap[idx].prev = 0; evlist->mmap[idx].prev = 0;
evlist->mmap[idx].mask = mask; evlist->mmap[idx].mask = mp->mask;
evlist->mmap[idx].base = mmap(NULL, evlist->mmap_len, prot, evlist->mmap[idx].base = mmap(NULL, evlist->mmap_len, mp->prot,
MAP_SHARED, fd, 0); MAP_SHARED, fd, 0);
if (evlist->mmap[idx].base == MAP_FAILED) { if (evlist->mmap[idx].base == MAP_FAILED) {
pr_debug2("failed to mmap perf event ring buffer, error %d\n", pr_debug2("failed to mmap perf event ring buffer, error %d\n",
...@@ -625,8 +630,8 @@ static int __perf_evlist__mmap(struct perf_evlist *evlist, ...@@ -625,8 +630,8 @@ static int __perf_evlist__mmap(struct perf_evlist *evlist,
} }
static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx, static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx,
int prot, int mask, int cpu, int thread, struct mmap_params *mp, int cpu,
int *output) int thread, int *output)
{ {
struct perf_evsel *evsel; struct perf_evsel *evsel;
...@@ -635,8 +640,7 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx, ...@@ -635,8 +640,7 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx,
if (*output == -1) { if (*output == -1) {
*output = fd; *output = fd;
if (__perf_evlist__mmap(evlist, idx, prot, mask, if (__perf_evlist__mmap(evlist, idx, mp, *output) < 0)
*output) < 0)
return -1; return -1;
} else { } else {
if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, *output) != 0) if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, *output) != 0)
...@@ -651,8 +655,8 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx, ...@@ -651,8 +655,8 @@ static int perf_evlist__mmap_per_evsel(struct perf_evlist *evlist, int idx,
return 0; return 0;
} }
static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot, static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist,
int mask) struct mmap_params *mp)
{ {
int cpu, thread; int cpu, thread;
int nr_cpus = cpu_map__nr(evlist->cpus); int nr_cpus = cpu_map__nr(evlist->cpus);
...@@ -663,8 +667,8 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot, ...@@ -663,8 +667,8 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot,
int output = -1; int output = -1;
for (thread = 0; thread < nr_threads; thread++) { for (thread = 0; thread < nr_threads; thread++) {
if (perf_evlist__mmap_per_evsel(evlist, cpu, prot, mask, if (perf_evlist__mmap_per_evsel(evlist, cpu, mp, cpu,
cpu, thread, &output)) thread, &output))
goto out_unmap; goto out_unmap;
} }
} }
...@@ -677,8 +681,8 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot, ...@@ -677,8 +681,8 @@ static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot,
return -1; return -1;
} }
static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist, int prot, static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist,
int mask) struct mmap_params *mp)
{ {
int thread; int thread;
int nr_threads = thread_map__nr(evlist->threads); int nr_threads = thread_map__nr(evlist->threads);
...@@ -687,8 +691,8 @@ static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist, int prot, ...@@ -687,8 +691,8 @@ static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist, int prot,
for (thread = 0; thread < nr_threads; thread++) { for (thread = 0; thread < nr_threads; thread++) {
int output = -1; int output = -1;
if (perf_evlist__mmap_per_evsel(evlist, thread, prot, mask, 0, if (perf_evlist__mmap_per_evsel(evlist, thread, mp, 0, thread,
thread, &output)) &output))
goto out_unmap; goto out_unmap;
} }
...@@ -793,7 +797,9 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages, ...@@ -793,7 +797,9 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
struct perf_evsel *evsel; struct perf_evsel *evsel;
const struct cpu_map *cpus = evlist->cpus; const struct cpu_map *cpus = evlist->cpus;
const struct thread_map *threads = evlist->threads; const struct thread_map *threads = evlist->threads;
int prot = PROT_READ | (overwrite ? 0 : PROT_WRITE), mask; struct mmap_params mp = {
.prot = PROT_READ | (overwrite ? 0 : PROT_WRITE),
};
if (evlist->mmap == NULL && perf_evlist__alloc_mmap(evlist) < 0) if (evlist->mmap == NULL && perf_evlist__alloc_mmap(evlist) < 0)
return -ENOMEM; return -ENOMEM;
...@@ -804,7 +810,7 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages, ...@@ -804,7 +810,7 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
evlist->overwrite = overwrite; evlist->overwrite = overwrite;
evlist->mmap_len = perf_evlist__mmap_size(pages); evlist->mmap_len = perf_evlist__mmap_size(pages);
pr_debug("mmap size %zuB\n", evlist->mmap_len); pr_debug("mmap size %zuB\n", evlist->mmap_len);
mask = evlist->mmap_len - page_size - 1; mp.mask = evlist->mmap_len - page_size - 1;
evlist__for_each(evlist, evsel) { evlist__for_each(evlist, evsel) {
if ((evsel->attr.read_format & PERF_FORMAT_ID) && if ((evsel->attr.read_format & PERF_FORMAT_ID) &&
...@@ -814,9 +820,9 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages, ...@@ -814,9 +820,9 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
} }
if (cpu_map__empty(cpus)) if (cpu_map__empty(cpus))
return perf_evlist__mmap_per_thread(evlist, prot, mask); return perf_evlist__mmap_per_thread(evlist, &mp);
return perf_evlist__mmap_per_cpu(evlist, prot, mask); return perf_evlist__mmap_per_cpu(evlist, &mp);
} }
int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target) int perf_evlist__create_maps(struct perf_evlist *evlist, struct target *target)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册