diff options
-rw-r--r-- | tools/perf/builtin-record.c | 52 |
1 files changed, 28 insertions, 24 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index 94e210f86077..9bc89050e6f8 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c | |||
@@ -82,7 +82,7 @@ struct mmap_data { | |||
82 | unsigned int prev; | 82 | unsigned int prev; |
83 | }; | 83 | }; |
84 | 84 | ||
85 | static struct mmap_data *mmap_array[MAX_NR_CPUS][MAX_COUNTERS]; | 85 | static struct mmap_data mmap_array[MAX_NR_CPUS]; |
86 | 86 | ||
87 | static unsigned long mmap_read_head(struct mmap_data *md) | 87 | static unsigned long mmap_read_head(struct mmap_data *md) |
88 | { | 88 | { |
@@ -365,18 +365,29 @@ try_again: | |||
365 | if (group && group_fd == -1) | 365 | if (group && group_fd == -1) |
366 | group_fd = fd[nr_cpu][counter][thread_index]; | 366 | group_fd = fd[nr_cpu][counter][thread_index]; |
367 | 367 | ||
368 | event_array[nr_poll].fd = fd[nr_cpu][counter][thread_index]; | 368 | if (counter || thread_index) { |
369 | event_array[nr_poll].events = POLLIN; | 369 | ret = ioctl(fd[nr_cpu][counter][thread_index], |
370 | nr_poll++; | 370 | PERF_EVENT_IOC_SET_OUTPUT, |
371 | 371 | fd[nr_cpu][0][0]); | |
372 | mmap_array[nr_cpu][counter][thread_index].counter = counter; | 372 | if (ret) { |
373 | mmap_array[nr_cpu][counter][thread_index].prev = 0; | 373 | error("failed to set output: %d (%s)\n", errno, |
374 | mmap_array[nr_cpu][counter][thread_index].mask = mmap_pages*page_size - 1; | 374 | strerror(errno)); |
375 | mmap_array[nr_cpu][counter][thread_index].base = mmap(NULL, (mmap_pages+1)*page_size, | 375 | exit(-1); |
376 | PROT_READ|PROT_WRITE, MAP_SHARED, fd[nr_cpu][counter][thread_index], 0); | 376 | } |
377 | if (mmap_array[nr_cpu][counter][thread_index].base == MAP_FAILED) { | 377 | } else { |
378 | error("failed to mmap with %d (%s)\n", errno, strerror(errno)); | 378 | mmap_array[nr_cpu].counter = counter; |
379 | exit(-1); | 379 | mmap_array[nr_cpu].prev = 0; |
380 | mmap_array[nr_cpu].mask = mmap_pages*page_size - 1; | ||
381 | mmap_array[nr_cpu].base = mmap(NULL, (mmap_pages+1)*page_size, | ||
382 | PROT_READ|PROT_WRITE, MAP_SHARED, fd[nr_cpu][counter][thread_index], 0); | ||
383 | if (mmap_array[nr_cpu].base == MAP_FAILED) { | ||
384 | error("failed to mmap with %d (%s)\n", errno, strerror(errno)); | ||
385 | exit(-1); | ||
386 | } | ||
387 | |||
388 | event_array[nr_poll].fd = fd[nr_cpu][counter][thread_index]; | ||
389 | event_array[nr_poll].events = POLLIN; | ||
390 | nr_poll++; | ||
380 | } | 391 | } |
381 | 392 | ||
382 | if (filter != NULL) { | 393 | if (filter != NULL) { |
@@ -477,16 +488,11 @@ static struct perf_event_header finished_round_event = { | |||
477 | 488 | ||
478 | static void mmap_read_all(void) | 489 | static void mmap_read_all(void) |
479 | { | 490 | { |
480 | int i, counter, thread; | 491 | int i; |
481 | 492 | ||
482 | for (i = 0; i < nr_cpu; i++) { | 493 | for (i = 0; i < nr_cpu; i++) { |
483 | for (counter = 0; counter < nr_counters; counter++) { | 494 | if (mmap_array[i].base) |
484 | for (thread = 0; thread < thread_num; thread++) { | 495 | mmap_read(&mmap_array[i]); |
485 | if (mmap_array[i][counter][thread].base) | ||
486 | mmap_read(&mmap_array[i][counter][thread]); | ||
487 | } | ||
488 | |||
489 | } | ||
490 | } | 496 | } |
491 | 497 | ||
492 | if (perf_header__has_feat(&session->header, HEADER_TRACE_INFO)) | 498 | 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 | for (i = 0; i < MAX_NR_CPUS; i++) { | 867 | for (i = 0; i < MAX_NR_CPUS; i++) { |
862 | for (j = 0; j < MAX_COUNTERS; j++) { | 868 | for (j = 0; j < MAX_COUNTERS; j++) { |
863 | fd[i][j] = malloc(sizeof(int)*thread_num); | 869 | fd[i][j] = malloc(sizeof(int)*thread_num); |
864 | mmap_array[i][j] = zalloc( | 870 | if (!fd[i][j]) |
865 | sizeof(struct mmap_data)*thread_num); | ||
866 | if (!fd[i][j] || !mmap_array[i][j]) | ||
867 | return -ENOMEM; | 871 | return -ENOMEM; |
868 | } | 872 | } |
869 | } | 873 | } |