Commit b1b5f65e authored by Phil Carmody's avatar Phil Carmody Committed by Linus Torvalds

calibrate: retry with wider bounds when converge seems to fail

Systems with unmaskable interrupts such as SMIs may massively
underestimate loops_per_jiffy, and fail to converge anywhere near the real
value.  A case seen on x86_64 was an initial estimate of 256<<12, which
converged to 511<<12 where the real value should have been over 630<<12.
This admitedly requires bypassing the TSC calibration (lpj_fine), and a
failure to settle in the direct calibration too, but is physically
possible.  This failure does not depend on my previous calibration
optimisation, but by luck is easy to fix with the optimisation in place
with a trivial retry loop.

In the context of the optimised converging method, as we can no longer
trust the starting estimate, enlarge the search bounds exponentially so
that the number of retries is logarithmically bounded.

[akpm@linux-foundation.org: mention x86_64 SMIs in comment]
Signed-off-by: default avatarPhil Carmody <ext-phil.2.carmody@nokia.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Tested-by: default avatarStephen Boyd <sboyd@codeaurora.org>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 191e5688
...@@ -122,7 +122,7 @@ static unsigned long __cpuinit calibrate_delay_direct(void) {return 0;} ...@@ -122,7 +122,7 @@ static unsigned long __cpuinit calibrate_delay_direct(void) {return 0;}
static unsigned long __cpuinit calibrate_delay_converge(void) static unsigned long __cpuinit calibrate_delay_converge(void)
{ {
/* First stage - slowly accelerate to find initial bounds */ /* First stage - slowly accelerate to find initial bounds */
unsigned long lpj, ticks, loopadd, chop_limit; unsigned long lpj, lpj_base, ticks, loopadd, loopadd_base, chop_limit;
int trials = 0, band = 0, trial_in_band = 0; int trials = 0, band = 0, trial_in_band = 0;
lpj = (1<<12); lpj = (1<<12);
...@@ -146,14 +146,18 @@ static unsigned long __cpuinit calibrate_delay_converge(void) ...@@ -146,14 +146,18 @@ static unsigned long __cpuinit calibrate_delay_converge(void)
* the largest likely undershoot. This defines our chop bounds. * the largest likely undershoot. This defines our chop bounds.
*/ */
trials -= band; trials -= band;
loopadd = lpj * band; loopadd_base = lpj * band;
lpj *= trials; lpj_base = lpj * trials;
chop_limit = lpj >> (LPS_PREC + 1);
recalibrate:
lpj = lpj_base;
loopadd = loopadd_base;
/* /*
* Do a binary approximation to get lpj set to * Do a binary approximation to get lpj set to
* equal one clock (up to LPS_PREC bits) * equal one clock (up to LPS_PREC bits)
*/ */
chop_limit = lpj >> LPS_PREC;
while (loopadd > chop_limit) { while (loopadd > chop_limit) {
lpj += loopadd; lpj += loopadd;
ticks = jiffies; ticks = jiffies;
...@@ -165,6 +169,16 @@ static unsigned long __cpuinit calibrate_delay_converge(void) ...@@ -165,6 +169,16 @@ static unsigned long __cpuinit calibrate_delay_converge(void)
lpj -= loopadd; lpj -= loopadd;
loopadd >>= 1; loopadd >>= 1;
} }
/*
* If we incremented every single time possible, presume we've
* massively underestimated initially, and retry with a higher
* start, and larger range. (Only seen on x86_64, due to SMIs)
*/
if (lpj + loopadd * 2 == lpj_base + loopadd_base * 2) {
lpj_base = lpj;
loopadd_base <<= 2;
goto recalibrate;
}
return lpj; return lpj;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment