[PATCH 09/13] perf event: Use machine->env to find the cpu -> socket mapping

From: Arnaldo Carvalho de Melo
Date: Wed Sep 09 2015 - 15:52:51 EST


From: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>

Instead of reading
/sysfs/devices/system/cpu/cpu%d/topology/physical_package_id for
each sample.

While at it, check that the sample has PERF_SAMPLE_CPU, i.e. that
sample.cpu >= 0, to avoid an out of bounds access.

Reported-by: Wang Nan <wangnan0@xxxxxxxxxx>
Based-on-a-patch-by: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Adrian Hunter <adrian.hunter@xxxxxxxxx>
Cc: Borislav Petkov <bp@xxxxxxx>
Cc: David Ahern <dsahern@xxxxxxxxx>
Cc: Frederic Weisbecker <fweisbec@xxxxxxxxx>
Cc: Kan Liang <kan.liang@xxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Stephane Eranian <eranian@xxxxxxxxxx>
Cc: Wang Nan <wangnan0@xxxxxxxxxx>
Link: http://lkml.kernel.org/n/tip-lkkb5iht6gbbngdpfv0nl7vh@xxxxxxxxxxxxxx
Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
---
tools/perf/util/event.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/event.c b/tools/perf/util/event.c
index 0bf8c9889fc0..497157affc9c 100644
--- a/tools/perf/util/event.c
+++ b/tools/perf/util/event.c
@@ -1021,7 +1021,14 @@ int perf_event__preprocess_sample(const union perf_event *event,

al->sym = NULL;
al->cpu = sample->cpu;
- al->socket = cpu_map__get_socket_id(al->cpu);
+ al->socket = -1;
+
+ if (al->cpu >= 0) {
+ struct perf_env *env = machine->env;
+
+ if (env && env->cpu)
+ al->socket = env->cpu[al->cpu].socket_id;
+ }

if (al->map) {
struct dso *dso = al->map->dso;
--
2.1.0

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