Skip to content

Commit d6c99f4

Browse files
icklesumitsemwal
authored andcommitted
dma-fence: Wrap querying the fence->status
The fence->status is an optional field that is only valid once the fence has been signaled. (Driver may fill the fence->status with an error code prior to calling dma_fence_signal().) Given the restriction upon its validity, wrap querying of the fence->status into a helper dma_fence_get_status(). Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Reviewed-by: Sumit Semwal <sumit.semwal@linaro.org> Signed-off-by: Sumit Semwal <sumit.semwal@linaro.org> Link: http://patchwork.freedesktop.org/patch/msgid/20170104141222.6992-2-chris@chris-wilson.co.uk
1 parent 83dd137 commit d6c99f4

4 files changed

Lines changed: 59 additions & 13 deletions

File tree

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,31 @@ int dma_fence_add_callback(struct dma_fence *fence, struct dma_fence_cb *cb,
281281
}
282282
EXPORT_SYMBOL(dma_fence_add_callback);
283283

284+
/**
285+
* dma_fence_get_status - returns the status upon completion
286+
* @fence: [in] the dma_fence to query
287+
*
288+
* This wraps dma_fence_get_status_locked() to return the error status
289+
* condition on a signaled fence. See dma_fence_get_status_locked() for more
290+
* details.
291+
*
292+
* Returns 0 if the fence has not yet been signaled, 1 if the fence has
293+
* been signaled without an error condition, or a negative error code
294+
* if the fence has been completed in err.
295+
*/
296+
int dma_fence_get_status(struct dma_fence *fence)
297+
{
298+
unsigned long flags;
299+
int status;
300+
301+
spin_lock_irqsave(fence->lock, flags);
302+
status = dma_fence_get_status_locked(fence);
303+
spin_unlock_irqrestore(fence->lock, flags);
304+
305+
return status;
306+
}
307+
EXPORT_SYMBOL(dma_fence_get_status);
308+
284309
/**
285310
* dma_fence_remove_callback - remove a callback from the signaling list
286311
* @fence: [in] the fence to wait on

‎drivers/dma-buf/sync_debug.c‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,30 +62,29 @@ void sync_file_debug_remove(struct sync_file *sync_file)
6262

6363
static const char *sync_status_str(int status)
6464
{
65-
if (status == 0)
66-
return "signaled";
65+
if (status < 0)
66+
return "error";
6767

6868
if (status > 0)
69-
return "active";
69+
return "signaled";
7070

71-
return "error";
71+
return "active";
7272
}
7373

7474
static void sync_print_fence(struct seq_file *s,
7575
struct dma_fence *fence, bool show)
7676
{
77-
int status = 1;
7877
struct sync_timeline *parent = dma_fence_parent(fence);
78+
int status;
7979

80-
if (dma_fence_is_signaled_locked(fence))
81-
status = fence->status;
80+
status = dma_fence_get_status_locked(fence);
8281

8382
seq_printf(s, " %s%sfence %s",
8483
show ? parent->name : "",
8584
show ? "_" : "",
8685
sync_status_str(status));
8786

88-
if (status <= 0) {
87+
if (status) {
8988
struct timespec64 ts64 =
9089
ktime_to_timespec64(fence->timestamp);
9190

@@ -136,7 +135,7 @@ static void sync_print_sync_file(struct seq_file *s,
136135
int i;
137136

138137
seq_printf(s, "[%p] %s: %s\n", sync_file, sync_file->name,
139-
sync_status_str(!dma_fence_is_signaled(sync_file->fence)));
138+
sync_status_str(dma_fence_get_status(sync_file->fence)));
140139

141140
if (dma_fence_is_array(sync_file->fence)) {
142141
struct dma_fence_array *array = to_dma_fence_array(sync_file->fence);

‎drivers/dma-buf/sync_file.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -373,10 +373,8 @@ static void sync_fill_fence_info(struct dma_fence *fence,
373373
sizeof(info->obj_name));
374374
strlcpy(info->driver_name, fence->ops->get_driver_name(fence),
375375
sizeof(info->driver_name));
376-
if (dma_fence_is_signaled(fence))
377-
info->status = fence->status >= 0 ? 1 : fence->status;
378-
else
379-
info->status = 0;
376+
377+
info->status = dma_fence_get_status(fence);
380378
info->timestamp_ns = ktime_to_ns(fence->timestamp);
381379
}
382380

‎include/linux/dma-fence.h‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,30 @@ static inline struct dma_fence *dma_fence_later(struct dma_fence *f1,
378378
return dma_fence_is_signaled(f2) ? NULL : f2;
379379
}
380380

381+
/**
382+
* dma_fence_get_status_locked - returns the status upon completion
383+
* @fence: [in] the dma_fence to query
384+
*
385+
* Drivers can supply an optional error status condition before they signal
386+
* the fence (to indicate whether the fence was completed due to an error
387+
* rather than success). The value of the status condition is only valid
388+
* if the fence has been signaled, dma_fence_get_status_locked() first checks
389+
* the signal state before reporting the error status.
390+
*
391+
* Returns 0 if the fence has not yet been signaled, 1 if the fence has
392+
* been signaled without an error condition, or a negative error code
393+
* if the fence has been completed in err.
394+
*/
395+
static inline int dma_fence_get_status_locked(struct dma_fence *fence)
396+
{
397+
if (dma_fence_is_signaled_locked(fence))
398+
return fence->status < 0 ? fence->status : 1;
399+
else
400+
return 0;
401+
}
402+
403+
int dma_fence_get_status(struct dma_fence *fence);
404+
381405
signed long dma_fence_wait_timeout(struct dma_fence *,
382406
bool intr, signed long timeout);
383407
signed long dma_fence_wait_any_timeout(struct dma_fence **fences,

0 commit comments

Comments
 (0)