perf evlist: Introduce perf_evlist__filter_pollfd method
authorArnaldo Carvalho de Melo <acme@redhat.com>
Wed, 13 Aug 2014 02:04:11 +0000 (23:04 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Thu, 25 Sep 2014 19:46:53 +0000 (16:46 -0300)
To remove all entries in evlist->pollfd[] that have revents matching at
least one of the bits in the specified mask.

It'll adjust evlist->nr_fds to the number of unfiltered fds and will
return this value, as a convenience and to avoid requiring direct access
to internal state of perf_evlist objects.

This will be used after polling the evlist fds so that we remove fds
that were closed by the kernel.

Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Don Zickus <dzickus@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-y2sca7z3wicvvy40a50lozwm@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/util/evlist.c
tools/perf/util/evlist.h

index a3e28b49128ab3f3bbdd77dd8f7a3e052ac58eb2..023bc3873ae96f455436edf3e7cd23837e11a83a 100644 (file)
@@ -428,6 +428,27 @@ void perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd)
        evlist->nr_fds++;
 }
 
+int perf_evlist__filter_pollfd(struct perf_evlist *evlist, short revents_and_mask)
+{
+       int fd, nr_fds = 0;
+
+       if (evlist->nr_fds == 0)
+               return 0;
+
+       for (fd = 0; fd < evlist->nr_fds; ++fd) {
+               if (evlist->pollfd[fd].revents & revents_and_mask)
+                       continue;
+
+               if (fd != nr_fds)
+                       evlist->pollfd[nr_fds] = evlist->pollfd[fd];
+
+               ++nr_fds;
+       }
+
+       evlist->nr_fds = nr_fds;
+       return nr_fds;
+}
+
 static void perf_evlist__id_hash(struct perf_evlist *evlist,
                                 struct perf_evsel *evsel,
                                 int cpu, int thread, u64 id)
index 106de53a6a74bc1304e1dc2a638b1f4379723292..1082420951f9815d6803f47800996ffcee67157e 100644 (file)
@@ -84,6 +84,8 @@ void perf_evlist__id_add(struct perf_evlist *evlist, struct perf_evsel *evsel,
 
 void perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd);
 
+int perf_evlist__filter_pollfd(struct perf_evlist *evlist, short revents_and_mask);
+
 struct perf_evsel *perf_evlist__id2evsel(struct perf_evlist *evlist, u64 id);
 
 struct perf_sample_id *perf_evlist__id2sid(struct perf_evlist *evlist, u64 id);