intel-gfx.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drm/i915: Only expand COND once in wait_for()
@ 2016-09-13 19:40 Chris Wilson
  2016-09-13 21:05 ` Zanoni, Paulo R
                   ` (5 more replies)
  0 siblings, 6 replies; 11+ messages in thread
From: Chris Wilson @ 2016-09-13 19:40 UTC (permalink / raw)
  To: intel-gfx; +Cc: Daniel Vetter

I was looking at some wait_for() timeouts on a slow system, with lots of
debug enabled (KASAN, lockdep, mmio_debug). Thinking that we were
mishandling the timeout, I tried to ensure that we loop at least once
after first testing COND. However, the double test of COND either side
of the timeout check makes that unlikely. But we can do an equivalent
loop, that keeps the COND check after testing for timeout (required so
that we are not preempted between testing COND and then testing for a
timeout) without expanding COND twice.

The advantage of only expanding COND once is a dramatic reduction in
code size:

   text	   data	    bss	    dec	    hex
1308733	   5184	   1152	1315069	 1410fd	before
1305341	   5184	   1152	1311677	 1403bd	after

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/i915/intel_drv.h | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h
index cb99a2540863..597899d71df9 100644
--- a/drivers/gpu/drm/i915/intel_drv.h
+++ b/drivers/gpu/drm/i915/intel_drv.h
@@ -52,13 +52,16 @@
  */
 #define _wait_for(COND, US, W) ({ \
 	unsigned long timeout__ = jiffies + usecs_to_jiffies(US) + 1;	\
-	int ret__ = 0;							\
-	while (!(COND)) {						\
-		if (time_after(jiffies, timeout__)) {			\
-			if (!(COND))					\
-				ret__ = -ETIMEDOUT;			\
+	int ret__;							\
+	for (;;) {							\
+		if (time_after(jiffies, timeout__))			\
+			ret__ = -ETIMEDOUT;				\
+		if (COND) {						\
+			ret__ = 0;					\
 			break;						\
 		}							\
+		if (ret__)						\
+			break;						\
 		if ((W) && drm_can_sleep()) {				\
 			usleep_range((W), (W)*2);			\
 		} else {						\
-- 
2.9.3

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2016-09-19  1:44 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-13 19:40 [PATCH] drm/i915: Only expand COND once in wait_for() Chris Wilson
2016-09-13 21:05 ` Zanoni, Paulo R
2016-09-14  5:37 ` ✗ Fi.CI.BAT: failure for " Patchwork
2016-09-14  9:22 ` [PATCH] " Chris Wilson
2016-09-14 12:10   ` Dave Gordon
2016-09-14 18:53     ` Paulo Zanoni
2016-09-15  9:50       ` Chris Wilson
2016-09-14 13:37   ` Zanoni, Paulo R
2016-09-14 12:49 ` ✗ Fi.CI.BAT: failure for drm/i915: Only expand COND once in wait_for() (rev2) Patchwork
2016-09-15  7:20 ` ✓ Fi.CI.BAT: success " Patchwork
2016-09-19  1:40 ` [lkp] [drm/i915] c19d736b05: WARNING: CPU: 0 PID: 236 at drivers/gpu/drm/i915/intel_display.c:1085 intel_disable_pipe+0x157/0x250 [i915] kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).