• L
    x86: quick TSC calibration · 6ac40ed0
    Linus Torvalds 提交于
    Introduce a fast TSC-calibration method on sane hardware.
    
    It only uses 17920 PIT timer ticks to calibrate the TSC, plus 256 ticks on
    each side to make sure the TSC values were very close to the tick, so the
    whole calibration takes 15ms. Yet, despite only takign 15ms,
    we can actually give pretty stringent guarantees of accuracy:
    
     - the code requires that we hit each 256-counter block at least 50 times,
       so the TSC error is basically at *MOST* just a few PIT cycles off in
       any direction. In practice, it's going to be about one microseconds
       off (which is how long it takes to read the counter)
    
     - so over 17920 PIT cycles, we can pretty much guarantee that the
       calibration error is less than one half of a percent.
    
    My testing bears this out: on my machine, the quick-calibration reports
    2934.085kHz, while the slow one reports 2933.415.
    
    Yes, the slower calibration is still more precise. For me, the slow
    calibration is stable to within about one hundreth of a percent, so it's
    (at a guess) roughly an order-and-a-half of magnitude more precise. The
    longer you wait, the more precise you can be.
    
    However, the nice thing about the fast TSC PIT synchronization is that
    it's pretty much _guaranteed_ to give that 0.5% precision, and fail
    gracefully (and very quickly) if it doesn't get it. And it really is
    fairly simple (even if there's a lot of _details_ there, and I didn't get
    all of those right ont he first try or even the second ;)
    
    The patch says "110 insertions", but 63 of those new lines are actually
    comments.
    Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
    Signed-off-by: NIngo Molnar <mingo@elte.hu>
    ---
     arch/x86/kernel/tsc.c |  111 ++++++++++++++++++++++++++++++++++++++++++++++++-
     1 files changed, 110 insertions(+), 1 deletions(-)
    6ac40ed0
tsc.c 21.4 KB