Skip to content

Commit

Permalink
perf tools: Allow handling a NULL cpu_map as meaning "all cpus"
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Arnaldo Carvalho de Melo committed Sep 26, 2012
1 parent 0b80f8b commit a14bb7a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
11 changes: 11 additions & 0 deletions tools/perf/util/cpumap.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define __PERF_CPUMAP_H

#include <stdio.h>
#include <stdbool.h>

struct cpu_map {
int nr;
Expand All @@ -14,4 +15,14 @@ void cpu_map__delete(struct cpu_map *map);
struct cpu_map *cpu_map__read(FILE *file);
size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp);

static inline int cpu_map__nr(const struct cpu_map *map)
{
return map ? map->nr : 1;
}

static inline bool cpu_map__all(const struct cpu_map *map)
{
return map ? map->map[0] == -1 : true;
}

#endif /* __PERF_CPUMAP_H */
12 changes: 6 additions & 6 deletions tools/perf/util/evlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ void perf_evlist__enable(struct perf_evlist *evlist)
int cpu, thread;
struct perf_evsel *pos;

for (cpu = 0; cpu < evlist->cpus->nr; cpu++) {
for (cpu = 0; cpu < cpu_map__nr(evlist->cpus); cpu++) {
list_for_each_entry(pos, &evlist->entries, node) {
for (thread = 0; thread < evlist->threads->nr; thread++)
ioctl(FD(pos, cpu, thread),
Expand All @@ -315,7 +315,7 @@ void perf_evlist__enable(struct perf_evlist *evlist)

static int perf_evlist__alloc_pollfd(struct perf_evlist *evlist)
{
int nfds = evlist->cpus->nr * evlist->threads->nr * evlist->nr_entries;
int nfds = cpu_map__nr(evlist->cpus) * evlist->threads->nr * evlist->nr_entries;
evlist->pollfd = malloc(sizeof(struct pollfd) * nfds);
return evlist->pollfd != NULL ? 0 : -ENOMEM;
}
Expand Down Expand Up @@ -475,8 +475,8 @@ void perf_evlist__munmap(struct perf_evlist *evlist)

static int perf_evlist__alloc_mmap(struct perf_evlist *evlist)
{
evlist->nr_mmaps = evlist->cpus->nr;
if (evlist->cpus->map[0] == -1)
evlist->nr_mmaps = cpu_map__nr(evlist->cpus);
if (cpu_map__all(evlist->cpus))
evlist->nr_mmaps = evlist->threads->nr;
evlist->mmap = zalloc(evlist->nr_mmaps * sizeof(struct perf_mmap));
return evlist->mmap != NULL ? 0 : -ENOMEM;
Expand Down Expand Up @@ -622,11 +622,11 @@ int perf_evlist__mmap(struct perf_evlist *evlist, unsigned int pages,
list_for_each_entry(evsel, &evlist->entries, node) {
if ((evsel->attr.read_format & PERF_FORMAT_ID) &&
evsel->sample_id == NULL &&
perf_evsel__alloc_id(evsel, cpus->nr, threads->nr) < 0)
perf_evsel__alloc_id(evsel, cpu_map__nr(cpus), threads->nr) < 0)
return -ENOMEM;
}

if (evlist->cpus->map[0] == -1)
if (cpu_map__all(cpus))
return perf_evlist__mmap_per_thread(evlist, prot, mask);

return perf_evlist__mmap_per_cpu(evlist, prot, mask);
Expand Down

0 comments on commit a14bb7a

Please sign in to comment.