Messages in this thread Patch in this message | | | From | Jiri Olsa <> | Subject | [PATCH 27/45] perf tools: Add cpu_map__empty_new interface | Date | Wed, 30 Sep 2015 16:10:40 +0200 |
| |
Adding cpu_map__empty_new interface to create empty cpumap with given size. The cpumap entries are initialized with -1.
It'll be used for caching cpu_map in following patches.
Link: http://lkml.kernel.org/n/tip-2q9tmp3shdscmtiv6h8afhvd@git.kernel.org Signed-off-by: Jiri Olsa <jolsa@kernel.org> --- tools/perf/util/cpumap.c | 17 +++++++++++++++++ tools/perf/util/cpumap.h | 1 + 2 files changed, 18 insertions(+)
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index e44849ad2c9c..891af6a5efed 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -230,6 +230,23 @@ struct cpu_map *cpu_map__dummy_new(void) return cpus; } +struct cpu_map *cpu_map__empty_new(int nr) +{ + struct cpu_map *cpus = malloc(sizeof(*cpus) + sizeof(int) * nr); + + if (cpus != NULL) { + int i; + + cpus->nr = nr; + for (i = 0; i < nr; i++) + cpus->map[i] = -1; + + atomic_set(&cpus->refcnt, 1); + } + + return cpus; +} + static void cpu_map__delete(struct cpu_map *map) { if (map) { diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index c5b28dd18f6b..1f536164050b 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -17,6 +17,7 @@ struct cpu_map { struct cpu_map_event; struct cpu_map *cpu_map__new(const char *cpu_list); +struct cpu_map *cpu_map__empty_new(int nr); struct cpu_map *cpu_map__dummy_new(void); struct cpu_map *cpu_map__new_event(struct cpu_map_event *event); struct cpu_map *cpu_map__read(FILE *file); -- 2.4.3
| |