From: Adrian Hunter <adrian.hunter@intel.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>,
linux-kernel@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@redhat.com>,
David Ahern <dsahern@gmail.com>, Don Zickus <dzickus@redhat.com>,
Frederic Weisbecker <fweisbec@gmail.com>,
Ingo Molnar <mingo@kernel.org>, Mike Galbraith <efault@gmx.de>,
Namhyung Kim <namhyung@kernel.org>,
Paul Mackerras <paulus@samba.org>,
Peter Zijlstra <peterz@infradead.org>,
Stephane Eranian <eranian@google.com>
Subject: Re: [PATCH 01/10] perf evlist: Introduce perf_evlist__filter_pollfd method
Date: Mon, 25 Aug 2014 09:57:53 +0300 [thread overview]
Message-ID: <53FADE71.8070006@intel.com> (raw)
In-Reply-To: <1408741190-5123-2-git-send-email-acme@kernel.org>
On 08/22/2014 11:59 PM, Arnaldo Carvalho de Melo wrote:
> From: Arnaldo Carvalho de Melo <acme@redhat.com>
>
> 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.
>
> 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: Ingo Molnar <mingo@kernel.org>
> 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-ki3oqbfjg84si3f9amhyqvzb@git.kernel.org
> Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
> ---
> tools/perf/util/evlist.c | 16 ++++++++++++++++
> tools/perf/util/evlist.h | 2 ++
> 2 files changed, 18 insertions(+)
>
> diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
> index a3e28b49128a..bd7896073d10 100644
> --- a/tools/perf/util/evlist.c
> +++ b/tools/perf/util/evlist.c
> @@ -428,6 +428,22 @@ 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 = 0, nr_fds = 0;
> +
> + while (fd < evlist->nr_fds) {
A for loop is clearer e.g.
for (fd = 0; fd < evlist->nr_fds; fd++) {
> + if ((evlist->pollfd[fd].revents & revents_and_mask) == 0)
> + ++nr_fds;
> +
> + if (++fd != nr_fds)
> + evlist->pollfd[nr_fds] = evlist->pollfd[fd];
That looks like it will go off the end of the array. Shouldn't it be:
if ((evlist->pollfd[fd].revents & revents_and_mask) == 0) {
if (fd != nr_fds)
evlist->pollfd[nr_fds] = evlist->pollfd[fd];
nr_fds += 1;
}
> + }
> +
> + 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)
> diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
> index 106de53a6a74..1082420951f9 100644
> --- a/tools/perf/util/evlist.h
> +++ b/tools/perf/util/evlist.h
> @@ -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);
>
next prev parent reply other threads:[~2014-08-25 6:59 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-22 20:59 [RFC 00/10] perf pollfd series Arnaldo Carvalho de Melo
2014-08-22 20:59 ` [PATCH 01/10] perf evlist: Introduce perf_evlist__filter_pollfd method Arnaldo Carvalho de Melo
2014-08-25 6:57 ` Adrian Hunter [this message]
2014-08-22 20:59 ` [PATCH 02/10] perf tests: Add test for perf_evlist__filter_pollfd() Arnaldo Carvalho de Melo
2014-08-22 20:59 ` [PATCH 03/10] perf evlist: Monitor POLLERR and POLLHUP events too Arnaldo Carvalho de Melo
2014-08-22 20:59 ` [PATCH 04/10] perf record: Filter out POLLHUP'ed file descriptors Arnaldo Carvalho de Melo
2014-08-22 20:59 ` [PATCH 05/10] perf trace: " Arnaldo Carvalho de Melo
2014-08-22 20:59 ` [PATCH 06/10] perf evlist: Allow growing pollfd on add method Arnaldo Carvalho de Melo
2014-08-25 9:41 ` Jiri Olsa
2014-08-25 9:47 ` Jiri Olsa
2014-08-25 15:59 ` Arnaldo Carvalho de Melo
2014-08-22 20:59 ` [PATCH 07/10] perf tests: Add pollfd growing test Arnaldo Carvalho de Melo
2014-08-22 20:59 ` [PATCH 08/10] perf kvm stat live: Use perf_evlist__add_pollfd() instead of local equivalent Arnaldo Carvalho de Melo
2014-08-26 14:04 ` David Ahern
2014-08-22 20:59 ` [PATCH 09/10] perf evlist: Introduce poll method for common code idiom Arnaldo Carvalho de Melo
2014-08-22 20:59 ` [PATCH 10/10] tools lib api: Adopt fdarray class from perf's evlist Arnaldo Carvalho de Melo
2014-08-26 7:46 ` Namhyung Kim
2014-08-26 13:08 ` Arnaldo Carvalho de Melo
2014-08-25 11:04 ` [RFC 00/10] perf pollfd series Jiri Olsa
2014-08-25 15:56 ` Arnaldo Carvalho de Melo
-- strict thread matches above, loose matches on Subject: below --
2014-09-03 21:59 [RFC 00/10] perf pollfd series v2 Arnaldo Carvalho de Melo
2014-09-03 21:59 ` [PATCH 01/10] perf evlist: Introduce perf_evlist__filter_pollfd method Arnaldo Carvalho de Melo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53FADE71.8070006@intel.com \
--to=adrian.hunter@intel.com \
--cc=acme@kernel.org \
--cc=acme@redhat.com \
--cc=dsahern@gmail.com \
--cc=dzickus@redhat.com \
--cc=efault@gmx.de \
--cc=eranian@google.com \
--cc=fweisbec@gmail.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=paulus@samba.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).