Re: [PATCH] perf: limit memory allocation to number cpus online

Previous thread: Re: [PATCH] drivers:staging: sources for ST core by Pavan Savoy on Tuesday, March 30, 2010 - 3:50 pm. (2 messages)

Next thread: KVM warning about uncertified CPU for SMP for AMD model 2, stepping 3 by Jiri Kosina on Tuesday, March 30, 2010 - 4:03 pm. (12 messages)
From: Tony Jones
Date: Tuesday, March 30, 2010 - 3:08 pm

Subject: perf: limit memory allocation to number cpus online
From: Tony Jones <tonyj@suse.de>
Date: Tue, 30 Mar 2010 12:18:08 -0700

Limit the dynamic allocation of fd, event_array and mmap_array to #cpus online 
rather than MAX_NR_CPUS.

Cc: Zhang Yanmin <yanmin_zhang@linux.intel.com>
Signed-off-by: Tony Jones <tonyj@suse.de>
---
 tools/perf/builtin-record.c |   10 +++++++---
 tools/perf/builtin-stat.c   |    4 ++--
 tools/perf/builtin-top.c    |   14 +++++++-------
 3 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 60ecdd3..25b5536 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -560,7 +560,6 @@ static int __cmd_record(int argc, const char **argv)
 	if ((!system_wide && !inherit) || profile_cpu != -1) {
 		open_counters(profile_cpu);
 	} else {
-		nr_cpus = read_cpu_map();
 		for (i = 0; i < nr_cpus; i++)
 			open_counters(cpumap[i]);
 	}
@@ -748,7 +747,12 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)
 		thread_num = 1;
 	}
 
-	for (i = 0; i < MAX_NR_CPUS; i++) {
+	if (system_wide && profile_cpu == -1)
+		nr_cpus = read_cpu_map();
+	else
+		nr_cpus = 1;
+
+	for (i = 0; i < nr_cpus; i++) {
 		for (j = 0; j < MAX_COUNTERS; j++) {
 			fd[i][j] = malloc(sizeof(int)*thread_num);
 			mmap_array[i][j] = zalloc(
@@ -758,7 +762,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)
 		}
 	}
 	event_array = malloc(
-		sizeof(struct pollfd)*MAX_NR_CPUS*MAX_COUNTERS*thread_num);
+		sizeof(struct pollfd)*nr_cpus*MAX_COUNTERS*thread_num);
 	if (!event_array)
 		return -ENOMEM;
 
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 1036ca7..d9b672e 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -540,7 +540,7 @@ static const struct option options[] = {
 int cmd_stat(int argc, const char **argv, const char *prefix __used)
 {
 	int status;
-	int i,j;
+	unsigned int ...
From: Zhang, Yanmin
Date: Sunday, April 25, 2010 - 11:51 pm

Acked. Sorry for replying late. There will be a much more valuable patch if it fixes
the cpu hotplug issue. For example, if my machine starts 16 cpu and I hot unplug
some of them by software method (i.e. echo 0 >/sys/devices/system/cpu/cpuXXX/online)
after kernel boots, perf will fail when collecting a system-wide statistics. That's


--

Previous thread: Re: [PATCH] drivers:staging: sources for ST core by Pavan Savoy on Tuesday, March 30, 2010 - 3:50 pm. (2 messages)

Next thread: KVM warning about uncertified CPU for SMP for AMD model 2, stepping 3 by Jiri Kosina on Tuesday, March 30, 2010 - 4:03 pm. (12 messages)