linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 1/7] perf: Refactor svg_build_topology_map
       [not found] <20190827214352.94272-1-meyerk@stormcage.eag.rdlabs.hpecorp.net>
@ 2019-08-27 21:43 ` Kyle Meyer
  2019-08-29  9:11   ` Jiri Olsa
  2019-09-02  8:16   ` [tip: perf/core] perf timechart: Refactor svg_build_topology_map() tip-bot2 for Kyle Meyer
  2019-08-27 21:43 ` [PATCH v4 2/7] perf/util/svghelper: Replace MAX_NR_CPUS with env->nr_cpus_online Kyle Meyer
                   ` (5 subsequent siblings)
  6 siblings, 2 replies; 16+ messages in thread
From: Kyle Meyer @ 2019-08-27 21:43 UTC (permalink / raw)
  Cc: Kyle Meyer, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, linux-kernel, Russ Anderson, Kyle Meyer

Exchange the parameters of svg_build_topology_map with struct perf_env
*env and adjust the function accordingly. This patch should not change any
behavior, it is merely refactoring for the following patch.

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-kernel@vger.kernel.org
Cc: Russ Anderson <russ.anderson@hpe.com>
Signed-off-by: Kyle Meyer <kyle.meyer@hpe.com>
---
 tools/perf/builtin-timechart.c |  5 +----
 tools/perf/util/svghelper.c    | 19 +++++++++++--------
 tools/perf/util/svghelper.h    |  4 +++-
 3 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 7d6a6ecf4e02..1ff81a790931 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -1518,10 +1518,7 @@ static int process_header(struct perf_file_section *section __maybe_unused,
 		if (!tchart->topology)
 			break;
 
-		if (svg_build_topology_map(ph->env.sibling_cores,
-					   ph->env.nr_sibling_cores,
-					   ph->env.sibling_threads,
-					   ph->env.nr_sibling_threads))
+		if (svg_build_topology_map(&ph->env))
 			fprintf(stderr, "problem building topology\n");
 		break;
 
diff --git a/tools/perf/util/svghelper.c b/tools/perf/util/svghelper.c
index bbdd87163285..4d2ac55267fc 100644
--- a/tools/perf/util/svghelper.c
+++ b/tools/perf/util/svghelper.c
@@ -752,23 +752,26 @@ static int str_to_bitmap(char *s, cpumask_t *b)
 	return ret;
 }
 
-int svg_build_topology_map(char *sib_core, int sib_core_nr,
-			   char *sib_thr, int sib_thr_nr)
+int svg_build_topology_map(struct perf_env *env)
 {
 	int i;
 	struct topology t;
+	char *sib_core, *sib_thr;
 
-	t.sib_core_nr = sib_core_nr;
-	t.sib_thr_nr = sib_thr_nr;
-	t.sib_core = calloc(sib_core_nr, sizeof(cpumask_t));
-	t.sib_thr = calloc(sib_thr_nr, sizeof(cpumask_t));
+	t.sib_core_nr = env->nr_sibling_cores;
+	t.sib_thr_nr = env->nr_sibling_threads;
+	t.sib_core = calloc(env->nr_sibling_cores, sizeof(cpumask_t));
+	t.sib_thr = calloc(env->nr_sibling_threads, sizeof(cpumask_t));
+
+	sib_core = env->sibling_cores;
+	sib_thr = env->sibling_threads;
 
 	if (!t.sib_core || !t.sib_thr) {
 		fprintf(stderr, "topology: no memory\n");
 		goto exit;
 	}
 
-	for (i = 0; i < sib_core_nr; i++) {
+	for (i = 0; i < env->nr_sibling_cores; i++) {
 		if (str_to_bitmap(sib_core, &t.sib_core[i])) {
 			fprintf(stderr, "topology: can't parse siblings map\n");
 			goto exit;
@@ -777,7 +780,7 @@ int svg_build_topology_map(char *sib_core, int sib_core_nr,
 		sib_core += strlen(sib_core) + 1;
 	}
 
-	for (i = 0; i < sib_thr_nr; i++) {
+	for (i = 0; i < env->nr_sibling_threads; i++) {
 		if (str_to_bitmap(sib_thr, &t.sib_thr[i])) {
 			fprintf(stderr, "topology: can't parse siblings map\n");
 			goto exit;
diff --git a/tools/perf/util/svghelper.h b/tools/perf/util/svghelper.h
index e55338d5c3bd..2add34c75733 100644
--- a/tools/perf/util/svghelper.h
+++ b/tools/perf/util/svghelper.h
@@ -4,6 +4,8 @@
 
 #include <linux/types.h>
 
+#include "env.h"
+
 void open_svg(const char *filename, int cpus, int rows, u64 start, u64 end);
 void svg_ubox(int Yslot, u64 start, u64 end, double height, const char *type, int fd, int err, int merges);
 void svg_lbox(int Yslot, u64 start, u64 end, double height, const char *type, int fd, int err, int merges);
@@ -28,7 +30,7 @@ void svg_partial_wakeline(u64 start, int row1, char *desc1, int row2, char *desc
 void svg_interrupt(u64 start, int row, const char *backtrace);
 void svg_text(int Yslot, u64 start, const char *text);
 void svg_close(void);
-int svg_build_topology_map(char *sib_core, int sib_core_nr, char *sib_thr, int sib_thr_nr);
+int svg_build_topology_map(struct perf_env *env);
 
 extern int svg_page_width;
 extern u64 svg_highlight;
-- 
2.12.3


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v4 2/7] perf/util/svghelper: Replace MAX_NR_CPUS with env->nr_cpus_online
       [not found] <20190827214352.94272-1-meyerk@stormcage.eag.rdlabs.hpecorp.net>
  2019-08-27 21:43 ` [PATCH v4 1/7] perf: Refactor svg_build_topology_map Kyle Meyer
@ 2019-08-27 21:43 ` Kyle Meyer
  2019-09-02  8:16   ` [tip: perf/core] perf svghelper: Replace MAX_NR_CPUS with perf_env::nr_cpus_online tip-bot2 for Kyle Meyer
  2019-08-27 21:43 ` [PATCH v4 3/7] perf/util/stat: Replace MAX_NR_CPUS with cpu__max_cpu Kyle Meyer
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 16+ messages in thread
From: Kyle Meyer @ 2019-08-27 21:43 UTC (permalink / raw)
  Cc: Kyle Meyer, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, linux-kernel, Russ Anderson, Kyle Meyer

nr_cpus, the number of CPUs online during a record session bound by
MAX_NR_CPUS, can be used as a dynamic alternative for MAX_NR_CPUS in
svg_build_topology_map. The value of nr_cpus can be passed into
str_to_bitmap, scan_core_topology, and svg_build_topology_map to replace
MAX_NR_CPUS as well.

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-kernel@vger.kernel.org
Cc: Russ Anderson <russ.anderson@hpe.com>
Signed-off-by: Kyle Meyer <kyle.meyer@hpe.com>
---
 tools/perf/util/svghelper.c | 33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/tools/perf/util/svghelper.c b/tools/perf/util/svghelper.c
index 4d2ac55267fc..be0af04a76e0 100644
--- a/tools/perf/util/svghelper.c
+++ b/tools/perf/util/svghelper.c
@@ -696,7 +696,8 @@ struct topology {
 	int sib_thr_nr;
 };
 
-static void scan_thread_topology(int *map, struct topology *t, int cpu, int *pos)
+static void scan_thread_topology(int *map, struct topology *t, int cpu,
+				 int *pos, int nr_cpus)
 {
 	int i;
 	int thr;
@@ -705,28 +706,24 @@ static void scan_thread_topology(int *map, struct topology *t, int cpu, int *pos
 		if (!test_bit(cpu, cpumask_bits(&t->sib_thr[i])))
 			continue;
 
-		for_each_set_bit(thr,
-				 cpumask_bits(&t->sib_thr[i]),
-				 MAX_NR_CPUS)
+		for_each_set_bit(thr, cpumask_bits(&t->sib_thr[i]), nr_cpus)
 			if (map[thr] == -1)
 				map[thr] = (*pos)++;
 	}
 }
 
-static void scan_core_topology(int *map, struct topology *t)
+static void scan_core_topology(int *map, struct topology *t, int nr_cpus)
 {
 	int pos = 0;
 	int i;
 	int cpu;
 
 	for (i = 0; i < t->sib_core_nr; i++)
-		for_each_set_bit(cpu,
-				 cpumask_bits(&t->sib_core[i]),
-				 MAX_NR_CPUS)
-			scan_thread_topology(map, t, cpu, &pos);
+		for_each_set_bit(cpu, cpumask_bits(&t->sib_core[i]), nr_cpus)
+			scan_thread_topology(map, t, cpu, &pos, nr_cpus);
 }
 
-static int str_to_bitmap(char *s, cpumask_t *b)
+static int str_to_bitmap(char *s, cpumask_t *b, int nr_cpus)
 {
 	int i;
 	int ret = 0;
@@ -739,7 +736,7 @@ static int str_to_bitmap(char *s, cpumask_t *b)
 
 	for (i = 0; i < m->nr; i++) {
 		c = m->map[i];
-		if (c >= MAX_NR_CPUS) {
+		if (c >= nr_cpus) {
 			ret = -1;
 			break;
 		}
@@ -754,10 +751,12 @@ static int str_to_bitmap(char *s, cpumask_t *b)
 
 int svg_build_topology_map(struct perf_env *env)
 {
-	int i;
+	int i, nr_cpus;
 	struct topology t;
 	char *sib_core, *sib_thr;
 
+	nr_cpus = min(env->nr_cpus_online, MAX_NR_CPUS);
+
 	t.sib_core_nr = env->nr_sibling_cores;
 	t.sib_thr_nr = env->nr_sibling_threads;
 	t.sib_core = calloc(env->nr_sibling_cores, sizeof(cpumask_t));
@@ -772,7 +771,7 @@ int svg_build_topology_map(struct perf_env *env)
 	}
 
 	for (i = 0; i < env->nr_sibling_cores; i++) {
-		if (str_to_bitmap(sib_core, &t.sib_core[i])) {
+		if (str_to_bitmap(sib_core, &t.sib_core[i], nr_cpus)) {
 			fprintf(stderr, "topology: can't parse siblings map\n");
 			goto exit;
 		}
@@ -781,7 +780,7 @@ int svg_build_topology_map(struct perf_env *env)
 	}
 
 	for (i = 0; i < env->nr_sibling_threads; i++) {
-		if (str_to_bitmap(sib_thr, &t.sib_thr[i])) {
+		if (str_to_bitmap(sib_thr, &t.sib_thr[i], nr_cpus)) {
 			fprintf(stderr, "topology: can't parse siblings map\n");
 			goto exit;
 		}
@@ -789,16 +788,16 @@ int svg_build_topology_map(struct perf_env *env)
 		sib_thr += strlen(sib_thr) + 1;
 	}
 
-	topology_map = malloc(sizeof(int) * MAX_NR_CPUS);
+	topology_map = malloc(sizeof(int) * nr_cpus);
 	if (!topology_map) {
 		fprintf(stderr, "topology: no memory\n");
 		goto exit;
 	}
 
-	for (i = 0; i < MAX_NR_CPUS; i++)
+	for (i = 0; i < nr_cpus; i++)
 		topology_map[i] = -1;
 
-	scan_core_topology(topology_map, &t);
+	scan_core_topology(topology_map, &t, nr_cpus);
 
 	return 0;
 
-- 
2.12.3


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v4 3/7] perf/util/stat: Replace MAX_NR_CPUS with cpu__max_cpu
       [not found] <20190827214352.94272-1-meyerk@stormcage.eag.rdlabs.hpecorp.net>
  2019-08-27 21:43 ` [PATCH v4 1/7] perf: Refactor svg_build_topology_map Kyle Meyer
  2019-08-27 21:43 ` [PATCH v4 2/7] perf/util/svghelper: Replace MAX_NR_CPUS with env->nr_cpus_online Kyle Meyer
@ 2019-08-27 21:43 ` Kyle Meyer
  2019-09-02  8:16   ` [tip: perf/core] perf stat: Replace MAX_NR_CPUS with cpu__max_cpu() tip-bot2 for Kyle Meyer
  2019-08-27 21:43 ` [PATCH v4 4/7] perf/util/session: Replace MAX_NR_CPUS with nr_cpus_online Kyle Meyer
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 16+ messages in thread
From: Kyle Meyer @ 2019-08-27 21:43 UTC (permalink / raw)
  Cc: Kyle Meyer, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, linux-kernel, Russ Anderson, Kyle Meyer

The function cpu__max_cpu returns the possible number of CPUs as defined
in the sysfs and can be used as an alternative for MAX_NR_CPUS in
zero_per_pkg and check_per_pkg.

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-kernel@vger.kernel.org
Cc: Russ Anderson <russ.anderson@hpe.com>
Signed-off-by: Kyle Meyer <kyle.meyer@hpe.com>
---
 tools/perf/util/stat.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
index 0cbfd1eca1dd..b754686b684d 100644
--- a/tools/perf/util/stat.c
+++ b/tools/perf/util/stat.c
@@ -209,7 +209,7 @@ void perf_evlist__reset_stats(struct evlist *evlist)
 static void zero_per_pkg(struct evsel *counter)
 {
 	if (counter->per_pkg_mask)
-		memset(counter->per_pkg_mask, 0, MAX_NR_CPUS);
+		memset(counter->per_pkg_mask, 0, cpu__max_cpu());
 }
 
 static int check_per_pkg(struct evsel *counter,
@@ -228,7 +228,7 @@ static int check_per_pkg(struct evsel *counter,
 		return 0;
 
 	if (!mask) {
-		mask = zalloc(MAX_NR_CPUS);
+		mask = zalloc(cpu__max_cpu());
 		if (!mask)
 			return -ENOMEM;
 
-- 
2.12.3


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v4 4/7] perf/util/session: Replace MAX_NR_CPUS with nr_cpus_online
       [not found] <20190827214352.94272-1-meyerk@stormcage.eag.rdlabs.hpecorp.net>
                   ` (2 preceding siblings ...)
  2019-08-27 21:43 ` [PATCH v4 3/7] perf/util/stat: Replace MAX_NR_CPUS with cpu__max_cpu Kyle Meyer
@ 2019-08-27 21:43 ` Kyle Meyer
  2019-09-02  8:16   ` [tip: perf/core] perf session: Replace MAX_NR_CPUS with perf_env::nr_cpus_online tip-bot2 for Kyle Meyer
  2019-08-27 21:43 ` [PATCH v4 5/7] perf/util/machine: Replace MAX_NR_CPUS with nr_cpus_online Kyle Meyer
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 16+ messages in thread
From: Kyle Meyer @ 2019-08-27 21:43 UTC (permalink / raw)
  Cc: Kyle Meyer, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, linux-kernel, Russ Anderson, Kyle Meyer

nr_cpus, the number of CPUs online during a record session bound by
MAX_NR_CPUS, can be used as a dynamic alternative for MAX_NR_CPUS in
perf_session__cpu_bitmap.

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-kernel@vger.kernel.org
Cc: Russ Anderson <russ.anderson@hpe.com>
Signed-off-by: Kyle Meyer <kyle.meyer@hpe.com>
---
 tools/perf/util/session.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 82e0438a9160..2f0d84a71ded 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -2291,6 +2291,7 @@ int perf_session__cpu_bitmap(struct perf_session *session,
 {
 	int i, err = -1;
 	struct perf_cpu_map *map;
+	int nr_cpus = min(session->header.env.nr_cpus_online, MAX_NR_CPUS);
 
 	for (i = 0; i < PERF_TYPE_MAX; ++i) {
 		struct evsel *evsel;
@@ -2315,7 +2316,7 @@ int perf_session__cpu_bitmap(struct perf_session *session,
 	for (i = 0; i < map->nr; i++) {
 		int cpu = map->map[i];
 
-		if (cpu >= MAX_NR_CPUS) {
+		if (cpu >= nr_cpus) {
 			pr_err("Requested CPU %d too large. "
 			       "Consider raising MAX_NR_CPUS\n", cpu);
 			goto out_delete_map;
-- 
2.12.3


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v4 5/7] perf/util/machine: Replace MAX_NR_CPUS with nr_cpus_online
       [not found] <20190827214352.94272-1-meyerk@stormcage.eag.rdlabs.hpecorp.net>
                   ` (3 preceding siblings ...)
  2019-08-27 21:43 ` [PATCH v4 4/7] perf/util/session: Replace MAX_NR_CPUS with nr_cpus_online Kyle Meyer
@ 2019-08-27 21:43 ` Kyle Meyer
  2019-09-02  8:16   ` [tip: perf/core] perf machine: Replace MAX_NR_CPUS with perf_env::nr_cpus_online tip-bot2 for Kyle Meyer
  2019-08-27 21:43 ` [PATCH v4 6/7] perf/util/header: Replace MAX_NR_CPUS with cpu__max_cpu Kyle Meyer
  2019-08-27 21:43 ` [PATCH v4 7/7] perf/lib/cpumap: Warn when exceeding MAX_NR_CPUS Kyle Meyer
  6 siblings, 1 reply; 16+ messages in thread
From: Kyle Meyer @ 2019-08-27 21:43 UTC (permalink / raw)
  Cc: Kyle Meyer, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, linux-kernel, Russ Anderson, Kyle Meyer

nr_cpus, the number of CPUs online during a record session bound by
MAX_NR_CPUS, can be used as a dynamic alternative for MAX_NR_CPUS in
__machine__synthesize_threads and machine__set_current_tid.

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-kernel@vger.kernel.org
Cc: Russ Anderson <russ.anderson@hpe.com>
Signed-off-by: Kyle Meyer <kyle.meyer@hpe.com>
---
 tools/perf/util/machine.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 5734460fc89e..194b9ec5f88b 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -2616,7 +2616,9 @@ int __machine__synthesize_threads(struct machine *machine, struct perf_tool *too
 
 pid_t machine__get_current_tid(struct machine *machine, int cpu)
 {
-	if (cpu < 0 || cpu >= MAX_NR_CPUS || !machine->current_tid)
+	int nr_cpus = min(machine->env->nr_cpus_online, MAX_NR_CPUS);
+
+	if (cpu < 0 || cpu >= nr_cpus || !machine->current_tid)
 		return -1;
 
 	return machine->current_tid[cpu];
@@ -2626,6 +2628,7 @@ int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid,
 			     pid_t tid)
 {
 	struct thread *thread;
+	int nr_cpus = min(machine->env->nr_cpus_online, MAX_NR_CPUS);
 
 	if (cpu < 0)
 		return -EINVAL;
@@ -2633,14 +2636,14 @@ int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid,
 	if (!machine->current_tid) {
 		int i;
 
-		machine->current_tid = calloc(MAX_NR_CPUS, sizeof(pid_t));
+		machine->current_tid = calloc(nr_cpus, sizeof(pid_t));
 		if (!machine->current_tid)
 			return -ENOMEM;
-		for (i = 0; i < MAX_NR_CPUS; i++)
+		for (i = 0; i < nr_cpus; i++)
 			machine->current_tid[i] = -1;
 	}
 
-	if (cpu >= MAX_NR_CPUS) {
+	if (cpu >= nr_cpus) {
 		pr_err("Requested CPU %d too large. ", cpu);
 		pr_err("Consider raising MAX_NR_CPUS\n");
 		return -EINVAL;
-- 
2.12.3


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v4 6/7] perf/util/header: Replace MAX_NR_CPUS with cpu__max_cpu
       [not found] <20190827214352.94272-1-meyerk@stormcage.eag.rdlabs.hpecorp.net>
                   ` (4 preceding siblings ...)
  2019-08-27 21:43 ` [PATCH v4 5/7] perf/util/machine: Replace MAX_NR_CPUS with nr_cpus_online Kyle Meyer
@ 2019-08-27 21:43 ` Kyle Meyer
  2019-09-02  8:16   ` [tip: perf/core] perf header: Replace MAX_NR_CPUS with cpu__max_cpu() tip-bot2 for Kyle Meyer
  2019-08-27 21:43 ` [PATCH v4 7/7] perf/lib/cpumap: Warn when exceeding MAX_NR_CPUS Kyle Meyer
  6 siblings, 1 reply; 16+ messages in thread
From: Kyle Meyer @ 2019-08-27 21:43 UTC (permalink / raw)
  Cc: Kyle Meyer, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, linux-kernel, Russ Anderson, Kyle Meyer

The function cpu__max_cpu returns the possible number of CPUs as defined
in the sysfs and can be used as an alternative for MAX_NR_CPUS in
write_cache. MAX_CACHES is replaced by cpu__max_cpu() * MAX_CACHE_LVL.

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-kernel@vger.kernel.org
Cc: Russ Anderson <russ.anderson@hpe.com>
Signed-off-by: Kyle Meyer <kyle.meyer@hpe.com>
---
 tools/perf/util/header.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 1f2965a07bef..881a586fab41 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1121,16 +1121,17 @@ static int build_caches(struct cpu_cache_level caches[], u32 size, u32 *cntp)
 	return 0;
 }
 
-#define MAX_CACHES (MAX_NR_CPUS * 4)
+#define MAX_CACHE_LVL 4
 
 static int write_cache(struct feat_fd *ff,
 		       struct evlist *evlist __maybe_unused)
 {
-	struct cpu_cache_level caches[MAX_CACHES];
+	u32 max_caches = cpu__max_cpu() * MAX_CACHE_LVL;
+	struct cpu_cache_level caches[max_caches];
 	u32 cnt = 0, i, version = 1;
 	int ret;
 
-	ret = build_caches(caches, MAX_CACHES, &cnt);
+	ret = build_caches(caches, max_caches, &cnt);
 	if (ret)
 		goto out;
 
-- 
2.12.3


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH v4 7/7] perf/lib/cpumap: Warn when exceeding MAX_NR_CPUS
       [not found] <20190827214352.94272-1-meyerk@stormcage.eag.rdlabs.hpecorp.net>
                   ` (5 preceding siblings ...)
  2019-08-27 21:43 ` [PATCH v4 6/7] perf/util/header: Replace MAX_NR_CPUS with cpu__max_cpu Kyle Meyer
@ 2019-08-27 21:43 ` Kyle Meyer
  2019-09-02  8:16   ` [tip: perf/core] libperf: Warn when exceeding MAX_NR_CPUS in cpumap tip-bot2 for Kyle Meyer
  6 siblings, 1 reply; 16+ messages in thread
From: Kyle Meyer @ 2019-08-27 21:43 UTC (permalink / raw)
  Cc: Kyle Meyer, Peter Zijlstra, Ingo Molnar,
	Arnaldo Carvalho de Melo, Alexander Shishkin, Jiri Olsa,
	Namhyung Kim, linux-kernel, Russ Anderson, Kyle Meyer

Display a warning when attempting to profile more than MAX_NR_CPU CPUs.
This patch should not change any behavior.

Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: linux-kernel@vger.kernel.org
Cc: Russ Anderson <russ.anderson@hpe.com>
Signed-off-by: Kyle Meyer <kyle.meyer@hpe.com>
---
 tools/perf/lib/cpumap.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/perf/lib/cpumap.c b/tools/perf/lib/cpumap.c
index 2834753576b2..1f0e6f334237 100644
--- a/tools/perf/lib/cpumap.c
+++ b/tools/perf/lib/cpumap.c
@@ -100,6 +100,9 @@ struct perf_cpu_map *perf_cpu_map__read(FILE *file)
 		if (prev >= 0) {
 			int new_max = nr_cpus + cpu - prev - 1;
 
+			WARN_ONCE(new_max >= MAX_NR_CPUS, "Perf can support %d CPUs. "
+							  "Consider raising MAX_NR_CPUS\n", MAX_NR_CPUS);
+
 			if (new_max >= max_entries) {
 				max_entries = new_max + MAX_NR_CPUS / 2;
 				tmp = realloc(tmp_cpus, max_entries * sizeof(int));
@@ -192,6 +195,9 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list)
 			end_cpu = start_cpu;
 		}
 
+		WARN_ONCE(end_cpu >= MAX_NR_CPUS, "Perf can support %d CPUs. "
+						  "Consider raising MAX_NR_CPUS\n", MAX_NR_CPUS);
+
 		for (; start_cpu <= end_cpu; start_cpu++) {
 			/* check for duplicates */
 			for (i = 0; i < nr_cpus; i++)
-- 
2.12.3


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 1/7] perf: Refactor svg_build_topology_map
  2019-08-27 21:43 ` [PATCH v4 1/7] perf: Refactor svg_build_topology_map Kyle Meyer
@ 2019-08-29  9:11   ` Jiri Olsa
  2019-08-29 15:49     ` Arnaldo Carvalho de Melo
  2019-09-02  8:16   ` [tip: perf/core] perf timechart: Refactor svg_build_topology_map() tip-bot2 for Kyle Meyer
  1 sibling, 1 reply; 16+ messages in thread
From: Jiri Olsa @ 2019-08-29  9:11 UTC (permalink / raw)
  To: Kyle Meyer
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Alexander Shishkin, Namhyung Kim, linux-kernel, Russ Anderson,
	Kyle Meyer

On Tue, Aug 27, 2019 at 04:43:46PM -0500, Kyle Meyer wrote:
> Exchange the parameters of svg_build_topology_map with struct perf_env
> *env and adjust the function accordingly. This patch should not change any
> behavior, it is merely refactoring for the following patch.
> 
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> Cc: Jiri Olsa <jolsa@redhat.com>
> Cc: Namhyung Kim <namhyung@kernel.org>
> Cc: linux-kernel@vger.kernel.org
> Cc: Russ Anderson <russ.anderson@hpe.com>
> Signed-off-by: Kyle Meyer <kyle.meyer@hpe.com>

for the patchset:

Reviewed-by: Jiri Olsa <jolsa@redhat.com>

thanks,
jirka

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH v4 1/7] perf: Refactor svg_build_topology_map
  2019-08-29  9:11   ` Jiri Olsa
@ 2019-08-29 15:49     ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 16+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-08-29 15:49 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Kyle Meyer, Peter Zijlstra, Ingo Molnar, Alexander Shishkin,
	Namhyung Kim, linux-kernel, Russ Anderson, Kyle Meyer

Em Thu, Aug 29, 2019 at 11:11:22AM +0200, Jiri Olsa escreveu:
> On Tue, Aug 27, 2019 at 04:43:46PM -0500, Kyle Meyer wrote:
> > Exchange the parameters of svg_build_topology_map with struct perf_env
> > *env and adjust the function accordingly. This patch should not change any
> > behavior, it is merely refactoring for the following patch.
> > 
> > Cc: Peter Zijlstra <peterz@infradead.org>
> > Cc: Ingo Molnar <mingo@redhat.com>
> > Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
> > Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
> > Cc: Jiri Olsa <jolsa@redhat.com>
> > Cc: Namhyung Kim <namhyung@kernel.org>
> > Cc: linux-kernel@vger.kernel.org
> > Cc: Russ Anderson <russ.anderson@hpe.com>
> > Signed-off-by: Kyle Meyer <kyle.meyer@hpe.com>
> 
> for the patchset:
> 
> Reviewed-by: Jiri Olsa <jolsa@redhat.com>

Thanks, applied to perf/core.

- Arnaldo

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [tip: perf/core] perf svghelper: Replace MAX_NR_CPUS with perf_env::nr_cpus_online
  2019-08-27 21:43 ` [PATCH v4 2/7] perf/util/svghelper: Replace MAX_NR_CPUS with env->nr_cpus_online Kyle Meyer
@ 2019-09-02  8:16   ` tip-bot2 for Kyle Meyer
  0 siblings, 0 replies; 16+ messages in thread
From: tip-bot2 for Kyle Meyer @ 2019-09-02  8:16 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Kyle Meyer, Jiri Olsa, Alexander Shishkin, Namhyung Kim,
	Peter Zijlstra, Russ Anderson, Arnaldo Carvalho de Melo,
	Ingo Molnar, Borislav Petkov, linux-kernel

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     f78f96676a256d7fa171a54b271a2ad2c6555c9c
Gitweb:        https://git.kernel.org/tip/f78f96676a256d7fa171a54b271a2ad2c6555c9c
Author:        Kyle Meyer <meyerk@hpe.com>
AuthorDate:    Tue, 27 Aug 2019 16:43:47 -05:00
Committer:     Arnaldo Carvalho de Melo <acme@redhat.com>
CommitterDate: Thu, 29 Aug 2019 17:38:32 -03:00

perf svghelper: Replace MAX_NR_CPUS with perf_env::nr_cpus_online

'nr_cpus', the number of CPUs online during a record session bound by
MAX_NR_CPUS, can be used as a dynamic alternative for MAX_NR_CPUS in
svg_build_topology_map().

The value of nr_cpus can be passed into str_to_bitmap(),
scan_core_topology(), and svg_build_topology_map() to replace
MAX_NR_CPUS as well.

Signed-off-by: Kyle Meyer <kyle.meyer@hpe.com>
Reviewed-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Russ Anderson <russ.anderson@hpe.com>
Link: http://lore.kernel.org/lkml/20190827214352.94272-3-meyerk@stormcage.eag.rdlabs.hpecorp.net
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/svghelper.c | 33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/tools/perf/util/svghelper.c b/tools/perf/util/svghelper.c
index 2e99715..fef0f8a 100644
--- a/tools/perf/util/svghelper.c
+++ b/tools/perf/util/svghelper.c
@@ -697,7 +697,8 @@ struct topology {
 	int sib_thr_nr;
 };
 
-static void scan_thread_topology(int *map, struct topology *t, int cpu, int *pos)
+static void scan_thread_topology(int *map, struct topology *t, int cpu,
+				 int *pos, int nr_cpus)
 {
 	int i;
 	int thr;
@@ -706,28 +707,24 @@ static void scan_thread_topology(int *map, struct topology *t, int cpu, int *pos
 		if (!test_bit(cpu, cpumask_bits(&t->sib_thr[i])))
 			continue;
 
-		for_each_set_bit(thr,
-				 cpumask_bits(&t->sib_thr[i]),
-				 MAX_NR_CPUS)
+		for_each_set_bit(thr, cpumask_bits(&t->sib_thr[i]), nr_cpus)
 			if (map[thr] == -1)
 				map[thr] = (*pos)++;
 	}
 }
 
-static void scan_core_topology(int *map, struct topology *t)
+static void scan_core_topology(int *map, struct topology *t, int nr_cpus)
 {
 	int pos = 0;
 	int i;
 	int cpu;
 
 	for (i = 0; i < t->sib_core_nr; i++)
-		for_each_set_bit(cpu,
-				 cpumask_bits(&t->sib_core[i]),
-				 MAX_NR_CPUS)
-			scan_thread_topology(map, t, cpu, &pos);
+		for_each_set_bit(cpu, cpumask_bits(&t->sib_core[i]), nr_cpus)
+			scan_thread_topology(map, t, cpu, &pos, nr_cpus);
 }
 
-static int str_to_bitmap(char *s, cpumask_t *b)
+static int str_to_bitmap(char *s, cpumask_t *b, int nr_cpus)
 {
 	int i;
 	int ret = 0;
@@ -740,7 +737,7 @@ static int str_to_bitmap(char *s, cpumask_t *b)
 
 	for (i = 0; i < m->nr; i++) {
 		c = m->map[i];
-		if (c >= MAX_NR_CPUS) {
+		if (c >= nr_cpus) {
 			ret = -1;
 			break;
 		}
@@ -755,10 +752,12 @@ static int str_to_bitmap(char *s, cpumask_t *b)
 
 int svg_build_topology_map(struct perf_env *env)
 {
-	int i;
+	int i, nr_cpus;
 	struct topology t;
 	char *sib_core, *sib_thr;
 
+	nr_cpus = min(env->nr_cpus_online, MAX_NR_CPUS);
+
 	t.sib_core_nr = env->nr_sibling_cores;
 	t.sib_thr_nr = env->nr_sibling_threads;
 	t.sib_core = calloc(env->nr_sibling_cores, sizeof(cpumask_t));
@@ -773,7 +772,7 @@ int svg_build_topology_map(struct perf_env *env)
 	}
 
 	for (i = 0; i < env->nr_sibling_cores; i++) {
-		if (str_to_bitmap(sib_core, &t.sib_core[i])) {
+		if (str_to_bitmap(sib_core, &t.sib_core[i], nr_cpus)) {
 			fprintf(stderr, "topology: can't parse siblings map\n");
 			goto exit;
 		}
@@ -782,7 +781,7 @@ int svg_build_topology_map(struct perf_env *env)
 	}
 
 	for (i = 0; i < env->nr_sibling_threads; i++) {
-		if (str_to_bitmap(sib_thr, &t.sib_thr[i])) {
+		if (str_to_bitmap(sib_thr, &t.sib_thr[i], nr_cpus)) {
 			fprintf(stderr, "topology: can't parse siblings map\n");
 			goto exit;
 		}
@@ -790,16 +789,16 @@ int svg_build_topology_map(struct perf_env *env)
 		sib_thr += strlen(sib_thr) + 1;
 	}
 
-	topology_map = malloc(sizeof(int) * MAX_NR_CPUS);
+	topology_map = malloc(sizeof(int) * nr_cpus);
 	if (!topology_map) {
 		fprintf(stderr, "topology: no memory\n");
 		goto exit;
 	}
 
-	for (i = 0; i < MAX_NR_CPUS; i++)
+	for (i = 0; i < nr_cpus; i++)
 		topology_map[i] = -1;
 
-	scan_core_topology(topology_map, &t);
+	scan_core_topology(topology_map, &t, nr_cpus);
 
 	return 0;
 

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [tip: perf/core] perf timechart: Refactor svg_build_topology_map()
  2019-08-27 21:43 ` [PATCH v4 1/7] perf: Refactor svg_build_topology_map Kyle Meyer
  2019-08-29  9:11   ` Jiri Olsa
@ 2019-09-02  8:16   ` tip-bot2 for Kyle Meyer
  1 sibling, 0 replies; 16+ messages in thread
From: tip-bot2 for Kyle Meyer @ 2019-09-02  8:16 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Kyle Meyer, Jiri Olsa, Alexander Shishkin, Namhyung Kim,
	Peter Zijlstra, Russ Anderson, Arnaldo Carvalho de Melo,
	Ingo Molnar, Borislav Petkov, linux-kernel

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     0ac1dd5b4a70cfc8591dd9426f800b484765badb
Gitweb:        https://git.kernel.org/tip/0ac1dd5b4a70cfc8591dd9426f800b484765badb
Author:        Kyle Meyer <meyerk@hpe.com>
AuthorDate:    Tue, 27 Aug 2019 16:43:46 -05:00
Committer:     Arnaldo Carvalho de Melo <acme@redhat.com>
CommitterDate: Thu, 29 Aug 2019 17:38:31 -03:00

perf timechart: Refactor svg_build_topology_map()

Exchange the parameters of svg_build_topology_map() with 'struct
perf_env *env' and adjust the function accordingly.

This patch should not change any behavior, it is merely refactoring for
the following patch.

Committer notes:

No need to include env.h from svghelper.h, all it needs is a forward
declaration for 'struct perf_env', so move the include directive to
svghelper.c, where it is really needed.

Signed-off-by: Kyle Meyer <kyle.meyer@hpe.com>
Reviewed-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Russ Anderson <russ.anderson@hpe.com>
Link: http://lore.kernel.org/lkml/20190827214352.94272-2-meyerk@stormcage.eag.rdlabs.hpecorp.net
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/builtin-timechart.c |  5 +----
 tools/perf/util/svghelper.c    | 20 ++++++++++++--------
 tools/perf/util/svghelper.h    |  4 +++-
 3 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/tools/perf/builtin-timechart.c b/tools/perf/builtin-timechart.c
index 7d6a6ec..1ff81a7 100644
--- a/tools/perf/builtin-timechart.c
+++ b/tools/perf/builtin-timechart.c
@@ -1518,10 +1518,7 @@ static int process_header(struct perf_file_section *section __maybe_unused,
 		if (!tchart->topology)
 			break;
 
-		if (svg_build_topology_map(ph->env.sibling_cores,
-					   ph->env.nr_sibling_cores,
-					   ph->env.sibling_threads,
-					   ph->env.nr_sibling_threads))
+		if (svg_build_topology_map(&ph->env))
 			fprintf(stderr, "problem building topology\n");
 		break;
 
diff --git a/tools/perf/util/svghelper.c b/tools/perf/util/svghelper.c
index bbdd871..2e99715 100644
--- a/tools/perf/util/svghelper.c
+++ b/tools/perf/util/svghelper.c
@@ -19,6 +19,7 @@
 #include <linux/zalloc.h>
 #include <perf/cpumap.h>
 
+#include "env.h"
 #include "perf.h"
 #include "svghelper.h"
 #include "cpumap.h"
@@ -752,23 +753,26 @@ static int str_to_bitmap(char *s, cpumask_t *b)
 	return ret;
 }
 
-int svg_build_topology_map(char *sib_core, int sib_core_nr,
-			   char *sib_thr, int sib_thr_nr)
+int svg_build_topology_map(struct perf_env *env)
 {
 	int i;
 	struct topology t;
+	char *sib_core, *sib_thr;
 
-	t.sib_core_nr = sib_core_nr;
-	t.sib_thr_nr = sib_thr_nr;
-	t.sib_core = calloc(sib_core_nr, sizeof(cpumask_t));
-	t.sib_thr = calloc(sib_thr_nr, sizeof(cpumask_t));
+	t.sib_core_nr = env->nr_sibling_cores;
+	t.sib_thr_nr = env->nr_sibling_threads;
+	t.sib_core = calloc(env->nr_sibling_cores, sizeof(cpumask_t));
+	t.sib_thr = calloc(env->nr_sibling_threads, sizeof(cpumask_t));
+
+	sib_core = env->sibling_cores;
+	sib_thr = env->sibling_threads;
 
 	if (!t.sib_core || !t.sib_thr) {
 		fprintf(stderr, "topology: no memory\n");
 		goto exit;
 	}
 
-	for (i = 0; i < sib_core_nr; i++) {
+	for (i = 0; i < env->nr_sibling_cores; i++) {
 		if (str_to_bitmap(sib_core, &t.sib_core[i])) {
 			fprintf(stderr, "topology: can't parse siblings map\n");
 			goto exit;
@@ -777,7 +781,7 @@ int svg_build_topology_map(char *sib_core, int sib_core_nr,
 		sib_core += strlen(sib_core) + 1;
 	}
 
-	for (i = 0; i < sib_thr_nr; i++) {
+	for (i = 0; i < env->nr_sibling_threads; i++) {
 		if (str_to_bitmap(sib_thr, &t.sib_thr[i])) {
 			fprintf(stderr, "topology: can't parse siblings map\n");
 			goto exit;
diff --git a/tools/perf/util/svghelper.h b/tools/perf/util/svghelper.h
index e55338d..81823e8 100644
--- a/tools/perf/util/svghelper.h
+++ b/tools/perf/util/svghelper.h
@@ -4,6 +4,8 @@
 
 #include <linux/types.h>
 
+struct perf_env;
+
 void open_svg(const char *filename, int cpus, int rows, u64 start, u64 end);
 void svg_ubox(int Yslot, u64 start, u64 end, double height, const char *type, int fd, int err, int merges);
 void svg_lbox(int Yslot, u64 start, u64 end, double height, const char *type, int fd, int err, int merges);
@@ -28,7 +30,7 @@ void svg_partial_wakeline(u64 start, int row1, char *desc1, int row2, char *desc
 void svg_interrupt(u64 start, int row, const char *backtrace);
 void svg_text(int Yslot, u64 start, const char *text);
 void svg_close(void);
-int svg_build_topology_map(char *sib_core, int sib_core_nr, char *sib_thr, int sib_thr_nr);
+int svg_build_topology_map(struct perf_env *env);
 
 extern int svg_page_width;
 extern u64 svg_highlight;

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [tip: perf/core] perf session: Replace MAX_NR_CPUS with perf_env::nr_cpus_online
  2019-08-27 21:43 ` [PATCH v4 4/7] perf/util/session: Replace MAX_NR_CPUS with nr_cpus_online Kyle Meyer
@ 2019-09-02  8:16   ` tip-bot2 for Kyle Meyer
  0 siblings, 0 replies; 16+ messages in thread
From: tip-bot2 for Kyle Meyer @ 2019-09-02  8:16 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Kyle Meyer, Jiri Olsa, Alexander Shishkin, Namhyung Kim,
	Peter Zijlstra, Russ Anderson, Arnaldo Carvalho de Melo,
	Ingo Molnar, Borislav Petkov, linux-kernel

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     7df4e36a4785618f0c63f3dc2bacb164780ab0f6
Gitweb:        https://git.kernel.org/tip/7df4e36a4785618f0c63f3dc2bacb164780ab0f6
Author:        Kyle Meyer <meyerk@hpe.com>
AuthorDate:    Tue, 27 Aug 2019 16:43:49 -05:00
Committer:     Arnaldo Carvalho de Melo <acme@redhat.com>
CommitterDate: Thu, 29 Aug 2019 17:38:32 -03:00

perf session: Replace MAX_NR_CPUS with perf_env::nr_cpus_online

nr_cpus, the number of CPUs online during a record session bound by
MAX_NR_CPUS, can be used as a dynamic alternative for MAX_NR_CPUS in
perf_session__cpu_bitmap.

Signed-off-by: Kyle Meyer <kyle.meyer@hpe.com>
Reviewed-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Russ Anderson <russ.anderson@hpe.com>
Link: http://lore.kernel.org/lkml/20190827214352.94272-5-meyerk@stormcage.eag.rdlabs.hpecorp.net
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/session.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c
index 7350b0d..13486bc 100644
--- a/tools/perf/util/session.c
+++ b/tools/perf/util/session.c
@@ -2292,6 +2292,7 @@ int perf_session__cpu_bitmap(struct perf_session *session,
 {
 	int i, err = -1;
 	struct perf_cpu_map *map;
+	int nr_cpus = min(session->header.env.nr_cpus_online, MAX_NR_CPUS);
 
 	for (i = 0; i < PERF_TYPE_MAX; ++i) {
 		struct evsel *evsel;
@@ -2316,7 +2317,7 @@ int perf_session__cpu_bitmap(struct perf_session *session,
 	for (i = 0; i < map->nr; i++) {
 		int cpu = map->map[i];
 
-		if (cpu >= MAX_NR_CPUS) {
+		if (cpu >= nr_cpus) {
 			pr_err("Requested CPU %d too large. "
 			       "Consider raising MAX_NR_CPUS\n", cpu);
 			goto out_delete_map;

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [tip: perf/core] perf stat: Replace MAX_NR_CPUS with cpu__max_cpu()
  2019-08-27 21:43 ` [PATCH v4 3/7] perf/util/stat: Replace MAX_NR_CPUS with cpu__max_cpu Kyle Meyer
@ 2019-09-02  8:16   ` tip-bot2 for Kyle Meyer
  0 siblings, 0 replies; 16+ messages in thread
From: tip-bot2 for Kyle Meyer @ 2019-09-02  8:16 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Kyle Meyer, Jiri Olsa, Alexander Shishkin, Namhyung Kim,
	Peter Zijlstra, Russ Anderson, Arnaldo Carvalho de Melo,
	Ingo Molnar, Borislav Petkov, linux-kernel

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     92b5a1545ad51e8225e691e9a29ba33cc9fe37bc
Gitweb:        https://git.kernel.org/tip/92b5a1545ad51e8225e691e9a29ba33cc9fe37bc
Author:        Kyle Meyer <meyerk@hpe.com>
AuthorDate:    Tue, 27 Aug 2019 16:43:48 -05:00
Committer:     Arnaldo Carvalho de Melo <acme@redhat.com>
CommitterDate: Thu, 29 Aug 2019 17:38:32 -03:00

perf stat: Replace MAX_NR_CPUS with cpu__max_cpu()

The function cpu__max_cpu() returns the possible number of CPUs as
defined in the sysfs and can be used as an alternative for MAX_NR_CPUS
in zero_per_pkg() and check_per_pkg().

Signed-off-by: Kyle Meyer <kyle.meyer@hpe.com>
Reviewed-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Russ Anderson <russ.anderson@hpe.com>
Link: http://lore.kernel.org/lkml/20190827214352.94272-4-meyerk@stormcage.eag.rdlabs.hpecorp.net
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/stat.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
index 66f8808..f6eb6af 100644
--- a/tools/perf/util/stat.c
+++ b/tools/perf/util/stat.c
@@ -210,7 +210,7 @@ void perf_evlist__reset_stats(struct evlist *evlist)
 static void zero_per_pkg(struct evsel *counter)
 {
 	if (counter->per_pkg_mask)
-		memset(counter->per_pkg_mask, 0, MAX_NR_CPUS);
+		memset(counter->per_pkg_mask, 0, cpu__max_cpu());
 }
 
 static int check_per_pkg(struct evsel *counter,
@@ -229,7 +229,7 @@ static int check_per_pkg(struct evsel *counter,
 		return 0;
 
 	if (!mask) {
-		mask = zalloc(MAX_NR_CPUS);
+		mask = zalloc(cpu__max_cpu());
 		if (!mask)
 			return -ENOMEM;
 

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [tip: perf/core] libperf: Warn when exceeding MAX_NR_CPUS in cpumap
  2019-08-27 21:43 ` [PATCH v4 7/7] perf/lib/cpumap: Warn when exceeding MAX_NR_CPUS Kyle Meyer
@ 2019-09-02  8:16   ` tip-bot2 for Kyle Meyer
  0 siblings, 0 replies; 16+ messages in thread
From: tip-bot2 for Kyle Meyer @ 2019-09-02  8:16 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Kyle Meyer, Jiri Olsa, Alexander Shishkin, Namhyung Kim,
	Peter Zijlstra, Russ Anderson, Arnaldo Carvalho de Melo,
	Ingo Molnar, Borislav Petkov, linux-kernel

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     df552793493ff83b2b7289389d29d417b3ef6d6d
Gitweb:        https://git.kernel.org/tip/df552793493ff83b2b7289389d29d417b3ef6d6d
Author:        Kyle Meyer <meyerk@hpe.com>
AuthorDate:    Tue, 27 Aug 2019 16:43:52 -05:00
Committer:     Arnaldo Carvalho de Melo <acme@redhat.com>
CommitterDate: Thu, 29 Aug 2019 17:38:32 -03:00

libperf: Warn when exceeding MAX_NR_CPUS in cpumap

Display a warning when attempting to profile more than MAX_NR_CPU CPUs.
This patch should not change any behavior.

Signed-off-by: Kyle Meyer <kyle.meyer@hpe.com>
Reviewed-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Russ Anderson <russ.anderson@hpe.com>
Link: http://lore.kernel.org/lkml/20190827214352.94272-8-meyerk@stormcage.eag.rdlabs.hpecorp.net
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/lib/cpumap.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/tools/perf/lib/cpumap.c b/tools/perf/lib/cpumap.c
index 2834753..1f0e6f3 100644
--- a/tools/perf/lib/cpumap.c
+++ b/tools/perf/lib/cpumap.c
@@ -100,6 +100,9 @@ struct perf_cpu_map *perf_cpu_map__read(FILE *file)
 		if (prev >= 0) {
 			int new_max = nr_cpus + cpu - prev - 1;
 
+			WARN_ONCE(new_max >= MAX_NR_CPUS, "Perf can support %d CPUs. "
+							  "Consider raising MAX_NR_CPUS\n", MAX_NR_CPUS);
+
 			if (new_max >= max_entries) {
 				max_entries = new_max + MAX_NR_CPUS / 2;
 				tmp = realloc(tmp_cpus, max_entries * sizeof(int));
@@ -192,6 +195,9 @@ struct perf_cpu_map *perf_cpu_map__new(const char *cpu_list)
 			end_cpu = start_cpu;
 		}
 
+		WARN_ONCE(end_cpu >= MAX_NR_CPUS, "Perf can support %d CPUs. "
+						  "Consider raising MAX_NR_CPUS\n", MAX_NR_CPUS);
+
 		for (; start_cpu <= end_cpu; start_cpu++) {
 			/* check for duplicates */
 			for (i = 0; i < nr_cpus; i++)

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [tip: perf/core] perf header: Replace MAX_NR_CPUS with cpu__max_cpu()
  2019-08-27 21:43 ` [PATCH v4 6/7] perf/util/header: Replace MAX_NR_CPUS with cpu__max_cpu Kyle Meyer
@ 2019-09-02  8:16   ` tip-bot2 for Kyle Meyer
  0 siblings, 0 replies; 16+ messages in thread
From: tip-bot2 for Kyle Meyer @ 2019-09-02  8:16 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Kyle Meyer, Jiri Olsa, Alexander Shishkin, Namhyung Kim,
	Peter Zijlstra, Russ Anderson, Arnaldo Carvalho de Melo,
	Ingo Molnar, Borislav Petkov, linux-kernel

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     dc84187f32a3e8eb86bd97f3b10494e1f1fe5e7f
Gitweb:        https://git.kernel.org/tip/dc84187f32a3e8eb86bd97f3b10494e1f1fe5e7f
Author:        Kyle Meyer <meyerk@hpe.com>
AuthorDate:    Tue, 27 Aug 2019 16:43:51 -05:00
Committer:     Arnaldo Carvalho de Melo <acme@redhat.com>
CommitterDate: Thu, 29 Aug 2019 17:38:32 -03:00

perf header: Replace MAX_NR_CPUS with cpu__max_cpu()

The function cpu__max_cpu() returns the possible number of CPUs as
defined in the sysfs and can be used as an alternative for MAX_NR_CPUS
in write_cache.

MAX_CACHES is replaced by cpu__max_cpu() * MAX_CACHE_LVL.

Signed-off-by: Kyle Meyer <kyle.meyer@hpe.com>
Reviewed-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Russ Anderson <russ.anderson@hpe.com>
Link: http://lore.kernel.org/lkml/20190827214352.94272-7-meyerk@stormcage.eag.rdlabs.hpecorp.net
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/header.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 0a842d9..dd2bb08 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1122,16 +1122,17 @@ static int build_caches(struct cpu_cache_level caches[], u32 size, u32 *cntp)
 	return 0;
 }
 
-#define MAX_CACHES (MAX_NR_CPUS * 4)
+#define MAX_CACHE_LVL 4
 
 static int write_cache(struct feat_fd *ff,
 		       struct evlist *evlist __maybe_unused)
 {
-	struct cpu_cache_level caches[MAX_CACHES];
+	u32 max_caches = cpu__max_cpu() * MAX_CACHE_LVL;
+	struct cpu_cache_level caches[max_caches];
 	u32 cnt = 0, i, version = 1;
 	int ret;
 
-	ret = build_caches(caches, MAX_CACHES, &cnt);
+	ret = build_caches(caches, max_caches, &cnt);
 	if (ret)
 		goto out;
 

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [tip: perf/core] perf machine: Replace MAX_NR_CPUS with perf_env::nr_cpus_online
  2019-08-27 21:43 ` [PATCH v4 5/7] perf/util/machine: Replace MAX_NR_CPUS with nr_cpus_online Kyle Meyer
@ 2019-09-02  8:16   ` tip-bot2 for Kyle Meyer
  0 siblings, 0 replies; 16+ messages in thread
From: tip-bot2 for Kyle Meyer @ 2019-09-02  8:16 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Kyle Meyer, Jiri Olsa, Alexander Shishkin, Namhyung Kim,
	Peter Zijlstra, Russ Anderson, Arnaldo Carvalho de Melo,
	Ingo Molnar, Borislav Petkov, linux-kernel

The following commit has been merged into the perf/core branch of tip:

Commit-ID:     8c7274691f0de5fb56f3b9fe9208ce7e515a2d2c
Gitweb:        https://git.kernel.org/tip/8c7274691f0de5fb56f3b9fe9208ce7e515a2d2c
Author:        Kyle Meyer <meyerk@hpe.com>
AuthorDate:    Tue, 27 Aug 2019 16:43:50 -05:00
Committer:     Arnaldo Carvalho de Melo <acme@redhat.com>
CommitterDate: Thu, 29 Aug 2019 17:38:32 -03:00

perf machine: Replace MAX_NR_CPUS with perf_env::nr_cpus_online

nr_cpus, the number of CPUs online during a record session bound by
MAX_NR_CPUS, can be used as a dynamic alternative for MAX_NR_CPUS in
__machine__synthesize_threads and machine__set_current_tid.

Signed-off-by: Kyle Meyer <kyle.meyer@hpe.com>
Reviewed-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Russ Anderson <russ.anderson@hpe.com>
Link: http://lore.kernel.org/lkml/20190827214352.94272-6-meyerk@stormcage.eag.rdlabs.hpecorp.net
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/perf/util/machine.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/tools/perf/util/machine.c b/tools/perf/util/machine.c
index 93483f1..a1542b4 100644
--- a/tools/perf/util/machine.c
+++ b/tools/perf/util/machine.c
@@ -2619,7 +2619,9 @@ int __machine__synthesize_threads(struct machine *machine, struct perf_tool *too
 
 pid_t machine__get_current_tid(struct machine *machine, int cpu)
 {
-	if (cpu < 0 || cpu >= MAX_NR_CPUS || !machine->current_tid)
+	int nr_cpus = min(machine->env->nr_cpus_online, MAX_NR_CPUS);
+
+	if (cpu < 0 || cpu >= nr_cpus || !machine->current_tid)
 		return -1;
 
 	return machine->current_tid[cpu];
@@ -2629,6 +2631,7 @@ int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid,
 			     pid_t tid)
 {
 	struct thread *thread;
+	int nr_cpus = min(machine->env->nr_cpus_online, MAX_NR_CPUS);
 
 	if (cpu < 0)
 		return -EINVAL;
@@ -2636,14 +2639,14 @@ int machine__set_current_tid(struct machine *machine, int cpu, pid_t pid,
 	if (!machine->current_tid) {
 		int i;
 
-		machine->current_tid = calloc(MAX_NR_CPUS, sizeof(pid_t));
+		machine->current_tid = calloc(nr_cpus, sizeof(pid_t));
 		if (!machine->current_tid)
 			return -ENOMEM;
-		for (i = 0; i < MAX_NR_CPUS; i++)
+		for (i = 0; i < nr_cpus; i++)
 			machine->current_tid[i] = -1;
 	}
 
-	if (cpu >= MAX_NR_CPUS) {
+	if (cpu >= nr_cpus) {
 		pr_err("Requested CPU %d too large. ", cpu);
 		pr_err("Consider raising MAX_NR_CPUS\n");
 		return -EINVAL;

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2019-09-02  8:19 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20190827214352.94272-1-meyerk@stormcage.eag.rdlabs.hpecorp.net>
2019-08-27 21:43 ` [PATCH v4 1/7] perf: Refactor svg_build_topology_map Kyle Meyer
2019-08-29  9:11   ` Jiri Olsa
2019-08-29 15:49     ` Arnaldo Carvalho de Melo
2019-09-02  8:16   ` [tip: perf/core] perf timechart: Refactor svg_build_topology_map() tip-bot2 for Kyle Meyer
2019-08-27 21:43 ` [PATCH v4 2/7] perf/util/svghelper: Replace MAX_NR_CPUS with env->nr_cpus_online Kyle Meyer
2019-09-02  8:16   ` [tip: perf/core] perf svghelper: Replace MAX_NR_CPUS with perf_env::nr_cpus_online tip-bot2 for Kyle Meyer
2019-08-27 21:43 ` [PATCH v4 3/7] perf/util/stat: Replace MAX_NR_CPUS with cpu__max_cpu Kyle Meyer
2019-09-02  8:16   ` [tip: perf/core] perf stat: Replace MAX_NR_CPUS with cpu__max_cpu() tip-bot2 for Kyle Meyer
2019-08-27 21:43 ` [PATCH v4 4/7] perf/util/session: Replace MAX_NR_CPUS with nr_cpus_online Kyle Meyer
2019-09-02  8:16   ` [tip: perf/core] perf session: Replace MAX_NR_CPUS with perf_env::nr_cpus_online tip-bot2 for Kyle Meyer
2019-08-27 21:43 ` [PATCH v4 5/7] perf/util/machine: Replace MAX_NR_CPUS with nr_cpus_online Kyle Meyer
2019-09-02  8:16   ` [tip: perf/core] perf machine: Replace MAX_NR_CPUS with perf_env::nr_cpus_online tip-bot2 for Kyle Meyer
2019-08-27 21:43 ` [PATCH v4 6/7] perf/util/header: Replace MAX_NR_CPUS with cpu__max_cpu Kyle Meyer
2019-09-02  8:16   ` [tip: perf/core] perf header: Replace MAX_NR_CPUS with cpu__max_cpu() tip-bot2 for Kyle Meyer
2019-08-27 21:43 ` [PATCH v4 7/7] perf/lib/cpumap: Warn when exceeding MAX_NR_CPUS Kyle Meyer
2019-09-02  8:16   ` [tip: perf/core] libperf: Warn when exceeding MAX_NR_CPUS in cpumap tip-bot2 for Kyle Meyer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).