Skip to content

Commit 7f2a09e

Browse files
JamesH65anholt
authored andcommitted
drm/vc4: Replace wait_for macros to remove use of msleep
The wait_for macro's for Broadcom VC4 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 v3d patch in case this tickles modesetting bugs (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
1 parent 83794ee commit 7f2a09e

1 file changed

Lines changed: 26 additions & 17 deletions

File tree

‎drivers/gpu/drm/vc4/vc4_drv.h‎

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -677,32 +677,41 @@ struct vc4_validated_shader_info {
677677
};
678678

679679
/**
680-
* _wait_for - magic (register) wait macro
680+
* __wait_for - magic wait macro
681681
*
682-
* Does the right thing for modeset paths when run under kdgb or similar atomic
683-
* contexts. Note that it's important that we check the condition again after
684-
* having timed out, since the timeout could be due to preemption or similar and
685-
* we've never had a chance to check the condition before the timeout.
682+
* Macro to help avoid open coding check/wait/timeout patterns. Note that it's
683+
* important that we check the condition again after having timed out, since the
684+
* timeout could be due to preemption or similar and we've never had a chance to
685+
* check the condition before the timeout.
686686
*/
687-
#define _wait_for(COND, MS, W) ({ \
688-
unsigned long timeout__ = jiffies + msecs_to_jiffies(MS) + 1; \
689-
int ret__ = 0; \
690-
while (!(COND)) { \
691-
if (time_after(jiffies, timeout__)) { \
692-
if (!(COND)) \
693-
ret__ = -ETIMEDOUT; \
687+
#define __wait_for(OP, COND, US, Wmin, Wmax) ({ \
688+
const ktime_t end__ = ktime_add_ns(ktime_get_raw(), 1000ll * (US)); \
689+
long wait__ = (Wmin); /* recommended min for usleep is 10 us */ \
690+
int ret__; \
691+
might_sleep(); \
692+
for (;;) { \
693+
const bool expired__ = ktime_after(ktime_get_raw(), end__); \
694+
OP; \
695+
/* Guarantee COND check prior to timeout */ \
696+
barrier(); \
697+
if (COND) { \
698+
ret__ = 0; \
694699
break; \
695700
} \
696-
if (W && drm_can_sleep()) { \
697-
msleep(W); \
698-
} else { \
699-
cpu_relax(); \
701+
if (expired__) { \
702+
ret__ = -ETIMEDOUT; \
703+
break; \
700704
} \
705+
usleep_range(wait__, wait__ * 2); \
706+
if (wait__ < (Wmax)) \
707+
wait__ <<= 1; \
701708
} \
702709
ret__; \
703710
})
704711

705-
#define wait_for(COND, MS) _wait_for(COND, MS, 1)
712+
#define _wait_for(COND, US, Wmin, Wmax) __wait_for(, (COND), (US), (Wmin), \
713+
(Wmax))
714+
#define wait_for(COND, MS) _wait_for((COND), (MS) * 1000, 10, 1000)
706715

707716
/* vc4_bo.c */
708717
struct drm_gem_object *vc4_create_object(struct drm_device *dev, size_t size);

0 commit comments

Comments
 (0)