linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Jan Kundrát" <jan.kundrat@cesnet.cz>
To: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Cc: <linux-spi@vger.kernel.org>, Mark Brown <broonie@kernel.org>
Subject: Re: High CPU load when using MAX14830 SPI UART controller
Date: Wed, 20 May 2020 12:44:43 +0200	[thread overview]
Message-ID: <4c5c972b-c8b8-4326-a1f9-438d88217a4a@cesnet.cz> (raw)
In-Reply-To: <20200519163353.20c03286@windsurf.home>

> With the sending of 20 bytes data frames every 16 ms, it means data is
> send ~62.5 per seconds.
>
> Looking at /proc/interrupts, I get ~260 interrupts per second on the
> MAX14830, which means that the "batch reading" implemented in
> 2b4bac48c10848ccffd484e7cd025dc085c1bd32 is effective but not to the
> point where I have a single interrupt per received frame.

Hi,
I was getting something similar when I first wrote that patch. The TL;DR 
version is that even though this UART has 128 byte FIFO per each direction 
of each UART, I wanted my patch to stay conservative and only batch reads 
in an opportunistic manner -- I wanted not to risk a possible RX FIFO 
overflow. That's why the IRQ handler is eager to trigger as soon as there 
are some data in the RX FIFO. Our setup has no HW flow control (no RTS/CTS, 
no software flow control), so one has to hope that the IRQ latency is low 
enough...

The MAX14830 supports also another mode of operation where the interrupt 
fires only when the RX buffer gets filled over a configurable minimal 
threshold. This can be combined with yet another interrupt which fires 
whenever there's some data in the RX FIFO for "too long". Unfortunately, 
this timer starts over again upon reception of any additional data, so it's 
the *youngest* byte in the RX FIFO that controls triggering of this delayed 
interrupt.

I am not sure how to balance the latency ("how soon is userspace notified 
about this byte") with CPU utilization ("don't read data byte-by-byte from 
this 128 byte buffer"). If there's some cross-driver support for "something 
like that" in the TTY layer, I'm sure that max310x.c could be adopted to 
make use of that. Otherwise, we could always add a pair of DT properties 
for controling:

a) the "start reading from RX FIFO" timeout,
b) "allow up to X bytes in the RX FIFO, I know that my platform has enough 
CPU and SPI bandwidth to finish reading that before the RX FIFO overflows"

BTW, there are also real SPI bus throughput limitations, see 
2258761213cb239e5e6c11b4ec9b1700fcb4fdcd for some numbers from my platform. 
The chip supports up to 26 MHz (but not all bus masters have clock 
granularities fine enough to use this), that's 3.25 MBps of raw throughput 
divided among four UARTs. Reading each register takes at least two bytes, 
one has to check the top-level IRQ status register (to decide which UART to 
check), then read per-UART IRQ registers, and only then start reading the 
data. Also, batched reading can only happen if userspace explicitly ignores 
framing errors, parity errors, etc, otherwise the driver will have to read 
byte-by-byte, and check the line status register, etc.

Anyway, I'll be happy to review and test any patches you might have; we're 
using these chips and we are interested in their performance and error-free 
operation.

With kind regards,
Jan

  parent reply	other threads:[~2020-05-20 10:54 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-19 14:33 High CPU load when using MAX14830 SPI UART controller Thomas Petazzoni
2020-05-19 15:24 ` Mark Brown
2020-05-20 10:18   ` Thomas Petazzoni
2020-05-20 11:26     ` Mark Brown
2020-07-21 13:39       ` Thomas Petazzoni
2020-07-21 22:30         ` Mark Brown
2020-05-20 10:44 ` Jan Kundrát [this message]
2020-07-21 13:51   ` Thomas Petazzoni
2020-07-21 14:20     ` Jan Kundrát
2020-07-21 21:49       ` Andy Shevchenko
2020-07-28  8:22       ` Thomas Petazzoni

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=4c5c972b-c8b8-4326-a1f9-438d88217a4a@cesnet.cz \
    --to=jan.kundrat@cesnet.cz \
    --cc=broonie@kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=thomas.petazzoni@bootlin.com \
    /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).