Commit 80ab2987 authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo

libperf: Add perf_evlist__poll() function

Move perf_evlist__poll() from tools/perf to libperf, it will be used in
the following patches.

And rename the existing perf's function to evlist__poll().
Signed-off-by: default avatarJiri 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-39-jolsa@kernel.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent f4009e7b
...@@ -1615,7 +1615,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv) ...@@ -1615,7 +1615,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
if (hits == rec->samples) { if (hits == rec->samples) {
if (done || draining) if (done || draining)
break; break;
err = perf_evlist__poll(rec->evlist, -1); err = evlist__poll(rec->evlist, -1);
/* /*
* Propagate error, only if there's any. Ignore positive * Propagate error, only if there's any. Ignore positive
* number of returned events and interrupt error. * number of returned events and interrupt error.
......
...@@ -1307,7 +1307,7 @@ static int __cmd_top(struct perf_top *top) ...@@ -1307,7 +1307,7 @@ static int __cmd_top(struct perf_top *top)
} }
/* Wait for a minimal set of events before starting the snapshot */ /* Wait for a minimal set of events before starting the snapshot */
perf_evlist__poll(top->evlist, 100); evlist__poll(top->evlist, 100);
perf_top__mmap_read(top); perf_top__mmap_read(top);
...@@ -1317,7 +1317,7 @@ static int __cmd_top(struct perf_top *top) ...@@ -1317,7 +1317,7 @@ static int __cmd_top(struct perf_top *top)
perf_top__mmap_read(top); perf_top__mmap_read(top);
if (opts->overwrite || (hits == top->samples)) if (opts->overwrite || (hits == top->samples))
ret = perf_evlist__poll(top->evlist, 100); ret = evlist__poll(top->evlist, 100);
if (resize) { if (resize) {
perf_top__resize(top); perf_top__resize(top);
......
...@@ -3474,7 +3474,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv) ...@@ -3474,7 +3474,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
if (trace->nr_events == before) { if (trace->nr_events == before) {
int timeout = done ? 100 : -1; int timeout = done ? 100 : -1;
if (!draining && perf_evlist__poll(evlist, timeout) > 0) { if (!draining && evlist__poll(evlist, timeout) > 0) {
if (evlist__filter_pollfd(evlist, POLLERR | POLLHUP | POLLNVAL) == 0) if (evlist__filter_pollfd(evlist, POLLERR | POLLHUP | POLLNVAL) == 0)
draining = true; draining = true;
......
...@@ -276,3 +276,8 @@ int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, ...@@ -276,3 +276,8 @@ int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd,
return pos; return pos;
} }
int perf_evlist__poll(struct perf_evlist *evlist, int timeout)
{
return fdarray__poll(&evlist->pollfd, timeout);
}
...@@ -31,5 +31,6 @@ LIBPERF_API void perf_evlist__disable(struct perf_evlist *evlist); ...@@ -31,5 +31,6 @@ LIBPERF_API void perf_evlist__disable(struct perf_evlist *evlist);
LIBPERF_API void perf_evlist__set_maps(struct perf_evlist *evlist, LIBPERF_API void perf_evlist__set_maps(struct perf_evlist *evlist,
struct perf_cpu_map *cpus, struct perf_cpu_map *cpus,
struct perf_thread_map *threads); struct perf_thread_map *threads);
LIBPERF_API int perf_evlist__poll(struct perf_evlist *evlist, int timeout);
#endif /* __LIBPERF_EVLIST_H */ #endif /* __LIBPERF_EVLIST_H */
...@@ -39,6 +39,7 @@ LIBPERF_0.0.1 { ...@@ -39,6 +39,7 @@ LIBPERF_0.0.1 {
perf_evlist__remove; perf_evlist__remove;
perf_evlist__next; perf_evlist__next;
perf_evlist__set_maps; perf_evlist__set_maps;
perf_evlist__poll;
local: local:
*; *;
}; };
...@@ -127,7 +127,7 @@ int test__syscall_openat_tp_fields(struct test *test __maybe_unused, int subtest ...@@ -127,7 +127,7 @@ int test__syscall_openat_tp_fields(struct test *test __maybe_unused, int subtest
} }
if (nr_events == before) if (nr_events == before)
perf_evlist__poll(evlist, 10); evlist__poll(evlist, 10);
if (++nr_polls > 5) { if (++nr_polls > 5) {
pr_debug("%s: no events!\n", __func__); pr_debug("%s: no events!\n", __func__);
......
...@@ -287,7 +287,7 @@ int test__PERF_RECORD(struct test *test __maybe_unused, int subtest __maybe_unus ...@@ -287,7 +287,7 @@ int test__PERF_RECORD(struct test *test __maybe_unused, int subtest __maybe_unus
* perf_event_attr.wakeup_events, just PERF_EVENT_SAMPLE does. * perf_event_attr.wakeup_events, just PERF_EVENT_SAMPLE does.
*/ */
if (total_events == before && false) if (total_events == before && false)
perf_evlist__poll(evlist, -1); evlist__poll(evlist, -1);
sleep(1); sleep(1);
if (++wakeups > 5) { if (++wakeups > 5) {
......
...@@ -130,7 +130,7 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unused ...@@ -130,7 +130,7 @@ int test__task_exit(struct test *test __maybe_unused, int subtest __maybe_unused
out_init: out_init:
if (!exited || !nr_exit) { if (!exited || !nr_exit) {
perf_evlist__poll(evlist, -1); evlist__poll(evlist, -1);
goto retry; goto retry;
} }
......
...@@ -418,9 +418,9 @@ int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask) ...@@ -418,9 +418,9 @@ int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask)
perf_evlist__munmap_filtered, NULL); perf_evlist__munmap_filtered, NULL);
} }
int perf_evlist__poll(struct evlist *evlist, int timeout) int evlist__poll(struct evlist *evlist, int timeout)
{ {
return fdarray__poll(&evlist->core.pollfd, timeout); return perf_evlist__poll(&evlist->core, timeout);
} }
static void perf_evlist__set_sid_idx(struct evlist *evlist, static void perf_evlist__set_sid_idx(struct evlist *evlist,
...@@ -1736,7 +1736,7 @@ static void *perf_evlist__poll_thread(void *arg) ...@@ -1736,7 +1736,7 @@ static void *perf_evlist__poll_thread(void *arg)
draining = true; draining = true;
if (!draining) if (!draining)
perf_evlist__poll(evlist, 1000); evlist__poll(evlist, 1000);
for (i = 0; i < evlist->core.nr_mmaps; i++) { for (i = 0; i < evlist->core.nr_mmaps; i++) {
struct mmap *map = &evlist->mmap[i]; struct mmap *map = &evlist->mmap[i];
......
...@@ -144,7 +144,7 @@ perf_evlist__find_tracepoint_by_name(struct evlist *evlist, ...@@ -144,7 +144,7 @@ perf_evlist__find_tracepoint_by_name(struct evlist *evlist,
int evlist__add_pollfd(struct evlist *evlist, int fd); int evlist__add_pollfd(struct evlist *evlist, int fd);
int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask); int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask);
int perf_evlist__poll(struct evlist *evlist, int timeout); int evlist__poll(struct evlist *evlist, int timeout);
struct evsel *perf_evlist__id2evsel(struct evlist *evlist, u64 id); struct evsel *perf_evlist__id2evsel(struct evlist *evlist, u64 id);
struct evsel *perf_evlist__id2evsel_strict(struct evlist *evlist, struct evsel *perf_evlist__id2evsel_strict(struct evlist *evlist,
......
...@@ -918,7 +918,7 @@ static PyObject *pyrf_evlist__poll(struct pyrf_evlist *pevlist, ...@@ -918,7 +918,7 @@ static PyObject *pyrf_evlist__poll(struct pyrf_evlist *pevlist,
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i", kwlist, &timeout)) if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i", kwlist, &timeout))
return NULL; return NULL;
n = perf_evlist__poll(evlist, timeout); n = evlist__poll(evlist, timeout);
if (n < 0) { if (n < 0) {
PyErr_SetFromErrno(PyExc_OSError); PyErr_SetFromErrno(PyExc_OSError);
return NULL; return NULL;
......
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