summaryrefslogtreecommitdiff
path: root/tools/perf/lib
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2019-08-06 13:21:53 +0200
committerArnaldo Carvalho de Melo <acme@redhat.com>2019-09-25 09:51:49 -0300
commit31f67fc462a9e5df3b900924c2bf649c7bc63af8 (patch)
tree87cc835c17edfd51fc8ce898528d159587f40dc2 /tools/perf/lib
parent379dd98c3d77de920f09f1933592982d200e076a (diff)
libperf: Add perf_evlist__alloc_pollfd() function
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>
Diffstat (limited to 'tools/perf/lib')
-rw-r--r--tools/perf/lib/evlist.c22
-rw-r--r--tools/perf/lib/include/internal/evlist.h2
2 files changed, 24 insertions, 0 deletions
diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index 3a16dd0c044f..3c3b97f40be0 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -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;
+}
diff --git a/tools/perf/lib/include/internal/evlist.h b/tools/perf/lib/include/internal/evlist.h
index 7d64185cfabd..88c0dfaf0ddc 100644
--- a/tools/perf/lib/include/internal/evlist.h
+++ b/tools/perf/lib/include/internal/evlist.h
@@ -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