public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Simon Richter <Simon.Richter@hogyros.de>
To: linux-kernel@vger.kernel.org
Subject: non-blocking behaviour with multiple readers
Date: Sat, 9 Feb 2008 13:57:08 +0100	[thread overview]
Message-ID: <20080209125702.GA10739@honey> (raw)

Hi,

[please CC me, I'm not subscribed to the list]

I'm writing a driver for a pretty simple USB device, and most of what I
need I can see in similar drivers; right now I'm lifting a lot of code
from drivers/usb/class/usblp.c.

In the read routine, this driver gathers a few locks, then checks
whether data is present and in the non-blocking case returns -EAGAIN,
otherwise waits for data to become available.

In the case of multiple readers, acquiring the locks might however
block, so I'm not sure whether it'd be better to check for non-blocking
first, and acquire the locks with trylock in this case, returning
-EAGAIN in case we fail to acquire any.

The semantic difference seems to be minimal: I believe that it is
acceptable to return -EAGAIN from read even if a previous poll()
suggested that the fd was now readable. Blocking on a non-blocking
read() until other tasks reading from the same fd have left the kernel
seems more like an optimization to me, saving a few syscalls if the
other reader doesn't read all the bytes.

The obvious consistency problem with multiple unsynchronized readers
aside: is that optimization worth a (short) block inside a non-blocking
read?

   Simon

                 reply	other threads:[~2008-02-09 13:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20080209125702.GA10739@honey \
    --to=simon.richter@hogyros.de \
    --cc=linux-kernel@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