dmaengine: qcom-bam: Process multiple pending descriptors
Subsystems (2)
PATCH 1/1 dmaengine: qcom-bam: Process multiple pending descriptors
The bam dmaengine has a circular FIFO to which we add hw descriptors that describes the transaction. The FIFO has space for about 4096 hw descriptors.
Currently we add one descriptor and wait for it to complete with interrupt and start processing the next pending descriptor. In this way, FIFO is underutilised and also adds additional interrupt overhead for each of the descriptor. This results in loss of throughput for clients that submits multiple descriptors together, that can be processed by bam and the client peripheral together. So instead, when a client does an issue_pending, we can keep pulling in descriptors from the pending queue and add it to the FIFO, till either the FIFO is full (or) client has requested for an interrupt notification for that descriptor. After this, receiving a completion interrupt implies that all descriptors that were submitted have completed. so notify completion for all the descriptors.
CURRENT:
------ ------- ---------------
|DES 0| |DESC 1| |DESC 2 + INT |
------ ------- ---------------
| | |
| | |
INTERRUPT: (INT) (INT) (INT)
CALLBACK: (CB) (CB) (CB) MTD_SPEEDTEST READ PAGE: 3560 KiB/s MTD_SPEEDTEST WRITE PAGE: 2664 KiB/s IOZONE READ: 2456 KB/s IOZONE WRITE: 1230 KB/s
bam dma interrupts (after tests): 96508
CHANGE:
------ ------- -------------
|DES 0| |DESC 1 |DESC 2 + INT |
------ ------- --------------
|
|
(INT)
(CB for 0, 1, 2)
MTD_SPEEDTEST READ PAGE: 3860 KiB/s
MTD_SPEEDTEST WRITE PAGE: 2837 KiB/s
IOZONE READ: 2677 KB/s
IOZONE WRITE: 1308 KB/s
bam dma interrupts (after tests): 58806--- drivers/dma/qcom/bam_dma.c | 180 +++++++++++++++++++++++++++++---------------- 1 file changed, 115 insertions(+), 65 deletions(-)
drivers/dma/qcom/bam_dma.c +115 -65
@@ -46,6 +46,7 @@#include <linux/of_address.h> #include <linux/of_irq.h> #include <linux/of_dma.h> +#include <linux/circ_buf.h> #include <linux/clk.h> #include <linux/dmaengine.h> #include <linux/pm_runtime.h>
@@ -76,7 +77,8 @@ struct bam_async_desc {u16 flags;struct bam_desc_hw *curr_desc; - +/* list node for the desc in the bam_chan list of descriptors */ +struct list_head desc_node;enum dma_transfer_direction dir;size_t length;struct bam_desc_hw desc[0 ];
@@ -371,6 +373,8 @@ struct bam_chan {unsigned int initialized;/* is the channel hw initialized? */ unsigned int paused;/* is the channel paused? */ unsigned int reconfigure;/* new slave config? */ +/* list of descriptors currently processed */ +struct list_head desc_list;struct list_head node; };
@@ -486,6 +490,8 @@ static void bam_chan_init_hw(struct bam_chan *bchan, bchan->initialized =1 ; +INIT_LIST_HEAD (&bchan->desc_list); +/* init FIFO pointers */ bchan->head =0 ; bchan->tail =0 ;
@@ -631,8 +637,6 @@ static struct dma_async_tx_descriptor *bam_prep_slave_sg(struct dma_chan *chan,if (flags &DMA_PREP_INTERRUPT ) async_desc->flags |=DESC_FLAG_EOT ; -else - async_desc->flags |=DESC_FLAG_INT ; async_desc->num_desc = num_alloc; async_desc->curr_desc = async_desc->desc;
@@ -680,13 +684,18 @@ static struct dma_async_tx_descriptor *bam_prep_slave_sg(struct dma_chan *chan,static int bam_dma_terminate_all (struct dma_chan *chan) {struct bam_chan *bchan =to_bam_chan (chan); +struct bam_async_desc *async_desc;unsigned long flag;LIST_HEAD (head);/* remove all transactions, including active transaction */ spin_lock_irqsave (&bchan->vc.lock, flag);if (bchan->curr_txd) { -list_add (&bchan->curr_txd->vd.node, &bchan->vc.desc_issued); +list_for_each_entry (async_desc, &bchan->desc_list, desc_node) { + bchan->curr_txd = async_desc; +list_add (&bchan->curr_txd->vd.node, + &bchan->vc.desc_issued); + } bchan->curr_txd =NULL ; }
@@ -761,7 +770,7 @@ static u32 process_channel_irqs(struct bam_device *bdev) {u32 i, srcs, pipe_stts;unsigned long flags; -struct bam_async_desc *async_desc; +struct bam_async_desc *async_desc, *tmp; srcs =readl_relaxed (bam_addr (bdev,0 ,BAM_IRQ_SRCS_EE ));
@@ -777,33 +786,39 @@ static u32 process_channel_irqs(struct bam_device *bdev)/* clear pipe irq */ pipe_stts =readl_relaxed (bam_addr (bdev, i,BAM_P_IRQ_STTS )); -writel_relaxed (pipe_stts,bam_addr (bdev, i,BAM_P_IRQ_CLR ));spin_lock_irqsave (&bchan->vc.lock, flags); - async_desc = bchan->curr_txd; - -if (async_desc) { - async_desc->num_desc -= async_desc->xfer_len; - async_desc->curr_desc += async_desc->xfer_len; - bchan->curr_txd =NULL ; - -/* manage FIFO */ - bchan->head += async_desc->xfer_len; - bchan->head %=MAX_DESCRIPTORS ; - -/* -* if complete, process cookie. Otherwise -* push back to front of desc_issued so that -* it gets restarted by the tasklet -*/ -if (!async_desc->num_desc) -vchan_cookie_complete (&async_desc->vd); -else -list_add (&async_desc->vd.node, - &bchan->vc.desc_issued); + +list_for_each_entry_safe (async_desc, tmp, + &bchan->desc_list, desc_node) { + bchan->curr_txd = async_desc; + +if (async_desc) { + async_desc->num_desc -= async_desc->xfer_len; + async_desc->curr_desc += async_desc->xfer_len; + +/* manage FIFO */ + bchan->head += async_desc->xfer_len; + bchan->head %=MAX_DESCRIPTORS ; + +/* +* if complete, process cookie. Otherwise +* push back to front of desc_issued so that +* it gets restarted by the tasklet +*/ +if (!async_desc->num_desc) { +vchan_cookie_complete (&async_desc->vd); + }else { +list_add (&async_desc->vd.node, + &bchan->vc.desc_issued); + } +list_del (&async_desc->desc_node); + } } + bchan->curr_txd =NULL ; +spin_unlock_irqrestore (&bchan->vc.lock, flags); }
@@ -863,6 +878,7 @@ static enum dma_status bam_tx_status(struct dma_chan *chan, dma_cookie_t cookie, struct dma_tx_state *txstate) {struct bam_chan *bchan =to_bam_chan (chan); +struct bam_async_desc *async_desc;struct virt_dma_desc *vd;int ret;size_t residue =0 ;
@@ -877,12 +893,21 @@ static enum dma_status bam_tx_status(struct dma_chan *chan, dma_cookie_t cookie,return bchan->paused ?DMA_PAUSED : ret;spin_lock_irqsave (&bchan->vc.lock, flags); + vd =vchan_find_desc (&bchan->vc, cookie); -if (vd) +if (vd) { residue = container_of(vd, struct bam_async_desc, vd)->length; -else if (bchan->curr_txd && bchan->curr_txd->vd.tx.cookie == cookie) -for (i =0 ; i < bchan->curr_txd->num_desc; i++) - residue += bchan->curr_txd->curr_desc[i].size; + }else if (bchan->curr_txd) { +list_for_each_entry (async_desc, &bchan->desc_list, desc_node) { + bchan->curr_txd = async_desc; + +if (bchan->curr_txd->vd.tx.cookie != cookie) +continue ; + +for (i =0 ; i < bchan->curr_txd->num_desc; i++) + residue += bchan->curr_txd->curr_desc[i].size; + } + }spin_unlock_irqrestore (&bchan->vc.lock, flags);
@@ -923,63 +948,88 @@ static void bam_start_dma(struct bam_chan *bchan) {struct virt_dma_desc *vd =vchan_next_desc (&bchan->vc);struct bam_device *bdev = bchan->bdev; -struct bam_async_desc *async_desc; +struct bam_async_desc *async_desc =NULL ;struct bam_desc_hw *desc;struct bam_desc_hw *fifo =PTR_ALIGN (bchan->fifo_virt,sizeof (struct bam_desc_hw ));int ret; +unsigned int avail;lockdep_assert_held (&bchan->vc.lock);if (!vd)return ; -list_del (&vd->node); - - async_desc = container_of(vd, struct bam_async_desc, vd); - bchan->curr_txd = async_desc; - ret =pm_runtime_get_sync (bdev->dev);if (ret <0 )return ; -/* on first use, initialize the channel hardware */ -if (!bchan->initialized) -bam_chan_init_hw (bchan, async_desc->dir); +while (vd) { +list_del (&vd->node); -/* apply new slave config changes, if necessary */ -if (bchan->reconfigure) -bam_apply_new_config (bchan, async_desc->dir); + async_desc = container_of(vd, struct bam_async_desc, vd); - desc = bchan->curr_txd->curr_desc; +/* on first use, initialize the channel hardware */ +if (!bchan->initialized) +bam_chan_init_hw (bchan, async_desc->dir); -if (async_desc->num_desc >MAX_DESCRIPTORS ) - async_desc->xfer_len =MAX_DESCRIPTORS ; -else - async_desc->xfer_len = async_desc->num_desc; +/* apply new slave config changes, if necessary */ +if (bchan->reconfigure) +bam_apply_new_config (bchan, async_desc->dir); -/* set any special flags on the last descriptor */ -if (async_desc->num_desc == async_desc->xfer_len) - desc[async_desc->xfer_len -1 ].flags = -cpu_to_le16 (async_desc->flags); -else - desc[async_desc->xfer_len -1 ].flags |= + bchan->curr_txd = async_desc; + desc = bchan->curr_txd->curr_desc; + avail =CIRC_SPACE (bchan->tail, bchan->head, +MAX_DESCRIPTORS +1 ); + +if (async_desc->num_desc > avail) + async_desc->xfer_len = avail; +else + async_desc->xfer_len = async_desc->num_desc; + +/* set any special flags on the last descriptor */ +if (async_desc->num_desc == async_desc->xfer_len) + desc[async_desc->xfer_len -1 ].flags |= +cpu_to_le16 (async_desc->flags); + + vd =vchan_next_desc (&bchan->vc); + +/* +* This will be the last descriptor in the chain if, +* - FIFO is FULL. +* - No more descriptors to add. +* - This descriptor has interrupt flags set, +* so that we will have to indicate finishing of +* that descriptor. +*/ +if (!(avail - async_desc->xfer_len) || !vd || + (async_desc->flags &DESC_FLAG_EOT )) { +/* set INT flag for the last descriptor if unset */ +if ((async_desc->num_desc != async_desc->xfer_len) || + (!(async_desc->flags &DESC_FLAG_EOT ))) + desc[async_desc->xfer_len -1 ].flags |=cpu_to_le16 (DESC_FLAG_INT ); + vd =NULL ; + } -if (bchan->tail + async_desc->xfer_len >MAX_DESCRIPTORS ) { -u32 partial =MAX_DESCRIPTORS - bchan->tail; +if (bchan->tail + async_desc->xfer_len >MAX_DESCRIPTORS ) { +u32 partial =MAX_DESCRIPTORS - bchan->tail; -memcpy (&fifo[bchan->tail], desc, - partial *sizeof (struct bam_desc_hw )); -memcpy (fifo, &desc[partial], (async_desc->xfer_len - partial) * +memcpy (&fifo[bchan->tail], desc, + partial *sizeof (struct bam_desc_hw )); +memcpy (fifo, &desc[partial], + (async_desc->xfer_len - partial) *sizeof (struct bam_desc_hw )); - }else { -memcpy (&fifo[bchan->tail], desc, - async_desc->xfer_len *sizeof (struct bam_desc_hw )); - } + }else { +memcpy (&fifo[bchan->tail], desc, + async_desc->xfer_len * +sizeof (struct bam_desc_hw )); + } - bchan->tail += async_desc->xfer_len; - bchan->tail %=MAX_DESCRIPTORS ; + bchan->tail += async_desc->xfer_len; + bchan->tail %=MAX_DESCRIPTORS ; +list_add_tail (&async_desc->desc_node, &bchan->desc_list); + }/* ensure descriptor writes and dma start not reordered */ wmb ();
Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Quoted 40 lines · Sricharan R
The bam dmaengine has a circular FIFO to which we add hw descriptors that describes the transaction. The FIFO has space for about 4096 hw descriptors.
Currently we add one descriptor and wait for it to complete with interrupt and start processing the next pending descriptor. In this way, FIFO is underutilised and also adds additional interrupt overhead for each of the descriptor. This results in loss of throughput for clients that submits multiple descriptors together, that can be processed by bam and the client peripheral together. So instead, when a client does an
issue_pending, we can keep pulling in descriptors from the pending queue and add it to the FIFO, till either the FIFO is full (or) client has requested for an interrupt notification for that descriptor. After this, receiving a completion interrupt implies that all descriptors that were submitted have completed. so notify completion for all the descriptors.CURRENT:
------ ------- --------------- |DES 0| |DESC 1| |DESC 2 + INT | ------ ------- --------------- | | | | | | INTERRUPT: (INT) (INT) (INT) CALLBACK: (CB) (CB) (CB)
MTD_SPEEDTESTREAD PAGE: 3560 KiB/sMTD_SPEEDTESTWRITE PAGE: 2664 KiB/s IOZONE READ: 2456 KB/s IOZONE WRITE: 1230 KB/sbam dma interrupts (after tests): 96508
CHANGE:
Quoted 7 lines
------ ------- -------------
|DES 0| |DESC 1 |DESC 2 + INT |
------ ------- --------------
|
|
(INT)
(CB for 0, 1, 2)I am not sure why suppressing callback helps? I think you should still continue filling up FIFO but also ensure interrupt so that callback can be invoked, user thread maybe waiting on that
FWIW waiting for interrupt and submitting is extremely inefficient and shouldn't be done, so that part of this is good.
Quoted 54 lines
MTD_SPEEDTESTREAD PAGE: 3860 KiB/sMTD_SPEEDTESTWRITE PAGE: 2837 KiB/s IOZONE READ: 2677 KB/s IOZONE WRITE: 1308 KB/sbam dma interrupts (after tests): 58806
Signed-off-by Sricharan R <[email protected]>--- drivers/dma/qcom/bam_dma.c | 180 +++++++++++++++++++++++++++++---------------- 1 file changed, 115 insertions(+), 65 deletions(-)drivers/dma/qcom/bam_dma.c +7
-1@@ -46,6 +46,7 @@#include <linux/of_address.h> #include <linux/of_irq.h> #include <linux/of_dma.h> +#include <linux/circ_buf.h> #include <linux/clk.h> #include <linux/dmaengine.h> #include <linux/pm_runtime.h> @@ -76,7 +77,8 @@ struct bam_async_desc {u16 flags;struct bam_desc_hw *curr_desc; - +/* list node for the desc in the bam_chan list of descriptors */ +struct list_head desc_node;enum dma_transfer_direction dir;size_t length;struct bam_desc_hw desc[0 ];@@ -371,6 +373,8 @@ struct bam_chan {unsigned int initialized;/* is the channel hw initialized? */ unsigned int paused;/* is the channel paused? */ unsigned int reconfigure;/* new slave config? */ +/* list of descriptors currently processed */ +struct list_head desc_list;struct list_head node; };@@ -486,6 +490,8 @@ static void bam_chan_init_hw(struct bam_chan *bchan, bchan->initialized =1 ; +INIT_LIST_HEAD (&bchan->desc_list); +/* init FIFO pointers */ bchan->head =0 ; bchan->tail =0 ;
drivers/dma/qcom/bam_dma.c static struct dma_async_tx_descriptor *bam_prep_slave_sg(struct dma_chan *chan, · line 635
Quoted 5 lines
drivers/dma/qcom/bam_dma.c +0
-2@@ -631,8 +637,6 @@ static struct dma_async_tx_descriptor *bam_prep_slave_sg(struct dma_chan *chan,if (flags &DMA_PREP_INTERRUPT ) async_desc->flags |=DESC_FLAG_EOT ; -else - async_desc->flags |=DESC_FLAG_INT ;
shouldn't we do DESC_FLAG_INT for DMA_PREP_INTERRUPT and not EOT which i suppose means end of transfers?
Quoted 9 lines
drivers/dma/qcom/bam_dma.c +1
-0async_desc->num_desc = num_alloc; async_desc->curr_desc = async_desc->desc;@@ -680,13 +684,18 @@ static struct dma_async_tx_descriptor *bam_prep_slave_sg(struct dma_chan *chan,static int bam_dma_terminate_all (struct dma_chan *chan) {struct bam_chan *bchan =to_bam_chan (chan); +struct bam_async_desc *async_desc;unsigned long flag;
drivers/dma/qcom/bam_dma.c static struct dma_async_tx_descriptor *bam_prep_slave_sg(struct dma_chan *chan, · line 697
Quoted 10 lines
drivers/dma/qcom/bam_dma.c +4
-1LIST_HEAD (head);/* remove all transactions, including active transaction */ spin_lock_irqsave (&bchan->vc.lock, flag);if (bchan->curr_txd) { -list_add (&bchan->curr_txd->vd.node, &bchan->vc.desc_issued); +list_for_each_entry (async_desc, &bchan->desc_list, desc_node) { + bchan->curr_txd = async_desc; +list_add (&bchan->curr_txd->vd.node, + &bchan->vc.desc_issued);
that is wrong, terminated should not add to issued list
Quoted 14 lines
drivers/dma/qcom/bam_dma.c +2
-1+ } bchan->curr_txd =NULL ; }@@ -761,7 +770,7 @@ static u32 process_channel_irqs(struct bam_device *bdev) {u32 i, srcs, pipe_stts;unsigned long flags; -struct bam_async_desc *async_desc; +struct bam_async_desc *async_desc, *tmp; srcs =readl_relaxed (bam_addr (bdev,0 ,BAM_IRQ_SRCS_EE ));
drivers/dma/qcom/bam_dma.c static u32 process_channel_irqs(struct bam_device *bdev) · line 780
Quoted 4 lines
drivers/dma/qcom/bam_dma.c +0
-1@@ -777,33 +786,39 @@ static u32 process_channel_irqs(struct bam_device *bdev)/* clear pipe irq */ pipe_stts =readl_relaxed (bam_addr (bdev, i,BAM_P_IRQ_STTS )); -
noise
Quoted 29 lines
drivers/dma/qcom/bam_dma.c +5
-21writel_relaxed (pipe_stts,bam_addr (bdev, i,BAM_P_IRQ_CLR ));spin_lock_irqsave (&bchan->vc.lock, flags); - async_desc = bchan->curr_txd; - -if (async_desc) { - async_desc->num_desc -= async_desc->xfer_len; - async_desc->curr_desc += async_desc->xfer_len; - bchan->curr_txd =NULL ; - -/* manage FIFO */ - bchan->head += async_desc->xfer_len; - bchan->head %=MAX_DESCRIPTORS ; - -/* -* if complete, process cookie. Otherwise -* push back to front of desc_issued so that -* it gets restarted by the tasklet -*/ -if (!async_desc->num_desc) -vchan_cookie_complete (&async_desc->vd); -else -list_add (&async_desc->vd.node, - &bchan->vc.desc_issued); + +list_for_each_entry_safe (async_desc, tmp, + &bchan->desc_list, desc_node) { + bchan->curr_txd = async_desc; +
drivers/dma/qcom/bam_dma.c static u32 process_channel_irqs(struct bam_device *bdev) · line 806
Quoted 10 lines
drivers/dma/qcom/bam_dma.c +10
-0+if (async_desc) { + async_desc->num_desc -= async_desc->xfer_len; + async_desc->curr_desc += async_desc->xfer_len; + +/* manage FIFO */ + bchan->head += async_desc->xfer_len; + bchan->head %=MAX_DESCRIPTORS ; + +/* +* if complete, process cookie. Otherwise
^^
double spaces
drivers/dma/qcom/bam_dma.c static u32 process_channel_irqs(struct bam_device *bdev) · line 809
Quoted 3 lines
drivers/dma/qcom/bam_dma.c +3
-0+* push back to front of desc_issued so that +* it gets restarted by the tasklet +*/
can you explain this part, why would you move this up in latter case?
Quoted 119 lines
drivers/dma/qcom/bam_dma.c +49
-27+if (!async_desc->num_desc) { +vchan_cookie_complete (&async_desc->vd); + }else { +list_add (&async_desc->vd.node, + &bchan->vc.desc_issued); + } +list_del (&async_desc->desc_node); + } } + bchan->curr_txd =NULL ; +spin_unlock_irqrestore (&bchan->vc.lock, flags); }@@ -863,6 +878,7 @@ static enum dma_status bam_tx_status(struct dma_chan *chan, dma_cookie_t cookie, struct dma_tx_state *txstate) {struct bam_chan *bchan =to_bam_chan (chan); +struct bam_async_desc *async_desc;struct virt_dma_desc *vd;int ret;size_t residue =0 ;@@ -877,12 +893,21 @@ static enum dma_status bam_tx_status(struct dma_chan *chan, dma_cookie_t cookie,return bchan->paused ?DMA_PAUSED : ret;spin_lock_irqsave (&bchan->vc.lock, flags); + vd =vchan_find_desc (&bchan->vc, cookie); -if (vd) +if (vd) { residue = container_of(vd, struct bam_async_desc, vd)->length; -else if (bchan->curr_txd && bchan->curr_txd->vd.tx.cookie == cookie) -for (i =0 ; i < bchan->curr_txd->num_desc; i++) - residue += bchan->curr_txd->curr_desc[i].size; + }else if (bchan->curr_txd) { +list_for_each_entry (async_desc, &bchan->desc_list, desc_node) { + bchan->curr_txd = async_desc; + +if (bchan->curr_txd->vd.tx.cookie != cookie) +continue ; + +for (i =0 ; i < bchan->curr_txd->num_desc; i++) + residue += bchan->curr_txd->curr_desc[i].size; + } + }spin_unlock_irqrestore (&bchan->vc.lock, flags);@@ -923,63 +948,88 @@ static void bam_start_dma(struct bam_chan *bchan) {struct virt_dma_desc *vd =vchan_next_desc (&bchan->vc);struct bam_device *bdev = bchan->bdev; -struct bam_async_desc *async_desc; +struct bam_async_desc *async_desc =NULL ;struct bam_desc_hw *desc;struct bam_desc_hw *fifo =PTR_ALIGN (bchan->fifo_virt,sizeof (struct bam_desc_hw ));int ret; +unsigned int avail;lockdep_assert_held (&bchan->vc.lock);if (!vd)return ; -list_del (&vd->node); - - async_desc = container_of(vd, struct bam_async_desc, vd); - bchan->curr_txd = async_desc; - ret =pm_runtime_get_sync (bdev->dev);if (ret <0 )return ; -/* on first use, initialize the channel hardware */ -if (!bchan->initialized) -bam_chan_init_hw (bchan, async_desc->dir); +while (vd) { +list_del (&vd->node); -/* apply new slave config changes, if necessary */ -if (bchan->reconfigure) -bam_apply_new_config (bchan, async_desc->dir); + async_desc = container_of(vd, struct bam_async_desc, vd); - desc = bchan->curr_txd->curr_desc; +/* on first use, initialize the channel hardware */ +if (!bchan->initialized) +bam_chan_init_hw (bchan, async_desc->dir); -if (async_desc->num_desc >MAX_DESCRIPTORS ) - async_desc->xfer_len =MAX_DESCRIPTORS ; -else - async_desc->xfer_len = async_desc->num_desc; +/* apply new slave config changes, if necessary */ +if (bchan->reconfigure) +bam_apply_new_config (bchan, async_desc->dir); -/* set any special flags on the last descriptor */ -if (async_desc->num_desc == async_desc->xfer_len) - desc[async_desc->xfer_len -1 ].flags = -cpu_to_le16 (async_desc->flags); -else - desc[async_desc->xfer_len - 1].flags |= + bchan->curr_txd = async_desc; + desc = bchan->curr_txd->curr_desc; + avail =CIRC_SPACE (bchan->tail, bchan->head, +MAX_DESCRIPTORS +1 ); + +if (async_desc->num_desc > avail) + async_desc->xfer_len = avail; +else + async_desc->xfer_len = async_desc->num_desc; + +/* set any special flags on the last descriptor */ +if (async_desc->num_desc == async_desc->xfer_len) + desc[async_desc->xfer_len -1 ].flags |= +cpu_to_le16 (async_desc->flags);
drivers/dma/qcom/bam_dma.c static void bam_start_dma(struct bam_chan *bchan) · line 1003
Quoted 10 lines
drivers/dma/qcom/bam_dma.c +10
-0+ + vd =vchan_next_desc (&bchan->vc); + +/* +* This will be the last descriptor in the chain if, +* - FIFO is FULL. +* - No more descriptors to add. +* - This descriptor has interrupt flags set, +* so that we will have to indicate finishing of +* that descriptor.
is this a HW limitation? Cant interrupt be generated while continuing the transfer of next one in FIFO?
Quoted 46 lines
drivers/dma/qcom/bam_dma.c +24
-11+*/ +if (!(avail - async_desc->xfer_len) || !vd || + (async_desc->flags &DESC_FLAG_EOT )) { +/* set INT flag for the last descriptor if unset */ +if ((async_desc->num_desc != async_desc->xfer_len) || + (!(async_desc->flags &DESC_FLAG_EOT ))) + desc[async_desc->xfer_len -1 ].flags |=cpu_to_le16 (DESC_FLAG_INT ); + vd =NULL ; + } -if (bchan->tail + async_desc->xfer_len >MAX_DESCRIPTORS ) { -u32 partial =MAX_DESCRIPTORS - bchan->tail; +if (bchan->tail + async_desc->xfer_len >MAX_DESCRIPTORS ) { +u32 partial =MAX_DESCRIPTORS - bchan->tail; -memcpy (&fifo[bchan->tail], desc, - partial *sizeof (struct bam_desc_hw )); -memcpy (fifo, &desc[partial], (async_desc->xfer_len - partial) * +memcpy (&fifo[bchan->tail], desc, + partial *sizeof (struct bam_desc_hw )); +memcpy (fifo, &desc[partial], + (async_desc->xfer_len - partial) *sizeof (struct bam_desc_hw )); - }else { -memcpy (&fifo[bchan->tail], desc, - async_desc->xfer_len *sizeof (struct bam_desc_hw )); - } + }else { +memcpy (&fifo[bchan->tail], desc, + async_desc->xfer_len * +sizeof (struct bam_desc_hw )); + } - bchan->tail += async_desc->xfer_len; - bchan->tail %=MAX_DESCRIPTORS ; + bchan->tail += async_desc->xfer_len; + bchan->tail %=MAX_DESCRIPTORS ; +list_add_tail (&async_desc->desc_node, &bchan->desc_list); + }/* ensure descriptor writes and dma start not reordered */ wmb ();Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Signature · 1 line
~Vinod
Hi Vinod,
Quoted 49 lines · Vinod Koul
Quoted 40 lines · Sricharan R
The bam dmaengine has a circular FIFO to which we add hw descriptors that describes the transaction. The FIFO has space for about 4096 hw descriptors.
Currently we add one descriptor and wait for it to complete with interrupt and start processing the next pending descriptor. In this way, FIFO is underutilised and also adds additional interrupt overhead for each of the descriptor. This results in loss of throughput for clients that submits multiple descriptors together, that can be processed by bam and the client peripheral together. So instead, when a client does an
issue_pending, we can keep pulling in descriptors from the pending queue and add it to the FIFO, till either the FIFO is full (or) client has requested for an interrupt notification for that descriptor. After this, receiving a completion interrupt implies that all descriptors that were submitted have completed. so notify completion for all the descriptors.CURRENT:
------ ------- --------------- |DES 0| |DESC 1| |DESC 2 + INT | ------ ------- --------------- | | | | | | INTERRUPT: (INT) (INT) (INT) CALLBACK: (CB) (CB) (CB)
MTD_SPEEDTESTREAD PAGE: 3560 KiB/sMTD_SPEEDTESTWRITE PAGE: 2664 KiB/s IOZONE READ: 2456 KB/s IOZONE WRITE: 1230 KB/sbam dma interrupts (after tests): 96508
CHANGE:
Quoted 7 lines
------ ------- ------------- |DES 0| |DESC 1 |DESC 2 + INT | ------ ------- -------------- | | (INT) (CB for 0, 1, 2)
Quoted 7 lines
I am not sure why suppressing callback helps? I think you should still continue filling up FIFO but also ensure interrupt so that callback can be invoked, user thread maybe waiting on that
FWIW waiting for interrupt and submitting is extremely inefficient and shouldn't be done, so that part of this is good.
Thanks for the review.
So one part is, adding desc to the FIFO till its full, so the BAM dmaengine is busy when there are pending descriptors without waiting for interrupt.
Another part is, currently, the driver signals the completion of the each descriptor with a interrupt, even though the client has not requested a DMA_PREP_INTERRUPT/registered a callback. Instead if the client has not requested for a interrupt for the completion of a descriptor, then generate a interrupt only for descriptor for which it was requested and also complete all the previous descriptors in that interrupt (means call all callbacks). So we still call all callbacks but at the end of a group of descriptors.
This was reducing the total number of interrupts. Nand was one such client which was requiring callback only at the end of a group of submitted descriptors.
Quoted 55 lines
Quoted 55 lines
MTD_SPEEDTESTREAD PAGE: 3860 KiB/sMTD_SPEEDTESTWRITE PAGE: 2837 KiB/s IOZONE READ: 2677 KB/s IOZONE WRITE: 1308 KB/sbam dma interrupts (after tests): 58806
Signed-off-by Sricharan R <[email protected]>--- drivers/dma/qcom/bam_dma.c | 180 +++++++++++++++++++++++++++++---------------- 1 file changed, 115 insertions(+), 65 deletions(-)drivers/dma/qcom/bam_dma.c +7
-1@@ -46,6 +46,7 @@#include <linux/of_address.h> #include <linux/of_irq.h> #include <linux/of_dma.h> +#include <linux/circ_buf.h> #include <linux/clk.h> #include <linux/dmaengine.h> #include <linux/pm_runtime.h> @@ -76,7 +77,8 @@ struct bam_async_desc {u16 flags;struct bam_desc_hw *curr_desc; - +/* list node for the desc in the bam_chan list of descriptors */ +struct list_head desc_node;enum dma_transfer_direction dir;size_t length;struct bam_desc_hw desc[0 ];@@ -371,6 +373,8 @@ struct bam_chan {unsigned int initialized;/* is the channel hw initialized? */ unsigned int paused;/* is the channel paused? */ unsigned int reconfigure;/* new slave config? */ +/* list of descriptors currently processed */ +struct list_head desc_list;struct list_head node; };@@ -486,6 +490,8 @@ static void bam_chan_init_hw(struct bam_chan *bchan, bchan->initialized =1 ; +INIT_LIST_HEAD (&bchan->desc_list); +/* init FIFO pointers */ bchan->head =0 ; bchan->tail =0 ;@@ -631,8 +637,6 @@ static struct dma_async_tx_descriptor *bam_prep_slave_sg(struct dma_chan *chan,
Quoted 7 lines
drivers/dma/qcom/bam_dma.c static struct dma_async_tx_descriptor *bam_prep_slave_sg(struct dma_chan *chan, · line 635
Quoted 4 lines
drivers/dma/qcom/bam_dma.c +0
-2if (flags &DMA_PREP_INTERRUPT ) async_desc->flags |=DESC_FLAG_EOT ; -else - async_desc->flags |=DESC_FLAG_INT ;shouldn't we do
DESC_FLAG_INTforDMA_PREP_INTERRUPTand not EOT which i suppose means end of transfers?
EOT generates a interrupt as well. So, right now we do interrupt for EOT if DMA_PREP_INTERRUPT was set, otherwise do interrupt with DESC_FLAG_INT.
Quoted 12 lines
Quoted 12 lines
drivers/dma/qcom/bam_dma.c +1
-0async_desc->num_desc = num_alloc; async_desc->curr_desc = async_desc->desc;@@ -680,13 +684,18 @@ static struct dma_async_tx_descriptor *bam_prep_slave_sg(struct dma_chan *chan,static int bam_dma_terminate_all (struct dma_chan *chan) {struct bam_chan *bchan =to_bam_chan (chan); +struct bam_async_desc *async_desc;unsigned long flag;LIST_HEAD (head);
Quoted 10 lines
drivers/dma/qcom/bam_dma.c static struct dma_async_tx_descriptor *bam_prep_slave_sg(struct dma_chan *chan, · line 697
Quoted 8 lines
drivers/dma/qcom/bam_dma.c +4
-1/* remove all transactions, including active transaction */ spin_lock_irqsave (&bchan->vc.lock, flag);if (bchan->curr_txd) { -list_add (&bchan->curr_txd->vd.node, &bchan->vc.desc_issued); +list_for_each_entry (async_desc, &bchan->desc_list, desc_node) { + bchan->curr_txd = async_desc; +list_add (&bchan->curr_txd->vd.node, + &bchan->vc.desc_issued);that is wrong, terminated should not add to issued list
hmm, since it was already done like that, i added the same for list of descriptors now.
Quoted 14 lines
Quoted 14 lines
drivers/dma/qcom/bam_dma.c +2
-1+ } bchan->curr_txd =NULL ; }@@ -761,7 +770,7 @@ static u32 process_channel_irqs(struct bam_device *bdev) {u32 i, srcs, pipe_stts;unsigned long flags; -struct bam_async_desc *async_desc; +struct bam_async_desc *async_desc, *tmp; srcs =readl_relaxed (bam_addr (bdev,0 ,BAM_IRQ_SRCS_EE ));
Quoted 7 lines
drivers/dma/qcom/bam_dma.c static u32 process_channel_irqs(struct bam_device *bdev) · line 780
Quoted 5 lines
drivers/dma/qcom/bam_dma.c +0
-1@@ -777,33 +786,39 @@ static u32 process_channel_irqs(struct bam_device *bdev)/* clear pipe irq */ pipe_stts =readl_relaxed (bam_addr (bdev, i,BAM_P_IRQ_STTS )); -noise
ok, will remove.
Quoted 41 lines
Quoted 30 lines
drivers/dma/qcom/bam_dma.c +5
-21writel_relaxed (pipe_stts,bam_addr (bdev, i,BAM_P_IRQ_CLR ));spin_lock_irqsave (&bchan->vc.lock, flags); - async_desc = bchan->curr_txd; - -if (async_desc) { - async_desc->num_desc -= async_desc->xfer_len; - async_desc->curr_desc += async_desc->xfer_len; - bchan->curr_txd =NULL ; - -/* manage FIFO */ - bchan->head += async_desc->xfer_len; - bchan->head %=MAX_DESCRIPTORS ; - -/* -* if complete, process cookie. Otherwise -* push back to front of desc_issued so that -* it gets restarted by the tasklet -*/ -if (!async_desc->num_desc) -vchan_cookie_complete (&async_desc->vd); -else -list_add (&async_desc->vd.node, - &bchan->vc.desc_issued); + +list_for_each_entry_safe (async_desc, tmp, + &bchan->desc_list, desc_node) { + bchan->curr_txd = async_desc; +drivers/dma/qcom/bam_dma.c static u32 process_channel_irqs(struct bam_device *bdev) · line 806
Quoted 10 lines
drivers/dma/qcom/bam_dma.c +10
-0+if (async_desc) { + async_desc->num_desc -= async_desc->xfer_len; + async_desc->curr_desc += async_desc->xfer_len; + +/* manage FIFO */ + bchan->head += async_desc->xfer_len; + bchan->head %=MAX_DESCRIPTORS ; + +/* +* if complete, process cookie. Otherwise ^^
Quoted 1 line
double spaces
ok.
Quoted 5 lines
drivers/dma/qcom/bam_dma.c static u32 process_channel_irqs(struct bam_device *bdev) · line 809
Quoted 3 lines
drivers/dma/qcom/bam_dma.c +3
-0+* push back to front of desc_issued so that +* it gets restarted by the tasklet +*/ can you explain this part, why would you move this up in latter case?
This means that, we were not able to push all the sgs of that descriptor in to the FIFO, as it become full, so only some sgs was pushed. So add the descriptor back to the issued list to process the remaining sgs.
Quoted 125 lines
Quoted 125 lines
drivers/dma/qcom/bam_dma.c +54
-27+if (!async_desc->num_desc) { +vchan_cookie_complete (&async_desc->vd); + }else { +list_add (&async_desc->vd.node, + &bchan->vc.desc_issued); + } +list_del (&async_desc->desc_node); + } } + bchan->curr_txd =NULL ; +spin_unlock_irqrestore (&bchan->vc.lock, flags); }@@ -863,6 +878,7 @@ static enum dma_status bam_tx_status(struct dma_chan *chan, dma_cookie_t cookie, struct dma_tx_state *txstate) {struct bam_chan *bchan =to_bam_chan (chan); +struct bam_async_desc *async_desc;struct virt_dma_desc *vd;int ret;size_t residue =0 ;@@ -877,12 +893,21 @@ static enum dma_status bam_tx_status(struct dma_chan *chan, dma_cookie_t cookie,return bchan->paused ?DMA_PAUSED : ret;spin_lock_irqsave (&bchan->vc.lock, flags); + vd =vchan_find_desc (&bchan->vc, cookie); -if (vd) +if (vd) { residue = container_of(vd, struct bam_async_desc, vd)->length; -else if (bchan->curr_txd && bchan->curr_txd->vd.tx.cookie == cookie) -for (i =0 ; i < bchan->curr_txd->num_desc; i++) - residue += bchan->curr_txd->curr_desc[i].size; + }else if (bchan->curr_txd) { +list_for_each_entry (async_desc, &bchan->desc_list, desc_node) { + bchan->curr_txd = async_desc; + +if (bchan->curr_txd->vd.tx.cookie != cookie) +continue ; + +for (i =0 ; i < bchan->curr_txd->num_desc; i++) + residue += bchan->curr_txd->curr_desc[i].size; + } + }spin_unlock_irqrestore (&bchan->vc.lock, flags);@@ -923,63 +948,88 @@ static void bam_start_dma(struct bam_chan *bchan) {struct virt_dma_desc *vd =vchan_next_desc (&bchan->vc);struct bam_device *bdev = bchan->bdev; -struct bam_async_desc *async_desc; +struct bam_async_desc *async_desc =NULL ;struct bam_desc_hw *desc;struct bam_desc_hw *fifo =PTR_ALIGN (bchan->fifo_virt,sizeof (struct bam_desc_hw ));int ret; +unsigned int avail;lockdep_assert_held (&bchan->vc.lock);if (!vd)return ; -list_del (&vd->node); - - async_desc = container_of(vd, struct bam_async_desc, vd); - bchan->curr_txd = async_desc; - ret =pm_runtime_get_sync (bdev->dev);if (ret <0 )return ; -/* on first use, initialize the channel hardware */ -if (!bchan->initialized) -bam_chan_init_hw (bchan, async_desc->dir); +while (vd) { +list_del (&vd->node); -/* apply new slave config changes, if necessary */ -if (bchan->reconfigure) -bam_apply_new_config (bchan, async_desc->dir); + async_desc = container_of(vd, struct bam_async_desc, vd); - desc = bchan->curr_txd->curr_desc; +/* on first use, initialize the channel hardware */ +if (!bchan->initialized) +bam_chan_init_hw (bchan, async_desc->dir); -if (async_desc->num_desc >MAX_DESCRIPTORS ) - async_desc->xfer_len =MAX_DESCRIPTORS ; -else - async_desc->xfer_len = async_desc->num_desc; +/* apply new slave config changes, if necessary */ +if (bchan->reconfigure) +bam_apply_new_config (bchan, async_desc->dir); -/* set any special flags on the last descriptor */ -if (async_desc->num_desc == async_desc->xfer_len) - desc[async_desc->xfer_len -1 ].flags = -cpu_to_le16 (async_desc->flags); -else - desc[async_desc->xfer_len - 1].flags |= + bchan->curr_txd = async_desc; + desc = bchan->curr_txd->curr_desc; + avail =CIRC_SPACE (bchan->tail, bchan->head, +MAX_DESCRIPTORS +1 ); + +if (async_desc->num_desc > avail) + async_desc->xfer_len = avail; +else + async_desc->xfer_len = async_desc->num_desc; + +/* set any special flags on the last descriptor */ +if (async_desc->num_desc == async_desc->xfer_len) + desc[async_desc->xfer_len -1 ].flags |= +cpu_to_le16 (async_desc->flags); + + vd =vchan_next_desc (&bchan->vc); + +/* +* This will be the last descriptor in the chain if,
Quoted 8 lines
drivers/dma/qcom/bam_dma.c static void bam_start_dma(struct bam_chan *bchan) · line 1003
Quoted 5 lines
drivers/dma/qcom/bam_dma.c +5
-0+* - FIFO is FULL. +* - No more descriptors to add. +* - This descriptor has interrupt flags set, +* so that we will have to indicate finishing of +* that descriptor. is this a HW limitation? Cant interrupt be generated while continuing the transfer of next one in FIFO?
No HW limitation here. I was doing this, so that we can keep a list of descriptors in which the last descriptor requires interrupt and when interrupt is generated, all the descriptors in the list are completed. But this can be still be optimised, by not stopping at end of the flags, continue to add descs just till FIFO is full, so bam works while interrupts are handled by the cpu. Will try that.
Regards,
Sricharan
Signature · 1 line
"QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation
Quoted 13 lines · Sricharan R
Quoted 7 lines
I am not sure why suppressing callback helps? I think you should still continue filling up FIFO but also ensure interrupt so that callback can be invoked, user thread maybe waiting on that
FWIW waiting for interrupt and submitting is extremely inefficient and shouldn't be done, so that part of this is good.
Thanks for the review.
So one part is, adding desc to the FIFO till its full, so the BAM dmaengine is busy when there are pending descriptors without waiting for interrupt.
Quoted 8 lines
Another part is, currently, the driver signals the completion of the each descriptor with a interrupt, even though the client has not requested a DMA_PREP_INTERRUPT/registered a callback. Instead if the client has not requested for a interrupt for the completion of a descriptor, then generate a interrupt only for descriptor for which it was requested and also complete all the previous descriptors in that interrupt (means call all callbacks). So we still call all callbacks but at the end of a group of descriptors.
okay that sounds sane, but somehow I was getting the impression that we might be suppressing, so you might want to update comments
Quoted 21 lines
Quoted 10 lines
Quoted 10 lines
drivers/dma/qcom/bam_dma.c +1
-0async_desc->num_desc = num_alloc; async_desc->curr_desc = async_desc->desc;@@ -680,13 +684,18 @@ static struct dma_async_tx_descriptor *bam_prep_slave_sg(struct dma_chan *chan,static int bam_dma_terminate_all (struct dma_chan *chan) {struct bam_chan *bchan =to_bam_chan (chan); +struct bam_async_desc *async_desc;unsigned long flag;LIST_HEAD (head);Quoted 10 lines
drivers/dma/qcom/bam_dma.c static struct dma_async_tx_descriptor *bam_prep_slave_sg(struct dma_chan *chan, · line 697
Quoted 8 lines
drivers/dma/qcom/bam_dma.c +4
-1/* remove all transactions, including active transaction */ spin_lock_irqsave (&bchan->vc.lock, flag);if (bchan->curr_txd) { -list_add (&bchan->curr_txd->vd.node, &bchan->vc.desc_issued); +list_for_each_entry (async_desc, &bchan->desc_list, desc_node) { + bchan->curr_txd = async_desc; +list_add (&bchan->curr_txd->vd.node, + &bchan->vc.desc_issued);that is wrong, terminated should not add to issued list
Quoted 1 line
hmm, since it was already done like that, i added the same for list of descriptors now.
Sounds like you should fix existing behaviour too :)
Signature · 1 line
~Vinod
Hi Vinod,
<snip>
Quoted 21 lines
Quoted 21 lines
Quoted 20 lines
Quoted 8 lines
drivers/dma/qcom/bam_dma.c +1
-0async_desc->num_desc = num_alloc; async_desc->curr_desc = async_desc->desc;@@ -680,13 +684,18 @@ static struct dma_async_tx_descriptor *bam_prep_slave_sg(struct dma_chan *chan,static int bam_dma_terminate_all (struct dma_chan *chan) {struct bam_chan *bchan =to_bam_chan (chan); +struct bam_async_desc *async_desc;unsigned long flag;drivers/dma/qcom/bam_dma.c static struct dma_async_tx_descriptor *bam_prep_slave_sg(struct dma_chan *chan, · line 697
Quoted 10 lines
drivers/dma/qcom/bam_dma.c +4
-1LIST_HEAD (head);/* remove all transactions, including active transaction */ spin_lock_irqsave (&bchan->vc.lock, flag);if (bchan->curr_txd) { -list_add (&bchan->curr_txd->vd.node, &bchan->vc.desc_issued); +list_for_each_entry (async_desc, &bchan->desc_list, desc_node) { + bchan->curr_txd = async_desc; +list_add (&bchan->curr_txd->vd.node, + &bchan->vc.desc_issued);that is wrong, terminated should not add to issued list
Quoted 4 lines
Quoted 1 line
hmm, since it was already done like that, i added the same for list of descriptors now.
Sounds like you should fix existing behaviour too :)
Just to clarify, the code below this, does a vchan_dma_desc_free_list, which removes the descriptors from issued list as well. So this is to pull and remove even all those descriptors submitted to the hardware as well. That said, posted a V3 and it would cause a conflict with https://patchwork.kernel.org/patch/9874691/ based on which goes in first.
Regards,
Sricharan
Signature · 5 lines
"QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation --- This email has been checked for viruses by Avast antivirus software. https://www.avast.com/antivirus