Skip to content

Commit 9c61e78

Browse files
dma-buf: some dma_fence_chain improvements
The callback and the irq work are never used at the same time. Putting them into an union saves us 24 bytes and makes the structure only 120 bytes in size. Signed-off-by: Christian König <[email protected]> Reviewed-by: Daniel Vetter <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent ade0e67 commit 9c61e78

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

drivers/dma-buf/dma-fence-chain.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ static void dma_fence_chain_cb(struct dma_fence *f, struct dma_fence_cb *cb)
137137
struct dma_fence_chain *chain;
138138

139139
chain = container_of(cb, typeof(*chain), cb);
140+
init_irq_work(&chain->work, dma_fence_chain_irq_work);
140141
irq_work_queue(&chain->work);
141142
dma_fence_put(f);
142143
}
@@ -239,7 +240,6 @@ void dma_fence_chain_init(struct dma_fence_chain *chain,
239240
rcu_assign_pointer(chain->prev, prev);
240241
chain->fence = fence;
241242
chain->prev_seqno = 0;
242-
init_irq_work(&chain->work, dma_fence_chain_irq_work);
243243

244244
/* Try to reuse the context of the previous chain node. */
245245
if (prev_chain && __dma_fence_is_later(seqno, prev->seqno, prev->ops)) {

include/linux/dma-fence-chain.h

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,36 @@
1616
/**
1717
* struct dma_fence_chain - fence to represent an node of a fence chain
1818
* @base: fence base class
19-
* @lock: spinlock for fence handling
2019
* @prev: previous fence of the chain
2120
* @prev_seqno: original previous seqno before garbage collection
2221
* @fence: encapsulated fence
23-
* @cb: callback structure for signaling
24-
* @work: irq work item for signaling
22+
* @lock: spinlock for fence handling
2523
*/
2624
struct dma_fence_chain {
2725
struct dma_fence base;
28-
spinlock_t lock;
2926
struct dma_fence __rcu *prev;
3027
u64 prev_seqno;
3128
struct dma_fence *fence;
32-
struct dma_fence_cb cb;
33-
struct irq_work work;
29+
union {
30+
/**
31+
* @cb: callback for signaling
32+
*
33+
* This is used to add the callback for signaling the
34+
* complection of the fence chain. Never used at the same time
35+
* as the irq work.
36+
*/
37+
struct dma_fence_cb cb;
38+
39+
/**
40+
* @work: irq work item for signaling
41+
*
42+
* Irq work structure to allow us to add the callback without
43+
* running into lock inversion. Never used at the same time as
44+
* the callback.
45+
*/
46+
struct irq_work work;
47+
};
48+
spinlock_t lock;
3449
};
3550

3651
extern const struct dma_fence_ops dma_fence_chain_ops;

0 commit comments

Comments
 (0)