dmaengine: virt-dma: convert tasklet to BH workqueue for callback invocation
Subsystems (30)
cover dmaengine: virt-dma: convert tasklet to BH workqueue for callback invocation
Hello!
I have Pine64 (Allwinner A64 ARMv8) board.
I've migrated from 5.4 kernel to 6.12 and noticed that DMA callback latencies became very high. I noticed that sometimes callbacks get called from ksoftirqd thread and in that case latencies are about 10 ms.
I found out that tasklet bacame deprecated and decided to rewrite DMA callback code to use BH workqueue. In my case, that fixed high latencies.
My change affects a lot of drivers, but the change is trivial. I've verified that affected drivers compile after change. But I cannot test it on all platforms.
Alexander Kochetkov (1):
dmaengine: virt-dma: convert tasklet to BH workqueue for callback
invocation
drivers/dma/amd/qdma/qdma.c | 1 + drivers/dma/arm-dma350.c | 1 + drivers/dma/bcm2835-dma.c | 2 +- drivers/dma/dma-axi-dmac.c | 8 ++++---- drivers/dma/dma-jz4780.c | 2 +- drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c | 2 +- drivers/dma/dw-edma/dw-edma-core.c | 2 +- drivers/dma/fsl-edma-common.c | 2 +- drivers/dma/fsl-edma-common.h | 1 + drivers/dma/fsl-qdma.c | 3 ++- drivers/dma/hisi_dma.c | 2 +- drivers/dma/hsu/hsu.c | 2 +- drivers/dma/idma64.c | 3 ++- drivers/dma/img-mdc-dma.c | 2 +- drivers/dma/imx-sdma.c | 2 +- drivers/dma/k3dma.c | 2 +- drivers/dma/loongson1-apb-dma.c | 2 +- drivers/dma/mediatek/mtk-cqdma.c | 2 +- drivers/dma/mediatek/mtk-hsdma.c | 3 ++- drivers/dma/mediatek/mtk-uart-apdma.c | 4 ++-- drivers/dma/owl-dma.c | 2 +- drivers/dma/pxa_dma.c | 2 +- drivers/dma/qcom/bam_dma.c | 4 ++-- drivers/dma/qcom/gpi.c | 1 + drivers/dma/qcom/qcom_adm.c | 2 +- drivers/dma/sa11x0-dma.c | 2 +- drivers/dma/sf-pdma/sf-pdma.c | 3 ++- drivers/dma/sprd-dma.c | 2 +- drivers/dma/st_fdma.c | 2 +- drivers/dma/stm32/stm32-dma.c | 1 + drivers/dma/stm32/stm32-dma3.c | 1 + drivers/dma/stm32/stm32-mdma.c | 1 + drivers/dma/sun6i-dma.c | 2 +- drivers/dma/tegra186-gpc-dma.c | 2 +- drivers/dma/tegra210-adma.c | 3 ++- drivers/dma/ti/edma.c | 2 +- drivers/dma/ti/k3-udma.c | 10 +++++----- drivers/dma/ti/omap-dma.c | 2 +- drivers/dma/uniphier-xdmac.c | 1 + drivers/dma/virt-dma.c | 6 +++--- drivers/dma/virt-dma.h | 10 +++++----- 41 files changed, 61 insertions(+), 48 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/1 dmaengine: virt-dma: convert tasklet to BH workqueue for callback invocation
Currently DMA callbacks are called from tasklet. However the tasklet is marked deprecated and must be replaced by BH workqueue. Tasklet callbacks are executed either in the Soft IRQ context or from ksoftirqd thread. BH workqueue work items are executed in the BH context. Changing tasklet to BH workqueue improved DMA callback latencies.
The commit changes virt-dma driver and all of its users:
- tasklet is replaced to work_struct, tasklet callback updated accordingly
- kill_tasklet() is replaced to cancel_work_sync()
- added include of linux/interrupt.h where necessary
Tested on Pine64 (Allwinner A64 ARMv8) with sun6i-dma driver. All other drivers are changed similarly and tested for compilation.
--- drivers/dma/amd/qdma/qdma.c | 1 + drivers/dma/arm-dma350.c | 1 + drivers/dma/bcm2835-dma.c | 2 +- drivers/dma/dma-axi-dmac.c | 8 ++++---- drivers/dma/dma-jz4780.c | 2 +- drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c | 2 +- drivers/dma/dw-edma/dw-edma-core.c | 2 +- drivers/dma/fsl-edma-common.c | 2 +- drivers/dma/fsl-edma-common.h | 1 + drivers/dma/fsl-qdma.c | 3 ++- drivers/dma/hisi_dma.c | 2 +- drivers/dma/hsu/hsu.c | 2 +- drivers/dma/idma64.c | 3 ++- drivers/dma/img-mdc-dma.c | 2 +- drivers/dma/imx-sdma.c | 2 +- drivers/dma/k3dma.c | 2 +- drivers/dma/loongson1-apb-dma.c | 2 +- drivers/dma/mediatek/mtk-cqdma.c | 2 +- drivers/dma/mediatek/mtk-hsdma.c | 3 ++- drivers/dma/mediatek/mtk-uart-apdma.c | 4 ++-- drivers/dma/owl-dma.c | 2 +- drivers/dma/pxa_dma.c | 2 +- drivers/dma/qcom/bam_dma.c | 4 ++-- drivers/dma/qcom/gpi.c | 1 + drivers/dma/qcom/qcom_adm.c | 2 +- drivers/dma/sa11x0-dma.c | 2 +- drivers/dma/sf-pdma/sf-pdma.c | 3 ++- drivers/dma/sprd-dma.c | 2 +- drivers/dma/st_fdma.c | 2 +- drivers/dma/stm32/stm32-dma.c | 1 + drivers/dma/stm32/stm32-dma3.c | 1 + drivers/dma/stm32/stm32-mdma.c | 1 + drivers/dma/sun6i-dma.c | 2 +- drivers/dma/tegra186-gpc-dma.c | 2 +- drivers/dma/tegra210-adma.c | 3 ++- drivers/dma/ti/edma.c | 2 +- drivers/dma/ti/k3-udma.c | 10 +++++----- drivers/dma/ti/omap-dma.c | 2 +- drivers/dma/uniphier-xdmac.c | 1 + drivers/dma/virt-dma.c | 6 +++--- drivers/dma/virt-dma.h | 10 +++++----- 41 files changed, 61 insertions(+), 48 deletions(-)
drivers/dma/amd/qdma/qdma.c +1 -0
@@ -13,6 +13,7 @@#include <linux/platform_device.h> #include <linux/platform_data/amd_qdma.h> #include <linux/regmap.h> +#include <linux/interrupt.h> #include "qdma.h"
drivers/dma/arm-dma350.c +1 -0
@@ -6,6 +6,7 @@#include <linux/dmaengine.h> #include <linux/dma-mapping.h> #include <linux/io.h> +#include <linux/interrupt.h> #include <linux/of.h> #include <linux/module.h> #include <linux/platform_device.h>
drivers/dma/bcm2835-dma.c +1 -1
@@ -846,7 +846,7 @@ static void bcm2835_dma_free(struct bcm2835_dmadev *od)list_for_each_entry_safe (c, next, &od->ddev.channels, vc.chan.device_node) {list_del (&c->vc.chan.device_node); -tasklet_kill (&c->vc.task); +cancel_work_sync (&c->vc.work); } dma_unmap_page_attrs(od->ddev.dev, od->zero_page, PAGE_SIZE,
drivers/dma/dma-axi-dmac.c +4 -4
@@ -1041,9 +1041,9 @@ static int axi_dmac_detect_caps(struct axi_dmac *dmac, unsigned int version)return 0 ; } -static void axi_dmac_tasklet_kill (void *task) +static void axi_dmac_cancel_work_sync (void *work) { -tasklet_kill (task); +cancel_work_sync (work); }static void axi_dmac_free_dma_controller (void *of_node)
@@ -1146,8 +1146,8 @@ static int axi_dmac_probe(struct platform_device *pdev)* Put the action in here so it get's done before unregistering the DMA * device. */ - ret =devm_add_action_or_reset (&pdev->dev, axi_dmac_tasklet_kill, - &dmac->chan.vchan.task); + ret =devm_add_action_or_reset (&pdev->dev, axi_dmac_cancel_work_sync, + &dmac->chan.vchan.work);if (ret)return ret;
drivers/dma/dma-jz4780.c +1 -1
@@ -1019,7 +1019,7 @@ static void jz4780_dma_remove(struct platform_device *pdev)free_irq (jzdma->irq, jzdma);for (i =0 ; i < jzdma->soc_data->nb_channels; i++) -tasklet_kill (&jzdma->chan[i].vchan.task); +cancel_work_sync (&jzdma->chan[i].vchan.work); }static const struct jz4780_dma_soc_data jz4740_dma_soc_data = {
drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c +1 -1
@@ -1649,7 +1649,7 @@ static void dw_remove(struct platform_device *pdev)list_for_each_entry_safe (chan, _chan, &dw->dma.channels, vc.chan.device_node) {list_del (&chan->vc.chan.device_node); -tasklet_kill (&chan->vc.task); +cancel_work_sync (&chan->vc.work); } }
drivers/dma/dw-edma/dw-edma-core.c +1 -1
@@ -1005,7 +1005,7 @@ int dw_edma_remove(struct dw_edma_chip *chip)dma_async_device_unregister (&dw->dma);list_for_each_entry_safe (chan, _chan, &dw->dma.channels, vc.chan.device_node) { -tasklet_kill (&chan->vc.task); +cancel_work_sync (&chan->vc.work);list_del (&chan->vc.chan.device_node); }
drivers/dma/fsl-edma-common.c +1 -1
@@ -894,7 +894,7 @@ void fsl_edma_cleanup_vchan(struct dma_device *dmadev)list_for_each_entry_safe (chan, _chan, &dmadev->channels, vchan.chan.device_node) {list_del (&chan->vchan.chan.device_node); -tasklet_kill (&chan->vchan.task); +cancel_work_sync (&chan->vchan.work); } }
drivers/dma/fsl-edma-common.h +1 -0
@@ -8,6 +8,7 @@#include <linux/dma-direction.h> #include <linux/platform_device.h> +#include <linux/interrupt.h> #include "virt-dma.h" #define EDMA_CR_EDBG BIT(1)
drivers/dma/fsl-qdma.c +2 -1
@@ -17,6 +17,7 @@#include <linux/of_dma.h> #include <linux/dma-mapping.h> #include <linux/platform_device.h> +#include <linux/interrupt.h> #include "virt-dma.h" #include "fsldma.h"
@@ -1261,7 +1262,7 @@ static void fsl_qdma_cleanup_vchan(struct dma_device *dmadev)list_for_each_entry_safe (chan, _chan, &dmadev->channels, vchan.chan.device_node) {list_del (&chan->vchan.chan.device_node); -tasklet_kill (&chan->vchan.task); +cancel_work_sync (&chan->vchan.work); } }
drivers/dma/hisi_dma.c +1 -1
@@ -720,7 +720,7 @@ static void hisi_dma_disable_qps(struct hisi_dma_dev *hdma_dev)for (i =0 ; i < hdma_dev->chan_num; i++) {hisi_dma_disable_qp (hdma_dev, i); -tasklet_kill (&hdma_dev->chan[i].vc.task); +cancel_work_sync (&hdma_dev->chan[i].vc.work); } }
drivers/dma/hsu/hsu.c +1 -1
@@ -500,7 +500,7 @@ int hsu_dma_remove(struct hsu_dma_chip *chip)for (i =0 ; i < hsu->nr_channels; i++) {struct hsu_dma_chan *hsuc = &hsu->chan[i]; -tasklet_kill (&hsuc->vchan.task); +cancel_work_sync (&hsuc->vchan.work); }return 0 ;
drivers/dma/idma64.c +2 -1
@@ -15,6 +15,7 @@#include <linux/module.h> #include <linux/platform_device.h> #include <linux/slab.h> +#include <linux/interrupt.h> #include <linux/dma/idma64.h>
@@ -624,7 +625,7 @@ static void idma64_remove(struct idma64_chip *chip)for (i =0 ; i < idma64->dma.chancnt; i++) {struct idma64_chan *idma64c = &idma64->chan[i]; -tasklet_kill (&idma64c->vchan.task); +cancel_work_sync (&idma64c->vchan.work); } }
drivers/dma/img-mdc-dma.c +1 -1
@@ -1031,7 +1031,7 @@ static void mdc_dma_remove(struct platform_device *pdev)devm_free_irq (&pdev->dev, mchan->irq, mchan); -tasklet_kill (&mchan->vc.task); +cancel_work_sync (&mchan->vc.work); }pm_runtime_disable (&pdev->dev);
drivers/dma/imx-sdma.c +1 -1
@@ -2427,7 +2427,7 @@ static void sdma_remove(struct platform_device *pdev)for (i =0 ; i <MAX_DMA_CHANNELS ; i++) {struct sdma_channel *sdmac = &sdma->channel[i]; -tasklet_kill (&sdmac->vc.task); +cancel_work_sync (&sdmac->vc.work);sdma_free_chan_resources (&sdmac->vc.chan); }
drivers/dma/k3dma.c +1 -1
@@ -981,7 +981,7 @@ static void k3_dma_remove(struct platform_device *op)list_for_each_entry_safe (c, cn, &d->slave.channels, vc.chan.device_node) {list_del (&c->vc.chan.device_node); -tasklet_kill (&c->vc.task); +cancel_work_sync (&c->vc.work); }tasklet_kill (&d->task);clk_disable_unprepare (d->clk);
drivers/dma/loongson1-apb-dma.c +1 -1
@@ -552,7 +552,7 @@ static void ls1x_dma_chan_remove(struct ls1x_dma *dma)if (chan->vc.chan.device == &dma->ddev) {list_del (&chan->vc.chan.device_node); -tasklet_kill (&chan->vc.task); +cancel_work_sync (&chan->vc.work); } } }
drivers/dma/mediatek/mtk-cqdma.c +1 -1
@@ -895,7 +895,7 @@ static void mtk_cqdma_remove(struct platform_device *pdev) vc = &cqdma->vc[i];list_del (&vc->vc.chan.device_node); -tasklet_kill (&vc->vc.task); +cancel_work_sync (&vc->vc.work); }/* disable interrupt */
drivers/dma/mediatek/mtk-hsdma.c +2 -1
@@ -22,6 +22,7 @@#include <linux/pm_runtime.h> #include <linux/refcount.h> #include <linux/slab.h> +#include <linux/interrupt.h> #include "../virt-dma.h"
@@ -1020,7 +1021,7 @@ static void mtk_hsdma_remove(struct platform_device *pdev) vc = &hsdma->vc[i];list_del (&vc->vc.chan.device_node); -tasklet_kill (&vc->vc.task); +cancel_work_sync (&vc->vc.work); }/* Disable DMA interrupt */
drivers/dma/mediatek/mtk-uart-apdma.c +2 -2
@@ -312,7 +312,7 @@ static void mtk_uart_apdma_free_chan_resources(struct dma_chan *chan)free_irq (c->irq, chan); -tasklet_kill (&c->vc.task); +cancel_work_sync (&c->vc.work);vchan_free_chan_resources (&c->vc);
@@ -463,7 +463,7 @@ static void mtk_uart_apdma_free(struct mtk_uart_apdmadev *mtkd) struct mtk_chan, vc.chan.device_node);list_del (&c->vc.chan.device_node); -tasklet_kill (&c->vc.task); +cancel_work_sync (&c->vc.work); } }
drivers/dma/owl-dma.c +1 -1
@@ -1055,7 +1055,7 @@ static inline void owl_dma_free(struct owl_dma *od)list_for_each_entry_safe (vchan, next, &od->dma.channels, vc.chan.device_node) {list_del (&vchan->vc.chan.device_node); -tasklet_kill (&vchan->vc.task); +cancel_work_sync (&vchan->vc.work); } }
drivers/dma/pxa_dma.c +1 -1
@@ -1218,7 +1218,7 @@ static void pxad_free_channels(struct dma_device *dmadev)list_for_each_entry_safe (c, cn, &dmadev->channels, vc.chan.device_node) {list_del (&c->vc.chan.device_node); -tasklet_kill (&c->vc.task); +cancel_work_sync (&c->vc.work); } }
drivers/dma/qcom/bam_dma.c +2 -2
@@ -1373,7 +1373,7 @@ static int bam_dma_probe(struct platform_device *pdev)dma_async_device_unregister (&bdev->common); err_bam_channel_exit:for (i =0 ; i < bdev->num_channels; i++) -tasklet_kill (&bdev->channels[i].vc.task); +cancel_work_sync (&bdev->channels[i].vc.work); err_tasklet_kill:tasklet_kill (&bdev->task); err_disable_clk:
@@ -1399,7 +1399,7 @@ static void bam_dma_remove(struct platform_device *pdev)for (i =0 ; i < bdev->num_channels; i++) {bam_dma_terminate_all (&bdev->channels[i].vc.chan); -tasklet_kill (&bdev->channels[i].vc.task); +cancel_work_sync (&bdev->channels[i].vc.work);if (!bdev->channels[i].fifo_virt)continue ;
drivers/dma/qcom/gpi.c +1 -0
@@ -14,6 +14,7 @@#include <linux/dma/qcom-gpi-dma.h> #include <linux/scatterlist.h> #include <linux/slab.h> +#include <linux/interrupt.h> #include "../dmaengine.h" #include "../virt-dma.h"
drivers/dma/qcom/qcom_adm.c +1 -1
@@ -919,7 +919,7 @@ static void adm_dma_remove(struct platform_device *pdev)/* mask IRQs for this channel/EE pair */ writel (0 , adev->regs +ADM_CH_RSLT_CONF (achan->id, adev->ee)); -tasklet_kill (&adev->channels[i].vc.task); +cancel_work_sync (&adev->channels[i].vc.work);adm_terminate_all (&adev->channels[i].vc.chan); }
drivers/dma/sa11x0-dma.c +1 -1
@@ -893,7 +893,7 @@ static void sa11x0_dma_free_channels(struct dma_device *dmadev)list_for_each_entry_safe (c, cn, &dmadev->channels, vc.chan.device_node) {list_del (&c->vc.chan.device_node); -tasklet_kill (&c->vc.task); +cancel_work_sync (&c->vc.work);kfree (c); } }
drivers/dma/sf-pdma/sf-pdma.c +2 -1
@@ -22,6 +22,7 @@#include <linux/of.h> #include <linux/of_dma.h> #include <linux/slab.h> +#include <linux/interrupt.h> #include "sf-pdma.h"
@@ -603,7 +604,7 @@ static void sf_pdma_remove(struct platform_device *pdev)devm_free_irq (&pdev->dev, ch->txirq, ch);devm_free_irq (&pdev->dev, ch->errirq, ch);list_del (&ch->vchan.chan.device_node); -tasklet_kill (&ch->vchan.task); +cancel_work_sync (&ch->vchan.work);tasklet_kill (&ch->done_tasklet);tasklet_kill (&ch->err_tasklet); }
drivers/dma/sprd-dma.c +1 -1
@@ -1253,7 +1253,7 @@ static void sprd_dma_remove(struct platform_device *pdev)list_for_each_entry_safe (c, cn, &sdev->dma_dev.channels, vc.chan.device_node) {list_del (&c->vc.chan.device_node); -tasklet_kill (&c->vc.task); +cancel_work_sync (&c->vc.work); }of_dma_controller_free (pdev->dev.of_node);
drivers/dma/st_fdma.c +1 -1
@@ -733,7 +733,7 @@ static void st_fdma_free(struct st_fdma_dev *fdev)for (i =0 ; i < fdev->nr_channels; i++) { fchan = &fdev->chans[i];list_del (&fchan->vchan.chan.device_node); -tasklet_kill (&fchan->vchan.task); +cancel_work_sync (&fchan->vchan.work); } }
drivers/dma/stm32/stm32-dma.c +1 -0
@@ -27,6 +27,7 @@#include <linux/reset.h> #include <linux/sched.h> #include <linux/slab.h> +#include <linux/interrupt.h> #include "../virt-dma.h"
drivers/dma/stm32/stm32-dma3.c +1 -0
@@ -20,6 +20,7 @@#include <linux/pm_runtime.h> #include <linux/reset.h> #include <linux/slab.h> +#include <linux/interrupt.h> #include "../virt-dma.h"
drivers/dma/stm32/stm32-mdma.c +1 -0
@@ -29,6 +29,7 @@#include <linux/pm_runtime.h> #include <linux/reset.h> #include <linux/slab.h> +#include <linux/interrupt.h> #include "../virt-dma.h"
drivers/dma/sun6i-dma.c +1 -1
@@ -1073,7 +1073,7 @@ static inline void sun6i_dma_free(struct sun6i_dma_dev *sdev)struct sun6i_vchan *vchan = &sdev->vchans[i];list_del (&vchan->vc.chan.device_node); -tasklet_kill (&vchan->vc.task); +cancel_work_sync (&vchan->vc.work); } }
drivers/dma/tegra186-gpc-dma.c +1 -1
@@ -1279,7 +1279,7 @@ static void tegra_dma_free_chan_resources(struct dma_chan *dc)tegra_dma_terminate_all (dc);synchronize_irq (tdc->irq); -tasklet_kill (&tdc->vc.task); +cancel_work_sync (&tdc->vc.work); tdc->config_init = false; tdc->slave_id =-1 ; tdc->sid_dir =DMA_TRANS_NONE ;
drivers/dma/tegra210-adma.c +2 -1
@@ -14,6 +14,7 @@#include <linux/platform_device.h> #include <linux/pm_runtime.h> #include <linux/slab.h> +#include <linux/interrupt.h> #include "virt-dma.h"
@@ -793,7 +794,7 @@ static void tegra_adma_free_chan_resources(struct dma_chan *dc)tegra_adma_terminate_all (dc);vchan_free_chan_resources (&tdc->vc); -tasklet_kill (&tdc->vc.task); +cancel_work_sync (&tdc->vc.work);free_irq (tdc->irq, tdc);pm_runtime_put (tdc2dev (tdc));
drivers/dma/ti/edma.c +1 -1
@@ -2560,7 +2560,7 @@ static void edma_cleanupp_vchan(struct dma_device *dmadev)list_for_each_entry_safe (echan, _echan, &dmadev->channels, vchan.chan.device_node) {list_del (&echan->vchan.chan.device_node); -tasklet_kill (&echan->vchan.task); +cancel_work_sync (&echan->vchan.work); } }
drivers/dma/ti/k3-udma.c +5 -5
@@ -4042,12 +4042,12 @@ static void udma_desc_pre_callback(struct virt_dma_chan *vc, }/* -* This tasklet handles the completion of a DMA descriptor by +* This workqueue handles the completion of a DMA descriptor by * calling its callback and freeing it. */ -static void udma_vchan_complete (struct tasklet_struct *t) +static void udma_vchan_complete (struct work_struct *w) { -struct virt_dma_chan *vc =from_tasklet (vc, t, task); +struct virt_dma_chan *vc =from_work (vc, w, work);struct virt_dma_desc *vd, *_vd;struct dmaengine_desc_callback cb;LIST_HEAD (head);
@@ -4112,7 +4112,7 @@ static void udma_free_chan_resources(struct dma_chan *chan) }vchan_free_chan_resources (&uc->vc); -tasklet_kill (&uc->vc.task); +cancel_work_sync (&uc->vc.work);bcdma_free_bchan_resources (uc);udma_free_tx_resources (uc);
@@ -5628,7 +5628,7 @@ static int udma_probe(struct platform_device *pdev)return -ENOMEM ;vchan_init (&uc->vc, &ud->ddev);/* Use custom vchan completion handling */ -tasklet_setup (&uc->vc.task, udma_vchan_complete); +INIT_WORK (&uc->vc.work, udma_vchan_complete);init_completion (&uc->teardown_completed);INIT_DELAYED_WORK (&uc->tx_drain.work, udma_check_tx_completion); }
drivers/dma/ti/omap-dma.c +1 -1
@@ -1521,7 +1521,7 @@ static void omap_dma_free(struct omap_dmadev *od) struct omap_chan, vc.chan.device_node);list_del (&c->vc.chan.device_node); -tasklet_kill (&c->vc.task); +cancel_work_sync (&c->vc.work);kfree (c); } }
drivers/dma/uniphier-xdmac.c +1 -0
@@ -13,6 +13,7 @@#include <linux/of_dma.h> #include <linux/platform_device.h> #include <linux/slab.h> +#include <linux/interrupt.h> #include "dmaengine.h" #include "virt-dma.h"
drivers/dma/virt-dma.c +3 -3
@@ -80,9 +80,9 @@ EXPORT_SYMBOL_GPL(vchan_find_desc);* This tasklet handles the completion of a DMA descriptor by * calling its callback and freeing it. */ -static void vchan_complete (struct tasklet_struct *t) +static void vchan_complete (struct work_struct *work) { -struct virt_dma_chan *vc =from_tasklet (vc, t, task); +struct virt_dma_chan *vc =from_work (vc, work, work);struct virt_dma_desc *vd, *_vd;struct dmaengine_desc_callback cb;LIST_HEAD (head);
@@ -131,7 +131,7 @@ void vchan_init(struct virt_dma_chan *vc, struct dma_device *dmadev)INIT_LIST_HEAD (&vc->desc_completed);INIT_LIST_HEAD (&vc->desc_terminated); -tasklet_setup (&vc->task, vchan_complete); +INIT_WORK (&vc->work, vchan_complete); vc->chan.device = dmadev;list_add_tail (&vc->chan.device_node, &dmadev->channels);
drivers/dma/virt-dma.h +5 -5
@@ -8,7 +8,7 @@#define VIRT_DMA_H #include <linux/dmaengine.h> -#include <linux/interrupt.h> +#include <linux/workqueue.h> #include "dmaengine.h"
@@ -21,7 +21,7 @@ struct virt_dma_desc {struct virt_dma_chan {struct dma_chan chan; -struct tasklet_struct task; +struct work_struct work;void (*desc_free)(struct virt_dma_desc *);spinlock_t lock;
@@ -106,7 +106,7 @@ static inline void vchan_cookie_complete(struct virt_dma_desc *vd) vd, cookie);list_add_tail (&vd->node, &vc->desc_completed); -tasklet_schedule (&vc->task); +queue_work (system_bh_wq, &vc->work); }/**
@@ -137,7 +137,7 @@ static inline void vchan_cyclic_callback(struct virt_dma_desc *vd)struct virt_dma_chan *vc =to_virt_chan (vd->tx.chan); vc->cyclic = vd; -tasklet_schedule (&vc->task); +queue_work (system_bh_wq, &vc->work); }/**
@@ -223,7 +223,7 @@ static inline void vchan_synchronize(struct virt_dma_chan *vc)LIST_HEAD (head);unsigned long flags; -tasklet_kill (&vc->task); +cancel_work_sync (&vc->work);spin_lock_irqsave (&vc->lock, flags);
Signature · 1 line
2.43.0
Quoted 13 lines · Alexander Kochetkov
Currently DMA callbacks are called from tasklet. However the tasklet is marked deprecated and must be replaced by BH workqueue. Tasklet callbacks are executed either in the Soft IRQ context or from ksoftirqd thread. BH workqueue work items are executed in the BH context. Changing tasklet to BH workqueue improved DMA callback latencies.
The commit changes virt-dma driver and all of its users:
- tasklet is replaced towork_struct, tasklet callback updated accordingly
-kill_tasklet()is replaced tocancel_work_sync()
- added include oflinux/interrupt.hwhere necessaryTested on Pine64 (Allwinner A64 ARMv8) with sun6i-dma driver. All other drivers are changed similarly and tested for compilation.
...
drivers/dma/amd/qdma/qdma.c line 16
Quoted 7 lines
drivers/dma/amd/qdma/qdma.c +1
-0@@ -13,6 +13,7 @@#include <linux/platform_device.h> #include <linux/platform_data/amd_qdma.h> #include <linux/regmap.h> +#include <linux/interrupt.h>
It seems it was ordered. Please, preserve the order. It not, try to squeeze to have longest possible ordered chain (it can be interleaved with something unordered, just look at
the big picture).
(Same applies to other similar cases)
...
What about the driver(s) that use threaded IRQ instead? Do you plan to convert them as well?
I am talking about current users of virt-dma that do not use tasklets.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 7 lines
It seems it was ordered. Please, preserve the order. It not, try to squeeze to have longest possible ordered chain (it can be interleaved with something unordered, just look at
the big picture).(Same applies to other similar cases)
I'll this that in v2. Thanks!
Quoted 11 lines
...
What about the driver(s) that use threaded IRQ instead? Do you plan to convert them as well?
I am talking about current users of virt-dma that do not use tasklets.
--
With Best Regards,
Andy Shevchenko
I think, I've found all the users of virt-dma. Could you, please, provide example of such driver?
Here is what I did to locate current users of virt-dma.
I got list of drivers using following command:
grep -r -e 'struct virt_dma_chan' -e 'virt-dma.h' . | sort | cut -f 1 -d : | uniq
./drivers/dma/amba-pl08x.c./drivers/dma/amd/ae4dma/ae4dma.h./drivers/dma/amd/ptdma/ptdma.h./drivers/dma/amd/qdma/qdma.c./drivers/dma/amd/qdma/qdma.h./drivers/dma/arm-dma350.c./drivers/dma/at_hdmac.c./drivers/dma/bcm2835-dma.c./drivers/dma/dma-axi-dmac.c./drivers/dma/dma-jz4780.c./drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c./drivers/dma/dw-axi-dmac/dw-axi-dmac.h./drivers/dma/dw-edma/dw-edma-core.c./drivers/dma/dw-edma/dw-edma-core.h./drivers/dma/fsl-dpaa2-qdma/dpaa2-qdma.c./drivers/dma/fsl-dpaa2-qdma/dpaa2-qdma.h./drivers/dma/fsl-edma-common.h./drivers/dma/fsl-qdma.c./drivers/dma/hisi_dma.c./drivers/dma/hsu/hsu.h./drivers/dma/idma64.h./drivers/dma/img-mdc-dma.c./drivers/dma/imx-sdma.c./drivers/dma/k3dma.c./drivers/dma/lgm/lgm-dma.c./drivers/dma/loongson1-apb-dma.c./drivers/dma/loongson2-apb-dma.c./drivers/dma/mediatek/mtk-cqdma.c./drivers/dma/mediatek/mtk-hsdma.c./drivers/dma/mediatek/mtk-uart-apdma.c./drivers/dma/milbeaut-hdmac.c./drivers/dma/milbeaut-xdmac.c./drivers/dma/moxart-dma.c./drivers/dma/owl-dma.c./drivers/dma/pxa_dma.c./drivers/dma/qcom/bam_dma.c./drivers/dma/qcom/gpi.c./drivers/dma/qcom/qcom_adm.c./drivers/dma/sa11x0-dma.c./drivers/dma/sf-pdma/sf-pdma.c./drivers/dma/sf-pdma/sf-pdma.h./drivers/dma/sh/rz-dmac.c./drivers/dma/sh/usb-dmac.c./drivers/dma/sprd-dma.c./drivers/dma/st_fdma.h./drivers/dma/stm32/stm32-dma.c./drivers/dma/stm32/stm32-dma3.c./drivers/dma/stm32/stm32-mdma.c./drivers/dma/sun4i-dma.c./drivers/dma/sun6i-dma.c./drivers/dma/tegra186-gpc-dma.c./drivers/dma/tegra210-adma.c./drivers/dma/ti/edma.c./drivers/dma/ti/k3-udma.c./drivers/dma/ti/omap-dma.c./drivers/dma/uniphier-mdmac.c./drivers/dma/uniphier-xdmac.c./drivers/dma/virt-dma.c./drivers/dma/virt-dma.h./drivers/dma/xilinx/xdma.c./drivers/dma/xilinx/xilinx_dpdma.c
After that I did following to find additional drivers, and found them inside misc.
grep -r -e ae4dma.h -e ptdma.h -e qdma.h -e dw-axi-dmac.h -e dw-edma-core.h -e dpaa2-qdma.h -e fsl-edma-common.h -e hsu.h -e idma64.h -e sf-pdma.h -e st_fdma.h . | sort | cut -f 1 -d : | uniq
./drivers/dma/amd/ae4dma/ae4dma-dev.c./drivers/dma/amd/ae4dma/ae4dma-pci.c./drivers/dma/amd/ae4dma/ae4dma.h./drivers/dma/amd/ptdma/ptdma-debugfs.c./drivers/dma/amd/ptdma/ptdma-dev.c./drivers/dma/amd/ptdma/ptdma-dmaengine.c./drivers/dma/amd/ptdma/ptdma-pci.c./drivers/dma/amd/qdma/qdma-comm-regs.c./drivers/dma/amd/qdma/qdma.c./drivers/dma/dw-axi-dmac/dw-axi-dmac-platform.c./drivers/dma/dw-edma/dw-edma-core.c./drivers/dma/dw-edma/dw-edma-pcie.c./drivers/dma/dw-edma/dw-edma-v0-core.c./drivers/dma/dw-edma/dw-edma-v0-debugfs.c./drivers/dma/dw-edma/dw-hdma-v0-core.c./drivers/dma/dw-edma/dw-hdma-v0-debugfs.c./drivers/dma/fsl-dpaa2-qdma/dpaa2-qdma.c./drivers/dma/fsl-edma-common.c./drivers/dma/fsl-edma-main.c./drivers/dma/fsl-edma-trace.c./drivers/dma/fsl-qdma.c./drivers/dma/hsu/hsu.c./drivers/dma/hsu/hsu.h./drivers/dma/hsu/pci.c./drivers/dma/idma64.c./drivers/dma/idma64.h./drivers/dma/mcf-edma-main.c./drivers/dma/mediatek/mtk-cqdma.c./drivers/dma/sf-pdma/sf-pdma.c./drivers/dma/st_fdma.c./drivers/dma/st_fdma.h./drivers/mfd/intel-lpss.c./drivers/net/ethernet/airoha/airoha_eth.c./drivers/net/ethernet/mediatek/mtk_eth_soc.c./drivers/net/ethernet/mediatek/mtk_eth_soc.h./drivers/pci/controller/pcie-xilinx-dma-pl.c./drivers/tty/serial/8250/8250_mid.c./include/linux/dma/hsu.h
Just realized, that I missed to check this drivers:./drivers/net/ethernet/airoha/airoha_eth.c ./drivers/net/ethernet/mediatek/mtk_eth_soc.c ./drivers/net/ethernet/mediatek/mtk_eth_soc.h ./drivers/pci/controller/pcie-xilinx-dma-pl.c ./drivers/tty/serial/8250/8250_mid.c
I've applied the following config to the kernel, to build all the drivers. I've modified some Kconfig files in order all options apply. And checked that every file in the above list builds successfully. Some drivers have compile errors, unrelated to virt-dma. Some drivers produce link errors, but compile success. I checked that each .o-file has a reasonable size.
CONFIG_FORCE_PCI=yCONFIG_PCI=yCONFIG_AMD_QDMA=yCONFIG_AMD_PTDMA=yCONFIG_DW_AXI_DMAC=yCONFIG_DW_EDMA=yCONFIG_DW_EDMA_PCIE=yCONFIG_INTEL_LDMA=yCONFIG_MTK_HSDMA=yCONFIG_MTK_CQDMA=yCONFIG_MTK_UART_APDMA=y
# CONFIG_QCOM_ADM=y - error: assignment to 'u32 *' {aka 'unsigned int *'} from incompatible pointer type 'phys_addr_t *' CONFIG_QCOM_GPI_DMA=yCONFIG_QCOM_BAM_DMA=yCONFIG_SF_PDMA=yCONFIG_STM32_DMA=yCONFIG_STM32_MDMA=yCONFIG_STM32_DMA3=yCONFIG_DMA_OMAP=yCONFIG_TI_EDMA=yCONFIG_TI_K3_UDMA=yCONFIG_XILINX_ZYNQMP_DPDMA=yCONFIG_XILINX_XDMA=yCONFIG_AMBA_PL08X=yCONFIG_ARM_DMA350=y
# CONFIG_FSL_DMA=y - error: implicit declaration of function '__ilog2 CONFIG_FSL_EDMA=yCONFIG_FSL_QDMA=yCONFIG_MCF_EDMA=yCONFIG_INTEL_IDMA64=yCONFIG_DMA_SUN6I=yCONFIG_DMA_SUN4I=yCONFIG_AT_HDMAC=y
# CONFIG_ST_FDMA=y - link errorsCONFIG_K3_DMA=yCONFIG_DMA_SA11X0=yCONFIG_AXI_DMAC=yCONFIG_IMG_MDC_DMA=yCONFIG_UNIPHIER_XDMAC=yCONFIG_UNIPHIER_MDMAC=yCONFIG_LOONGSON1_APB_DMA=yCONFIG_LOONGSON2_APB_DMA=yCONFIG_DMA_BCM2835=yCONFIG_TEGRA210_ADMA=yCONFIG_TEGRA186_GPC_DMA=yCONFIG_MOXART_DMA=yCONFIG_DMA_JZ4780=yCONFIG_IMX_SDMA=yCONFIG_OWL_DMA=yCONFIG_SPRD_DMA=yCONFIG_MILBEAUT_XDMAC=yCONFIG_MILBEAUT_HDMAC=yCONFIG_HISI_DMA=y
# CONFIG_FSL_DPAA2_QDMA=y - link errorsCONFIG_RZ_DMAC=yCONFIG_RENESAS_USB_DMAC=yCONFIG_PXA_DMA=yCONFIG_HSU_DMA=yCONFIG_HSU_DMA_PCI=yCONFIG_MFD_INTEL_LPSS=y
On Fri, Jun 13, 2025 at 9:51 PM Alexander Kochetkov <[email protected]> wrote:
...
Quoted 5 lines
Quoted 4 lines
What about the driver(s) that use threaded IRQ instead? Do you plan to convert them as well?
I am talking about current users of virt-dma that do not use tasklets.
Quoted 7 lines
I think, I've found all the users of virt-dma. Could you, please, provide example of such driver?
Here is what I did to locate current users of virt-dma.I got list of drivers using following command:
grep -r -e 'structvirt_dma_chan' -e 'virt-dma.h' . | sort | cut -f 1 -d : | uniq
Side note, git grep -lw 'struct virt_dma_chan' will get you the list much faster and easier to remember the command.
Same for virt-dma.h.
...
Quoted 2 lines
./drivers/dma/sh/rz-dmac.c./drivers/dma/sh/usb-dmac.c
These, for instance, are not in the patch.
...
Quoted 5 lines
After that I did following to find additional drivers, and found them inside misc.
grep -r -eae4dma.h-eptdma.h-eqdma.h-edw-axi-dmac.h-edw-edma-core.h-edpaa2-qdma.h-efsl-edma-common.h-ehsu.h-eidma64.h-esf-pdma.h-est_fdma.h. | sort | cut -f 1 -d : | uniq
Same side note as above :-)
Quoted 4 lines
I've applied the following config to the kernel, to build all the drivers. I've modified some
Kconfigfiles in order all options apply. And checked that every file in the above list builds successfully. Some drivers have compile errors, unrelated to virt-dma.
Any pointers? This needs to be fixed independently on your series.
Quoted 3 lines
Some drivers
produce link errors, but compile success. I checked that each .o-file has a reasonable size.
...
Quoted 2 lines
#
CONFIG_QCOM_ADM=y- error: assignment to 'u32 *' {aka 'unsigned int *'} from incompatible pointer type 'phys_addr_t*'
Have you tried to check via git log -p -- drivers/ ... which commit brought that?
...
Quoted 1 line
#
CONFIG_FSL_DMA=y- error: implicit declaration of function '__ilog2
This needs a log2.h?
However it seems this is defined in asm/bitops.h for PPC. And it's only a single architecture which does this interesting trick. Perhaps it needs to be fixed differently, i.e. making sure that code uses ilog2() from log2.h directly.
Signature · 2 lines
With Best Regards, Andy Shevchenko