From: David Jander <david@protonic.nl>
To: Mark Brown <broonie@kernel.org>
Cc: linux-spi@vger.kernel.org, Andrew Lunn <andrew@lunn.ch>,
Marc Kleine-Budde <mkl@pengutronix.de>,
Oleksij Rempel <o.rempel@pengutronix.de>
Subject: Re: [RFC] [PATCH 3/3] drivers: spi: spi.c: Don't use the message queue if possible in spi_sync
Date: Fri, 10 Jun 2022 09:27:53 +0200 [thread overview]
Message-ID: <20220610092753.6e6c9e59@erd992> (raw)
In-Reply-To: <YqIgXDZAHPAQ1Y4O@sirena.org.uk>
On Thu, 9 Jun 2022 17:31:24 +0100
Mark Brown <broonie@kernel.org> wrote:
> On Thu, Jun 09, 2022 at 05:34:21PM +0200, David Jander wrote:
> > Mark Brown <broonie@kernel.org> wrote:
> > > On Wed, Jun 08, 2022 at 09:54:09AM +0200, David Jander wrote:
> > > > Mark Brown <broonie@kernel.org> wrote:
>
> > > I think the rest of it is fine or at least I'm finding it difficult to
> > > see anything beyond the concurrency issues. I think we need to do an
> > > audit to find any users that are doing a spi_sync() to complete a
> > > sequence of spi_async() operations but I'm not aware of any and if it
> > > delivers the performance benefits it's probably worth changing that
> > > aspect of the driver API.
>
> > I just discovered a different issue (hit upon by Oleksij Rempel while
> > assisting with testing):
>
> > Apparently some drivers tend to rely on the fact that master->cur_msg is not
> > NULL and always points to the message being transferred.
> > This could be a show-stopper to this patch set, if it cannot be solved.
> > I am currently analyzing the different cases, to see if and how they could
> > eventually get fixed. The crux of the issue is the fact that there are two
> > different API's towards the driver:
>
> That seems resolvable? If we have two things actually handling a
> message at once then we're in for a bad time so we should be able to
> arrange for cur_msg to be set in the sync path - the usage in the
> message pump between popping off the queue and getting to actually
> starting the transfer could be a local variable with the changes to the
> sync path I think?
Ok, I first thought that this wouldn't be possible without taking the
necessary spinlock, but looking a little closer, I think I understand now.
One question to confirm I understand the code correctly:
An SPI driver that implements its own transfer_one_message() is required to
_always_ call spi_finalize_current_message() _before_ returning, right?
If this is a guarantee and we take the io_mutex at the beginning of
__spi_pump_messages(), then ctlr->cur_msg is only manipulated with the
io_mutex held, and that would make it safe to be used in the sync path, which
is also behind the io_mutex.
Would appreciate if you could confirm this, just to be sure I understand the
code correctly.
The fact that spi_finalize_current_message() is a separate API function, and
not called directly from __spi_pump_messages() had me confused that it might
be called in a different context (from IRQ thread or something like that)
possibly after __spi_pump_messages() had already returned. But that doesn't
make much sense... right?
> > 1. transfer_one(): This call does not provide a reference to the message that
> > contains the transfers. So all information stored only in the underlying
> > spi_message are not accessible to the driver. Apparently some work around
> > this by accessing master->cur_msg.
>
> > 2. transfer_one_message(): I suspect this is a newer API. It takes the
> > spi_message as argument, thus giving the driver access to all information it
> > needs (like return status, and the complete list of transfers).
>
> It's the other way around - transfer_one() is the result of providing a
> transfer_one_message() which factors out more of the code given that a
> huge proportion of drivers are for hardware which works at the transfer
> level and doesn't understand messages, just as transfer_one_message()
> and the message queue are factoring out code which was originally open
> coded in drivers.
Ah, thanks for the context. This makes sense or course.
Best regards,
--
David Jander
next prev parent reply other threads:[~2022-06-10 7:28 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-05-25 14:29 [RFC] [PATCH 0/3] Optimize spi_sync path David Jander
2022-05-25 14:29 ` [RFC] [PATCH 1/3] drivers: spi: API: spi_finalize_current_message -> spi_finalize_message David Jander
2022-05-25 14:29 ` [RFC] [PATCH 2/3] drivers: spi: spi.c: Move ctlr->cur_msg_prepared to struct spi_message David Jander
2022-05-25 14:29 ` [RFC] [PATCH 3/3] drivers: spi: spi.c: Don't use the message queue if possible in spi_sync David Jander
2022-05-25 14:46 ` David Jander
2022-06-07 18:30 ` Mark Brown
2022-06-08 7:54 ` David Jander
2022-06-08 11:29 ` Mark Brown
2022-06-09 15:34 ` David Jander
2022-06-09 16:31 ` Mark Brown
2022-06-10 7:27 ` David Jander [this message]
2022-06-10 13:41 ` Mark Brown
2022-06-10 18:17 ` Mark Brown
2022-06-13 9:05 ` David Jander
2022-06-13 11:56 ` Mark Brown
2022-07-15 7:47 ` Thomas Kopp
2022-07-15 9:02 ` Thomas Kopp
2022-06-08 13:43 ` Andy Shevchenko
2022-06-08 14:55 ` David Jander
2022-05-30 12:06 ` [RFC] [PATCH 0/3] Optimize spi_sync path Mark Brown
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=20220610092753.6e6c9e59@erd992 \
--to=david@protonic.nl \
--cc=andrew@lunn.ch \
--cc=broonie@kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=mkl@pengutronix.de \
--cc=o.rempel@pengutronix.de \
/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).