From: Arnd Bergmann <arnd@arndb.de>
To: Ulf Hansson <ulf.hansson@linaro.org>
Cc: David Daney <ddaney@caviumnetworks.com>,
Matt Redfearn <matt.redfearn@imgtec.com>,
linux-mmc <linux-mmc@vger.kernel.org>,
Aleksey Makarov <aleksey.makarov@caviumnetworks.com>,
Chandrakala Chavva <cchavva@caviumnetworks.com>,
David Daney <david.daney@cavium.com>,
Aleksey Makarov <aleksey.makarov@auriga.com>,
Leonid Rosenboim <lrosenboim@caviumnetworks.com>,
Peter Swain <pswain@cavium.com>,
Aaron Williams <aaron.williams@cavium.com>
Subject: Re: [RESEND PATCH v7 2/2] mmc: OCTEON: Add host driver for OCTEON MMC controller
Date: Thu, 21 Apr 2016 15:19:31 +0200 [thread overview]
Message-ID: <4611130.vJzBsRp8Hx@wuerfel> (raw)
In-Reply-To: <CAPDyKFpM4P8LrAnVB5kRxWrgEfPS7iTtF=YBeKuyvSM=O-KF8w@mail.gmail.com>
On Thursday 21 April 2016 14:44:08 Ulf Hansson wrote:
> [...]
>
> >> So the question I have is *why* do you have to be in IRQ context when
> >> using the semaphore...
> >>
> >> I would rather see that you use a threaded IRQ handler, perhaps in
> >> conjunction with a hard IRQ handler if that is needed.
> >
> > That does not solve the problem though: it is not allowed for a mutex
> > to be taken in the request function but released in the interrupt,
> > both have to be in the same thread.
> >
> > Using a threaded IRQ handler would help by avoiding the spinlock
> > inside of it (it could be replaced with a mutex there), but it
> > doesn't solve the problem of serializing between the slots.
>
> My point is, the may not need to be released in the IRQ handler, but
> instead in the threaded IRQ handler.
That doesn't change anything.
> >> Although to clarify a bit more, the mmc core invokes *all* mmc host
> >> ops callbacks from non-atomic context.
> >
> > Oh, so you mean the .request() function must not sleep and cannot
> > call mutex_lock() or down() or wait_event()?
>
> No.
>
> *non-atomic* context. :-)
>
> I should probably said thread/process context instead.
>
My mistake, you were being clear enough here, I just misread.
> >> In the ->request() callback:
> >> ....
> >> mutex_lock()
> >> In the threaded IRQ handler:
> >> ...
> >> mutex_unlock()
> >>
> >> Do you think something along these lines should work for your case?
> >
> > This is the case I described above, it is against the rules for mutexes()
> > and you will get a lockdep warning if you attempt this.
>
> No.
>
> Considering my comments in this reply, can you please re-think and see
> if my solution could make sense?
The problem is not that mutex_unlock() has to be called from non-atomic
context (it doesn't, you are allowed to call mutex_unlock while holding
a spinlock), but instead the problem is that it has to be done from the
same thread that called mutex_lock(), and the threaded IRQ handler
is never the same thread that is currently holding the mutex.
My suggestion with using
wait_event(host->wq, !cmpxchg(host->current_req, NULL, mrq));
should sufficiently solve the problem, but the suggestion of using
a kthread (even though not needed for taking a mutex) would still
have some advantages and one disadvantage:
+ We never need to spin in the irq context (also achievable using
a threaded handler)
+ The request callback always returns immediately after queuing up
the request to the kthread, rather than blocking for a potentially
long time while waiting for an operation in another slot to complete
+ it very easily avoids the problem of serialization between
the slots, and ensures that each slot gets an equal chance to
send the next request.
- you get a slightly higher latency for waking up the kthread in
oder to do a simple request (comparable amount of latency that
is introduced by an irq thread).
Arnd
next prev parent reply other threads:[~2016-04-21 13:20 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-31 15:26 [RESEND PATCH v7 1/2] mmc: OCTEON: Add DT bindings for OCTEON MMC controller Matt Redfearn
2016-03-31 15:26 ` [RESEND PATCH v7 2/2] mmc: OCTEON: Add host driver " Matt Redfearn
2016-04-19 20:46 ` Arnd Bergmann
2016-04-19 21:45 ` David Daney
2016-04-19 22:09 ` Arnd Bergmann
2016-04-19 23:27 ` David Daney
2016-04-19 23:57 ` Arnd Bergmann
2016-04-20 0:02 ` Arnd Bergmann
2016-04-21 8:02 ` Ulf Hansson
2016-04-21 10:15 ` Arnd Bergmann
2016-04-21 12:44 ` Ulf Hansson
2016-04-21 13:19 ` Arnd Bergmann [this message]
2016-04-22 13:54 ` Ulf Hansson
2016-04-22 16:42 ` Arnd Bergmann
2016-04-22 17:49 ` David Daney
2016-04-22 20:23 ` Arnd Bergmann
2016-04-14 12:45 ` [RESEND PATCH v7 1/2] mmc: OCTEON: Add DT bindings " Ulf Hansson
2016-04-18 8:53 ` Matt Redfearn
2016-04-18 11:13 ` Ulf Hansson
2016-04-18 11:37 ` Matt Redfearn
2016-04-18 12:08 ` Ulf Hansson
2016-04-18 12:57 ` Matt Redfearn
2016-04-18 22:59 ` David Daney
2016-04-19 9:15 ` Ulf Hansson
2016-04-19 16:13 ` David Daney
2016-04-19 19:33 ` Ulf Hansson
2016-04-19 20:25 ` David Daney
2016-04-19 20:56 ` Arnd Bergmann
2016-04-19 21:50 ` David Daney
2016-04-20 9:32 ` Ulf Hansson
2016-04-20 22:32 ` David Daney
2016-04-20 22:42 ` Arnd Bergmann
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=4611130.vJzBsRp8Hx@wuerfel \
--to=arnd@arndb.de \
--cc=aaron.williams@cavium.com \
--cc=aleksey.makarov@auriga.com \
--cc=aleksey.makarov@caviumnetworks.com \
--cc=cchavva@caviumnetworks.com \
--cc=david.daney@cavium.com \
--cc=ddaney@caviumnetworks.com \
--cc=linux-mmc@vger.kernel.org \
--cc=lrosenboim@caviumnetworks.com \
--cc=matt.redfearn@imgtec.com \
--cc=pswain@cavium.com \
--cc=ulf.hansson@linaro.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