Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1240946

[PATCH 40/56] perf stat report: Cache aggregated map entries in extra cpumap

From Jiri Olsa <jolsa@kernel.org>
Newsgroups linux.kernel
Subject [PATCH 40/56] perf stat report: Cache aggregated map entries in extra cpumap
Date 2015-10-06 22:10 +0200
Message-ID <qgGIH-84P-41@gated-at.bofh.it> (permalink)
References <qgGz0-7BP-7@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Currently any time we need to access socket or core id for
given cpu, we access the sysfs topology file.

Adding cpus_aggr_map cpu_map to cache those entries.

Link: http://lkml.kernel.org/n/tip-2cw82b5piydhao8sft09am3r@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 tools/perf/builtin-stat.c | 60 +++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 56 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 9ce8ce6377ab..f38edfc1985c 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -101,6 +101,8 @@ static struct target target = {
 	.uid	= UINT_MAX,
 };
 
+typedef int (*aggr_get_id_t)(struct cpu_map *m, int cpu);
+
 static int			run_count			=  1;
 static bool			no_inherit			= false;
 static volatile pid_t		child_pid			= -1;
@@ -120,7 +122,7 @@ static unsigned int		unit_width			= 4; /* strlen("unit") */
 static bool			forever				= false;
 static struct timespec		ref_time;
 static struct cpu_map		*aggr_map;
-static int			(*aggr_get_id)(struct cpu_map *m, int cpu);
+static aggr_get_id_t		aggr_get_id;
 
 struct perf_stat {
 	bool			 record;
@@ -1150,6 +1152,7 @@ static int stat__set_big_num(const struct option *opt __maybe_unused,
 	return 0;
 }
 
+
 static int perf_stat__get_socket(struct cpu_map *map, int cpu)
 {
 	return cpu_map__get_socket(map, cpu, NULL);
@@ -1160,22 +1163,63 @@ static int perf_stat__get_core(struct cpu_map *map, int cpu)
 	return cpu_map__get_core(map, cpu, NULL);
 }
 
+static int cpu_map__get_max(struct cpu_map *map)
+{
+	int i, max = -1;
+
+	for (i = 0; i < map->nr; i++) {
+		if (map->map[i] > max)
+			max = map->map[i];
+	}
+
+	return max;
+}
+
+static struct cpu_map *cpus_aggr_map;
+
+static int perf_stat__get_aggr(aggr_get_id_t get_id, struct cpu_map *map, int idx)
+{
+	int cpu;
+
+	if (idx > map->nr)
+		return -1;
+
+	cpu = map->map[idx];
+
+	if (cpus_aggr_map->map[cpu] == -1)
+		cpus_aggr_map->map[cpu] = get_id(map, idx);
+
+	return cpus_aggr_map->map[cpu];
+}
+
+static int perf_stat__get_socket_cached(struct cpu_map *map, int idx)
+{
+	return perf_stat__get_aggr(perf_stat__get_socket, map, idx);
+}
+
+static int perf_stat__get_core_cached(struct cpu_map *map, int idx)
+{
+	return perf_stat__get_aggr(perf_stat__get_core, map, idx);
+}
+
 static int perf_stat_init_aggr_mode(void)
 {
+	int nr;
+
 	switch (stat_config.aggr_mode) {
 	case AGGR_SOCKET:
 		if (cpu_map__build_socket_map(evsel_list->cpus, &aggr_map)) {
 			perror("cannot build socket map");
 			return -1;
 		}
-		aggr_get_id = perf_stat__get_socket;
+		aggr_get_id = perf_stat__get_socket_cached;
 		break;
 	case AGGR_CORE:
 		if (cpu_map__build_core_map(evsel_list->cpus, &aggr_map)) {
 			perror("cannot build core map");
 			return -1;
 		}
-		aggr_get_id = perf_stat__get_core;
+		aggr_get_id = perf_stat__get_core_cached;
 		break;
 	case AGGR_NONE:
 	case AGGR_GLOBAL:
@@ -1184,7 +1228,15 @@ static int perf_stat_init_aggr_mode(void)
 	default:
 		break;
 	}
-	return 0;
+
+	/*
+	 * The evsel_list->cpus is the base we operate on,
+	 * taking the highest cpu number to be the size of
+	 * the aggregation translate cpumap.
+	 */
+	nr = cpu_map__get_max(evsel_list->cpus);
+	cpus_aggr_map = cpu_map__empty_new(nr + 1);
+	return cpus_aggr_map ? 0 : -ENOMEM;
 }
 
 /*
-- 
2.4.3

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

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCHv3 00/56] perf stat: Add scripting support Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:00 +0200
  [PATCH 36/56] perf stat record: Synthesize attr update events Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:00 +0200
  [PATCH 08/56] perf tools: Add perf_event__fprintf_cpu_map function Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:00 +0200
  [PATCH 25/56] perf tools: Move id_offset out of struct perf_evsel union Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:00 +0200
  [PATCH 28/56] perf stat record: Add record command Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:00 +0200
  [PATCH 45/56] perf stat report: Process stat and stat round events Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:00 +0200
  [PATCH 43/56] perf stat report: Process stat config event Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:00 +0200
  [PATCH 39/56] perf tools: Add data arg to cpu_map__build_map callback Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:00 +0200
  [PATCH 13/56] perf tools: Add stat event synthesize function Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:00 +0200
  [PATCH 32/56] perf stat record: Add pipe support for record command Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:10 +0200
  [PATCH 29/56] perf stat record: Initialize record features Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:10 +0200
  [PATCH 19/56] perf tools: Add attr_update event unit type Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:10 +0200
  [PATCH 37/56] perf tools: Add cpu_map__empty_new interface Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:10 +0200
  [PATCH 50/56] perf script: Process cpu/threads maps Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:10 +0200
  [PATCH 26/56] perf stat: Rename perf_stat struct into perf_stat_evsel Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:10 +0200
  [PATCH 24/56] perf tools: Introduce stat feature Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:10 +0200
  [PATCH 52/56] perf script: Add process_stat/process_stat_interval scripting interface Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:10 +0200
  [PATCH 16/56] perf tools: Add stat round event synthesize function Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:10 +0200
  [PATCH 35/56] perf stat record: Do not allow record with multiple runs mode Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:10 +0200
  [PATCH 22/56] perf tools: Add perf_event__fprintf_attr_update function Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:10 +0200
  [PATCH 40/56] perf stat report: Cache aggregated map entries in extra cpumap Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:10 +0200
  [PATCH 42/56] perf stat report: Process cpu/threads maps Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:10 +0200
  [PATCH 34/56] perf stat record: Write stat round events on record Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:10 +0200
  [PATCH 21/56] perf tools: Add attr_update event name type Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:10 +0200
  [PATCH 20/56] perf tools: Add attr_update event scale type Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:10 +0200
  [PATCH 18/56] perf tools: Add attr_update event Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:10 +0200
  [PATCH 10/56] perf tools: Add stat config event synthesize function Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:20 +0200
  [PATCH 04/56] perf tools: Add perf_event__fprintf_thread_map function Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:20 +0200
  [PATCH 06/56] perf tools: Add cpu_map event synthesize function Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:20 +0200
  [PATCH 14/56] perf tools: Add stat event read function Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:20 +0200
  [PATCH 12/56] perf tools: Add stat event Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:20 +0200
  [PATCH 11/56] perf tools: Add stat config event read function Jiri Olsa <jolsa@kernel.org> - 2015-10-06 22:20 +0200
  RE: [PATCHv3 00/56] perf stat: Add scripting support "Liang, Kan" <kan.liang@intel.com> - 2015-10-08 20:40 +0200
    Re: [PATCHv3 00/56] perf stat: Add scripting support Jiri Olsa <jolsa@redhat.com> - 2015-10-08 22:20 +0200
      RE: [PATCHv3 00/56] perf stat: Add scripting support "Liang, Kan" <kan.liang@intel.com> - 2015-10-09 20:40 +0200
        Re: [PATCHv3 00/56] perf stat: Add scripting support Jiri Olsa <jolsa@redhat.com> - 2015-10-14 13:00 +0200
          RE: [PATCHv3 00/56] perf stat: Add scripting support "Liang, Kan" <kan.liang@intel.com> - 2015-10-14 21:50 +0200

csiph-web