summaryrefslogtreecommitdiffstats
path: root/tools/perf/util/evsel.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2011-01-12 17:03:24 -0200
committerArnaldo Carvalho de Melo <acme@redhat.com>2011-01-22 19:56:29 -0200
commit70082dd92c4b288bd723a77897e2b555f0e63113 (patch)
tree907a2d78fcaabc28cd4d034901e0eac800d1ed17 /tools/perf/util/evsel.c
parentdd7927f4f8ee75b032ff15aeef4bda49719a443a (diff)
downloadlinux-70082dd92c4b288bd723a77897e2b555f0e63113.tar.gz
linux-70082dd92c4b288bd723a77897e2b555f0e63113.tar.xz
linux-70082dd92c4b288bd723a77897e2b555f0e63113.zip
perf evsel: Introduce mmap support
Out of the code in 'perf top'. Record is next in line. 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: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/evsel.c')
-rw-r--r--tools/perf/util/evsel.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 82a00536892a..f5006958f8da 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1,9 +1,13 @@
#include "evsel.h"
+#include "evlist.h"
#include "../perf.h"
#include "util.h"
#include "cpumap.h"
#include "thread.h"
+#include <unistd.h>
+#include <sys/mman.h>
+
#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr, int idx)
@@ -49,10 +53,32 @@ void perf_evsel__close_fd(struct perf_evsel *evsel, int ncpus, int nthreads)
}
}
+void perf_evsel__munmap(struct perf_evsel *evsel, int ncpus, int nthreads)
+{
+ struct perf_mmap *mm;
+ int cpu, thread;
+
+ for (cpu = 0; cpu < ncpus; cpu++)
+ for (thread = 0; thread < nthreads; ++thread) {
+ mm = xyarray__entry(evsel->mmap, cpu, thread);
+ if (mm->base != NULL) {
+ munmap(mm->base, evsel->mmap_len);
+ mm->base = NULL;
+ }
+ }
+}
+
+int perf_evsel__alloc_mmap(struct perf_evsel *evsel, int ncpus, int nthreads)
+{
+ evsel->mmap = xyarray__new(ncpus, nthreads, sizeof(struct perf_mmap));
+ return evsel->mmap != NULL ? 0 : -ENOMEM;
+}
+
void perf_evsel__delete(struct perf_evsel *evsel)
{
assert(list_empty(&evsel->node));
xyarray__delete(evsel->fd);
+ xyarray__delete(evsel->mmap);
free(evsel);
}
@@ -208,3 +234,48 @@ int perf_evsel__open_per_thread(struct perf_evsel *evsel,
{
return __perf_evsel__open(evsel, &empty_cpu_map.map, threads, group, inherit);
}
+
+int perf_evsel__mmap(struct perf_evsel *evsel, struct cpu_map *cpus,
+ struct thread_map *threads, int pages,
+ struct perf_evlist *evlist)
+{
+ unsigned int page_size = sysconf(_SC_PAGE_SIZE);
+ int mask = pages * page_size - 1, cpu;
+ struct perf_mmap *mm;
+ int thread;
+
+ if (evsel->mmap == NULL &&
+ perf_evsel__alloc_mmap(evsel, cpus->nr, threads->nr) < 0)
+ return -ENOMEM;
+
+ evsel->mmap_len = (pages + 1) * page_size;
+
+ for (cpu = 0; cpu < cpus->nr; cpu++) {
+ for (thread = 0; thread < threads->nr; thread++) {
+ mm = xyarray__entry(evsel->mmap, cpu, thread);
+ mm->prev = 0;
+ mm->mask = mask;
+ mm->base = mmap(NULL, evsel->mmap_len, PROT_READ,
+ MAP_SHARED, FD(evsel, cpu, thread), 0);
+ if (mm->base == MAP_FAILED)
+ goto out_unmap;
+
+ if (evlist != NULL)
+ perf_evlist__add_pollfd(evlist, FD(evsel, cpu, thread));
+ }
+ }
+
+ return 0;
+
+out_unmap:
+ do {
+ while (--thread >= 0) {
+ mm = xyarray__entry(evsel->mmap, cpu, thread);
+ munmap(mm->base, evsel->mmap_len);
+ mm->base = NULL;
+ }
+ thread = threads->nr;
+ } while (--cpu >= 0);
+
+ return -1;
+}