Skip to content

Commit

Permalink
[hrtimer] Enforce resolution as lower limit of intervals
Browse files Browse the repository at this point in the history
Roman Zippel pointed out that the missing lower limit of intervals
leads to an accounting error in the overrun count. Enforce the lower
limit of intervals to resolution in the timer forwarding code.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
  • Loading branch information
Thomas Gleixner committed Jan 12, 2006
1 parent e278763 commit c9db4fa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 1 addition & 2 deletions include/linux/hrtimer.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ static inline int hrtimer_active(const struct hrtimer *timer)
}

/* Forward a hrtimer so it expires after now: */
extern unsigned long hrtimer_forward(struct hrtimer *timer,
const ktime_t interval);
extern unsigned long hrtimer_forward(struct hrtimer *timer, ktime_t interval);

/* Precise sleep: */
extern long hrtimer_nanosleep(struct timespec *rqtp,
Expand Down
5 changes: 4 additions & 1 deletion kernel/hrtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ void unlock_hrtimer_base(const struct hrtimer *timer, unsigned long *flags)
* The number of overruns is added to the overrun field.
*/
unsigned long
hrtimer_forward(struct hrtimer *timer, const ktime_t interval)
hrtimer_forward(struct hrtimer *timer, ktime_t interval)
{
unsigned long orun = 1;
ktime_t delta, now;
Expand All @@ -287,6 +287,9 @@ hrtimer_forward(struct hrtimer *timer, const ktime_t interval)
if (delta.tv64 < 0)
return 0;

if (interval.tv64 < timer->base->resolution.tv64)
interval.tv64 = timer->base->resolution.tv64;

if (unlikely(delta.tv64 >= interval.tv64)) {
nsec_t incr = ktime_to_ns(interval);

Expand Down

0 comments on commit c9db4fa

Please sign in to comment.