History

NOHZ: prevent multiplication overflow - stop timer for huge timeouts

get_next_timer_interrupt() returns a delta of (LONG_MAX > 1) in case there is no timer pending. On 64 bit machines this results in a multiplication overflow in tick_nohz_stop_sched_tick(). Reported by: Dave Miller <davem@davemloft.net> Make the return value a constant and limit the return value to a 32 bit value. When the max timeout value is returned, we can safely stop the tick timer device. The max jiffies delta results in a 12 days timeout for HZ=1000. In the long term the get_next_timer_interrupt() code needs to be reworked to return ktime instead of jiffies, but we have to wait until the last users of the original NO_IDLE_HZ code are converted.

Thomas Gleixner committed 19 years ago

Commit eaad0841 parent 6e98ee73 files · +30 −2Browse files

Showing the changes to kernel/timer.c (1 of 3 files). Show all

Unified · Split

kernel/timer.c+9−1
@@ -666,7 +666,7 @@ static inline void __run_timers(tvec_base_t *base) · 665 unmodified lines
666666 static unsigned long __next_timer_interrupt(tvec_base_t *base)
667667 {
668668 unsigned long timer_jiffies = base->timer_jiffies;
669− unsigned long expires = timer_jiffies + (LONG_MAX >> 1);
669+ unsigned long expires = timer_jiffies + NEXT_TIMER_MAX_DELTA;
670670 int index, slot, array, found = 0;
671671 struct timer_list *nte;
672672 tvec_t *varray[4];
@@ -752,6 +752,14 @@ static unsigned long cmp_next_hrtimer_event(unsigned long now, · 79 unmodified lines
752752
753753 tsdelta = ktime_to_timespec(hr_delta);
754754 delta = timespec_to_jiffies(&tsdelta);
755+
756+ /*
757+ * Limit the delta to the max value, which is checked in
758+ * tick_nohz_stop_sched_tick():
759+ */
760+ if (delta > NEXT_TIMER_MAX_DELTA)
761+ delta = NEXT_TIMER_MAX_DELTA;
762+
755763 /*
756764 * Take rounding errors in to account and make sure, that it
757765 * expires in the next tick. Otherwise we go into an endless

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t