mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-03 15:47:36 +00:00
libperf: Add perf_evlist__add_pollfd() function
Move perf_evlist__add_pollfd() from tools/perf to libperf, it will be used in the following patches. Also rename perf's perf_evlist__add_pollfd()/perf_evlist__filter_pollfd() to evlist__add_pollfd()/evlist__filter_pollfd(). 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-38-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
31f67fc462
commit
f4009e7bf7
7 changed files with 28 additions and 27 deletions
|
@ -967,10 +967,10 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (perf_evlist__add_pollfd(kvm->evlist, kvm->timerfd) < 0)
|
if (evlist__add_pollfd(kvm->evlist, kvm->timerfd) < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
nr_stdin = perf_evlist__add_pollfd(kvm->evlist, fileno(stdin));
|
nr_stdin = evlist__add_pollfd(kvm->evlist, fileno(stdin));
|
||||||
if (nr_stdin < 0)
|
if (nr_stdin < 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
|
|
@ -1624,7 +1624,7 @@ static int __cmd_record(struct record *rec, int argc, const char **argv)
|
||||||
err = 0;
|
err = 0;
|
||||||
waking++;
|
waking++;
|
||||||
|
|
||||||
if (perf_evlist__filter_pollfd(rec->evlist, POLLERR | POLLHUP) == 0)
|
if (evlist__filter_pollfd(rec->evlist, POLLERR | POLLHUP) == 0)
|
||||||
draining = true;
|
draining = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3475,7 +3475,7 @@ static int trace__run(struct trace *trace, int argc, const char **argv)
|
||||||
int timeout = done ? 100 : -1;
|
int timeout = done ? 100 : -1;
|
||||||
|
|
||||||
if (!draining && perf_evlist__poll(evlist, timeout) > 0) {
|
if (!draining && perf_evlist__poll(evlist, timeout) > 0) {
|
||||||
if (perf_evlist__filter_pollfd(evlist, POLLERR | POLLHUP | POLLNVAL) == 0)
|
if (evlist__filter_pollfd(evlist, POLLERR | POLLHUP | POLLNVAL) == 0)
|
||||||
draining = true;
|
draining = true;
|
||||||
|
|
||||||
goto again;
|
goto again;
|
||||||
|
|
|
@ -12,6 +12,9 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <poll.h>
|
||||||
#include <perf/cpumap.h>
|
#include <perf/cpumap.h>
|
||||||
#include <perf/threadmap.h>
|
#include <perf/threadmap.h>
|
||||||
#include <api/fd/array.h>
|
#include <api/fd/array.h>
|
||||||
|
@ -260,3 +263,16 @@ int perf_evlist__alloc_pollfd(struct perf_evlist *evlist)
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd,
|
||||||
|
void *ptr, short revent)
|
||||||
|
{
|
||||||
|
int pos = fdarray__add(&evlist->pollfd, fd, revent | POLLERR | POLLHUP);
|
||||||
|
|
||||||
|
if (pos >= 0) {
|
||||||
|
evlist->pollfd.priv[pos].ptr = ptr;
|
||||||
|
fcntl(fd, F_SETFL, O_NONBLOCK);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
|
@ -25,6 +25,8 @@ struct perf_evlist {
|
||||||
};
|
};
|
||||||
|
|
||||||
int perf_evlist__alloc_pollfd(struct perf_evlist *evlist);
|
int perf_evlist__alloc_pollfd(struct perf_evlist *evlist);
|
||||||
|
int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd,
|
||||||
|
void *ptr, short revent);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* __perf_evlist__for_each_entry - iterate thru all the evsels
|
* __perf_evlist__for_each_entry - iterate thru all the evsels
|
||||||
|
|
|
@ -398,26 +398,9 @@ int perf_evlist__enable_event_idx(struct evlist *evlist,
|
||||||
return perf_evlist__enable_event_thread(evlist, evsel, idx);
|
return perf_evlist__enable_event_thread(evlist, evsel, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __perf_evlist__add_pollfd(struct evlist *evlist, int fd,
|
int evlist__add_pollfd(struct evlist *evlist, int fd)
|
||||||
struct mmap *map, short revent)
|
|
||||||
{
|
{
|
||||||
int pos = fdarray__add(&evlist->core.pollfd, fd, revent | POLLERR | POLLHUP);
|
return perf_evlist__add_pollfd(&evlist->core, fd, NULL, POLLIN);
|
||||||
/*
|
|
||||||
* Save the idx so that when we filter out fds POLLHUP'ed we can
|
|
||||||
* close the associated evlist->mmap[] entry.
|
|
||||||
*/
|
|
||||||
if (pos >= 0) {
|
|
||||||
evlist->core.pollfd.priv[pos].ptr = map;
|
|
||||||
|
|
||||||
fcntl(fd, F_SETFL, O_NONBLOCK);
|
|
||||||
}
|
|
||||||
|
|
||||||
return pos;
|
|
||||||
}
|
|
||||||
|
|
||||||
int perf_evlist__add_pollfd(struct evlist *evlist, int fd)
|
|
||||||
{
|
|
||||||
return __perf_evlist__add_pollfd(evlist, fd, NULL, POLLIN);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd,
|
static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd,
|
||||||
|
@ -429,7 +412,7 @@ static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd,
|
||||||
perf_mmap__put(map);
|
perf_mmap__put(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
int perf_evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask)
|
int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask)
|
||||||
{
|
{
|
||||||
return fdarray__filter(&evlist->core.pollfd, revents_and_mask,
|
return fdarray__filter(&evlist->core.pollfd, revents_and_mask,
|
||||||
perf_evlist__munmap_filtered, NULL);
|
perf_evlist__munmap_filtered, NULL);
|
||||||
|
@ -708,7 +691,7 @@ static int evlist__mmap_per_evsel(struct evlist *evlist, int idx,
|
||||||
* Therefore don't add it for polling.
|
* Therefore don't add it for polling.
|
||||||
*/
|
*/
|
||||||
if (!evsel->core.system_wide &&
|
if (!evsel->core.system_wide &&
|
||||||
__perf_evlist__add_pollfd(evlist, fd, &maps[idx], revent) < 0) {
|
perf_evlist__add_pollfd(&evlist->core, fd, &maps[idx], revent) < 0) {
|
||||||
perf_mmap__put(&maps[idx]);
|
perf_mmap__put(&maps[idx]);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,8 +141,8 @@ struct evsel *
|
||||||
perf_evlist__find_tracepoint_by_name(struct evlist *evlist,
|
perf_evlist__find_tracepoint_by_name(struct evlist *evlist,
|
||||||
const char *name);
|
const char *name);
|
||||||
|
|
||||||
int perf_evlist__add_pollfd(struct evlist *evlist, int fd);
|
int evlist__add_pollfd(struct evlist *evlist, int fd);
|
||||||
int perf_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 perf_evlist__poll(struct evlist *evlist, int timeout);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue