mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Leon Woestenberg" <leon.woestenberg@gmail.com>
To: linux-kernel@vger.kernel.org
Subject: Use of mutex in interrupt context flawed/impossible, need advice.
Date: Thu, 22 Nov 2007 17:02:44 +0100	[thread overview]
Message-ID: <c384c5ea0711220802i21e3df45q1d328aea63e7ebf4@mail.gmail.com> (raw)

Hello,


I'm converting an out-of-tree (*1) driver from binary semaphore to mutex.

Userspace updates a look-up-table using write(). The driver tries to
write this LUT to the FPGA in the (video frame) interrupt handler. It
is important that the LUT is consistent and thus changed atomically.
Note that it is not important that the LUT is updated each interrupt.

The current approach is to try-down()ing a binary semaphore in
interrupt context, and write the LUT to the FPGA if the semaphore was
down()ed, do nothing else.
The write() down()s the semaphore as well before updating the
in-driver-copy of the LUT, then up()s it again.

I understand this design is not clean (*2), and not even possible with
mutexes, as mutex_trylock() is not interrupt safe.

My current approach would be to have userspace write into a shadow
copy, and use a spinlock to update the live copy. The interrupt then
would try a spinlock.

My feeling is that we have a  valid use of mutex_trylock() in
interrupt context; "i.e. update LUT if we can do so consistently and
in time, or not at all".

I would like to know why this is not so, and if someone has a cleaner
proposal than the "try spinlock" approach?

Regards,
-- 
Leon

*1: specific to driving a certain FPGA with certain logic. I can post
the source code on request.
*2: http://lkml.org/lkml/2007/6/23/143

             reply	other threads:[~2007-11-22 16:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-22 16:02 Leon Woestenberg [this message]
2007-11-22 16:11 ` Oliver Neukum
2007-11-22 16:19   ` Leon Woestenberg
2007-11-22 16:49     ` Michal Schmidt
2007-11-22 17:17 ` Arjan van de Ven
     [not found] <fa.DDwTo7jhtvU2nkv268RloCrwiwc@ifi.uio.no>
2007-11-23  1:07 ` Robert Hancock

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=c384c5ea0711220802i21e3df45q1d328aea63e7ebf4@mail.gmail.com \
    --to=leon.woestenberg@gmail.com \
    --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

all inboxes | Powered by JetHome®