Skip to content

Commit 23acc2b

Browse files
ChristianKoenigAMDgregkh
authored andcommitted
dma-buf: keep the signaling time of merged fences v3
commit f781f66 upstream. Some Android CTS is testing if the signaling time keeps consistent during merges. v2: use the current time if the fence is still in the signaling path and the timestamp not yet available. v3: improve comment, fix one more case to use the correct timestamp Signed-off-by: Christian König <[email protected]> Reviewed-by: Luben Tuikov <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Cc: Jindong Yue <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 665e6fd commit 23acc2b

File tree

4 files changed

+27
-8
lines changed

4 files changed

+27
-8
lines changed

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

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,36 @@ struct dma_fence *__dma_fence_unwrap_merge(unsigned int num_fences,
6666
{
6767
struct dma_fence_array *result;
6868
struct dma_fence *tmp, **array;
69+
ktime_t timestamp;
6970
unsigned int i;
7071
size_t count;
7172

7273
count = 0;
74+
timestamp = ns_to_ktime(0);
7375
for (i = 0; i < num_fences; ++i) {
74-
dma_fence_unwrap_for_each(tmp, &iter[i], fences[i])
75-
if (!dma_fence_is_signaled(tmp))
76+
dma_fence_unwrap_for_each(tmp, &iter[i], fences[i]) {
77+
if (!dma_fence_is_signaled(tmp)) {
7678
++count;
79+
} else if (test_bit(DMA_FENCE_FLAG_TIMESTAMP_BIT,
80+
&tmp->flags)) {
81+
if (ktime_after(tmp->timestamp, timestamp))
82+
timestamp = tmp->timestamp;
83+
} else {
84+
/*
85+
* Use the current time if the fence is
86+
* currently signaling.
87+
*/
88+
timestamp = ktime_get();
89+
}
90+
}
7791
}
7892

93+
/*
94+
* If we couldn't find a pending fence just return a private signaled
95+
* fence with the timestamp of the last signaled one.
96+
*/
7997
if (count == 0)
80-
return dma_fence_get_stub();
98+
return dma_fence_allocate_private_stub(timestamp);
8199

82100
array = kmalloc_array(count, sizeof(*array), GFP_KERNEL);
83101
if (!array)
@@ -138,7 +156,7 @@ struct dma_fence *__dma_fence_unwrap_merge(unsigned int num_fences,
138156
} while (tmp);
139157

140158
if (count == 0) {
141-
tmp = dma_fence_get_stub();
159+
tmp = dma_fence_allocate_private_stub(ktime_get());
142160
goto return_tmp;
143161
}
144162

drivers/dma-buf/dma-fence.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,11 @@ EXPORT_SYMBOL(dma_fence_get_stub);
150150

151151
/**
152152
* dma_fence_allocate_private_stub - return a private, signaled fence
153+
* @timestamp: timestamp when the fence was signaled
153154
*
154155
* Return a newly allocated and signaled stub fence.
155156
*/
156-
struct dma_fence *dma_fence_allocate_private_stub(void)
157+
struct dma_fence *dma_fence_allocate_private_stub(ktime_t timestamp)
157158
{
158159
struct dma_fence *fence;
159160

@@ -169,7 +170,7 @@ struct dma_fence *dma_fence_allocate_private_stub(void)
169170
set_bit(DMA_FENCE_FLAG_ENABLE_SIGNAL_BIT,
170171
&fence->flags);
171172

172-
dma_fence_signal(fence);
173+
dma_fence_signal_timestamp(fence, timestamp);
173174

174175
return fence;
175176
}

drivers/gpu/drm/drm_syncobj.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ EXPORT_SYMBOL(drm_syncobj_replace_fence);
353353
*/
354354
static int drm_syncobj_assign_null_handle(struct drm_syncobj *syncobj)
355355
{
356-
struct dma_fence *fence = dma_fence_allocate_private_stub();
356+
struct dma_fence *fence = dma_fence_allocate_private_stub(ktime_get());
357357

358358
if (IS_ERR(fence))
359359
return PTR_ERR(fence);

include/linux/dma-fence.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ static inline signed long dma_fence_wait(struct dma_fence *fence, bool intr)
584584
}
585585

586586
struct dma_fence *dma_fence_get_stub(void);
587-
struct dma_fence *dma_fence_allocate_private_stub(void);
587+
struct dma_fence *dma_fence_allocate_private_stub(ktime_t timestamp);
588588
u64 dma_fence_context_alloc(unsigned num);
589589

590590
extern const struct dma_fence_ops dma_fence_array_ops;

0 commit comments

Comments
 (0)