Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754614AbbGUMcp (ORCPT ); Tue, 21 Jul 2015 08:32:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55904 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754569AbbGUMcm (ORCPT ); Tue, 21 Jul 2015 08:32:42 -0400 From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: lkml , David Ahern , Ingo Molnar , Namhyung Kim , Peter Zijlstra Subject: [PATCH 17/47] perf tools: Add cpu_map__new_event function Date: Tue, 21 Jul 2015 14:31:37 +0200 Message-Id: <1437481927-29538-18-git-send-email-jolsa@kernel.org> In-Reply-To: <1437481927-29538-1-git-send-email-jolsa@kernel.org> References: <1437481927-29538-1-git-send-email-jolsa@kernel.org> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2935 Lines: 99 Introducing cpu_map__new_event function to create struct cpu_map object from cpu_map event. Link: http://lkml.kernel.org/n/tip-tepv49tbjsqeprmf8k05lc6r@git.kernel.org Signed-off-by: Jiri Olsa --- tools/perf/tests/cpumap.c | 10 ++++++++++ tools/perf/util/cpumap.c | 27 +++++++++++++++++++++++++++ tools/perf/util/cpumap.h | 3 +++ 3 files changed, 40 insertions(+) diff --git a/tools/perf/tests/cpumap.c b/tools/perf/tests/cpumap.c index 475c040f8a8d..af8a3f520a2a 100644 --- a/tools/perf/tests/cpumap.c +++ b/tools/perf/tests/cpumap.c @@ -7,11 +7,21 @@ static int process_event(struct perf_tool *tool __maybe_unused, struct machine *machine __maybe_unused) { struct cpu_map_event *map = &event->cpu_map; + struct cpu_map *cpus; TEST_ASSERT_VAL("wrong nr", map->nr == 3); TEST_ASSERT_VAL("wrong cpu", map->cpu[0] == 1); TEST_ASSERT_VAL("wrong cpu", map->cpu[1] == 2); TEST_ASSERT_VAL("wrong cpu", map->cpu[2] == 4); + + cpus = cpu_map__new_event(&event->cpu_map); + TEST_ASSERT_VAL("wrong nr", cpus->nr == 3); + TEST_ASSERT_VAL("wrong cpu", cpus->map[0] == 1); + TEST_ASSERT_VAL("wrong cpu", cpus->map[1] == 2); + TEST_ASSERT_VAL("wrong cpu", cpus->map[2] == 4); + TEST_ASSERT_VAL("wrong refcnt", + atomic_read(&cpus->refcnt) == 1); + cpu_map__put(cpus); return 0; } diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c index 3667e2123e5b..81e82cadda50 100644 --- a/tools/perf/util/cpumap.c +++ b/tools/perf/util/cpumap.c @@ -179,6 +179,33 @@ out: return cpus; } +static void cpu_map__copy_event(struct cpu_map *cpus, + struct cpu_map_event *event) +{ + unsigned i; + + cpus->nr = event->nr; + + for (i = 0; i < event->nr; i++) + cpus->map[i] = (int) event->cpu[i]; + + atomic_set(&cpus->refcnt, 1); +} + +struct cpu_map *cpu_map__new_event(struct cpu_map_event *event) +{ + struct cpu_map *cpus; + int size; + + size = sizeof(cpus) + (event->nr * sizeof(cpus->map[0])); + + cpus = zalloc(size); + if (cpus) + cpu_map__copy_event(cpus, event); + + return cpus; +} + size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp) { int i; diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h index 0af9cecb4c51..44a68b63bf48 100644 --- a/tools/perf/util/cpumap.h +++ b/tools/perf/util/cpumap.h @@ -14,8 +14,11 @@ struct cpu_map { int map[]; }; +struct cpu_map_event; + struct cpu_map *cpu_map__new(const char *cpu_list); 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); size_t cpu_map__fprintf(struct cpu_map *map, FILE *fp); int cpu_map__get_socket(struct cpu_map *map, int idx); -- 2.4.3 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/