Skip to content

Commit 13bb26a

Browse files
rjarzmikVinod Koul
authored andcommitted
dmaengine: virt-dma: don't always free descriptor upon completion
This patch attempts to enhance the case of a transfer submitted multiple times, and where the cost of creating the descriptors chain is not negligible. This happens with big video buffers (several megabytes, ie. several thousands of linked descriptors in one scatter-gather list). In these cases, a video driver would want to do : - tx = dmaengine_prep_slave_sg() - dma_engine_submit(tx); - dma_async_issue_pending() - wait for video completion - read video data (or not, skipping a frame is also possible) - dma_engine_submit(tx) => here, the descriptors chain recalculation will take time => the dma coherent allocation over and over might create holes in the dma pool, which is counter-productive. - dma_async_issue_pending() - etc ... In order to cope with this case, virt-dma is modified to prevent freeing the descriptors upon completion if DMA_CTRL_REUSE flag is set in the transfer. This patch is a respin of the former DMA_CTRL_ACK approach, which was reverted due to a regression in audio drivers. Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr> Signed-off-by: Vinod Koul <vinod.koul@intel.com>
1 parent 8005c49 commit 13bb26a

2 files changed

Lines changed: 52 additions & 6 deletions

File tree

‎drivers/dma/virt-dma.c‎

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ dma_cookie_t vchan_tx_submit(struct dma_async_tx_descriptor *tx)
2929
spin_lock_irqsave(&vc->lock, flags);
3030
cookie = dma_cookie_assign(tx);
3131

32-
list_add_tail(&vd->node, &vc->desc_submitted);
32+
list_move_tail(&vd->node, &vc->desc_submitted);
3333
spin_unlock_irqrestore(&vc->lock, flags);
3434

3535
dev_dbg(vc->chan.device->dev, "vchan %p: txd %p[%x]: submitted\n",
@@ -39,6 +39,33 @@ dma_cookie_t vchan_tx_submit(struct dma_async_tx_descriptor *tx)
3939
}
4040
EXPORT_SYMBOL_GPL(vchan_tx_submit);
4141

42+
/**
43+
* vchan_tx_desc_free - free a reusable descriptor
44+
* @tx: the transfer
45+
*
46+
* This function frees a previously allocated reusable descriptor. The only
47+
* other way is to clear the DMA_CTRL_REUSE flag and submit one last time the
48+
* transfer.
49+
*
50+
* Returns 0 upon success
51+
*/
52+
int vchan_tx_desc_free(struct dma_async_tx_descriptor *tx)
53+
{
54+
struct virt_dma_chan *vc = to_virt_chan(tx->chan);
55+
struct virt_dma_desc *vd = to_virt_desc(tx);
56+
unsigned long flags;
57+
58+
spin_lock_irqsave(&vc->lock, flags);
59+
list_del(&vd->node);
60+
spin_unlock_irqrestore(&vc->lock, flags);
61+
62+
dev_dbg(vc->chan.device->dev, "vchan %p: txd %p[%x]: freeing\n",
63+
vc, vd, vd->tx.cookie);
64+
vc->desc_free(vd);
65+
return 0;
66+
}
67+
EXPORT_SYMBOL_GPL(vchan_tx_desc_free);
68+
4269
struct virt_dma_desc *vchan_find_desc(struct virt_dma_chan *vc,
4370
dma_cookie_t cookie)
4471
{
@@ -83,8 +110,10 @@ static void vchan_complete(unsigned long arg)
83110
cb_data = vd->tx.callback_param;
84111

85112
list_del(&vd->node);
86-
87-
vc->desc_free(vd);
113+
if (dmaengine_desc_test_reuse(&vd->tx))
114+
list_add(&vd->node, &vc->desc_allocated);
115+
else
116+
vc->desc_free(vd);
88117

89118
if (cb)
90119
cb(cb_data);
@@ -96,9 +125,13 @@ void vchan_dma_desc_free_list(struct virt_dma_chan *vc, struct list_head *head)
96125
while (!list_empty(head)) {
97126
struct virt_dma_desc *vd = list_first_entry(head,
98127
struct virt_dma_desc, node);
99-
list_del(&vd->node);
100-
dev_dbg(vc->chan.device->dev, "txd %p: freeing\n", vd);
101-
vc->desc_free(vd);
128+
if (dmaengine_desc_test_reuse(&vd->tx)) {
129+
list_move_tail(&vd->node, &vc->desc_allocated);
130+
} else {
131+
dev_dbg(vc->chan.device->dev, "txd %p: freeing\n", vd);
132+
list_del(&vd->node);
133+
vc->desc_free(vd);
134+
}
102135
}
103136
}
104137
EXPORT_SYMBOL_GPL(vchan_dma_desc_free_list);
@@ -108,6 +141,7 @@ void vchan_init(struct virt_dma_chan *vc, struct dma_device *dmadev)
108141
dma_cookie_init(&vc->chan);
109142

110143
spin_lock_init(&vc->lock);
144+
INIT_LIST_HEAD(&vc->desc_allocated);
111145
INIT_LIST_HEAD(&vc->desc_submitted);
112146
INIT_LIST_HEAD(&vc->desc_issued);
113147
INIT_LIST_HEAD(&vc->desc_completed);

‎drivers/dma/virt-dma.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct virt_dma_chan {
2929
spinlock_t lock;
3030

3131
/* protected by vc.lock */
32+
struct list_head desc_allocated;
3233
struct list_head desc_submitted;
3334
struct list_head desc_issued;
3435
struct list_head desc_completed;
@@ -55,10 +56,17 @@ static inline struct dma_async_tx_descriptor *vchan_tx_prep(struct virt_dma_chan
5556
struct virt_dma_desc *vd, unsigned long tx_flags)
5657
{
5758
extern dma_cookie_t vchan_tx_submit(struct dma_async_tx_descriptor *);
59+
extern int vchan_tx_desc_free(struct dma_async_tx_descriptor *);
60+
unsigned long flags;
5861

5962
dma_async_tx_descriptor_init(&vd->tx, &vc->chan);
6063
vd->tx.flags = tx_flags;
6164
vd->tx.tx_submit = vchan_tx_submit;
65+
vd->tx.desc_free = vchan_tx_desc_free;
66+
67+
spin_lock_irqsave(&vc->lock, flags);
68+
list_add_tail(&vd->node, &vc->desc_allocated);
69+
spin_unlock_irqrestore(&vc->lock, flags);
6270

6371
return &vd->tx;
6472
}
@@ -134,18 +142,22 @@ static inline struct virt_dma_desc *vchan_next_desc(struct virt_dma_chan *vc)
134142
static inline void vchan_get_all_descriptors(struct virt_dma_chan *vc,
135143
struct list_head *head)
136144
{
145+
list_splice_tail_init(&vc->desc_allocated, head);
137146
list_splice_tail_init(&vc->desc_submitted, head);
138147
list_splice_tail_init(&vc->desc_issued, head);
139148
list_splice_tail_init(&vc->desc_completed, head);
140149
}
141150

142151
static inline void vchan_free_chan_resources(struct virt_dma_chan *vc)
143152
{
153+
struct virt_dma_desc *vd;
144154
unsigned long flags;
145155
LIST_HEAD(head);
146156

147157
spin_lock_irqsave(&vc->lock, flags);
148158
vchan_get_all_descriptors(vc, &head);
159+
list_for_each_entry(vd, &head, node)
160+
dmaengine_desc_clear_reuse(&vd->tx);
149161
spin_unlock_irqrestore(&vc->lock, flags);
150162

151163
vchan_dma_desc_free_list(vc, &head);

0 commit comments

Comments
 (0)