libperf: Add perf_evlist__alloc_pollfd() function
authorJiri Olsa <jolsa@kernel.org>
Tue, 6 Aug 2019 11:21:53 +0000 (13:21 +0200)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 25 Sep 2019 12:51:49 +0000 (09:51 -0300)
Move perf_evlist__alloc_pollfd() from tools/perf to libperf, it will be
used in the following patches.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lore.kernel.org/lkml/20190913132355.21634-37-jolsa@kernel.org
[ Added api/fd/array.h include to the lib/evlist.c file ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/lib/evlist.c
tools/perf/lib/include/internal/evlist.h
tools/perf/util/evlist.c
tools/perf/util/evlist.h

index 3a16dd0..3c3b97f 100644 (file)
@@ -14,6 +14,7 @@
 #include <unistd.h>
 #include <perf/cpumap.h>
 #include <perf/threadmap.h>
+#include <api/fd/array.h>
 
 void perf_evlist__init(struct perf_evlist *evlist)
 {
@@ -238,3 +239,24 @@ add:
        perf_evlist__id_add(evlist, evsel, cpu, thread, id);
        return 0;
 }
+
+int perf_evlist__alloc_pollfd(struct perf_evlist *evlist)
+{
+       int nr_cpus = perf_cpu_map__nr(evlist->cpus);
+       int nr_threads = perf_thread_map__nr(evlist->threads);
+       int nfds = 0;
+       struct perf_evsel *evsel;
+
+       perf_evlist__for_each_entry(evlist, evsel) {
+               if (evsel->system_wide)
+                       nfds += nr_cpus;
+               else
+                       nfds += nr_cpus * nr_threads;
+       }
+
+       if (fdarray__available_entries(&evlist->pollfd) < nfds &&
+           fdarray__grow(&evlist->pollfd, nfds) < 0)
+               return -ENOMEM;
+
+       return 0;
+}
index 7d64185..88c0dfa 100644 (file)
@@ -24,6 +24,8 @@ struct perf_evlist {
        struct hlist_head        heads[PERF_EVLIST__HLIST_SIZE];
 };
 
+int perf_evlist__alloc_pollfd(struct perf_evlist *evlist);
+
 /**
  * __perf_evlist__for_each_entry - iterate thru all the evsels
  * @list: list_head instance to iterate
index 6069fb5..c47f23e 100644 (file)
@@ -398,27 +398,6 @@ int perf_evlist__enable_event_idx(struct evlist *evlist,
                return perf_evlist__enable_event_thread(evlist, evsel, idx);
 }
 
-int perf_evlist__alloc_pollfd(struct evlist *evlist)
-{
-       int nr_cpus = perf_cpu_map__nr(evlist->core.cpus);
-       int nr_threads = perf_thread_map__nr(evlist->core.threads);
-       int nfds = 0;
-       struct evsel *evsel;
-
-       evlist__for_each_entry(evlist, evsel) {
-               if (evsel->core.system_wide)
-                       nfds += nr_cpus;
-               else
-                       nfds += nr_cpus * nr_threads;
-       }
-
-       if (fdarray__available_entries(&evlist->core.pollfd) < nfds &&
-           fdarray__grow(&evlist->core.pollfd, nfds) < 0)
-               return -ENOMEM;
-
-       return 0;
-}
-
 static int __perf_evlist__add_pollfd(struct evlist *evlist, int fd,
                                     struct mmap *map, short revent)
 {
@@ -944,7 +923,7 @@ int evlist__mmap_ex(struct evlist *evlist, unsigned int pages,
        if (!evlist->mmap)
                return -ENOMEM;
 
-       if (evlist->core.pollfd.entries == NULL && perf_evlist__alloc_pollfd(evlist) < 0)
+       if (evlist->core.pollfd.entries == NULL && perf_evlist__alloc_pollfd(&evlist->core) < 0)
                return -ENOMEM;
 
        evlist->core.mmap_len = evlist__mmap_size(pages);
index 80b3361..bebbaa9 100644 (file)
@@ -142,7 +142,6 @@ perf_evlist__find_tracepoint_by_name(struct evlist *evlist,
                                     const char *name);
 
 int perf_evlist__add_pollfd(struct evlist *evlist, int fd);
-int perf_evlist__alloc_pollfd(struct evlist *evlist);
 int perf_evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask);
 
 int perf_evlist__poll(struct evlist *evlist, int timeout);