diff options
author | Jiri Olsa <jolsa@kernel.org> | 2015-10-25 15:51:25 +0100 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2015-12-17 18:38:18 +0100 |
commit | f77b57ad4fc42a074eae564bbb6660f0a3ff5503 (patch) | |
tree | 9c33eec565c48c35e34dc95ae53921244611cca6 /tools/perf/util/cpumap.c | |
parent | perf cpu_map: Add cpu_map event synthesize function (diff) | |
download | linux-f77b57ad4fc42a074eae564bbb6660f0a3ff5503.tar.xz linux-f77b57ad4fc42a074eae564bbb6660f0a3ff5503.zip |
perf cpu_map: Add cpu_map__new_event function
Introducing the cpu_map__new_event function to create a struct cpu_map
object from a cpu_map event.
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Kan Liang <kan.liang@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/1445784728-21732-10-git-send-email-jolsa@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/cpumap.c')
-rw-r--r-- | tools/perf/util/cpumap.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 10af1e7524fb..a0717b93d8f5 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -5,6 +5,7 @@ #include <assert.h> #include <stdio.h> #include <stdlib.h> +#include <linux/bitmap.h> #include "asm/bug.h" static struct cpu_map *cpu_map__default_new(void) @@ -179,6 +180,47 @@ out: return cpus; } +static struct cpu_map *cpu_map__from_entries(struct cpu_map_entries *cpus) +{ + struct cpu_map *map; + + map = cpu_map__empty_new(cpus->nr); + if (map) { + unsigned i; + + for (i = 0; i < cpus->nr; i++) + map->map[i] = (int)cpus->cpu[i]; + } + + return map; +} + +static struct cpu_map *cpu_map__from_mask(struct cpu_map_mask *mask) +{ + struct cpu_map *map; + int nr, nbits = mask->nr * mask->long_size * BITS_PER_BYTE; + + nr = bitmap_weight(mask->mask, nbits); + + map = cpu_map__empty_new(nr); + if (map) { + int cpu, i = 0; + + for_each_set_bit(cpu, mask->mask, nbits) + map->map[i++] = cpu; + } + return map; + +} + +struct cpu_map *cpu_map__new_data(struct cpu_map_data *data) +{ + if (data->type == PERF_CPU_MAP__CPUS) + return cpu_map__from_entries((struct cpu_map_entries *)data->data); + else + return cpu_map__from_mask((struct cpu_map_mask *)data->data); +} + size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp) { int i; |