WARN when schedule_timeout() times out too early

Submitted by Ville Syrjälä on April 27, 2018, 8:21 p.m.

Details

Message ID 20180427202122.28301-1-ville.syrjala@linux.intel.com
State New
Headers show
Series "WARN when schedule_timeout() times out too early" ( rev: 1 ) in Intel GFX - Try Bot

Not browsing as part of any series.

Commit Message

Ville Syrjälä April 27, 2018, 8:21 p.m.
From: Ville Syrjälä <ville.syrjala@linux.intel.com>

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 kernel/time/timer.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Patch hide | download patch | download mbox

diff --git a/kernel/time/timer.c b/kernel/time/timer.c
index 4a4fd567fb26..662db60576c5 100644
--- a/kernel/time/timer.c
+++ b/kernel/time/timer.c
@@ -1763,6 +1763,8 @@  signed long __sched schedule_timeout(signed long timeout)
 {
 	struct process_timer timer;
 	unsigned long expire;
+	signed long total_timeout = timeout;
+	ktime_t t = ktime_get();
 
 	switch (timeout)
 	{
@@ -1789,6 +1791,7 @@  signed long __sched schedule_timeout(signed long timeout)
 				"value %lx\n", timeout);
 			dump_stack();
 			current->state = TASK_RUNNING;
+			timeout = 0;
 			goto out;
 		}
 	}
@@ -1807,6 +1810,15 @@  signed long __sched schedule_timeout(signed long timeout)
 	timeout = expire - jiffies;
 
  out:
+	if (timeout < 0) {
+		s64 diff = ktime_us_delta(ktime_get(), t);
+		s64 expected = jiffies_to_usecs(total_timeout - 1);
+
+		WARN(diff < expected,
+		     "schedule_timeout() returned after %lld usecs, expected at least %lld usec\n",
+		     diff, expected);
+	}
+
 	return timeout < 0 ? 0 : timeout;
 }
 EXPORT_SYMBOL(schedule_timeout);