Skip to content

Commit 9daee61

Browse files
JamesH65anholt
authored andcommitted
drm/v3d: Replace wait_for macros to remove use of msleep
The wait_for macro's for Broadcom V3D driver used msleep, which is inappropriate due to its inaccuracy at low values (minimum wait time is about 30ms on the Raspberry Pi). This sleep was triggering in v3d_clean_caches(), causing us to only be able to dispatch ~33 compute jobs per second. This patch replaces the macro with the one from the Intel i915 version which uses usleep_range to provide more accurate waits. v2: Split from the vc4 patch so that we can confidently apply to stable (by anholt) Signed-off-by: James Hughes <james.hughes@raspberrypi.com> Signed-off-by: Eric Anholt <eric@anholt.net> Link: https://patchwork.freedesktop.org/patch/msgid/20200217153145.13780-1-james.hughes@raspberrypi.com Link: raspberrypi#3460 Fixes: 57692c9 ("drm/v3d: Introduce a new DRM driver for Broadcom V3D V3.x+")
1 parent 7f2a09e commit 9daee61

1 file changed

Lines changed: 28 additions & 13 deletions

File tree

‎drivers/gpu/drm/v3d/v3d_drv.h‎

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -254,27 +254,42 @@ struct v3d_csd_job {
254254
};
255255

256256
/**
257-
* _wait_for - magic (register) wait macro
257+
* __wait_for - magic wait macro
258258
*
259-
* Does the right thing for modeset paths when run under kdgb or similar atomic
260-
* contexts. Note that it's important that we check the condition again after
261-
* having timed out, since the timeout could be due to preemption or similar and
262-
* we've never had a chance to check the condition before the timeout.
259+
* Macro to help avoid open coding check/wait/timeout patterns. Note that it's
260+
* important that we check the condition again after having timed out, since the
261+
* timeout could be due to preemption or similar and we've never had a chance to
262+
* check the condition before the timeout.
263263
*/
264-
#define wait_for(COND, MS) ({ \
265-
unsigned long timeout__ = jiffies + msecs_to_jiffies(MS) + 1; \
266-
int ret__ = 0; \
267-
while (!(COND)) { \
268-
if (time_after(jiffies, timeout__)) { \
269-
if (!(COND)) \
270-
ret__ = -ETIMEDOUT; \
264+
#define __wait_for(OP, COND, US, Wmin, Wmax) ({ \
265+
const ktime_t end__ = ktime_add_ns(ktime_get_raw(), 1000ll * (US)); \
266+
long wait__ = (Wmin); /* recommended min for usleep is 10 us */ \
267+
int ret__; \
268+
might_sleep(); \
269+
for (;;) { \
270+
const bool expired__ = ktime_after(ktime_get_raw(), end__); \
271+
OP; \
272+
/* Guarantee COND check prior to timeout */ \
273+
barrier(); \
274+
if (COND) { \
275+
ret__ = 0; \
271276
break; \
272277
} \
273-
msleep(1); \
278+
if (expired__) { \
279+
ret__ = -ETIMEDOUT; \
280+
break; \
281+
} \
282+
usleep_range(wait__, wait__ * 2); \
283+
if (wait__ < (Wmax)) \
284+
wait__ <<= 1; \
274285
} \
275286
ret__; \
276287
})
277288

289+
#define _wait_for(COND, US, Wmin, Wmax) __wait_for(, (COND), (US), (Wmin), \
290+
(Wmax))
291+
#define wait_for(COND, MS) _wait_for((COND), (MS) * 1000, 10, 1000)
292+
278293
static inline unsigned long nsecs_to_jiffies_timeout(const u64 n)
279294
{
280295
/* nsecs_to_jiffies64() does not guard against overflow */

0 commit comments

Comments
 (0)