spi: opportunistically skip ctlr->cur_msg_completion
authorDavid Jander <david@protonic.nl>
Tue, 21 Jun 2022 06:12:34 +0000 (08:12 +0200)
committerMark Brown <broonie@kernel.org>
Mon, 27 Jun 2022 12:27:26 +0000 (13:27 +0100)
commitdc3029056b02414c29b6627e3dd7b16624725ae9
tree64225ab8af02e3275de5a0bb8bbf358d1a240680
parent69fa95905d40846756d22402690ddf5361a9d13b
spi: opportunistically skip ctlr->cur_msg_completion

There are only a few drivers that do not call
spi_finalize_current_message() in the context of transfer_one_message(),
and even for those cases the completion ctlr->cur_msg_completion is not
needed always. The calls to complete() and wait_for_completion() each
take a spin-lock, which is costly. This patch makes it possible to avoid
those calls in the big majority of cases, by introducing two flags that
with the help of ordering via barriers can avoid using the completion
safely. In case of a race with the context calling
spi_finalize_current_message(), the scheme errs on the safe side and takes
the completion.
The impact of this patch is worth the effort: On a i.MX8MM SoC, the time
the SPI bus is idle between two consecutive calls to spi_sync(), is
reduced from 19.6us to 16.8us... roughly 15%.

Signed-off-by: David Jander <david@protonic.nl>
Link: https://lore.kernel.org/r/20220621061234.3626638-12-david@protonic.nl
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi.c
include/linux/spi/spi.h