History

Merge branch 'perf/urgent' of git://git.kernel.org/pub/scm/linux/kernel/git/acme/linux-2.6 into perf/urgent

Ingo Molnar committed 15 years ago

Commit 52004ea2 parents 9bbeacf aece9486 files · +116 −54Browse files

Unified · Split

6 files
  1. tools/perf/builtin-record.c +1 −1
  2. tools/perf/builtin-test.c +1 −1
  3. tools/perf/builtin-top.c +4 −4
  4. tools/perf/util/evlist.c +107 −46
  5. tools/perf/util/evlist.h +2 −1
  6. tools/perf/util/python.c +1 −1
tools/perf/builtin-record.c+1−1
@@ -427,7 +427,7 @@ static void mmap_read_all(void) · 426 unmodified lines
427427 {
428428 int i;
429429
430− for (i = 0; i < evsel_list->cpus->nr; i++) {
430+ for (i = 0; i < evsel_list->nr_mmaps; i++) {
431431 if (evsel_list->mmap[i].base)
432432 mmap_read(&evsel_list->mmap[i]);
433433 }
tools/perf/builtin-test.c+1−1
@@ -549,7 +549,7 @@ static int test__basic_mmap(void) · 548 unmodified lines
549549 ++foo;
550550 }
551551
552− while ((event = perf_evlist__read_on_cpu(evlist, 0)) != NULL) {
552+ while ((event = perf_evlist__mmap_read(evlist, 0)) != NULL) {
553553 struct perf_sample sample;
554554
555555 if (event->header.type != PERF_RECORD_SAMPLE) {
tools/perf/builtin-top.c+4−4
@@ -801,12 +801,12 @@ static void perf_event__process_sample(const union perf_event *event, · 800 unmodified lines
801801 }
802802 }
803803
804−static void perf_session__mmap_read_cpu(struct perf_session *self, int cpu)
804+static void perf_session__mmap_read_idx(struct perf_session *self, int idx)
805805 {
806806 struct perf_sample sample;
807807 union perf_event *event;
808808
809− while ((event = perf_evlist__read_on_cpu(top.evlist, cpu)) != NULL) {
809+ while ((event = perf_evlist__mmap_read(top.evlist, idx)) != NULL) {
810810 perf_session__parse_sample(self, event, &sample);
811811
812812 if (event->header.type == PERF_RECORD_SAMPLE)
@@ -820,8 +820,8 @@ static void perf_session__mmap_read(struct perf_session *self) · 7 unmodified lines
820820 {
821821 int i;
822822
823− for (i = 0; i < top.evlist->cpus->nr; i++)
824− perf_session__mmap_read_cpu(self, i);
823+ for (i = 0; i < top.evlist->nr_mmaps; i++)
824+ perf_session__mmap_read_idx(self, i);
825825 }
826826
827827 static void start_counters(struct perf_evlist *evlist)
tools/perf/util/evlist.c+107−46
@@ -166,11 +166,11 @@ struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id) · 165 unmodified lines
166166 return NULL;
167167 }
168168
169−union perf_event *perf_evlist__read_on_cpu(struct perf_evlist *evlist, int cpu)
169+union perf_event *perf_evlist__mmap_read(struct perf_evlist *evlist, int idx)
170170 {
171171 /* XXX Move this to perf.c, making it generally available */
172172 unsigned int page_size = sysconf(_SC_PAGE_SIZE);
173− struct perf_mmap *md = &evlist->mmap[cpu];
173+ struct perf_mmap *md = &evlist->mmap[idx];
174174 unsigned int head = perf_mmap__read_head(md);
175175 unsigned int old = md->prev;
176176 unsigned char *data = md->base + page_size;
@@ -235,31 +235,37 @@ union perf_event *perf_evlist__read_on_cpu(struct perf_evlist *evlist, int cpu) · 58 unmodified lines
235235
236236 void perf_evlist__munmap(struct perf_evlist *evlist)
237237 {
238− int cpu;
238+ int i;
239239
240− for (cpu = 0; cpu < evlist->cpus->nr; cpu++) {
241− if (evlist->mmap[cpu].base != NULL) {
242− munmap(evlist->mmap[cpu].base, evlist->mmap_len);
243− evlist->mmap[cpu].base = NULL;
240+ for (i = 0; i < evlist->nr_mmaps; i++) {
241+ if (evlist->mmap[i].base != NULL) {
242+ munmap(evlist->mmap[i].base, evlist->mmap_len);
243+ evlist->mmap[i].base = NULL;
244244 }
245245 }
246+
247+ free(evlist->mmap);
248+ evlist->mmap = NULL;
246249 }
247250
248251 int perf_evlist__alloc_mmap(struct perf_evlist *evlist)
249252 {
250− evlist->mmap = zalloc(evlist->cpus->nr * sizeof(struct perf_mmap));
253+ evlist->nr_mmaps = evlist->cpus->nr;
254+ if (evlist->cpus->map[0] == -1)
255+ evlist->nr_mmaps = evlist->threads->nr;
256+ evlist->mmap = zalloc(evlist->nr_mmaps * sizeof(struct perf_mmap));
251257 return evlist->mmap != NULL ? 0 : -ENOMEM;
252258 }
253259
254260 static int __perf_evlist__mmap(struct perf_evlist *evlist, struct perf_evsel *evsel,
255− int cpu, int prot, int mask, int fd)
261+ int idx, int prot, int mask, int fd)
256262 {
257− evlist->mmap[cpu].prev = 0;
258− evlist->mmap[cpu].mask = mask;
259− evlist->mmap[cpu].base = mmap(NULL, evlist->mmap_len, prot,
263+ evlist->mmap[idx].prev = 0;
264+ evlist->mmap[idx].mask = mask;
265+ evlist->mmap[idx].base = mmap(NULL, evlist->mmap_len, prot,
260266 MAP_SHARED, fd, 0);
261− if (evlist->mmap[cpu].base == MAP_FAILED) {
262− if (evlist->cpus->map[cpu] == -1 && evsel->attr.inherit)
267+ if (evlist->mmap[idx].base == MAP_FAILED) {
268+ if (evlist->cpus->map[idx] == -1 && evsel->attr.inherit)
263269 ui__warning("Inherit is not allowed on per-task "
264270 "events using mmap.\n");
265271 return -1;
@@ -269,6 +275,86 @@ static int __perf_evlist__mmap(struct perf_evlist *evlist, struct perf_evsel *ev · 3 unmodified lines
269275 return 0;
270276 }
271277
278+static int perf_evlist__mmap_per_cpu(struct perf_evlist *evlist, int prot, int mask)
279+{
280+ struct perf_evsel *evsel;
281+ int cpu, thread;
282+
283+ for (cpu = 0; cpu < evlist->cpus->nr; cpu++) {
284+ int output = -1;
285+
286+ for (thread = 0; thread < evlist->threads->nr; thread++) {
287+ list_for_each_entry(evsel, &evlist->entries, node) {
288+ int fd = FD(evsel, cpu, thread);
289+
290+ if (output == -1) {
291+ output = fd;
292+ if (__perf_evlist__mmap(evlist, evsel, cpu,
293+ prot, mask, output) < 0)
294+ goto out_unmap;
295+ } else {
296+ if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, output) != 0)
297+ goto out_unmap;
298+ }
299+
300+ if ((evsel->attr.read_format & PERF_FORMAT_ID) &&
301+ perf_evlist__id_add_fd(evlist, evsel, cpu, thread, fd) < 0)
302+ goto out_unmap;
303+ }
304+ }
305+ }
306+
307+ return 0;
308+
309+out_unmap:
310+ for (cpu = 0; cpu < evlist->cpus->nr; cpu++) {
311+ if (evlist->mmap[cpu].base != NULL) {
312+ munmap(evlist->mmap[cpu].base, evlist->mmap_len);
313+ evlist->mmap[cpu].base = NULL;
314+ }
315+ }
316+ return -1;
317+}
318+
319+static int perf_evlist__mmap_per_thread(struct perf_evlist *evlist, int prot, int mask)
320+{
321+ struct perf_evsel *evsel;
322+ int thread;
323+
324+ for (thread = 0; thread < evlist->threads->nr; thread++) {
325+ int output = -1;
326+
327+ list_for_each_entry(evsel, &evlist->entries, node) {
328+ int fd = FD(evsel, 0, thread);
329+
330+ if (output == -1) {
331+ output = fd;
332+ if (__perf_evlist__mmap(evlist, evsel, thread,
333+ prot, mask, output) < 0)
334+ goto out_unmap;
335+ } else {
336+ if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT, output) != 0)
337+ goto out_unmap;
338+ }
339+
340+ if ((evsel->attr.read_format & PERF_FORMAT_ID) &&
341+ perf_evlist__id_add_fd(evlist, evsel, 0, thread, fd) < 0)
342+ goto out_unmap;
343+ }
344+ }
345+
346+ return 0;
347+
348+out_unmap:
349+ for (thread = 0; thread < evlist->threads->nr; thread++) {
350+ if (evlist->mmap[thread].base != NULL) {
351+ munmap(evlist->mmap[thread].base, evlist->mmap_len);
352+ evlist->mmap[thread].base = NULL;
353+ }
354+ }
355+ return -1;
356+}
357+
272358 /** perf_evlist__mmap - Create per cpu maps to receive events
273359 *
274360 * @evlist - list of events
@@ -287,11 +373,11 @@ static int __perf_evlist__mmap(struct perf_evlist *evlist, struct perf_evsel *ev · 12 unmodified lines
287373 int perf_evlist__mmap(struct perf_evlist *evlist, int pages, bool overwrite)
288374 {
289375 unsigned int page_size = sysconf(_SC_PAGE_SIZE);
290− int mask = pages * page_size - 1, cpu;
291− struct perf_evsel *first_evsel, *evsel;
376+ int mask = pages * page_size - 1;
377+ struct perf_evsel *evsel;
292378 const struct cpu_map *cpus = evlist->cpus;
293379 const struct thread_map *threads = evlist->threads;
294− int thread, prot = PROT_READ | (overwrite ? 0 : PROT_WRITE);
380+ int prot = PROT_READ | (overwrite ? 0 : PROT_WRITE);
295381
296382 if (evlist->mmap == NULL && perf_evlist__alloc_mmap(evlist) < 0)
297383 return -ENOMEM;
@@ -301,43 +387,18 @@ int perf_evlist__mmap(struct perf_evlist *evlist, int pages, bool overwrite) · 3 unmodified lines
301387
302388 evlist->overwrite = overwrite;
303389 evlist->mmap_len = (pages + 1) * page_size;
304− first_evsel = list_entry(evlist->entries.next, struct perf_evsel, node);
305390
306391 list_for_each_entry(evsel, &evlist->entries, node) {
307392 if ((evsel->attr.read_format & PERF_FORMAT_ID) &&
308393 evsel->sample_id == NULL &&
309394 perf_evsel__alloc_id(evsel, cpus->nr, threads->nr) < 0)
310395 return -ENOMEM;
311−
312− for (cpu = 0; cpu < cpus->nr; cpu++) {
313− for (thread = 0; thread < threads->nr; thread++) {
314− int fd = FD(evsel, cpu, thread);
315−
316− if (evsel->idx || thread) {
317− if (ioctl(fd, PERF_EVENT_IOC_SET_OUTPUT,
318− FD(first_evsel, cpu, 0)) != 0)
319− goto out_unmap;
320− } else if (__perf_evlist__mmap(evlist, evsel, cpu,
321− prot, mask, fd) < 0)
322− goto out_unmap;
323−
324− if ((evsel->attr.read_format & PERF_FORMAT_ID) &&
325− perf_evlist__id_add_fd(evlist, evsel, cpu, thread, fd) < 0)
326− goto out_unmap;
327− }
328− }
329396 }
330397
331− return 0;
398+ if (evlist->cpus->map[0] == -1)
399+ return perf_evlist__mmap_per_thread(evlist, prot, mask);
332400
333−out_unmap:
334− for (cpu = 0; cpu < cpus->nr; cpu++) {
335− if (evlist->mmap[cpu].base != NULL) {
336− munmap(evlist->mmap[cpu].base, evlist->mmap_len);
337− evlist->mmap[cpu].base = NULL;
338− }
339− }
340− return -1;
401+ return perf_evlist__mmap_per_cpu(evlist, prot, mask);
341402 }
342403
343404 int perf_evlist__create_maps(struct perf_evlist *evlist, pid_t target_pid,
@@ -348,7 +409,7 @@ int perf_evlist__create_maps(struct perf_evlist *evlist, pid_t target_pid, · 4 unmodified lines
348409 if (evlist->threads == NULL)
349410 return -1;
350411
351− if (target_tid != -1)
412+ if (cpu_list == NULL && target_tid != -1)
352413 evlist->cpus = cpu_map__dummy_new();
353414 else
354415 evlist->cpus = cpu_map__new(cpu_list);
tools/perf/util/evlist.h+2−1
@@ -17,6 +17,7 @@ struct perf_evlist { · 16 unmodified lines
1717 struct hlist_head heads[PERF_EVLIST__HLIST_SIZE];
1818 int nr_entries;
1919 int nr_fds;
20+ int nr_mmaps;
2021 int mmap_len;
2122 bool overwrite;
2223 union perf_event event_copy;
@@ -46,7 +47,7 @@ void perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd); · 23 unmodified lines
4647
4748 struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id);
4849
49−union perf_event *perf_evlist__read_on_cpu(struct perf_evlist *self, int cpu);
50+union perf_event *perf_evlist__mmap_read(struct perf_evlist *self, int idx);
5051
5152 int perf_evlist__alloc_mmap(struct perf_evlist *evlist);
5253 int perf_evlist__mmap(struct perf_evlist *evlist, int pages, bool overwrite);
tools/perf/util/python.c+1−1
@@ -680,7 +680,7 @@ static PyObject *pyrf_evlist__read_on_cpu(struct pyrf_evlist *pevlist, · 679 unmodified lines
680680 &cpu, &sample_id_all))
681681 return NULL;
682682
683− event = perf_evlist__read_on_cpu(evlist, cpu);
683+ event = perf_evlist__mmap_read(evlist, cpu);
684684 if (event != NULL) {
685685 struct perf_evsel *first;
686686 PyObject *pyevent = pyrf_event__new(event);