Commit 0e2e63dd authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Ingo Molnar

perf-record: Share per-cpu buffers

It seems a waste of space to create a buffer per
event, share it per-cpu.
Signed-off-by: default avatarPeter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <20100521090710.634824884@chello.nl>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 57adc51d
...@@ -82,7 +82,7 @@ struct mmap_data { ...@@ -82,7 +82,7 @@ struct mmap_data {
unsigned int prev; 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) static unsigned long mmap_read_head(struct mmap_data *md)
{ {
...@@ -365,18 +365,29 @@ static void create_counter(int counter, int cpu) ...@@ -365,18 +365,29 @@ static void create_counter(int counter, int cpu)
if (group && group_fd == -1) if (group && group_fd == -1)
group_fd = fd[nr_cpu][counter][thread_index]; group_fd = fd[nr_cpu][counter][thread_index];
event_array[nr_poll].fd = fd[nr_cpu][counter][thread_index]; if (counter || thread_index) {
event_array[nr_poll].events = POLLIN; ret = ioctl(fd[nr_cpu][counter][thread_index],
nr_poll++; PERF_EVENT_IOC_SET_OUTPUT,
fd[nr_cpu][0][0]);
mmap_array[nr_cpu][counter][thread_index].counter = counter; if (ret) {
mmap_array[nr_cpu][counter][thread_index].prev = 0; error("failed to set output: %d (%s)\n", errno,
mmap_array[nr_cpu][counter][thread_index].mask = mmap_pages*page_size - 1; strerror(errno));
mmap_array[nr_cpu][counter][thread_index].base = mmap(NULL, (mmap_pages+1)*page_size, exit(-1);
PROT_READ|PROT_WRITE, MAP_SHARED, fd[nr_cpu][counter][thread_index], 0); }
if (mmap_array[nr_cpu][counter][thread_index].base == MAP_FAILED) { } else {
error("failed to mmap with %d (%s)\n", errno, strerror(errno)); mmap_array[nr_cpu].counter = counter;
exit(-1); 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) { if (filter != NULL) {
...@@ -477,16 +488,11 @@ static struct perf_event_header finished_round_event = { ...@@ -477,16 +488,11 @@ static struct perf_event_header finished_round_event = {
static void mmap_read_all(void) static void mmap_read_all(void)
{ {
int i, counter, thread; int i;
for (i = 0; i < nr_cpu; i++) { for (i = 0; i < nr_cpu; i++) {
for (counter = 0; counter < nr_counters; counter++) { if (mmap_array[i].base)
for (thread = 0; thread < thread_num; thread++) { mmap_read(&mmap_array[i]);
if (mmap_array[i][counter][thread].base)
mmap_read(&mmap_array[i][counter][thread]);
}
}
} }
if (perf_header__has_feat(&session->header, HEADER_TRACE_INFO)) if (perf_header__has_feat(&session->header, HEADER_TRACE_INFO))
...@@ -861,9 +867,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used) ...@@ -861,9 +867,7 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)
for (i = 0; i < MAX_NR_CPUS; i++) { for (i = 0; i < MAX_NR_CPUS; i++) {
for (j = 0; j < MAX_COUNTERS; j++) { for (j = 0; j < MAX_COUNTERS; j++) {
fd[i][j] = malloc(sizeof(int)*thread_num); fd[i][j] = malloc(sizeof(int)*thread_num);
mmap_array[i][j] = zalloc( if (!fd[i][j])
sizeof(struct mmap_data)*thread_num);
if (!fd[i][j] || !mmap_array[i][j])
return -ENOMEM; return -ENOMEM;
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment