From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753942AbcLHXrp (ORCPT ); Thu, 8 Dec 2016 18:47:45 -0500 Received: from ozlabs.org ([103.22.144.67]:38437 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752737AbcLHXrl (ORCPT ); Thu, 8 Dec 2016 18:47:41 -0500 Date: Fri, 9 Dec 2016 10:41:12 +1100 From: David Gibson To: Thomas Gleixner Cc: LKML , John Stultz , Peter Zijlstra , Ingo Molnar , Liav Rehana , Chris Metcalf , Richard Cochran , Parit Bhargava , Laurent Vivier , "Christopher S. Hall" Subject: Re: [patch 4/6] timekeeping: Use mul_u64_u32_shr() instead of open coding it Message-ID: <20161208234112.GM13139@umbus.fritz.box> References: <20161208202623.883855034@linutronix.de> <20161208204228.921674404@linutronix.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="H7cT1SUwsqXggVRO" Content-Disposition: inline In-Reply-To: <20161208204228.921674404@linutronix.de> User-Agent: Mutt/1.7.1 (2016-10-04) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --H7cT1SUwsqXggVRO Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Dec 08, 2016 at 08:49:38PM -0000, Thomas Gleixner wrote: > The resume code must deal with a clocksource delta which is potentially b= ig > enough to overflow the 64bit mult. >=20 > Replace the open coded handling with the proper function. >=20 > Signed-off-by: Thomas Gleixner Reviewed-by: David Gibson > --- > kernel/time/timekeeping.c | 26 +++++--------------------- > 1 file changed, 5 insertions(+), 21 deletions(-) >=20 > --- a/kernel/time/timekeeping.c > +++ b/kernel/time/timekeeping.c > @@ -1615,7 +1615,7 @@ void timekeeping_resume(void) > struct clocksource *clock =3D tk->tkr_mono.clock; > unsigned long flags; > struct timespec64 ts_new, ts_delta; > - cycle_t cycle_now, cycle_delta; > + cycle_t cycle_now; > =20 > sleeptime_injected =3D false; > read_persistent_clock64(&ts_new); > @@ -1641,27 +1641,11 @@ void timekeeping_resume(void) > cycle_now =3D tk->tkr_mono.read(clock); > if ((clock->flags & CLOCK_SOURCE_SUSPEND_NONSTOP) && > cycle_now > tk->tkr_mono.cycle_last) { > - u64 num, max =3D ULLONG_MAX; > - u32 mult =3D clock->mult; > - u32 shift =3D clock->shift; > - s64 nsec =3D 0; > - > - cycle_delta =3D 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 =3D div64_u64(cycle_delta, max); > - nsec =3D (((u64) max * mult) >> shift) * num; > - cycle_delta -=3D num * max; > - } > - nsec +=3D ((u64) cycle_delta * mult) >> shift; > + u64 nsec, cyc_delta; > =20 > + cyc_delta =3D clocksource_delta(cycle_now, tk->tkr_mono.cycle_last, > + tk->tkr_mono.mask); > + nsec =3D mul_u64_u32_shr(cyc_delta, clock->mult, clock->shift); > ts_delta =3D ns_to_timespec64(nsec); > sleeptime_injected =3D true; > } else if (timespec64_compare(&ts_new, &timekeeping_suspend_time) > 0) { >=20 >=20 --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --H7cT1SUwsqXggVRO Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAEBCAAGBQJYSe+YAAoJEGw4ysog2bOStxQQAK8KdOJGfiHWaFh3/PCNv0L4 Fq4RzDk3w3f6QTmdCeMXENEY6YivH2J8MdRUGE1ftJSNcR3Zwb6D1Um7kZkpw1f/ 6f29Zw0c8zVMYIDWIhvRWC6w4CRgs5tL7DNIiwGkKw+8jguKTcL0MFG+2WHAwOyU Hb2UwxFafT12zOSU27RlHy0s+SlVGgpmAx8ajnznoZYufg9PNZHhBkG4P45+Daqm Jrk1KNnMKdHX2MBwKqqkju47OnHa43UxfaCKfmF9xH/Zbteopr77kEGEETNbpJqI kmJeD6Qb0o+HlL3AH4leB1u5D3zOTUfHrUom+paZHABvh2YOjz63AvwG5uKpFt74 F4F8rcCPT/Pk7I04VuFaCCckgwNq+U/PSm8RwHecSixaAxa2WTZISA/P9i0wAH2/ el1T8M/PL0EiR1wt/NpMFIQyc2CWGciGFpi/TY/Tf5dk65gT9L3GPK2gVYFYP/PB qw75/pqFYPko5BSkXpLp28yIToAMe1GMykp8YnE+InuDAv5zACwsIev8IJ5NUQLV FTlEfodOrNrzl2vSLniHA9K/m9dQFZkPnFQUwlAmiaySNjgun32QMmQ8PmJ0k9Vp opzHQ+D74dOWpUOxagwDWsfAFmif8iKfr6OIqVH9VjC9mub8uxKyC17aeOixOITP 6v5b67kRTZ1gaJ5ZJtXM =wWMr -----END PGP SIGNATURE----- --H7cT1SUwsqXggVRO--