diff options
author | Chris Wilson <chris@chris-wilson.co.uk> | 2017-01-04 09:12:21 -0500 |
---|---|---|
committer | Sumit Semwal <sumit.semwal@linaro.org> | 2017-01-09 09:36:58 -0500 |
commit | d6c99f4bf093a58d3ab47caaec74b81f18bc4e3f (patch) | |
tree | 246eff35230c79ce6560cf7fe23ce453a6ed62bb | |
parent | 83dd1376fd92f33bdeca9e83d479534a4e7f870b (diff) |
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
-rw-r--r-- | drivers/dma-buf/dma-fence.c | 25 | ||||
-rw-r--r-- | drivers/dma-buf/sync_debug.c | 17 | ||||
-rw-r--r-- | drivers/dma-buf/sync_file.c | 6 | ||||
-rw-r--r-- | include/linux/dma-fence.h | 24 |
4 files changed, 59 insertions, 13 deletions
diff --git a/drivers/dma-buf/dma-fence.c b/drivers/dma-buf/dma-fence.c index cb6eef308cd9..5e66dfece03c 100644 --- a/drivers/dma-buf/dma-fence.c +++ b/drivers/dma-buf/dma-fence.c | |||
@@ -282,6 +282,31 @@ int dma_fence_add_callback(struct dma_fence *fence, struct dma_fence_cb *cb, | |||
282 | EXPORT_SYMBOL(dma_fence_add_callback); | 282 | EXPORT_SYMBOL(dma_fence_add_callback); |
283 | 283 | ||
284 | /** | 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 | |||
309 | /** | ||
285 | * dma_fence_remove_callback - remove a callback from the signaling list | 310 | * dma_fence_remove_callback - remove a callback from the signaling list |
286 | * @fence: [in] the fence to wait on | 311 | * @fence: [in] the fence to wait on |
287 | * @cb: [in] the callback to remove | 312 | * @cb: [in] the callback to remove |
diff --git a/drivers/dma-buf/sync_debug.c b/drivers/dma-buf/sync_debug.c index 48b20e34fb6d..c769dc653b34 100644 --- a/drivers/dma-buf/sync_debug.c +++ b/drivers/dma-buf/sync_debug.c | |||
@@ -62,30 +62,29 @@ void sync_file_debug_remove(struct sync_file *sync_file) | |||
62 | 62 | ||
63 | static const char *sync_status_str(int status) | 63 | static const char *sync_status_str(int status) |
64 | { | 64 | { |
65 | if (status == 0) | 65 | if (status < 0) |
66 | return "signaled"; | 66 | return "error"; |
67 | 67 | ||
68 | if (status > 0) | 68 | if (status > 0) |
69 | return "active"; | 69 | return "signaled"; |
70 | 70 | ||
71 | return "error"; | 71 | return "active"; |
72 | } | 72 | } |
73 | 73 | ||
74 | static void sync_print_fence(struct seq_file *s, | 74 | static void sync_print_fence(struct seq_file *s, |
75 | struct dma_fence *fence, bool show) | 75 | struct dma_fence *fence, bool show) |
76 | { | 76 | { |
77 | int status = 1; | ||
78 | struct sync_timeline *parent = dma_fence_parent(fence); | 77 | struct sync_timeline *parent = dma_fence_parent(fence); |
78 | int status; | ||
79 | 79 | ||
80 | if (dma_fence_is_signaled_locked(fence)) | 80 | status = dma_fence_get_status_locked(fence); |
81 | status = fence->status; | ||
82 | 81 | ||
83 | seq_printf(s, " %s%sfence %s", | 82 | seq_printf(s, " %s%sfence %s", |
84 | show ? parent->name : "", | 83 | show ? parent->name : "", |
85 | show ? "_" : "", | 84 | show ? "_" : "", |
86 | sync_status_str(status)); | 85 | sync_status_str(status)); |
87 | 86 | ||
88 | if (status <= 0) { | 87 | if (status) { |
89 | struct timespec64 ts64 = | 88 | struct timespec64 ts64 = |
90 | ktime_to_timespec64(fence->timestamp); | 89 | ktime_to_timespec64(fence->timestamp); |
91 | 90 | ||
@@ -136,7 +135,7 @@ static void sync_print_sync_file(struct seq_file *s, | |||
136 | int i; | 135 | int i; |
137 | 136 | ||
138 | seq_printf(s, "[%p] %s: %s\n", sync_file, sync_file->name, | 137 | 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))); |
140 | 139 | ||
141 | if (dma_fence_is_array(sync_file->fence)) { | 140 | if (dma_fence_is_array(sync_file->fence)) { |
142 | struct dma_fence_array *array = to_dma_fence_array(sync_file->fence); | 141 | struct dma_fence_array *array = to_dma_fence_array(sync_file->fence); |
diff --git a/drivers/dma-buf/sync_file.c b/drivers/dma-buf/sync_file.c index 07cb9b908f30..2321035f6204 100644 --- a/drivers/dma-buf/sync_file.c +++ b/drivers/dma-buf/sync_file.c | |||
@@ -373,10 +373,8 @@ static void sync_fill_fence_info(struct dma_fence *fence, | |||
373 | sizeof(info->obj_name)); | 373 | sizeof(info->obj_name)); |
374 | strlcpy(info->driver_name, fence->ops->get_driver_name(fence), | 374 | strlcpy(info->driver_name, fence->ops->get_driver_name(fence), |
375 | sizeof(info->driver_name)); | 375 | sizeof(info->driver_name)); |
376 | if (dma_fence_is_signaled(fence)) | 376 | |
377 | info->status = fence->status >= 0 ? 1 : fence->status; | 377 | info->status = dma_fence_get_status(fence); |
378 | else | ||
379 | info->status = 0; | ||
380 | info->timestamp_ns = ktime_to_ns(fence->timestamp); | 378 | info->timestamp_ns = ktime_to_ns(fence->timestamp); |
381 | } | 379 | } |
382 | 380 | ||
diff --git a/include/linux/dma-fence.h b/include/linux/dma-fence.h index d51a7d23c358..19f7af905182 100644 --- a/include/linux/dma-fence.h +++ b/include/linux/dma-fence.h | |||
@@ -378,6 +378,30 @@ static inline struct dma_fence *dma_fence_later(struct dma_fence *f1, | |||
378 | return dma_fence_is_signaled(f2) ? NULL : f2; | 378 | return dma_fence_is_signaled(f2) ? NULL : f2; |
379 | } | 379 | } |
380 | 380 | ||
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 | |||
381 | signed long dma_fence_wait_timeout(struct dma_fence *, | 405 | signed long dma_fence_wait_timeout(struct dma_fence *, |
382 | bool intr, signed long timeout); | 406 | bool intr, signed long timeout); |
383 | signed long dma_fence_wait_any_timeout(struct dma_fence **fences, | 407 | signed long dma_fence_wait_any_timeout(struct dma_fence **fences, |