[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20160713130344.8319-2-nicstange@gmail.com>
Date: Wed, 13 Jul 2016 15:03:42 +0200
From: Nicolai Stange <nicstange@...il.com>
To: Thomas Gleixner <tglx@...utronix.de>
Cc: Ingo Molnar <mingo@...hat.com>, "H. Peter Anvin" <hpa@...or.com>,
x86@...nel.org, Borislav Petkov <bp@...e.de>,
Paolo Bonzini <pbonzini@...hat.com>,
Viresh Kumar <viresh.kumar@...aro.org>,
Hidehiro Kawai <hidehiro.kawai.ez@...achi.com>,
"Peter Zijlstra (Intel)" <peterz@...radead.org>,
Len Brown <len.brown@...el.com>,
"Christopher S. Hall" <christopher.s.hall@...el.com>,
Adrian Hunter <adrian.hunter@...el.com>,
linux-kernel@...r.kernel.org, Nicolai Stange <nicstange@...il.com>
Subject: [PATCH v3 1/3] arch, x86, tsc deadline clockevent dev: reduce frequency roundoff error
In setup_APIC_timer(), the registered clockevent device's frequency
is calculated by first dividing tsc_khz by TSC_DIVISOR and multiplying
it with 1000 afterwards.
The multiplication with 1000 is done for converting from kHz to Hz and the
division by TSC_DIVISOR is carried out in order to make sure that the final
result fits into an u32.
However, with the order given in this calculation, the roundoff error
introduced by the division gets magnified by a factor of 1000 by the
following multiplication.
Increase the accuracy by reversing the order of the division and
multiplication. In order not to overflow during this calculation, cast
temporarily to u64.
Signed-off-by: Nicolai Stange <nicstange@...il.com>
---
arch/x86/kernel/apic/apic.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index 89a5bce..dce654c 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -563,7 +563,8 @@ static void setup_APIC_timer(void)
CLOCK_EVT_FEAT_DUMMY);
levt->set_next_event = lapic_next_deadline;
clockevents_config_and_register(levt,
- (tsc_khz / TSC_DIVISOR) * 1000,
+ (u32)(((u64)tsc_khz * 1000) /
+ TSC_DIVISOR),
0xF, ~0UL);
} else
clockevents_register_device(levt);
--
2.9.0
Powered by blists - more mailing lists