Skip to content

Commit ea8be08

Browse files
Marek Vasutbroonie
authored andcommitted
spi: stm32: Rate-limit the 'Communication suspended' message
The 'spi_stm32 44004000.spi: Communication suspended' message means that when using PIO, the kernel did not read the FIFO fast enough and so the SPI controller paused the transfer. Currently, this is printed on every single such event, so if the kernel is busy and the controller is pausing the transfers often, the kernel will be all the more busy scrolling this message into the log buffer every few milliseconds. That is not helpful. Instead, rate-limit the message and print it every once in a while. It is not possible to use the default dev_warn_ratelimited(), because that is still too verbose, as it prints 10 lines (DEFAULT_RATELIMIT_BURST) every 5 seconds (DEFAULT_RATELIMIT_INTERVAL). The policy here is to print 1 line every 50 seconds (DEFAULT_RATELIMIT_INTERVAL * 10), because 1 line is more than enough and the cycles saved on printing are better left to the CPU to handle the SPI. However, dev_warn_once() is also not useful, as the user should be aware that this condition is possibly recurring or ongoing. Thus the custom rate-limit policy. Finally, turn the message from dev_warn() to dev_dbg(), since the system does not suffer any sort of malfunction if this message appears, it is just slowing down. This further reduces the printing into the log buffer and frees the CPU to do useful work. Fixes: dcbe0d8 ("spi: add driver for STM32 SPI controller") Signed-off-by: Marek Vasut <marex@denx.de> Cc: Alexandre Torgue <alexandre.torgue@st.com> Cc: Amelie Delaunay <amelie.delaunay@st.com> Cc: Antonio Borneo <borneo.antonio@gmail.com> Cc: Mark Brown <broonie@kernel.org> Link: https://lore.kernel.org/r/20200905151913.117775-1-marex@denx.de Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 837ba18 commit ea8be08

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

drivers/spi/spi-stm32.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,11 @@ static irqreturn_t stm32h7_spi_irq_thread(int irq, void *dev_id)
936936
}
937937

938938
if (sr & STM32H7_SPI_SR_SUSP) {
939-
dev_warn(spi->dev, "Communication suspended\n");
939+
static DEFINE_RATELIMIT_STATE(rs,
940+
DEFAULT_RATELIMIT_INTERVAL * 10,
941+
1);
942+
if (__ratelimit(&rs))
943+
dev_dbg_ratelimited(spi->dev, "Communication suspended\n");
940944
if (!spi->cur_usedma && (spi->rx_buf && (spi->rx_len > 0)))
941945
stm32h7_spi_read_rxfifo(spi, false);
942946
/*

0 commit comments

Comments
 (0)