Skip to content

Commit c029a2b

Browse files
committed
timekeeping: Use mul_u64_u32_shr() instead of open coding it
The resume code must deal with a clocksource delta which is potentially big enough to overflow the 64bit mult. Replace the open coded handling with the proper function. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Parit Bhargava <prarit@redhat.com> Cc: Laurent Vivier <lvivier@redhat.com> Cc: "Christopher S. Hall" <christopher.s.hall@intel.com> Cc: Chris Metcalf <cmetcalf@mellanox.com> Cc: Richard Cochran <richardcochran@gmail.com> Cc: Liav Rehana <liavr@mellanox.com> Cc: John Stultz <john.stultz@linaro.org> Link: http://lkml.kernel.org/r/20161208204228.921674404@linutronix.de Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
1 parent cbd99e3 commit c029a2b

1 file changed

Lines changed: 5 additions & 21 deletions

File tree

‎kernel/time/timekeeping.c‎

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,7 @@ void timekeeping_resume(void)
16441644
struct clocksource *clock = tk->tkr_mono.clock;
16451645
unsigned long flags;
16461646
struct timespec64 ts_new, ts_delta;
1647-
cycle_t cycle_now, cycle_delta;
1647+
cycle_t cycle_now;
16481648

16491649
sleeptime_injected = false;
16501650
read_persistent_clock64(&ts_new);
@@ -1670,27 +1670,11 @@ void timekeeping_resume(void)
16701670
cycle_now = tk->tkr_mono.read(clock);
16711671
if ((clock->flags & CLOCK_SOURCE_SUSPEND_NONSTOP) &&
16721672
cycle_now > tk->tkr_mono.cycle_last) {
1673-
u64 num, max = ULLONG_MAX;
1674-
u32 mult = clock->mult;
1675-
u32 shift = clock->shift;
1676-
s64 nsec = 0;
1677-
1678-
cycle_delta = clocksource_delta(cycle_now, tk->tkr_mono.cycle_last,
1679-
tk->tkr_mono.mask);
1680-
1681-
/*
1682-
* "cycle_delta * mutl" may cause 64 bits overflow, if the
1683-
* suspended time is too long. In that case we need do the
1684-
* 64 bits math carefully
1685-
*/
1686-
do_div(max, mult);
1687-
if (cycle_delta > max) {
1688-
num = div64_u64(cycle_delta, max);
1689-
nsec = (((u64) max * mult) >> shift) * num;
1690-
cycle_delta -= num * max;
1691-
}
1692-
nsec += ((u64) cycle_delta * mult) >> shift;
1673+
u64 nsec, cyc_delta;
16931674

1675+
cyc_delta = clocksource_delta(cycle_now, tk->tkr_mono.cycle_last,
1676+
tk->tkr_mono.mask);
1677+
nsec = mul_u64_u32_shr(cyc_delta, clock->mult, clock->shift);
16941678
ts_delta = ns_to_timespec64(nsec);
16951679
sleeptime_injected = true;
16961680
} else if (timespec64_compare(&ts_new, &timekeeping_suspend_time) > 0) {

0 commit comments

Comments
 (0)