aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/perf/builtin-record.c20
-rw-r--r--tools/perf/builtin-top.c26
-rw-r--r--tools/perf/util/evlist.c9
-rw-r--r--tools/perf/util/evlist.h6
4 files changed, 33 insertions, 28 deletions
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 252ace873d32..1614d89b4765 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -72,9 +72,6 @@ static struct perf_evlist *evsel_list;
72static long samples = 0; 72static long samples = 0;
73static u64 bytes_written = 0; 73static u64 bytes_written = 0;
74 74
75static struct pollfd *event_array;
76
77static int nr_poll = 0;
78static int nr_cpu = 0; 75static int nr_cpu = 0;
79 76
80static int file_new = 1; 77static int file_new = 1;
@@ -432,9 +429,9 @@ try_again:
432 exit(-1); 429 exit(-1);
433 } 430 }
434 431
435 event_array[nr_poll].fd = FD(evsel, nr_cpu, thread_index); 432 evlist->pollfd[evlist->nr_fds].fd = FD(evsel, nr_cpu, thread_index);
436 event_array[nr_poll].events = POLLIN; 433 evlist->pollfd[evlist->nr_fds].events = POLLIN;
437 nr_poll++; 434 evlist->nr_fds++;
438 } 435 }
439 436
440 if (filter != NULL) { 437 if (filter != NULL) {
@@ -793,7 +790,7 @@ static int __cmd_record(int argc, const char **argv)
793 if (hits == samples) { 790 if (hits == samples) {
794 if (done) 791 if (done)
795 break; 792 break;
796 err = poll(event_array, nr_poll, -1); 793 err = poll(evsel_list->pollfd, evsel_list->nr_fds, -1);
797 waking++; 794 waking++;
798 } 795 }
799 796
@@ -948,9 +945,8 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)
948 if (perf_header__push_event(pos->attr.config, event_name(pos))) 945 if (perf_header__push_event(pos->attr.config, event_name(pos)))
949 goto out_free_fd; 946 goto out_free_fd;
950 } 947 }
951 event_array = malloc((sizeof(struct pollfd) * MAX_NR_CPUS * 948
952 MAX_COUNTERS * threads->nr)); 949 if (perf_evlist__alloc_pollfd(evsel_list, cpus->nr, threads->nr) < 0)
953 if (!event_array)
954 goto out_free_fd; 950 goto out_free_fd;
955 951
956 if (user_interval != ULLONG_MAX) 952 if (user_interval != ULLONG_MAX)
@@ -968,13 +964,11 @@ int cmd_record(int argc, const char **argv, const char *prefix __used)
968 } else { 964 } else {
969 fprintf(stderr, "frequency and count are zero, aborting\n"); 965 fprintf(stderr, "frequency and count are zero, aborting\n");
970 err = -EINVAL; 966 err = -EINVAL;
971 goto out_free_event_array; 967 goto out_free_fd;
972 } 968 }
973 969
974 err = __cmd_record(argc, argv); 970 err = __cmd_record(argc, argv);
975 971
976out_free_event_array:
977 free(event_array);
978out_free_fd: 972out_free_fd:
979 thread_map__delete(threads); 973 thread_map__delete(threads);
980 threads = NULL; 974 threads = NULL;
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 216b62ed4b89..1bc465215fc6 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -1193,8 +1193,6 @@ static void perf_session__mmap_read_counter(struct perf_session *self,
1193 md->prev = old; 1193 md->prev = old;
1194} 1194}
1195 1195
1196static struct pollfd *event_array;
1197
1198static void perf_session__mmap_read(struct perf_session *self) 1196static void perf_session__mmap_read(struct perf_session *self)
1199{ 1197{
1200 struct perf_evsel *counter; 1198 struct perf_evsel *counter;
@@ -1212,10 +1210,10 @@ static void perf_session__mmap_read(struct perf_session *self)
1212 } 1210 }
1213} 1211}
1214 1212
1215int nr_poll;
1216int group_fd; 1213int group_fd;
1217 1214
1218static void start_counter(int i, struct perf_evsel *evsel) 1215static void start_counter(int i, struct perf_evlist *evlist,
1216 struct perf_evsel *evsel)
1219{ 1217{
1220 struct xyarray *mmap_array = evsel->priv; 1218 struct xyarray *mmap_array = evsel->priv;
1221 struct mmap_data *mm; 1219 struct mmap_data *mm;
@@ -1281,9 +1279,9 @@ try_again:
1281 if (group && group_fd == -1) 1279 if (group && group_fd == -1)
1282 group_fd = FD(evsel, i, thread_index); 1280 group_fd = FD(evsel, i, thread_index);
1283 1281
1284 event_array[nr_poll].fd = FD(evsel, i, thread_index); 1282 evlist->pollfd[evlist->nr_fds].fd = FD(evsel, i, thread_index);
1285 event_array[nr_poll].events = POLLIN; 1283 evlist->pollfd[evlist->nr_fds].events = POLLIN;
1286 nr_poll++; 1284 evlist->nr_fds++;
1287 1285
1288 mm = xyarray__entry(mmap_array, i, thread_index); 1286 mm = xyarray__entry(mmap_array, i, thread_index);
1289 mm->prev = 0; 1287 mm->prev = 0;
@@ -1316,11 +1314,11 @@ static int __cmd_top(void)
1316 for (i = 0; i < cpus->nr; i++) { 1314 for (i = 0; i < cpus->nr; i++) {
1317 group_fd = -1; 1315 group_fd = -1;
1318 list_for_each_entry(counter, &evsel_list->entries, node) 1316 list_for_each_entry(counter, &evsel_list->entries, node)
1319 start_counter(i, counter); 1317 start_counter(i, evsel_list, counter);
1320 } 1318 }
1321 1319
1322 /* Wait for a minimal set of events before starting the snapshot */ 1320 /* Wait for a minimal set of events before starting the snapshot */
1323 poll(&event_array[0], nr_poll, 100); 1321 poll(evsel_list->pollfd, evsel_list->nr_fds, 100);
1324 1322
1325 perf_session__mmap_read(session); 1323 perf_session__mmap_read(session);
1326 1324
@@ -1345,7 +1343,7 @@ static int __cmd_top(void)
1345 perf_session__mmap_read(session); 1343 perf_session__mmap_read(session);
1346 1344
1347 if (hits == samples) 1345 if (hits == samples)
1348 ret = poll(event_array, nr_poll, 100); 1346 ret = poll(evsel_list->pollfd, evsel_list->nr_fds, 100);
1349 } 1347 }
1350 1348
1351 return 0; 1349 return 0;
@@ -1426,11 +1424,6 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
1426 usage_with_options(top_usage, options); 1424 usage_with_options(top_usage, options);
1427 } 1425 }
1428 1426
1429 event_array = malloc((sizeof(struct pollfd) *
1430 MAX_NR_CPUS * MAX_COUNTERS * threads->nr));
1431 if (!event_array)
1432 return -ENOMEM;
1433
1434 /* CPU and PID are mutually exclusive */ 1427 /* CPU and PID are mutually exclusive */
1435 if (target_tid > 0 && cpu_list) { 1428 if (target_tid > 0 && cpu_list) {
1436 printf("WARNING: PID switch overriding CPU\n"); 1429 printf("WARNING: PID switch overriding CPU\n");
@@ -1480,6 +1473,9 @@ int cmd_top(int argc, const char **argv, const char *prefix __used)
1480 pos->attr.sample_period = default_interval; 1473 pos->attr.sample_period = default_interval;
1481 } 1474 }
1482 1475
1476 if (perf_evlist__alloc_pollfd(evsel_list, cpus->nr, threads->nr) < 0)
1477 goto out_free_fd;
1478
1483 sym_evsel = list_entry(evsel_list->entries.next, struct perf_evsel, node); 1479 sym_evsel = list_entry(evsel_list->entries.next, struct perf_evsel, node);
1484 1480
1485 symbol_conf.priv_size = (sizeof(struct sym_entry) + 1481 symbol_conf.priv_size = (sizeof(struct sym_entry) +
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 7b4faec23737..2abf949259d0 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -1,3 +1,4 @@
1#include <poll.h>
1#include "evlist.h" 2#include "evlist.h"
2#include "evsel.h" 3#include "evsel.h"
3#include "util.h" 4#include "util.h"
@@ -28,6 +29,7 @@ static void perf_evlist__purge(struct perf_evlist *evlist)
28void perf_evlist__delete(struct perf_evlist *evlist) 29void perf_evlist__delete(struct perf_evlist *evlist)
29{ 30{
30 perf_evlist__purge(evlist); 31 perf_evlist__purge(evlist);
32 free(evlist->pollfd);
31 free(evlist); 33 free(evlist);
32} 34}
33 35
@@ -51,3 +53,10 @@ int perf_evlist__add_default(struct perf_evlist *evlist)
51 perf_evlist__add(evlist, evsel); 53 perf_evlist__add(evlist, evsel);
52 return 0; 54 return 0;
53} 55}
56
57int perf_evlist__alloc_pollfd(struct perf_evlist *evlist, int ncpus, int nthreads)
58{
59 int nfds = ncpus * nthreads * evlist->nr_entries;
60 evlist->pollfd = malloc(sizeof(struct pollfd) * nfds);
61 return evlist->pollfd != NULL ? 0 : -ENOMEM;
62}
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 48db91a8abf3..a7d7e122e3c6 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -3,9 +3,13 @@
3 3
4#include <linux/list.h> 4#include <linux/list.h>
5 5
6struct pollfd;
7
6struct perf_evlist { 8struct perf_evlist {
7 struct list_head entries; 9 struct list_head entries;
8 int nr_entries; 10 int nr_entries;
11 int nr_fds;
12 struct pollfd *pollfd;
9}; 13};
10 14
11struct perf_evsel; 15struct perf_evsel;
@@ -16,4 +20,6 @@ void perf_evlist__delete(struct perf_evlist *evlist);
16void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry); 20void perf_evlist__add(struct perf_evlist *evlist, struct perf_evsel *entry);
17int perf_evlist__add_default(struct perf_evlist *evlist); 21int perf_evlist__add_default(struct perf_evlist *evlist);
18 22
23int perf_evlist__alloc_pollfd(struct perf_evlist *evlist, int ncpus, int nthreads);
24
19#endif /* __PERF_EVLIST_H */ 25#endif /* __PERF_EVLIST_H */