netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Leonardo Chiquitto <leonardo.lists@gmail.com>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: netdev@vger.kernel.org, "David S. Miller" <davem@davemloft.net>
Subject: Re: POLLPRI/poll() behavior change since 2.6.31
Date: Thu, 6 Jan 2011 16:10:23 -0200	[thread overview]
Message-ID: <AANLkTi=iiT9rYobAzJgbd6SBwkOqDBHKTenmb+4xhs9=@mail.gmail.com> (raw)
In-Reply-To: <1294332929.3074.49.camel@edumazet-laptop>

On Thu, Jan 6, 2011 at 2:55 PM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> Le jeudi 06 janvier 2011 à 13:50 -0200, Leonardo Chiquitto a écrit :
>> Hello,
>>
>> Since 2.6.31, poll() no longer returns when waiting exclusively for a
>> POLLPRI event. If we wait for POLLPRI | POLLIN, though, it will
>> correctly return POLLPRI as a received event.
>>
>> The reproducer (code below) will print the following when running on
>> 2.6.30:
>>
>> $ ./pollpri-oob
>> main: starting
>> main: setup_pipe ok (sfd[0] = 5, sfd[1] = 4)
>> parent: child <pid 3790> started
>> child: polling...
>> parent: sending the message
>> parent: waiting for child to exit
>> child: poll(): some data <1,2> has arrived!
>> child: done
>> parent: done
>>
>> ... and will block when running on 2.6.37-rc7:
>>
>> $ ./pollpri-oob
>> main: starting
>> main: setup_pipe ok (sfd[0] = 5, sfd[1] = 4)
>> parent: child <pid 14148> started
>> child: polling...
>> parent: sending the message
>> parent: waiting for child to exit
>> [hangs here]
>>
>> I've bisected this behavior change to the following commit:
>>
>> commit 4938d7e0233a455f04507bac81d0886c71529537
>> Author: Eric Dumazet <dada1@cosmosbay.com>
>> Date:   Tue Jun 16 15:33:36 2009 -0700
>>
>>   poll: avoid extra wakeups in select/poll
>>
>>   After introduction of keyed wakeups Davide Libenzi did on epoll, we are
>>   able to avoid spurious wakeups in poll()/select() code too.
>>
>>   For example, typical use of poll()/select() is to wait for incoming
>>   network frames on many sockets.  But TX completion for UDP/TCP frames call
>>   sock_wfree() which in turn schedules thread.
>>
>>   When scheduled, thread does a full scan of all polled fds and can sleep
>>   again, because nothing is really available.  If number of fds is large,
>>   this cause significant load.
>>
>>   This patch makes select()/poll() aware of keyed wakeups and useless
>>   wakeups are avoided.  This reduces number of context switches by about 50%
>>   on some setups, and work performed by sofirq handlers.
>>
>>
>> I don't know if the new behavior is correct, but we've got one report of
>> an application that broke due to the change.
>
> Hi Leonardo
>
> Hmm, this is because    sock_def_readable() uses :
>
> wake_up_interruptible_sync_poll(&wq->wait, POLLIN | POLLRDNORM |
> POLLRDBAND);
>
> So POLLPRI bit is not signaled.
>
> I would just add POLLPRI flag in sock_def_readable()
>
> (Alternatively, define a tcp_def_readable() function to pass POLLPRI
> only if TCP_URG is set, but is it worth the pain for a seldom used
> feature ?)
>
> David, do you have an opinion on this ?
>
> Thanks
>
> diff --git a/net/core/sock.c b/net/core/sock.c
> index e5af8d5..7fd3541 100644
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -1907,7 +1907,7 @@ static void sock_def_readable(struct sock *sk, int len)
>        rcu_read_lock();
>        wq = rcu_dereference(sk->sk_wq);
>        if (wq_has_sleeper(wq))
> -               wake_up_interruptible_sync_poll(&wq->wait, POLLIN |
> +               wake_up_interruptible_sync_poll(&wq->wait, POLLIN | POLLPRI |
>                                                POLLRDNORM | POLLRDBAND);
>        sk_wake_async(sk, SOCK_WAKE_WAITD, POLL_IN);
>        rcu_read_unlock();

Eric,

Thanks for the quick reply. I tested your patch and confirm that it resolves the
problem.

Regards,
Leonardo

  reply	other threads:[~2011-01-06 18:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-06 15:50 POLLPRI/poll() behavior change since 2.6.31 Leonardo Chiquitto
2011-01-06 16:55 ` Eric Dumazet
2011-01-06 18:10   ` Leonardo Chiquitto [this message]
2011-01-06 22:40   ` Davide Libenzi
2011-01-07 13:31     ` Eric Dumazet
2011-01-06 17:44 ` [PATCH] net: add POLLPRI to sock_def_readable() Eric Dumazet
2011-01-06 18:55   ` David Miller

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='AANLkTi=iiT9rYobAzJgbd6SBwkOqDBHKTenmb+4xhs9=@mail.gmail.com' \
    --to=leonardo.lists@gmail.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=netdev@vger.kernel.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).