diff options
author | Terje Bergstrom <tbergstrom@nvidia.com> | 2017-05-16 16:59:31 -0400 |
---|---|---|
committer | mobile promotions <svcmobile_promotions@nvidia.com> | 2017-05-24 15:14:03 -0400 |
commit | ee25b33ca4aafbbab6e9b7cd963f9011a59037cd (patch) | |
tree | 80f10d0027de77ea23a5c6b71c46b7da61c61102 /drivers/gpu/nvgpu/include | |
parent | 9db45cf0376c6de8d71cc8087d0ec76dff72c00b (diff) |
gpu: nvgpu: Proper timeout for NVGPU_COND_WAIT
The timeout parameter to NVGPU_COND_WAIT()
was passed directly to wait_event_timeout(), which takes jiffies.
Also allows zero timeout to disable timeout.
The return value of NVGPU_COND_WAIT() was defined in a way specific
to how Linux wait_event_() calls work. Replace that with proper error
reporting and change the callers to check against error codes.
JIRA NVGPU-14
Change-Id: Idbd2c8fbbef7589c3ca4f4c5732852bc71217515
Signed-off-by: Terje Bergstrom <tbergstrom@nvidia.com>
Reviewed-on: http://git-master/r/1484927
Reviewed-by: mobile promotions <svcmobile_promotions@nvidia.com>
Tested-by: mobile promotions <svcmobile_promotions@nvidia.com>
Diffstat (limited to 'drivers/gpu/nvgpu/include')
-rw-r--r-- | drivers/gpu/nvgpu/include/nvgpu/linux/cond.h | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/drivers/gpu/nvgpu/include/nvgpu/linux/cond.h b/drivers/gpu/nvgpu/include/nvgpu/linux/cond.h index 3eb52861..01ca5291 100644 --- a/drivers/gpu/nvgpu/include/nvgpu/linux/cond.h +++ b/drivers/gpu/nvgpu/include/nvgpu/linux/cond.h | |||
@@ -24,10 +24,57 @@ struct nvgpu_cond { | |||
24 | wait_queue_head_t wq; | 24 | wait_queue_head_t wq; |
25 | }; | 25 | }; |
26 | 26 | ||
27 | /** | ||
28 | * NVGPU_COND_WAIT - Wait for a condition to be true | ||
29 | * | ||
30 | * @c - The condition variable to sleep on | ||
31 | * @condition - The condition that needs to be true | ||
32 | * @timeout_ms - Timeout in milliseconds, or 0 for infinite wait | ||
33 | * | ||
34 | * Wait for a condition to become true. Returns -ETIMEOUT if | ||
35 | * the wait timed out with condition false. | ||
36 | */ | ||
27 | #define NVGPU_COND_WAIT(c, condition, timeout_ms) \ | 37 | #define NVGPU_COND_WAIT(c, condition, timeout_ms) \ |
28 | wait_event_timeout((c)->wq, condition, timeout_ms) | 38 | ({\ |
39 | int ret = 0; \ | ||
40 | long _timeout_ms = timeout_ms;\ | ||
41 | if (_timeout_ms > 0) { \ | ||
42 | long _ret = wait_event_timeout((c)->wq, condition, \ | ||
43 | msecs_to_jiffies(_timeout_ms)); \ | ||
44 | if (_ret == 0) \ | ||
45 | ret = -ETIMEDOUT; \ | ||
46 | } else { \ | ||
47 | wait_event((c)->wq, condition); \ | ||
48 | } \ | ||
49 | ret;\ | ||
50 | }) | ||
29 | 51 | ||
52 | /** | ||
53 | * NVGPU_COND_WAIT_INTERRUPTIBLE - Wait for a condition to be true | ||
54 | * | ||
55 | * @c - The condition variable to sleep on | ||
56 | * @condition - The condition that needs to be true | ||
57 | * @timeout_ms - Timeout in milliseconds, or 0 for infinite wait | ||
58 | * | ||
59 | * Wait for a condition to become true. Returns -ETIMEOUT if | ||
60 | * the wait timed out with condition false or -ERESTARTSYS on | ||
61 | * signal. | ||
62 | */ | ||
30 | #define NVGPU_COND_WAIT_INTERRUPTIBLE(c, condition, timeout_ms) \ | 63 | #define NVGPU_COND_WAIT_INTERRUPTIBLE(c, condition, timeout_ms) \ |
31 | wait_event_interruptible_timeout((c)->wq, condition, timeout_ms) | 64 | ({ \ |
65 | int ret = 0; \ | ||
66 | long _timeout_ms = timeout_ms;\ | ||
67 | if (_timeout_ms > 0) { \ | ||
68 | long _ret = wait_event_interruptible_timeout((c)->wq, condition, \ | ||
69 | msecs_to_jiffies(_timeout_ms)); \ | ||
70 | if (_ret == 0) \ | ||
71 | ret = -ETIMEDOUT; \ | ||
72 | else if (_ret == -ERESTARTSYS) \ | ||
73 | ret = -ERESTARTSYS; \ | ||
74 | } else { \ | ||
75 | wait_event_interruptible((c)->wq, condition); \ | ||
76 | } \ | ||
77 | ret; \ | ||
78 | }) | ||
32 | 79 | ||
33 | #endif /* __NVGPU_LOCK_LINUX_H__ */ | 80 | #endif /* __NVGPU_LOCK_LINUX_H__ */ |