From: jeremie.galarneau@efficios.com (Jérémie Galarneau)
Subject: [lttng-dev] [PATCH lttng-tools v4 6/8] Change lttng_poll_wait behaviour of compat-poll to match compat-epoll
Date: Wed, 24 Apr 2019 17:08:53 -0400 [thread overview]
Message-ID: <20190424210852.GB4486@gmail.com> (raw)
In-Reply-To: <20190401175925.8512-7-ylamarre@efficios.com>
On Mon, Apr 01, 2019 at 01:59:23PM -0400, Yannick Lamarre wrote:
> This removes the need to verify for idle file descriptors and mitigates
> risks of bug due to behaviour mismatch.
>
> Signed-off-by: Yannick Lamarre <ylamarre at efficios.com>
> ---
>
> The assert in the for loop is removed.
>
> src/common/compat/compat-poll.c | 37 +++++++++++++++++++++++++++++++++----
> 1 file changed, 33 insertions(+), 4 deletions(-)
>
> diff --git a/src/common/compat/compat-poll.c b/src/common/compat/compat-poll.c
> index be655728..5b752a28 100644
> --- a/src/common/compat/compat-poll.c
> +++ b/src/common/compat/compat-poll.c
> @@ -293,7 +293,8 @@ error:
> */
> int compat_poll_wait(struct lttng_poll_event *events, int timeout)
> {
> - int ret;
> + int ret, active_fd_count;
> + int idle_pfd_index = 0;
>
> if (events == NULL || events->current.events == NULL) {
> ERR("poll wait arguments error");
> @@ -325,11 +326,39 @@ int compat_poll_wait(struct lttng_poll_event *events, int timeout)
> goto error;
> }
>
> + active_fd_count = ret;
> +
> /*
> - * poll() should always iterate on all FDs since we handle the pollset in
> - * user space and after poll returns, we have to try every fd for a match.
> + * Swap all active pollfd structs to the beginning of the
> + * array to emulate compat-epoll behaviour. This algorithm takes
> + * advantage of poll's returned value and the burst nature of active
> + * events on the file descriptors. The while loop guarantees that
> + * idle_pfd will always point to an idle fd.
> */
> - return events->wait.nb_fd;
> + if (active_fd_count == events->wait.nb_fd) {
> + goto end;
> + }
> + while (idle_pfd_index < active_fd_count &&
> + events->wait.events[idle_pfd_index].revents != 0) {
> + idle_pfd_index++;
> + }
> +
> + for (int i = idle_pfd_index + 1; idle_pfd_index < active_fd_count;
> + i++) {
Declare 'i' at the beginning of the function.
Thanks!
J?r?mie
> + struct pollfd swap_pfd;
> + struct pollfd *idle_pfd = &events->wait.events[idle_pfd_index];
> + struct pollfd *current_pfd = &events->wait.events[i];
> +
> + if (ipfd->revents != 0) {
> + swap_pfd = *current_pfd;
> + *current_pfd = *idle_pfd;
> + *idle_pfd = swap_pfd;
> + idle_pfd_index++;
> + }
> + }
> +
> +end:
> + return ret;
>
> error:
> return -1;
> --
> 2.11.0
>
prev parent reply other threads:[~2019-04-24 21:08 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20190401175925.8512-1-ylamarre@efficios.com>
[not found] ` <20190401175925.8512-5-ylamarre@efficios.com>
2019-04-24 21:02 ` [lttng-dev] [PATCH lttng-tools v4 4/8] Adapt poll layer behaviour to match the epoll layer Jérémie Galarneau
[not found] ` <20190401175925.8512-7-ylamarre@efficios.com>
2019-04-24 21:08 ` Jérémie Galarneau [this message]
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=20190424210852.GB4486@gmail.com \
--to=jeremie.galarneau@efficios.com \
/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