perf tests: Improve topology test to check all aggregation types

Improve the topology test to check all aggregation types. This is to
lock down the behaviour before 'id' is changed into a struct in later
commits.

Committer testing:

  $ perf test topology
  41: Session topology: Ok
  $

  $ perf test -v topology
  41: Session topology:
  --- start ---
  test child forked, pid 965552
  templ file: /tmp/perf-test-mO7NtI
  Problems creating module maps, continuing anyway...
  CPU 0, core 0, socket 0
  CPU 1, core 1, socket 0
  CPU 2, core 2, socket 0
  CPU 3, core 4, socket 0
  CPU 4, core 5, socket 0
  CPU 5, core 6, socket 0
  CPU 6, core 8, socket 0
  CPU 7, core 9, socket 0
  CPU 8, core 10, socket 0
  CPU 9, core 12, socket 0
  CPU 10, core 13, socket 0
  CPU 11, core 14, socket 0
  CPU 12, core 0, socket 0
  CPU 13, core 1, socket 0
  CPU 14, core 2, socket 0
  CPU 15, core 4, socket 0
  CPU 16, core 5, socket 0
  CPU 17, core 6, socket 0
  CPU 18, core 8, socket 0
  CPU 19, core 9, socket 0
  CPU 20, core 10, socket 0
  CPU 21, core 12, socket 0
  CPU 22, core 13, socket 0
  CPU 23, core 14, socket 0
  test child finished with 0
  ---- end ----
  Session topology: Ok
  $

Signed-off-by: James Clark <james.clark@arm.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Tested-by: John Garry <john.garry@huawei.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Richter <tmricht@linux.ibm.com>
Link: https://lore.kernel.org/r/20201126141328.6509-2-james.clark@arm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
James Clark 2020-11-26 16:13:17 +02:00 committed by Arnaldo Carvalho de Melo
parent b27d20ab1c
commit 23331eeb73

View file

@ -64,10 +64,11 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map)
.path = path,
.mode = PERF_DATA_MODE_READ,
};
int i;
int i, id;
session = perf_session__new(&data, false, NULL);
TEST_ASSERT_VAL("can't get session", !IS_ERR(session));
cpu__setup_cpunode_map();
/* On platforms with large numbers of CPUs process_cpu_topology()
* might issue an error while reading the perf.data file section
@ -85,11 +86,18 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map)
* "socket_id number is too big. You may need to upgrade the
* perf tool."
*
* This is the reason why this test might be skipped.
* This is the reason why this test might be skipped. aarch64 and
* s390 always write this part of the header, even when the above
* condition is true (see do_core_id_test in header.c). So always
* run this test on those platforms.
*/
if (!session->header.env.cpu)
if (!session->header.env.cpu
&& strncmp(session->header.env.arch, "s390", 4)
&& strncmp(session->header.env.arch, "aarch64", 7))
return TEST_SKIP;
TEST_ASSERT_VAL("Session header CPU map not set", session->header.env.cpu);
for (i = 0; i < session->header.env.nr_cpus_avail; i++) {
if (!cpu_map__has(map, i))
continue;
@ -98,14 +106,45 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map)
session->header.env.cpu[i].socket_id);
}
// Test that core ID contains socket, die and core
for (i = 0; i < map->nr; i++) {
TEST_ASSERT_VAL("Core ID doesn't match",
(session->header.env.cpu[map->map[i]].core_id == (cpu_map__get_core(map, i, NULL) & 0xffff)));
id = cpu_map__get_core(map, i, NULL);
TEST_ASSERT_VAL("Core map - Core ID doesn't match",
session->header.env.cpu[map->map[i]].core_id == cpu_map__id_to_cpu(id));
TEST_ASSERT_VAL("Socket ID doesn't match",
(session->header.env.cpu[map->map[i]].socket_id == cpu_map__get_socket(map, i, NULL)));
TEST_ASSERT_VAL("Core map - Socket ID doesn't match",
session->header.env.cpu[map->map[i]].socket_id ==
cpu_map__id_to_socket(id));
TEST_ASSERT_VAL("Core map - Die ID doesn't match",
session->header.env.cpu[map->map[i]].die_id == cpu_map__id_to_die(id));
}
// Test that die ID contains socket and die
for (i = 0; i < map->nr; i++) {
id = cpu_map__get_die(map, i, NULL);
TEST_ASSERT_VAL("Die map - Socket ID doesn't match",
session->header.env.cpu[map->map[i]].socket_id ==
cpu_map__id_to_socket(id << 16));
TEST_ASSERT_VAL("Die map - Die ID doesn't match",
session->header.env.cpu[map->map[i]].die_id ==
cpu_map__id_to_die(id << 16));
}
// Test that socket ID contains only socket
for (i = 0; i < map->nr; i++) {
id = cpu_map__get_socket(map, i, NULL);
TEST_ASSERT_VAL("Socket map - Socket ID doesn't match",
session->header.env.cpu[map->map[i]].socket_id == id);
}
// Test that node ID contains only node
for (i = 0; i < map->nr; i++) {
id = cpu_map__get_node(map, i, NULL);
TEST_ASSERT_VAL("Node map - Node ID doesn't match",
cpu__get_node(map->map[i]) == id);
}
perf_session__delete(session);
return 0;