mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-03 02:49:09 +08:00
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>
This commit is contained in:
parent
cbd99e3b28
commit
c029a2bec6
@ -1644,7 +1644,7 @@ void timekeeping_resume(void)
|
||||
struct clocksource *clock = tk->tkr_mono.clock;
|
||||
unsigned long flags;
|
||||
struct timespec64 ts_new, ts_delta;
|
||||
cycle_t cycle_now, cycle_delta;
|
||||
cycle_t cycle_now;
|
||||
|
||||
sleeptime_injected = false;
|
||||
read_persistent_clock64(&ts_new);
|
||||
@ -1670,27 +1670,11 @@ void timekeeping_resume(void)
|
||||
cycle_now = tk->tkr_mono.read(clock);
|
||||
if ((clock->flags & CLOCK_SOURCE_SUSPEND_NONSTOP) &&
|
||||
cycle_now > tk->tkr_mono.cycle_last) {
|
||||
u64 num, max = ULLONG_MAX;
|
||||
u32 mult = clock->mult;
|
||||
u32 shift = clock->shift;
|
||||
s64 nsec = 0;
|
||||
|
||||
cycle_delta = clocksource_delta(cycle_now, tk->tkr_mono.cycle_last,
|
||||
tk->tkr_mono.mask);
|
||||
|
||||
/*
|
||||
* "cycle_delta * mutl" may cause 64 bits overflow, if the
|
||||
* suspended time is too long. In that case we need do the
|
||||
* 64 bits math carefully
|
||||
*/
|
||||
do_div(max, mult);
|
||||
if (cycle_delta > max) {
|
||||
num = div64_u64(cycle_delta, max);
|
||||
nsec = (((u64) max * mult) >> shift) * num;
|
||||
cycle_delta -= num * max;
|
||||
}
|
||||
nsec += ((u64) cycle_delta * mult) >> shift;
|
||||
u64 nsec, cyc_delta;
|
||||
|
||||
cyc_delta = clocksource_delta(cycle_now, tk->tkr_mono.cycle_last,
|
||||
tk->tkr_mono.mask);
|
||||
nsec = mul_u64_u32_shr(cyc_delta, clock->mult, clock->shift);
|
||||
ts_delta = ns_to_timespec64(nsec);
|
||||
sleeptime_injected = true;
|
||||
} else if (timespec64_compare(&ts_new, &timekeeping_suspend_time) > 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user