Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d40e944c authored by Roman Zippel's avatar Roman Zippel Committed by Thomas Gleixner
Browse files

ntp: improve adjtimex frequency rounding



Change PPM_SCALE_INV_SHIFT so that it doesn't throw away any input bits
(19 is the amount of the factor 2 in PPM_SCALE), the output frequency
can then be calculated back to its input value, as the inverse divide
produce a slightly larger value, which is then correctly rounded by the
final shift.

Reported-by: default avatarMartin Ziegler <ziegler@uni-freiburg.de>
Signed-off-by: default avatarRoman Zippel <zippel@linux-m68k.org>
Cc: John Stultz <johnstul@us.ibm.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent 5cd1c9c5
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -82,7 +82,7 @@
 */
 */
#define SHIFT_USEC 16		/* frequency offset scale (shift) */
#define SHIFT_USEC 16		/* frequency offset scale (shift) */
#define PPM_SCALE (NSEC_PER_USEC << (NTP_SCALE_SHIFT - SHIFT_USEC))
#define PPM_SCALE (NSEC_PER_USEC << (NTP_SCALE_SHIFT - SHIFT_USEC))
#define PPM_SCALE_INV_SHIFT 20
#define PPM_SCALE_INV_SHIFT 19
#define PPM_SCALE_INV ((1ll << (PPM_SCALE_INV_SHIFT + NTP_SCALE_SHIFT)) / \
#define PPM_SCALE_INV ((1ll << (PPM_SCALE_INV_SHIFT + NTP_SCALE_SHIFT)) / \
		       PPM_SCALE + 1)
		       PPM_SCALE + 1)


+2 −3
Original line number Original line Diff line number Diff line
@@ -406,9 +406,8 @@ adj_done:
	if (time_status & (STA_UNSYNC|STA_CLOCKERR))
	if (time_status & (STA_UNSYNC|STA_CLOCKERR))
		result = TIME_ERROR;
		result = TIME_ERROR;


	txc->freq	   = shift_right((s32)(time_freq >> PPM_SCALE_INV_SHIFT) *
	txc->freq	   = shift_right((time_freq >> PPM_SCALE_INV_SHIFT) *
					 (s64)PPM_SCALE_INV,
					 (s64)PPM_SCALE_INV, NTP_SCALE_SHIFT);
					 NTP_SCALE_SHIFT);
	txc->maxerror	   = time_maxerror;
	txc->maxerror	   = time_maxerror;
	txc->esterror	   = time_esterror;
	txc->esterror	   = time_esterror;
	txc->status	   = time_status;
	txc->status	   = time_status;