Commit 34794913 authored by Ian Rogers's avatar Ian Rogers Committed by Arnaldo Carvalho de Melo

perf cpumap: Add CPU to aggr_cpu_id

With no aggregration, such as 'perf stat -A', the aggr_cpu_id lacks a
way to describe per CPU aggregation and the core is set to the CPU in
places like print_counter_aggrdata in stat-display.c.

Setting the core to the CPU is undesirable as the CPU will exceed valid
core values and lead to confusion. Add a CPU variable to address this.
Signed-off-by: default avatarIan Rogers <irogers@google.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Mike Leach <mike.leach@linaro.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Riccardo Mancini <rickyman7@gmail.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Vineet Singh <vineet.singh@intel.com>
Cc: coresight@lists.linaro.org
Cc: linux-arm-kernel@lists.infradead.org
Cc: zhengjun.xing@intel.com
Link: https://lore.kernel.org/r/20220105061351.120843-25-irogers@google.comSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent f9e891ea
...@@ -119,6 +119,22 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map) ...@@ -119,6 +119,22 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map)
session->header.env.cpu[i].socket_id); session->header.env.cpu[i].socket_id);
} }
// Test that CPU ID contains socket, die, core and CPU
for (i = 0; i < map->nr; i++) {
id = aggr_cpu_id__cpu(perf_cpu_map__cpu(map, i), NULL);
TEST_ASSERT_VAL("Cpu map - CPU ID doesn't match", map->map[i] == id.cpu);
TEST_ASSERT_VAL("Cpu map - Core ID doesn't match",
session->header.env.cpu[map->map[i]].core_id == id.core);
TEST_ASSERT_VAL("Cpu map - Socket ID doesn't match",
session->header.env.cpu[map->map[i]].socket_id == id.socket);
TEST_ASSERT_VAL("Cpu map - Die ID doesn't match",
session->header.env.cpu[map->map[i]].die_id == id.die);
TEST_ASSERT_VAL("Cpu map - Node ID is set", id.node == -1);
TEST_ASSERT_VAL("Cpu map - Thread is set", id.thread == -1);
}
// Test that core ID contains socket, die and core // Test that core ID contains socket, die and core
for (i = 0; i < map->nr; i++) { for (i = 0; i < map->nr; i++) {
id = aggr_cpu_id__core(perf_cpu_map__cpu(map, i), NULL); id = aggr_cpu_id__core(perf_cpu_map__cpu(map, i), NULL);
...@@ -145,6 +161,7 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map) ...@@ -145,6 +161,7 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map)
TEST_ASSERT_VAL("Die map - Node ID is set", id.node == -1); TEST_ASSERT_VAL("Die map - Node ID is set", id.node == -1);
TEST_ASSERT_VAL("Die map - Core is set", id.core == -1); TEST_ASSERT_VAL("Die map - Core is set", id.core == -1);
TEST_ASSERT_VAL("Die map - CPU is set", id.cpu == -1);
TEST_ASSERT_VAL("Die map - Thread is set", id.thread == -1); TEST_ASSERT_VAL("Die map - Thread is set", id.thread == -1);
} }
...@@ -157,6 +174,7 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map) ...@@ -157,6 +174,7 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map)
TEST_ASSERT_VAL("Socket map - Node ID is set", id.node == -1); TEST_ASSERT_VAL("Socket map - Node ID is set", id.node == -1);
TEST_ASSERT_VAL("Socket map - Die ID is set", id.die == -1); TEST_ASSERT_VAL("Socket map - Die ID is set", id.die == -1);
TEST_ASSERT_VAL("Socket map - Core is set", id.core == -1); TEST_ASSERT_VAL("Socket map - Core is set", id.core == -1);
TEST_ASSERT_VAL("Socket map - CPU is set", id.cpu == -1);
TEST_ASSERT_VAL("Socket map - Thread is set", id.thread == -1); TEST_ASSERT_VAL("Socket map - Thread is set", id.thread == -1);
} }
...@@ -168,6 +186,7 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map) ...@@ -168,6 +186,7 @@ static int check_cpu_topology(char *path, struct perf_cpu_map *map)
TEST_ASSERT_VAL("Node map - Socket is set", id.socket == -1); TEST_ASSERT_VAL("Node map - Socket is set", id.socket == -1);
TEST_ASSERT_VAL("Node map - Die ID is set", id.die == -1); TEST_ASSERT_VAL("Node map - Die ID is set", id.die == -1);
TEST_ASSERT_VAL("Node map - Core is set", id.core == -1); TEST_ASSERT_VAL("Node map - Core is set", id.core == -1);
TEST_ASSERT_VAL("Node map - CPU is set", id.cpu == -1);
TEST_ASSERT_VAL("Node map - Thread is set", id.thread == -1); TEST_ASSERT_VAL("Node map - Thread is set", id.thread == -1);
} }
perf_session__delete(session); perf_session__delete(session);
......
...@@ -242,7 +242,7 @@ struct aggr_cpu_id aggr_cpu_id__core(int cpu, void *data) ...@@ -242,7 +242,7 @@ struct aggr_cpu_id aggr_cpu_id__core(int cpu, void *data)
struct aggr_cpu_id id; struct aggr_cpu_id id;
int core = cpu__get_core_id(cpu); int core = cpu__get_core_id(cpu);
/* aggr_cpu_id__die returns a struct with socket and die set*/ /* aggr_cpu_id__die returns a struct with socket and die set. */
id = aggr_cpu_id__die(cpu, data); id = aggr_cpu_id__die(cpu, data);
if (aggr_cpu_id__is_empty(&id)) if (aggr_cpu_id__is_empty(&id))
return id; return id;
...@@ -256,6 +256,20 @@ struct aggr_cpu_id aggr_cpu_id__core(int cpu, void *data) ...@@ -256,6 +256,20 @@ struct aggr_cpu_id aggr_cpu_id__core(int cpu, void *data)
} }
struct aggr_cpu_id aggr_cpu_id__cpu(int cpu, void *data)
{
struct aggr_cpu_id id;
/* aggr_cpu_id__core returns a struct with socket, die and core set. */
id = aggr_cpu_id__core(cpu, data);
if (aggr_cpu_id__is_empty(&id))
return id;
id.cpu = cpu;
return id;
}
struct aggr_cpu_id aggr_cpu_id__node(int cpu, void *data __maybe_unused) struct aggr_cpu_id aggr_cpu_id__node(int cpu, void *data __maybe_unused)
{ {
struct aggr_cpu_id id = aggr_cpu_id__empty(); struct aggr_cpu_id id = aggr_cpu_id__empty();
...@@ -579,7 +593,8 @@ bool aggr_cpu_id__equal(const struct aggr_cpu_id *a, const struct aggr_cpu_id *b ...@@ -579,7 +593,8 @@ bool aggr_cpu_id__equal(const struct aggr_cpu_id *a, const struct aggr_cpu_id *b
a->node == b->node && a->node == b->node &&
a->socket == b->socket && a->socket == b->socket &&
a->die == b->die && a->die == b->die &&
a->core == b->core; a->core == b->core &&
a->cpu == b->cpu;
} }
bool aggr_cpu_id__is_empty(const struct aggr_cpu_id *a) bool aggr_cpu_id__is_empty(const struct aggr_cpu_id *a)
...@@ -588,7 +603,8 @@ bool aggr_cpu_id__is_empty(const struct aggr_cpu_id *a) ...@@ -588,7 +603,8 @@ bool aggr_cpu_id__is_empty(const struct aggr_cpu_id *a)
a->node == -1 && a->node == -1 &&
a->socket == -1 && a->socket == -1 &&
a->die == -1 && a->die == -1 &&
a->core == -1; a->core == -1 &&
a->cpu == -1;
} }
struct aggr_cpu_id aggr_cpu_id__empty(void) struct aggr_cpu_id aggr_cpu_id__empty(void)
...@@ -598,7 +614,8 @@ struct aggr_cpu_id aggr_cpu_id__empty(void) ...@@ -598,7 +614,8 @@ struct aggr_cpu_id aggr_cpu_id__empty(void)
.node = -1, .node = -1,
.socket = -1, .socket = -1,
.die = -1, .die = -1,
.core = -1 .core = -1,
.cpu = -1
}; };
return ret; return ret;
} }
...@@ -22,6 +22,8 @@ struct aggr_cpu_id { ...@@ -22,6 +22,8 @@ struct aggr_cpu_id {
int die; int die;
/** The core id as read from /sys/devices/system/cpu/cpuX/topology/core_id. */ /** The core id as read from /sys/devices/system/cpu/cpuX/topology/core_id. */
int core; int core;
/** CPU aggregation, note there is one CPU for each SMT thread. */
int cpu;
}; };
/** A collection of aggr_cpu_id values, the "built" version is sorted and uniqued. */ /** A collection of aggr_cpu_id values, the "built" version is sorted and uniqued. */
...@@ -109,6 +111,12 @@ struct aggr_cpu_id aggr_cpu_id__die(int cpu, void *data); ...@@ -109,6 +111,12 @@ struct aggr_cpu_id aggr_cpu_id__die(int cpu, void *data);
* compatible with aggr_cpu_id_get_t. * compatible with aggr_cpu_id_get_t.
*/ */
struct aggr_cpu_id aggr_cpu_id__core(int cpu, void *data); struct aggr_cpu_id aggr_cpu_id__core(int cpu, void *data);
/**
* aggr_cpu_id__core - Create an aggr_cpu_id with the cpu, core, die and socket
* populated with the cpu, core, die and socket for cpu. The function signature
* is compatible with aggr_cpu_id_get_t.
*/
struct aggr_cpu_id aggr_cpu_id__cpu(int cpu, void *data);
/** /**
* aggr_cpu_id__node - Create an aggr_cpu_id with the numa node populated for * aggr_cpu_id__node - Create an aggr_cpu_id with the numa node populated for
* cpu. The function signature is compatible with aggr_cpu_id_get_t. * cpu. The function signature is compatible with aggr_cpu_id_get_t.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment