All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Brown <broonie@kernel.org>
To: David Jander <david@protonic.nl>
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 19:17:22 +0100	[thread overview]
Message-ID: <YqOKsumo2aXgCvFB@sirena.org.uk> (raw)
In-Reply-To: <YqNKCegdejr522lH@sirena.org.uk>

[-- Attachment #1: Type: text/plain, Size: 2420 bytes --]

On Fri, Jun 10, 2022 at 02:41:34PM +0100, Mark Brown wrote:
> On Fri, Jun 10, 2022 at 09:27:53AM +0200, David Jander wrote:
> > Mark Brown <broonie@kernel.org> wrote:

> > 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?

> Yes, it should.

Sorry, my mistake - I misremembered how that worked.  They might return
without having completed the message since the message pump is a
workqueue so it'll just go idle, spi_sync() will work because the caller
will block on the completion in the message.  It's cur_msg that's
stopping any new work being scheduled.  I was confusing this with the
handling of individual transfers, it's been a while since I got deep
into this.

The bit about allowing us to finalise in any context still applies - the
goal with that interface is to avoid the need to context switch back to
the message pump to report that the message completed, and ideally
immediately start work on the next message if the controller can cope
with that.

> > 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.

> I think that should work.  If there's something missed it should be
> possible to make things work that way.

Can we move the cleanup of cur_msg out of spi_finalize_current_message()
and into the context holding the io_mutex with that blocking on a
completion?  Don't know what the overhead of that is like, I think it
should be fine for the case where we don't actually block on the
completion and it shouldn't be any worse in the case where we're
completing in the interrupt.  Also the kthread_queue_work() that's in
there could be moved out to only the queued case since with your new
approach for spi_sync() we'll idle the hardware in the calling context
and don't need to schedule the thread at all, that should save some
overhead.

Sorry about misremembering this bit.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2022-06-10 18:17 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
2022-06-10 13:41                 ` Mark Brown
2022-06-10 18:17                   ` Mark Brown [this message]
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=YqOKsumo2aXgCvFB@sirena.org.uk \
    --to=broonie@kernel.org \
    --cc=andrew@lunn.ch \
    --cc=david@protonic.nl \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.