Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Jiri Olsa and committed by
Arnaldo Carvalho de Melo
f4009e7b 31f67fc4

+28 -27
+2 -2
tools/perf/builtin-kvm.c
··· 967 967 goto out; 968 968 } 969 969 970 - if (perf_evlist__add_pollfd(kvm->evlist, kvm->timerfd) < 0) 970 + if (evlist__add_pollfd(kvm->evlist, kvm->timerfd) < 0) 971 971 goto out; 972 972 973 - nr_stdin = perf_evlist__add_pollfd(kvm->evlist, fileno(stdin)); 973 + nr_stdin = evlist__add_pollfd(kvm->evlist, fileno(stdin)); 974 974 if (nr_stdin < 0) 975 975 goto out; 976 976
+1 -1
tools/perf/builtin-record.c
··· 1624 1624 err = 0; 1625 1625 waking++; 1626 1626 1627 - if (perf_evlist__filter_pollfd(rec->evlist, POLLERR | POLLHUP) == 0) 1627 + if (evlist__filter_pollfd(rec->evlist, POLLERR | POLLHUP) == 0) 1628 1628 draining = true; 1629 1629 } 1630 1630
+1 -1
tools/perf/builtin-trace.c
··· 3475 3475 int timeout = done ? 100 : -1; 3476 3476 3477 3477 if (!draining && perf_evlist__poll(evlist, timeout) > 0) { 3478 - if (perf_evlist__filter_pollfd(evlist, POLLERR | POLLHUP | POLLNVAL) == 0) 3478 + if (evlist__filter_pollfd(evlist, POLLERR | POLLHUP | POLLNVAL) == 0) 3479 3479 draining = true; 3480 3480 3481 3481 goto again;
+16
tools/perf/lib/evlist.c
··· 12 12 #include <stdlib.h> 13 13 #include <errno.h> 14 14 #include <unistd.h> 15 + #include <fcntl.h> 16 + #include <signal.h> 17 + #include <poll.h> 15 18 #include <perf/cpumap.h> 16 19 #include <perf/threadmap.h> 17 20 #include <api/fd/array.h> ··· 262 259 return -ENOMEM; 263 260 264 261 return 0; 262 + } 263 + 264 + int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, 265 + void *ptr, short revent) 266 + { 267 + int pos = fdarray__add(&evlist->pollfd, fd, revent | POLLERR | POLLHUP); 268 + 269 + if (pos >= 0) { 270 + evlist->pollfd.priv[pos].ptr = ptr; 271 + fcntl(fd, F_SETFL, O_NONBLOCK); 272 + } 273 + 274 + return pos; 265 275 }
+2
tools/perf/lib/include/internal/evlist.h
··· 25 25 }; 26 26 27 27 int perf_evlist__alloc_pollfd(struct perf_evlist *evlist); 28 + int perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, 29 + void *ptr, short revent); 28 30 29 31 /** 30 32 * __perf_evlist__for_each_entry - iterate thru all the evsels
+4 -21
tools/perf/util/evlist.c
··· 398 398 return perf_evlist__enable_event_thread(evlist, evsel, idx); 399 399 } 400 400 401 - static int __perf_evlist__add_pollfd(struct evlist *evlist, int fd, 402 - struct mmap *map, short revent) 401 + int evlist__add_pollfd(struct evlist *evlist, int fd) 403 402 { 404 - int pos = fdarray__add(&evlist->core.pollfd, fd, revent | POLLERR | POLLHUP); 405 - /* 406 - * Save the idx so that when we filter out fds POLLHUP'ed we can 407 - * close the associated evlist->mmap[] entry. 408 - */ 409 - if (pos >= 0) { 410 - evlist->core.pollfd.priv[pos].ptr = map; 411 - 412 - fcntl(fd, F_SETFL, O_NONBLOCK); 413 - } 414 - 415 - return pos; 416 - } 417 - 418 - int perf_evlist__add_pollfd(struct evlist *evlist, int fd) 419 - { 420 - return __perf_evlist__add_pollfd(evlist, fd, NULL, POLLIN); 403 + return perf_evlist__add_pollfd(&evlist->core, fd, NULL, POLLIN); 421 404 } 422 405 423 406 static void perf_evlist__munmap_filtered(struct fdarray *fda, int fd, ··· 412 429 perf_mmap__put(map); 413 430 } 414 431 415 - int perf_evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask) 432 + int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask) 416 433 { 417 434 return fdarray__filter(&evlist->core.pollfd, revents_and_mask, 418 435 perf_evlist__munmap_filtered, NULL); ··· 691 708 * Therefore don't add it for polling. 692 709 */ 693 710 if (!evsel->core.system_wide && 694 - __perf_evlist__add_pollfd(evlist, fd, &maps[idx], revent) < 0) { 711 + perf_evlist__add_pollfd(&evlist->core, fd, &maps[idx], revent) < 0) { 695 712 perf_mmap__put(&maps[idx]); 696 713 return -1; 697 714 }
+2 -2
tools/perf/util/evlist.h
··· 141 141 perf_evlist__find_tracepoint_by_name(struct evlist *evlist, 142 142 const char *name); 143 143 144 - int perf_evlist__add_pollfd(struct evlist *evlist, int fd); 145 - int perf_evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask); 144 + int evlist__add_pollfd(struct evlist *evlist, int fd); 145 + int evlist__filter_pollfd(struct evlist *evlist, short revents_and_mask); 146 146 147 147 int perf_evlist__poll(struct evlist *evlist, int timeout); 148 148