[PATCH 05/10] perf-record: Share per-cpu buffers

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Peter Zijlstra
Date: Friday, May 21, 2010 - 2:02 am

It seems a waste of space to create a buffer per event, share it per-cpu.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
---
 tools/perf/builtin-record.c |   52 +++++++++++++++++++++++---------------------
 1 file changed, 28 insertions(+), 24 deletions(-)

Index: linux-2.6/tools/perf/builtin-record.c
===================================================================
--- linux-2.6.orig/tools/perf/builtin-record.c
+++ linux-2.6/tools/perf/builtin-record.c
@@ -85,7 +85,7 @@ struct mmap_data {
 	unsigned int		prev;
 };
 
-static struct mmap_data		*mmap_array[MAX_NR_CPUS][MAX_COUNTERS];
+static struct mmap_data		mmap_array[MAX_NR_CPUS];
 
 static unsigned long mmap_read_head(struct mmap_data *md)
 {
@@ -380,18 +380,29 @@ try_again:
 		if (group && group_fd == -1)
 			group_fd = fd[nr_cpu][counter][thread_index];
 
-		event_array[nr_poll].fd = fd[nr_cpu][counter][thread_index];
-		event_array[nr_poll].events = POLLIN;
-		nr_poll++;
-
-		mmap_array[nr_cpu][counter][thread_index].counter = counter;
-		mmap_array[nr_cpu][counter][thread_index].prev = 0;
-		mmap_array[nr_cpu][counter][thread_index].mask = mmap_pages*page_size - 1;
-		mmap_array[nr_cpu][counter][thread_index].base = mmap(NULL, (mmap_pages+1)*page_size,
-			PROT_READ|PROT_WRITE, MAP_SHARED, fd[nr_cpu][counter][thread_index], 0);
-		if (mmap_array[nr_cpu][counter][thread_index].base == MAP_FAILED) {
-			error("failed to mmap with %d (%s)\n", errno, strerror(errno));
-			exit(-1);
+		if (counter || thread_index) {
+			ret = ioctl(fd[nr_cpu][counter][thread_index],
+					PERF_EVENT_IOC_SET_OUTPUT,
+					fd[nr_cpu][0][0]);
+			if (ret) {
+				error("failed to set output: %d (%s)\n", errno,
+						strerror(errno));
+				exit(-1);
+			}
+		} else {
+			mmap_array[nr_cpu].counter = counter;
+			mmap_array[nr_cpu].prev = 0;
+			mmap_array[nr_cpu].mask = mmap_pages*page_size - 1;
+			mmap_array[nr_cpu].base = mmap(NULL, (mmap_pages+1)*page_size,
+				PROT_READ|PROT_WRITE, MAP_SHARED, fd[nr_cpu][counter][thread_index], 0);
+			if (mmap_array[nr_cpu].base == MAP_FAILED) {
+				error("failed to mmap with %d (%s)\n", errno, strerror(errno));
+				exit(-1);
+			}
+
+			event_array[nr_poll].fd = fd[nr_cpu][counter][thread_index];
+			event_array[nr_poll].events = POLLIN;
+			nr_poll++;
 		}
 
 		if (filter != NULL) {
@@ -492,16 +503,11 @@ static struct perf_event_header finished
 
 static void mmap_read_all(void)
 {
-	int i, counter, thread;
+	int i;
 
 	for (i = 0; i < nr_cpu; i++) {
-		for (counter = 0; counter < nr_counters; counter++) {
-			for (thread = 0; thread < thread_num; thread++) {
-				if (mmap_array[i][counter][thread].base)
-					mmap_read(&mmap_array[i][counter][thread]);
-			}
-
-		}
+		if (mmap_array[i].base)
+			mmap_read(&mmap_array[i]);
 	}
 
 	if (perf_header__has_feat(&session->header, HEADER_TRACE_INFO))
@@ -876,9 +882,7 @@ int cmd_record(int argc, const char **ar
 	for (i = 0; i < MAX_NR_CPUS; i++) {
 		for (j = 0; j < MAX_COUNTERS; j++) {
 			fd[i][j] = malloc(sizeof(int)*thread_num);
-			mmap_array[i][j] = zalloc(
-				sizeof(struct mmap_data)*thread_num);
-			if (!fd[i][j] || !mmap_array[i][j])
+			if (!fd[i][j])
 				return -ENOMEM;
 		}
 	}


--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 00/10] perf tracepoint and output optimizations, Peter Zijlstra, (Fri May 21, 2:02 am)
[PATCH 05/10] perf-record: Share per-cpu buffers, Peter Zijlstra, (Fri May 21, 2:02 am)
[PATCH 06/10] perf: Fix wakeup storm for RO mmap()s, Peter Zijlstra, (Fri May 21, 2:02 am)
[PATCH 08/10] perf: Optimize the !vmalloc backed buffer, Peter Zijlstra, (Fri May 21, 2:02 am)
Re: [PATCH 02/10] perf, trace: Use per-tracepoint-per-cpu ..., Frederic Weisbecker, (Fri May 21, 2:40 am)
Re: [PATCH 05/10] perf-record: Share per-cpu buffers, Frederic Weisbecker, (Fri May 21, 2:44 am)
Re: [PATCH 05/10] perf-record: Share per-cpu buffers, Peter Zijlstra, (Fri May 21, 3:03 am)
Re: [PATCH 02/10] perf, trace: Use per-tracepoint-per-cpu ..., Frederic Weisbecker, (Fri May 21, 3:13 am)
Re: [PATCH 02/10] perf, trace: Use per-tracepoint-per-cpu ..., Frederic Weisbecker, (Fri May 21, 3:19 am)
Re: [PATCH 02/10] perf, trace: Use per-tracepoint-per-cpu ..., Frederic Weisbecker, (Fri May 21, 3:21 am)
Re: [PATCH 02/10] perf, trace: Use per-tracepoint-per-cpu ..., Frederic Weisbecker, (Fri May 21, 3:38 am)
[PATCH 02b/10] perf, trace: Fix probe unregister race, Peter Zijlstra, (Fri May 21, 3:41 am)
Re: [PATCH 02b/10] perf, trace: Fix probe unregister race, Frederic Weisbecker, (Fri May 21, 3:43 am)
[tip:perf/core] perf, trace: Optimize tracepoints by using ..., tip-bot for Peter Zi ..., (Fri May 21, 4:28 am)
[tip:perf/core] perf-record: Share per-cpu buffers, tip-bot for Peter Zi ..., (Fri May 21, 4:29 am)
[tip:perf/core] perf: Fix wakeup storm for RO mmap()s, tip-bot for Peter Zi ..., (Fri May 21, 4:29 am)
[tip:perf/core] perf: Optimize the !vmalloc backed buffer, tip-bot for Peter Zi ..., (Fri May 21, 4:29 am)
Re: [PATCH 01/10] perf, trace: Remove IRQ-disable from per ..., Frank Ch. Eigler, (Fri May 21, 10:43 am)
Re: [PATCH 01/10] perf, trace: Remove IRQ-disable from per ..., Frank Ch. Eigler, (Fri May 21, 11:07 am)
Re: [PATCH 01/10] perf, trace: Remove IRQ-disable from per ..., Frederic Weisbecker, (Mon May 24, 4:31 am)
[PATCH 01a/10] perf, trace: Fix !x86 build issue, Peter Zijlstra, (Tue May 25, 12:30 am)
[tip:perf/core] perf, trace: Fix IRQ-disable removal from ..., tip-bot for Peter Zi ..., (Tue May 25, 1:06 am)
[tip:perf/core] perf, trace: Fix !x86 build bug, tip-bot for Peter Zi ..., (Tue May 25, 2:30 am)
[tip:perf/urgent] perf_events, trace: Fix probe unregister ..., tip-bot for Peter Zi ..., (Mon May 31, 12:19 am)
[tip:perf/urgent] perf_events, trace: Fix perf_trace_destr ..., tip-bot for Peter Zi ..., (Mon May 31, 12:20 am)