mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-26 05:34:13 +08:00
f7da7782ab
If IRQ handlers are threaded (either because CONFIG_PREEMPT_RT_BASE is
enabled or "threadirqs" was passed on the command line) and if system
load is sufficiently high that wakeup latency of IRQ threads degrades,
SPI DMA transactions on the BCM2835 occasionally break like this:
ks8851 spi0.0: SPI transfer timed out
bcm2835-dma 3f007000.dma: DMA transfer could not be terminated
ks8851 spi0.0 eth2: ks8851_rdfifo: spi_sync() failed
The root cause is an assumption made by the DMA driver which is
documented in a code comment in bcm2835_dma_terminate_all():
/*
* Stop DMA activity: we assume the callback will not be called
* after bcm_dma_abort() returns (even if it does, it will see
* c->desc is NULL and exit.)
*/
That assumption falls apart if the IRQ handler bcm2835_dma_callback() is
threaded: A client may terminate a descriptor and issue a new one
before the IRQ handler had a chance to run. In fact the IRQ handler may
miss an *arbitrary* number of descriptors. The result is the following
race condition:
1. A descriptor finishes, its interrupt is deferred to the IRQ thread.
2. A client calls dma_terminate_async() which sets channel->desc = NULL.
3. The client issues a new descriptor. Because channel->desc is NULL,
bcm2835_dma_issue_pending() immediately starts the descriptor.
4. Finally the IRQ thread runs and writes BCM2835_DMA_INT to the CS
register to acknowledge the interrupt. This clears the ACTIVE flag,
so the newly issued descriptor is paused in the middle of the
transaction. Because channel->desc is not NULL, the IRQ thread
finalizes the descriptor and tries to start the next one.
I see two possible solutions: The first is to call synchronize_irq()
in bcm2835_dma_issue_pending() to wait until the IRQ thread has
finished before issuing a new descriptor. The downside of this approach
is unnecessary latency if clients desire rapidly terminating and
re-issuing descriptors and don't have any use for an IRQ callback.
(The SPI TX DMA channel is a case in point.)
A better alternative is to make the IRQ thread recognize that it has
missed descriptors and avoid finalizing the newly issued descriptor.
So first of all, set the ACTIVE flag when acknowledging the interrupt.
This keeps a newly issued descriptor running.
If the descriptor was finished, the channel remains idle despite the
ACTIVE flag being set. However the ACTIVE flag can then no longer be
used to check whether the channel is idle, so instead check whether
the register containing the current control block address is zero
and finalize the current descriptor only if so.
That way, there is no impact on latency and throughput if the client
doesn't care for the interrupt: Only minimal additional overhead is
introduced for non-cyclic descriptors as one further MMIO read is
necessary per interrupt to check for idleness of the channel. Cyclic
descriptors are sped up slightly by removing one MMIO write per
interrupt.
Fixes:
|
||
---|---|---|
.. | ||
bestcomm | ||
dw | ||
dw-axi-dmac | ||
hsu | ||
ioat | ||
ipu | ||
mediatek | ||
ppc4xx | ||
qcom | ||
sh | ||
ti | ||
xilinx | ||
acpi-dma.c | ||
altera-msgdma.c | ||
amba-pl08x.c | ||
at_hdmac_regs.h | ||
at_hdmac.c | ||
at_xdmac.c | ||
bcm2835-dma.c | ||
bcm-sba-raid.c | ||
coh901318_lli.c | ||
coh901318.c | ||
coh901318.h | ||
dma-axi-dmac.c | ||
dma-jz4740.c | ||
dma-jz4780.c | ||
dmaengine.c | ||
dmaengine.h | ||
dmatest.c | ||
ep93xx_dma.c | ||
fsl_raid.c | ||
fsl_raid.h | ||
fsl-edma-common.c | ||
fsl-edma-common.h | ||
fsl-edma.c | ||
fsldma.c | ||
fsldma.h | ||
idma64.c | ||
idma64.h | ||
img-mdc-dma.c | ||
imx-dma.c | ||
imx-sdma.c | ||
iop-adma.c | ||
k3dma.c | ||
Kconfig | ||
lpc18xx-dmamux.c | ||
Makefile | ||
mcf-edma.c | ||
mic_x100_dma.c | ||
mic_x100_dma.h | ||
mmp_pdma.c | ||
mmp_tdma.c | ||
moxart-dma.c | ||
mpc512x_dma.c | ||
mv_xor_v2.c | ||
mv_xor.c | ||
mv_xor.h | ||
mxs-dma.c | ||
nbpfaxi.c | ||
of-dma.c | ||
owl-dma.c | ||
pch_dma.c | ||
pl330.c | ||
pxa_dma.c | ||
s3c24xx-dma.c | ||
sa11x0-dma.c | ||
sirf-dma.c | ||
sprd-dma.c | ||
st_fdma.c | ||
st_fdma.h | ||
ste_dma40_ll.c | ||
ste_dma40_ll.h | ||
ste_dma40.c | ||
stm32-dma.c | ||
stm32-dmamux.c | ||
stm32-mdma.c | ||
sun4i-dma.c | ||
sun6i-dma.c | ||
tegra20-apb-dma.c | ||
tegra210-adma.c | ||
timb_dma.c | ||
TODO | ||
txx9dmac.c | ||
txx9dmac.h | ||
uniphier-mdmac.c | ||
virt-dma.c | ||
virt-dma.h | ||
xgene-dma.c | ||
zx_dma.c |