diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-01-29 06:08:13 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-01-29 13:24:40 -0500 |
commit | 7bb41152b9be7e31f10d8919bce5034135525d9d (patch) | |
tree | 4a79423cd6f01f5e61251e6058ed41427230f63b /tools | |
parent | ef2bf6d043ac9bd4a6f38d862af407154a4754d9 (diff) |
perf evlist: Support non overwrite mode in perf_evlist__read_on_cpu
I.e. stash the overwrite mode in struct perf_evlist and act accordingly
in perf_evlist__read_on_cpu, not checking for overwrites and touching
the tail after consuming one event, like perf record does, for instance.
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')
-rw-r--r-- | tools/perf/util/evlist.c | 35 | ||||
-rw-r--r-- | tools/perf/util/evlist.h | 1 | ||||
-rw-r--r-- | tools/perf/util/evsel.c | 1 |
3 files changed, 22 insertions, 15 deletions
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index df0610e9c61b..b498eecbe850 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c | |||
@@ -116,24 +116,25 @@ event_t *perf_evlist__read_on_cpu(struct perf_evlist *evlist, int cpu) | |||
116 | unsigned int old = md->prev; | 116 | unsigned int old = md->prev; |
117 | unsigned char *data = md->base + page_size; | 117 | unsigned char *data = md->base + page_size; |
118 | event_t *event = NULL; | 118 | event_t *event = NULL; |
119 | int diff; | ||
120 | |||
121 | /* | ||
122 | * If we're further behind than half the buffer, there's a chance | ||
123 | * the writer will bite our tail and mess up the samples under us. | ||
124 | * | ||
125 | * If we somehow ended up ahead of the head, we got messed up. | ||
126 | * | ||
127 | * In either case, truncate and restart at head. | ||
128 | */ | ||
129 | diff = head - old; | ||
130 | if (diff > md->mask / 2 || diff < 0) { | ||
131 | fprintf(stderr, "WARNING: failed to keep up with mmap data.\n"); | ||
132 | 119 | ||
120 | if (evlist->overwrite) { | ||
133 | /* | 121 | /* |
134 | * head points to a known good entry, start there. | 122 | * If we're further behind than half the buffer, there's a chance |
123 | * the writer will bite our tail and mess up the samples under us. | ||
124 | * | ||
125 | * If we somehow ended up ahead of the head, we got messed up. | ||
126 | * | ||
127 | * In either case, truncate and restart at head. | ||
135 | */ | 128 | */ |
136 | old = head; | 129 | int diff = head - old; |
130 | if (diff > md->mask / 2 || diff < 0) { | ||
131 | fprintf(stderr, "WARNING: failed to keep up with mmap data.\n"); | ||
132 | |||
133 | /* | ||
134 | * head points to a known good entry, start there. | ||
135 | */ | ||
136 | old = head; | ||
137 | } | ||
137 | } | 138 | } |
138 | 139 | ||
139 | if (old != head) { | 140 | if (old != head) { |
@@ -166,5 +167,9 @@ event_t *perf_evlist__read_on_cpu(struct perf_evlist *evlist, int cpu) | |||
166 | } | 167 | } |
167 | 168 | ||
168 | md->prev = old; | 169 | md->prev = old; |
170 | |||
171 | if (!evlist->overwrite) | ||
172 | perf_mmap__write_tail(md, old); | ||
173 | |||
169 | return event; | 174 | return event; |
170 | } | 175 | } |
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h index acbe48eac608..2706ae40c8b3 100644 --- a/tools/perf/util/evlist.h +++ b/tools/perf/util/evlist.h | |||
@@ -16,6 +16,7 @@ struct perf_evlist { | |||
16 | int nr_entries; | 16 | int nr_entries; |
17 | int nr_fds; | 17 | int nr_fds; |
18 | int mmap_len; | 18 | int mmap_len; |
19 | bool overwrite; | ||
19 | event_t event_copy; | 20 | event_t event_copy; |
20 | struct perf_mmap *mmap; | 21 | struct perf_mmap *mmap; |
21 | struct pollfd *pollfd; | 22 | struct pollfd *pollfd; |
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 76ab553637d6..f98b3e585039 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c | |||
@@ -327,6 +327,7 @@ int perf_evlist__mmap(struct perf_evlist *evlist, struct cpu_map *cpus, | |||
327 | perf_evlist__alloc_pollfd(evlist, cpus->nr, threads->nr) < 0) | 327 | perf_evlist__alloc_pollfd(evlist, cpus->nr, threads->nr) < 0) |
328 | return -ENOMEM; | 328 | return -ENOMEM; |
329 | 329 | ||
330 | evlist->overwrite = overwrite; | ||
330 | evlist->mmap_len = (pages + 1) * page_size; | 331 | evlist->mmap_len = (pages + 1) * page_size; |
331 | first_evsel = list_entry(evlist->entries.next, struct perf_evsel, node); | 332 | first_evsel = list_entry(evlist->entries.next, struct perf_evsel, node); |
332 | 333 | ||