From: Eric Wong <normalperson@yhbt.net>
To: Andreas Voellmy <andreas.voellmy@yale.edu>
Cc: viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: epoll with ONESHOT possibly fails to deliver events
Date: Thu, 13 Dec 2012 09:32:42 +0000 [thread overview]
Message-ID: <20121213093242.GA25436@dcvr.yhbt.net> (raw)
In-Reply-To: <AF8622CA-CF9D-4F57-B4EB-FE088A752D80@yale.edu>
Andreas Voellmy <andreas.voellmy@yale.edu> wrote:
> Using strace, I checked that my program is using epoll api as I
> described. Here is a fragment of the strace output that demonstrates
> my use:
>
> recvfrom(161, "GET / HTTP/1.1\r\nHost: 10.12.0.1:"..., 90, 0, NULL, NULL) = 90
> sendto(161, "HTTP/1.1 200 OK\r\nDate: Tue, 09 O"..., 323, 0, NULL, 0) = 323
> write(6, "\1\0\0\0\0\0\0\0", 8) = 8
> recvfrom(161, 0x7f05ef6c3070, 90, 0, 0, 0) = -1 EAGAIN (Resource temporarily unavailable)
> epoll_ctl(7, EPOLL_CTL_MOD, 161, {EPOLLIN|EPOLLONESHOT|EPOLLET, {u32=161, u64=4294967457}}) = 0
> epoll_wait(7, {{EPOLLIN, {u32=161, u64=4294967457}}, {EPOLLIN, {u32=160, u64=16673999036704882848}}, {EPOLLIN, {u32=162, u64=22028646743015586}}}, 64, 0) = 3
>
> I.e. we do the following (1) receive until EAGAIN, (2) register socket
> with epoll_ctl. In addition epoll_wait is called repeatedly, often
> following (2), as in the fragment above.
>
> Is this considered a correct usage of the epoll API? If not, what is
> wrong with this usage?
It looks right to me.
> On Dec 11, 2012, at 5:23 PM, Andreas Voellmy <andreas.voellmy@yale.edu> wrote:
> > I am using epoll for the Linux (version 3.4.0) implementation of the
> > event notification subsystem of GHC's (Glasgow Haskell Compiler) RTS
> > (runtime system). I am running into a bug that has only popped up
> > using many cores (> 16) and under particular kind of load. I've been
> > debugging for a couple of days now, and I can't find the error in
> > the way that I am using epoll. I'm starting to wonder whether I am
> > either misunderstanding the semantics of epoll and TCP sockets
> > (likely) or there may be a bug in epoll itself (less likely).
Everything you describe with your epoll usage seems valid and lines up
with my use of it.
> > Another thread, distinct from all of the threads serving particular
> > sockets, is perfoming epoll_wait calls. When sockets are returned as
> > being ready from an epoll_wait call, the thread signals to the
> > condition variable for the socket.
Perhaps there is a bug in the way your epoll_wait thread
uses the condition variable to notify other threads?
Fwiw, I just use epoll_wait(maxevents=1) in my normal threads (right
after I call epoll_ctl()). This means I can avoid both the condition
variable and also avoid using a dedicated thread calling epoll_wait().
> > Since I am using EPOLLONESHOT, I assume that there is no need to
> > also perform epoll_ctl with EPOLL_CTL_DEL here.
Correct.
> > The problem I am encountering is that sometimes a thread will block
> > waiting for the readiness signal and will never get notified, even
> > though there is data to be read. This behavior seems to go away when
> > I remove EPOLLONESHOT flag when registering the event.
Is the thread the one waiting on the condition variable or epoll_wait?
In your situation (stream I/O via multiple threads, single epoll
descriptor), I think EPOLLONESHOT is the /only/ sane thing to do.
next prev parent reply other threads:[~2012-12-13 9:40 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-12-11 22:23 Andreas Voellmy
2012-12-12 23:49 ` Andreas Voellmy
2012-12-13 9:32 ` Eric Wong [this message]
2012-12-13 15:29 ` Andreas Voellmy
2012-12-14 0:16 ` Andreas Voellmy
2012-12-15 14:50 ` Andreas Voellmy
2012-12-18 2:07 ` Eric Wong
2012-12-18 2:35 ` Andreas Voellmy
2012-12-18 17:27 ` Andreas Voellmy
2012-12-19 19:39 ` Andreas Voellmy
2012-12-20 21:32 ` Eric Wong
2012-12-20 22:25 ` Junchang(Jason) Wang
2012-12-21 15:32 ` Andreas Voellmy
2012-12-22 2:54 ` Eric Wong
2012-12-14 0:08 ` Phil Turmel
2012-12-14 0:15 ` Phil Turmel
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=20121213093242.GA25436@dcvr.yhbt.net \
--to=normalperson@yhbt.net \
--cc=andreas.voellmy@yale.edu \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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
Powered by JetHome