lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Tue,  6 Oct 2015 21:54:46 +0200
From:	Jiri Olsa <jolsa@...nel.org>
To:	Arnaldo Carvalho de Melo <acme@...nel.org>
Cc:	lkml <linux-kernel@...r.kernel.org>,
	David Ahern <dsahern@...il.com>,
	Ingo Molnar <mingo@...nel.org>,
	Namhyung Kim <namhyung@...nel.org>,
	Peter Zijlstra <a.p.zijlstra@...llo.nl>,
	"Liang, Kan" <kan.liang@...el.com>
Subject: [PATCH 07/56] perf tools: Add cpu_map__new_event function

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 <jolsa@...nel.org>
---
 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 c51c29fd0732..e44849ad2c9c 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 8982d538da83..c5b28dd18f6b 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_id(int cpu);
-- 
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists