diff options
| -rw-r--r-- | arch/x86/kernel/tsc.c | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c index 346cae5ac423..aa11413e7c1d 100644 --- a/arch/x86/kernel/tsc.c +++ b/arch/x86/kernel/tsc.c | |||
| @@ -122,6 +122,10 @@ static u64 tsc_read_refs(u64 *pm, u64 *hpet) | |||
| 122 | return ULLONG_MAX; | 122 | return ULLONG_MAX; |
| 123 | } | 123 | } |
| 124 | 124 | ||
| 125 | #define CAL_MS 50 | ||
| 126 | #define CAL_LATCH (CLOCK_TICK_RATE / (1000 / CAL_MS)) | ||
| 127 | #define CAL_PIT_LOOPS 5000 | ||
| 128 | |||
| 125 | /* | 129 | /* |
| 126 | * Try to calibrate the TSC against the Programmable | 130 | * Try to calibrate the TSC against the Programmable |
| 127 | * Interrupt Timer and return the frequency of the TSC | 131 | * Interrupt Timer and return the frequency of the TSC |
| @@ -144,8 +148,8 @@ static unsigned long pit_calibrate_tsc(void) | |||
| 144 | * (LSB then MSB) to begin countdown. | 148 | * (LSB then MSB) to begin countdown. |
| 145 | */ | 149 | */ |
| 146 | outb(0xb0, 0x43); | 150 | outb(0xb0, 0x43); |
| 147 | outb((CLOCK_TICK_RATE / (1000 / 50)) & 0xff, 0x42); | 151 | outb(CAL_LATCH & 0xff, 0x42); |
| 148 | outb((CLOCK_TICK_RATE / (1000 / 50)) >> 8, 0x42); | 152 | outb(CAL_LATCH >> 8, 0x42); |
| 149 | 153 | ||
| 150 | tsc = t1 = t2 = get_cycles(); | 154 | tsc = t1 = t2 = get_cycles(); |
| 151 | 155 | ||
| @@ -166,18 +170,18 @@ static unsigned long pit_calibrate_tsc(void) | |||
| 166 | /* | 170 | /* |
| 167 | * Sanity checks: | 171 | * Sanity checks: |
| 168 | * | 172 | * |
| 169 | * If we were not able to read the PIT more than 5000 | 173 | * If we were not able to read the PIT more than PIT_MIN_LOOPS |
| 170 | * times, then we have been hit by a massive SMI | 174 | * times, then we have been hit by a massive SMI |
| 171 | * | 175 | * |
| 172 | * If the maximum is 10 times larger than the minimum, | 176 | * If the maximum is 10 times larger than the minimum, |
| 173 | * then we got hit by an SMI as well. | 177 | * then we got hit by an SMI as well. |
| 174 | */ | 178 | */ |
| 175 | if (pitcnt < 5000 || tscmax > 10 * tscmin) | 179 | if (pitcnt < CAL_PIT_LOOPS || tscmax > 10 * tscmin) |
| 176 | return ULONG_MAX; | 180 | return ULONG_MAX; |
| 177 | 181 | ||
| 178 | /* Calculate the PIT value */ | 182 | /* Calculate the PIT value */ |
| 179 | delta = t2 - t1; | 183 | delta = t2 - t1; |
| 180 | do_div(delta, 50); | 184 | do_div(delta, CAL_MS); |
| 181 | return delta; | 185 | return delta; |
| 182 | } | 186 | } |
| 183 | 187 | ||
