Skip to content

Commit f66a889

Browse files
committed
perf evlist: Introduce poll method for common code idiom
Since we have access two evlist members in all these poll calls, provide a helper. This will also help to make the patch introducing the pollfd class more clear, as the evlist specific uses will be hiden away perf_evlist__poll(). Acked-by: Jiri Olsa <jolsa@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jean Pihet <jean.pihet@linaro.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/n/tip-jr9d4aop4lvy9453qahbcgp0@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent 0a04c9e commit f66a889

9 files changed

Lines changed: 15 additions & 8 deletions

File tree

‎tools/perf/builtin-record.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
459459
if (hits == rec->samples) {
460460
if (done)
461461
break;
462-
err = poll(rec->evlist->pollfd, rec->evlist->nr_fds, -1);
462+
err = perf_evlist__poll(rec->evlist, -1);
463463
/*
464464
* Propagate error, only if there's any. Ignore positive
465465
* number of returned events and interrupt error.

‎tools/perf/builtin-top.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ static int __cmd_top(struct perf_top *top)
964964
perf_evlist__enable(top->evlist);
965965

966966
/* Wait for a minimal set of events before starting the snapshot */
967-
poll(top->evlist->pollfd, top->evlist->nr_fds, 100);
967+
perf_evlist__poll(top->evlist, 100);
968968

969969
perf_top__mmap_read(top);
970970

@@ -991,7 +991,7 @@ static int __cmd_top(struct perf_top *top)
991991
perf_top__mmap_read(top);
992992

993993
if (hits == top->samples)
994-
ret = poll(top->evlist->pollfd, top->evlist->nr_fds, 100);
994+
ret = perf_evlist__poll(top->evlist, 100);
995995
}
996996

997997
ret = 0;

‎tools/perf/builtin-trace.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2171,7 +2171,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
21712171
if (trace->nr_events == before) {
21722172
int timeout = done ? 100 : -1;
21732173

2174-
if (poll(evlist->pollfd, evlist->nr_fds, timeout) > 0)
2174+
if (perf_evlist__poll(evlist, timeout) > 0)
21752175
goto again;
21762176
} else {
21772177
goto again;

‎tools/perf/tests/open-syscall-tp-fields.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ int test__syscall_open_tp_fields(void)
105105
}
106106

107107
if (nr_events == before)
108-
poll(evlist->pollfd, evlist->nr_fds, 10);
108+
perf_evlist__poll(evlist, 10);
109109

110110
if (++nr_polls > 5) {
111111
pr_debug("%s: no events!\n", __func__);

‎tools/perf/tests/perf-record.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ int test__PERF_RECORD(void)
268268
* perf_event_attr.wakeup_events, just PERF_EVENT_SAMPLE does.
269269
*/
270270
if (total_events == before && false)
271-
poll(evlist->pollfd, evlist->nr_fds, -1);
271+
perf_evlist__poll(evlist, -1);
272272

273273
sleep(1);
274274
if (++wakeups > 5) {

‎tools/perf/tests/task-exit.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ int test__task_exit(void)
105105
}
106106

107107
if (!exited || !nr_exit) {
108-
poll(evlist->pollfd, evlist->nr_fds, -1);
108+
perf_evlist__poll(evlist, -1);
109109
goto retry;
110110
}
111111

‎tools/perf/util/evlist.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,11 @@ int perf_evlist__filter_pollfd(struct perf_evlist *evlist, short revents_and_mas
475475
return nr_fds;
476476
}
477477

478+
int perf_evlist__poll(struct perf_evlist *evlist, int timeout)
479+
{
480+
return poll(evlist->pollfd, evlist->nr_fds, timeout);
481+
}
482+
478483
static void perf_evlist__id_hash(struct perf_evlist *evlist,
479484
struct perf_evsel *evsel,
480485
int cpu, int thread, u64 id)

‎tools/perf/util/evlist.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd);
8787
int perf_evlist__alloc_pollfd(struct perf_evlist *evlist);
8888
int perf_evlist__filter_pollfd(struct perf_evlist *evlist, short revents_and_mask);
8989

90+
int perf_evlist__poll(struct perf_evlist *evlist, int timeout);
91+
9092
struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id);
9193

9294
struct perf_sample_id *perf_evlist__id2sid(struct perf_evlist *evlist, u64 id);

‎tools/perf/util/python.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -736,7 +736,7 @@ static PyObject *pyrf_evlist__poll(struct pyrf_evlist *pevlist,
736736
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|i", kwlist, &timeout))
737737
return NULL;
738738

739-
n = poll(evlist->pollfd, evlist->nr_fds, timeout);
739+
n = perf_evlist__poll(evlist, timeout);
740740
if (n < 0) {
741741
PyErr_SetFromErrno(PyExc_OSError);
742742
return NULL;

0 commit comments

Comments
 (0)