All of lore.kernel.org
 help / color / mirror / Atom feed
From: Imre Deak <imre.deak@intel.com>
To: intel-gfx@lists.freedesktop.org
Subject: [PATCH] drm/i915: fix wait_remaining_ms_from_jiffies
Date: Wed, 29 Jan 2014 10:52:33 +0200	[thread overview]
Message-ID: <1390985553-3507-1-git-send-email-imre.deak@intel.com> (raw)

schedule_timeout_uninterruptible() takes jiffies not ms.

Also we should check whether jiffies has overflowed since the timestamp
for event A was taken. This is highly unlikely on 64 bit, but on 32 bit
machines jiffies initially is -300*HZ. If the panel power is initially
off the first wait from edp_panel_vdd_on()->wait_panel_power_cycle()
will result in a call timestamp_jiffies of 0, so on 32 bit machines we
would wait ~300 sec + to_wait_ms. Fix this by checking if the initial
timestamp is not in the future.

Signed-off-by: Imre Deak <imre.deak@intel.com>
---
 drivers/gpu/drm/i915/i915_drv.h | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 3673ba1..6a80393 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -2643,12 +2643,13 @@ timespec_to_jiffies_timeout(const struct timespec *value)
  * doesn't happen exactly after event A, you record the timestamp (jiffies) of
  * when event A happened, then just before event B you call this function and
  * pass the timestamp as the first argument, and X as the second argument.
+ * Note that the recorded timestamp (timestamp_jiffies) can't be in the future
+ * otherwise the function won't wait at all.
  */
 static inline void
 wait_remaining_ms_from_jiffies(unsigned long timestamp_jiffies, int to_wait_ms)
 {
-	unsigned long target_jiffies, tmp_jiffies;
-	unsigned int remaining_ms;
+	unsigned long target_jiffies, tmp_jiffies, remaining_jiffies;
 
 	/*
 	 * Don't re-read the value of "jiffies" every time since it may change
@@ -2658,12 +2659,12 @@ wait_remaining_ms_from_jiffies(unsigned long timestamp_jiffies, int to_wait_ms)
 	target_jiffies = timestamp_jiffies +
 			 msecs_to_jiffies_timeout(to_wait_ms);
 
-	if (time_after(target_jiffies, tmp_jiffies)) {
-		remaining_ms = jiffies_to_msecs((long)target_jiffies -
-						(long)tmp_jiffies);
-		while (remaining_ms)
-			remaining_ms =
-				schedule_timeout_uninterruptible(remaining_ms);
+	if (time_after(target_jiffies, tmp_jiffies) &&
+	    time_before_eq(timestamp_jiffies, tmp_jiffies)) {
+		remaining_jiffies = target_jiffies - tmp_jiffies;
+		while (remaining_jiffies)
+			remaining_jiffies =
+			    schedule_timeout_uninterruptible(remaining_jiffies);
 	}
 }
 
-- 
1.8.4

             reply	other threads:[~2014-01-29  8:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-29  8:52 Imre Deak [this message]
2014-01-29  9:23 ` [PATCH] drm/i915: fix wait_remaining_ms_from_jiffies Chris Wilson
2014-01-29 11:37 ` Jani Nikula
2014-01-29 19:39   ` Daniel Vetter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1390985553-3507-1-git-send-email-imre.deak@intel.com \
    --to=imre.deak@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.