diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-09-26 11:41:14 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2012-09-26 11:41:14 -0400 |
commit | a14bb7a6fd4a3d563ca971daf462ba4dc294a7a6 (patch) | |
tree | 5ad6003f5cf57019c55b44023e10401e2d01b78e /tools | |
parent | 0b80f8b32f31f80e001fb6355fd86769555c4a3c (diff) |
perf tools: Allow handling a NULL cpu_map as meaning "all cpus"
Or one with cpu_map->map[0] == -1.
Reducing the boilerplate in setting up an evlist by nor requiring a
cpu_map to be created at all.
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
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/n/tip-rnaqn3dtnsfo1wlbbf3fhx00@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/perf/util/cpumap.h | 11 | ||||
-rw-r--r-- | tools/perf/util/evlist.c | 12 |
2 files changed, 17 insertions, 6 deletions
diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 17b5264f6436..2f68a3b8c285 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h | |||
@@ -2,6 +2,7 @@ | |||
2 | #define __PERF_CPUMAP_H | 2 | #define __PERF_CPUMAP_H |
3 | 3 | ||
4 | #include <stdio.h> | 4 | #include <stdio.h> |
5 | #include <stdbool.h> | ||
5 | 6 | ||
6 | struct cpu_map { | 7 | struct cpu_map { |
7 | int nr; | 8 | int nr; |
@@ -14,4 +15,14 @@ void cpu_map__delete(struct cpu_map *map); | |||
14 | struct cpu_map *cpu_map__read(FILE *file); | 15 | struct cpu_map *cpu_map__read(FILE *file); |
15 | size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp); | 16 | size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp); |
16 | 17 | ||
18 | static inline int cpu_map__nr(const struct cpu_map *map) | ||
19 | { | ||
20 | return map ? map->nr : 1; | ||
21 | } | ||
22 | |||
23 | static inline bool cpu_map__all(const struct cpu_map *map) | ||
24 | { | ||
25 | return map ? map->map[0] == -1 : true; | ||
26 | } | ||
27 | |||
17 | #endif /* __PERF_CPUMAP_H */ | 28 | #endif /* __PERF_CPUMAP_H */ |
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c index 892353729c7a..27f6de3aab16 100644 --- a/tools/perf/util/evlist.c +++ b/tools/perf/util/evlist.c | |||
@@ -304,7 +304,7 @@ void perf_evlist__enable(struct perf_evlist *evlist) | |||
304 | int cpu, thread; | 304 | int cpu, thread; |
305 | struct perf_evsel *pos; | 305 | struct perf_evsel *pos; |
306 | 306 | ||
307 | for (cpu = 0; cpu < evlist->cpus->nr; cpu++) { | 307 | for (cpu = 0; cpu < cpu_map__nr(evlist->cpus); cpu++) { |
308 | list_for_each_entry(pos, &evlist->entries, node) { | 308 | list_for_each_entry(pos, &evlist->entries, node) { |
309 | for (thread = 0; thread < evlist->threads->nr; thread++) | 309 | for (thread = 0; thread < evlist->threads->nr; thread++) |
310 | ioctl(FD(pos, cpu, thread), | 310 | ioctl(FD(pos, cpu, thread), |
@@ -315,7 +315,7 @@ void perf_evlist__enable(struct perf_evlist *evlist) | |||
315 | 315 | ||
316 | static int perf_evlist__alloc_pollfd(struct perf_evlist *evlist) | 316 | static int perf_evlist__alloc_pollfd(struct perf_evlist *evlist) |
317 | { | 317 | { |
318 | int nfds = evlist->cpus->nr * evlist->threads->nr * evlist->nr_entries; | 318 | int nfds = cpu_map__nr(evlist->cpus) * evlist->threads->nr * evlist->nr_entries; |
319 | evlist->pollfd = malloc(sizeof(struct pollfd) * nfds); | 319 | evlist->pollfd = malloc(sizeof(struct pollfd) * nfds); |
320 | return evlist->pollfd != NULL ? 0 : -ENOMEM; | 320 | return evlist->pollfd != NULL ? 0 : -ENOMEM; |
321 | } | 321 | } |
@@ -475,8 +475,8 @@ void perf_evlist__munmap(struct perf_evlist *evlist) | |||
475 | 475 | ||
476 | static int perf_evlist__alloc_mmap(struct perf_evlist *evlist) | 476 | static int perf_evlist__alloc_mmap(struct perf_evlist *evlist) |
477 | { | 477 | { |
478 | evlist->nr_mmaps = evlist->cpus->nr; | 478 | evlist->nr_mmaps = cpu_map__nr(evlist->cpus); |
479 | if (evlist->cpus->map[0] == -1) | 479 | if (cpu_map__all(evlist->cpus)) |
480 | evlist->nr_mmaps = evlist->threads->nr; | 480 | evlist->nr_mmaps = evlist->threads->nr; |
481 | evlist->mmap = zalloc(evlist->nr_mmaps * sizeof(struct perf_mmap)); | 481 | evlist->mmap = zalloc(evlist->nr_mmaps * sizeof(struct perf_mmap)); |
482 | return evlist->mmap != NULL ? 0 : -ENOMEM; | 482 | return evlist->mmap != NULL ? 0 : -ENOMEM; |
@@ -622,11 +622,11 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages, | |||
622 | list_for_each_entry(evsel, &evlist->entries, node) { | 622 | list_for_each_entry(evsel, &evlist->entries, node) { |
623 | if ((evsel->attr.read_format & PERF_FORMAT_ID) && | 623 | if ((evsel->attr.read_format & PERF_FORMAT_ID) && |
624 | evsel->sample_id == NULL && | 624 | evsel->sample_id == NULL && |
625 | perf_evsel__alloc_id(evsel, cpus->nr, threads->nr) < 0) | 625 | perf_evsel__alloc_id(evsel, cpu_map__nr(cpus), threads->nr) < 0) |
626 | return -ENOMEM; | 626 | return -ENOMEM; |
627 | } | 627 | } |
628 | 628 | ||
629 | if (evlist->cpus->map[0] == -1) | 629 | if (cpu_map__all(cpus)) |
630 | return perf_evlist__mmap_per_thread(evlist, prot, mask); | 630 | return perf_evlist__mmap_per_thread(evlist, prot, mask); |
631 | 631 | ||
632 | return perf_evlist__mmap_per_cpu(evlist, prot, mask); | 632 | return perf_evlist__mmap_per_cpu(evlist, prot, mask); |