aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKan Liang <kan.liang@intel.com>2015-09-04 04:58:31 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-09-14 11:50:17 -0400
commitc84974ed9fb672930929e0d20ea3c366635a54aa (patch)
treead79e300ef18d2b5eeb6741f8f7302175e898e00
parentfbf99625b88fd8808bf2b80efac453d63cae08e8 (diff)
perf test: Add entry to test cpu topology
This patch test cpu core_id and socket_id which are stored in perf_env. Commiter note: # perf test topo 40: Test topology in session: Ok # perf test -v topo 40: Test topology in session: --- start --- test child forked, pid 31767 templ file: /tmp/perf-test-VTZ1PL CPU 0, core 0, socket 0 CPU 1, core 1, socket 0 CPU 2, core 0, socket 0 CPU 3, core 1, socket 0 test child finished with 0 ---- end ---- Test topology in session: Ok # Based-on-a-patch-by: Jiri Olsa <jolsa@kernel.org> Signed-off-by: Kan Liang <kan.liang@intel.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Jiri Olsa <jolsa@kernel.org> Link: http://lkml.kernel.org/r/1441357111-64522-1-git-send-email-kan.liang@intel.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/tests/Build1
-rw-r--r--tools/perf/tests/builtin-test.c4
-rw-r--r--tools/perf/tests/tests.h1
-rw-r--r--tools/perf/tests/topology.c115
4 files changed, 121 insertions, 0 deletions
diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index 51fb737f82fc..c6f198ae65fb 100644
--- a/tools/perf/tests/Build
+++ b/tools/perf/tests/Build
@@ -33,6 +33,7 @@ perf-y += parse-no-sample-id-all.o
33perf-y += kmod-path.o 33perf-y += kmod-path.o
34perf-y += thread-map.o 34perf-y += thread-map.o
35perf-y += llvm.o 35perf-y += llvm.o
36perf-y += topology.o
36 37
37perf-$(CONFIG_X86) += perf-time-to-tsc.o 38perf-$(CONFIG_X86) += perf-time-to-tsc.o
38ifdef CONFIG_AUXTRACE 39ifdef CONFIG_AUXTRACE
diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
index 69a77f71d594..98b0b2486100 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -187,6 +187,10 @@ static struct test {
187#endif 187#endif
188#endif 188#endif
189 { 189 {
190 .desc = "Test topology in session",
191 .func = test_session_topology,
192 },
193 {
190 .func = NULL, 194 .func = NULL,
191 }, 195 },
192}; 196};
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 4e2c5458269a..0b3549672c16 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -64,6 +64,7 @@ int test__kmod_path__parse(void);
64int test__thread_map(void); 64int test__thread_map(void);
65int test__llvm(void); 65int test__llvm(void);
66int test__insn_x86(void); 66int test__insn_x86(void);
67int test_session_topology(void);
67 68
68#if defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__) 69#if defined(__x86_64__) || defined(__i386__) || defined(__arm__) || defined(__aarch64__)
69#ifdef HAVE_DWARF_UNWIND_SUPPORT 70#ifdef HAVE_DWARF_UNWIND_SUPPORT
diff --git a/tools/perf/tests/topology.c b/tools/perf/tests/topology.c
new file mode 100644
index 000000000000..c3aff53a976a
--- /dev/null
+++ b/tools/perf/tests/topology.c
@@ -0,0 +1,115 @@
1#include <string.h>
2#include <stdlib.h>
3#include <stdio.h>
4#include "tests.h"
5#include "util.h"
6#include "session.h"
7#include "evlist.h"
8#include "debug.h"
9
10#define TEMPL "/tmp/perf-test-XXXXXX"
11#define DATA_SIZE 10
12
13static int get_temp(char *path)
14{
15 int fd;
16
17 strcpy(path, TEMPL);
18
19 fd = mkstemp(path);
20 if (fd < 0) {
21 perror("mkstemp failed");
22 return -1;
23 }
24
25 close(fd);
26 return 0;
27}
28
29static int session_write_header(char *path)
30{
31 struct perf_session *session;
32 struct perf_data_file file = {
33 .path = path,
34 .mode = PERF_DATA_MODE_WRITE,
35 };
36
37 session = perf_session__new(&file, false, NULL);
38 TEST_ASSERT_VAL("can't get session", session);
39
40 session->evlist = perf_evlist__new_default();
41 TEST_ASSERT_VAL("can't get evlist", session->evlist);
42
43 perf_header__set_feat(&session->header, HEADER_CPU_TOPOLOGY);
44 perf_header__set_feat(&session->header, HEADER_NRCPUS);
45
46 session->header.data_size += DATA_SIZE;
47
48 TEST_ASSERT_VAL("failed to write header",
49 !perf_session__write_header(session, session->evlist, file.fd, true));
50
51 perf_session__delete(session);
52
53 return 0;
54}
55
56static int check_cpu_topology(char *path, struct cpu_map *map)
57{
58 struct perf_session *session;
59 struct perf_data_file file = {
60 .path = path,
61 .mode = PERF_DATA_MODE_READ,
62 };
63 int i;
64
65 session = perf_session__new(&file, false, NULL);
66 TEST_ASSERT_VAL("can't get session", session);
67
68 for (i = 0; i < session->header.env.nr_cpus_online; i++) {
69 pr_debug("CPU %d, core %d, socket %d\n", i,
70 session->header.env.cpu[i].core_id,
71 session->header.env.cpu[i].socket_id);
72 }
73
74 for (i = 0; i < map->nr; i++) {
75 TEST_ASSERT_VAL("Core ID doesn't match",
76 (session->header.env.cpu[map->map[i]].core_id == (cpu_map__get_core(map, i) & 0xffff)));
77
78 TEST_ASSERT_VAL("Socket ID doesn't match",
79 (session->header.env.cpu[map->map[i]].socket_id == cpu_map__get_socket(map, i)));
80 }
81
82 perf_session__delete(session);
83
84 return 0;
85}
86
87int test_session_topology(void)
88{
89 char path[PATH_MAX];
90 struct cpu_map *map;
91 int ret = -1;
92
93 TEST_ASSERT_VAL("can't get templ file", !get_temp(path));
94
95 pr_debug("templ file: %s\n", path);
96
97 if (session_write_header(path))
98 goto free_path;
99
100 map = cpu_map__new(NULL);
101 if (map == NULL) {
102 pr_debug("failed to get system cpumap\n");
103 goto free_path;
104 }
105
106 if (check_cpu_topology(path, map))
107 goto free_map;
108 ret = 0;
109
110free_map:
111 cpu_map__put(map);
112free_path:
113 unlink(path);
114 return ret;
115}