Commit 96d2ab484e7a9bafdab44b8c7d1ef5944319b18c

Authored by Arjan van de Ven
1 parent 704af52bd1

hrtimer: fix signed/unsigned bug in slack estimator

the slack estimator used unsigned math; however for very short delay it's
possible that by the time you calculate the timeout, it's already passed and
you get a negative time/slack... in an unsigned variable... which then gets
turned into a 100 msec delay rather than zero.

This patch fixes this by using a signed typee in the right places.

Signed-off-by: Arjan van de Ven <arjan@linux.intel.com>

Showing 1 changed file with 8 additions and 5 deletions Side-by-side Diff

... ... @@ -41,9 +41,9 @@
41 41 * better solutions..
42 42 */
43 43  
44   -static unsigned long __estimate_accuracy(struct timespec *tv)
  44 +static long __estimate_accuracy(struct timespec *tv)
45 45 {
46   - unsigned long slack;
  46 + long slack;
47 47 int divfactor = 1000;
48 48  
49 49 if (task_nice(current) > 0)
50 50  
... ... @@ -54,10 +54,13 @@
54 54  
55 55 if (slack > 100 * NSEC_PER_MSEC)
56 56 slack = 100 * NSEC_PER_MSEC;
  57 +
  58 + if (slack < 0)
  59 + slack = 0;
57 60 return slack;
58 61 }
59 62  
60   -static unsigned long estimate_accuracy(struct timespec *tv)
  63 +static long estimate_accuracy(struct timespec *tv)
61 64 {
62 65 unsigned long ret;
63 66 struct timespec now;
... ... @@ -330,7 +333,7 @@
330 333 timed_out = 1;
331 334 }
332 335  
333   - if (end_time)
  336 + if (end_time && !timed_out)
334 337 slack = estimate_accuracy(end_time);
335 338  
336 339 retval = 0;
... ... @@ -656,7 +659,7 @@
656 659 timed_out = 1;
657 660 }
658 661  
659   - if (end_time)
  662 + if (end_time && !timed_out)
660 663 slack = estimate_accuracy(end_time);
661 664  
662 665 for (;;) {