Ingo Molnar | bb29ab2 | 2007-07-09 18:51:59 +0200 | [diff] [blame] | 1 | #include <linux/sched.h> |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 2 | #include <linux/clocksource.h> |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 3 | #include <linux/workqueue.h> |
| 4 | #include <linux/cpufreq.h> |
| 5 | #include <linux/jiffies.h> |
| 6 | #include <linux/init.h> |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 7 | #include <linux/dmi.h> |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 8 | |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 9 | #include <asm/delay.h> |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 10 | #include <asm/tsc.h> |
| 11 | #include <asm/io.h> |
Zachary Amsden | 6cb9a83 | 2007-03-05 00:30:35 -0800 | [diff] [blame] | 12 | #include <asm/timer.h> |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 13 | |
| 14 | #include "mach_timer.h" |
| 15 | |
Thomas Gleixner | d9a5c0a | 2007-03-24 23:02:49 +0100 | [diff] [blame] | 16 | static int tsc_enabled; |
| 17 | |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 18 | /* |
| 19 | * On some systems the TSC frequency does not |
| 20 | * change with the cpu frequency. So we need |
| 21 | * an extra value to store the TSC freq |
| 22 | */ |
| 23 | unsigned int tsc_khz; |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 24 | EXPORT_SYMBOL_GPL(tsc_khz); |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 25 | |
Vivek Goyal | 664c0d3 | 2007-01-10 23:15:36 -0800 | [diff] [blame] | 26 | int tsc_disable; |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 27 | |
| 28 | #ifdef CONFIG_X86_TSC |
| 29 | static int __init tsc_setup(char *str) |
| 30 | { |
| 31 | printk(KERN_WARNING "notsc: Kernel compiled with CONFIG_X86_TSC, " |
| 32 | "cannot disable TSC.\n"); |
| 33 | return 1; |
| 34 | } |
| 35 | #else |
| 36 | /* |
| 37 | * disable flag for tsc. Takes effect by clearing the TSC cpu flag |
| 38 | * in cpu/common.c |
| 39 | */ |
| 40 | static int __init tsc_setup(char *str) |
| 41 | { |
| 42 | tsc_disable = 1; |
| 43 | |
| 44 | return 1; |
| 45 | } |
| 46 | #endif |
| 47 | |
| 48 | __setup("notsc", tsc_setup); |
| 49 | |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 50 | /* |
| 51 | * code to mark and check if the TSC is unstable |
| 52 | * due to cpufreq or due to unsynced TSCs |
| 53 | */ |
| 54 | static int tsc_unstable; |
| 55 | |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 56 | int check_tsc_unstable(void) |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 57 | { |
| 58 | return tsc_unstable; |
| 59 | } |
Rusty Russell | d7e28ff | 2007-07-19 01:49:23 -0700 | [diff] [blame] | 60 | EXPORT_SYMBOL_GPL(check_tsc_unstable); |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 61 | |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 62 | /* Accellerators for sched_clock() |
| 63 | * convert from cycles(64bits) => nanoseconds (64bits) |
| 64 | * basic equation: |
| 65 | * ns = cycles / (freq / ns_per_sec) |
| 66 | * ns = cycles * (ns_per_sec / freq) |
| 67 | * ns = cycles * (10^9 / (cpu_khz * 10^3)) |
| 68 | * ns = cycles * (10^6 / cpu_khz) |
| 69 | * |
| 70 | * Then we use scaling math (suggested by george@mvista.com) to get: |
| 71 | * ns = cycles * (10^6 * SC / cpu_khz) / SC |
| 72 | * ns = cycles * cyc2ns_scale / SC |
| 73 | * |
| 74 | * And since SC is a constant power of two, we can convert the div |
| 75 | * into a shift. |
| 76 | * |
| 77 | * We can use khz divisor instead of mhz to keep a better percision, since |
| 78 | * cyc2ns_scale is limited to 10^6 * 2^10, which fits in 32 bits. |
| 79 | * (mathieu.desnoyers@polymtl.ca) |
| 80 | * |
| 81 | * -johnstul@us.ibm.com "math is hard, lets go shopping!" |
| 82 | */ |
Jeremy Fitzhardinge | 688340e | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 83 | unsigned long cyc2ns_scale __read_mostly; |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 84 | |
| 85 | #define CYC2NS_SCALE_FACTOR 10 /* 2^10, carefully chosen */ |
| 86 | |
| 87 | static inline void set_cyc2ns_scale(unsigned long cpu_khz) |
| 88 | { |
| 89 | cyc2ns_scale = (1000000 << CYC2NS_SCALE_FACTOR)/cpu_khz; |
| 90 | } |
| 91 | |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 92 | /* |
| 93 | * Scheduler clock - returns current time in nanosec units. |
| 94 | */ |
Jeremy Fitzhardinge | 688340e | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 95 | unsigned long long native_sched_clock(void) |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 96 | { |
| 97 | unsigned long long this_offset; |
| 98 | |
| 99 | /* |
Ingo Molnar | f969098 | 2007-02-13 13:26:22 +0100 | [diff] [blame] | 100 | * Fall back to jiffies if there's no TSC available: |
Ingo Molnar | bb29ab2 | 2007-07-09 18:51:59 +0200 | [diff] [blame] | 101 | * ( But note that we still use it if the TSC is marked |
| 102 | * unstable. We do this because unlike Time Of Day, |
| 103 | * the scheduler clock tolerates small errors and it's |
| 104 | * very important for it to be as fast as the platform |
| 105 | * can achive it. ) |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 106 | */ |
Ingo Molnar | bb29ab2 | 2007-07-09 18:51:59 +0200 | [diff] [blame] | 107 | if (unlikely(!tsc_enabled && !tsc_unstable)) |
Ingo Molnar | f969098 | 2007-02-13 13:26:22 +0100 | [diff] [blame] | 108 | /* No locking but a rare wrong value is not a big deal: */ |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 109 | return (jiffies_64 - INITIAL_JIFFIES) * (1000000000 / HZ); |
| 110 | |
| 111 | /* read the Time Stamp Counter: */ |
Jeremy Fitzhardinge | 688340e | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 112 | rdtscll(this_offset); |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 113 | |
| 114 | /* return the value in ns */ |
| 115 | return cycles_2_ns(this_offset); |
| 116 | } |
| 117 | |
Jeremy Fitzhardinge | 688340e | 2007-07-17 18:37:04 -0700 | [diff] [blame] | 118 | /* We need to define a real function for sched_clock, to override the |
| 119 | weak default version */ |
| 120 | #ifdef CONFIG_PARAVIRT |
| 121 | unsigned long long sched_clock(void) |
| 122 | { |
| 123 | return paravirt_sched_clock(); |
| 124 | } |
| 125 | #else |
| 126 | unsigned long long sched_clock(void) |
| 127 | __attribute__((alias("native_sched_clock"))); |
| 128 | #endif |
| 129 | |
Zachary Amsden | 1182d85 | 2007-03-05 00:30:36 -0800 | [diff] [blame] | 130 | unsigned long native_calculate_cpu_khz(void) |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 131 | { |
| 132 | unsigned long long start, end; |
| 133 | unsigned long count; |
| 134 | u64 delta64; |
| 135 | int i; |
| 136 | unsigned long flags; |
| 137 | |
| 138 | local_irq_save(flags); |
| 139 | |
| 140 | /* run 3 times to ensure the cache is warm */ |
| 141 | for (i = 0; i < 3; i++) { |
| 142 | mach_prepare_counter(); |
| 143 | rdtscll(start); |
| 144 | mach_countup(&count); |
| 145 | rdtscll(end); |
| 146 | } |
| 147 | /* |
| 148 | * Error: ECTCNEVERSET |
| 149 | * The CTC wasn't reliable: we got a hit on the very first read, |
| 150 | * or the CPU was so fast/slow that the quotient wouldn't fit in |
| 151 | * 32 bits.. |
| 152 | */ |
| 153 | if (count <= 1) |
| 154 | goto err; |
| 155 | |
| 156 | delta64 = end - start; |
| 157 | |
| 158 | /* cpu freq too fast: */ |
| 159 | if (delta64 > (1ULL<<32)) |
| 160 | goto err; |
| 161 | |
| 162 | /* cpu freq too slow: */ |
| 163 | if (delta64 <= CALIBRATE_TIME_MSEC) |
| 164 | goto err; |
| 165 | |
| 166 | delta64 += CALIBRATE_TIME_MSEC/2; /* round for do_div */ |
| 167 | do_div(delta64,CALIBRATE_TIME_MSEC); |
| 168 | |
| 169 | local_irq_restore(flags); |
| 170 | return (unsigned long)delta64; |
| 171 | err: |
| 172 | local_irq_restore(flags); |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | int recalibrate_cpu_khz(void) |
| 177 | { |
| 178 | #ifndef CONFIG_SMP |
| 179 | unsigned long cpu_khz_old = cpu_khz; |
| 180 | |
| 181 | if (cpu_has_tsc) { |
| 182 | cpu_khz = calculate_cpu_khz(); |
| 183 | tsc_khz = cpu_khz; |
| 184 | cpu_data[0].loops_per_jiffy = |
| 185 | cpufreq_scale(cpu_data[0].loops_per_jiffy, |
| 186 | cpu_khz_old, cpu_khz); |
| 187 | return 0; |
| 188 | } else |
| 189 | return -ENODEV; |
| 190 | #else |
| 191 | return -ENODEV; |
| 192 | #endif |
| 193 | } |
| 194 | |
| 195 | EXPORT_SYMBOL(recalibrate_cpu_khz); |
| 196 | |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 197 | #ifdef CONFIG_CPU_FREQ |
| 198 | |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 199 | /* |
| 200 | * if the CPU frequency is scaled, TSC-based delays will need a different |
| 201 | * loops_per_jiffy value to function properly. |
| 202 | */ |
| 203 | static unsigned int ref_freq = 0; |
| 204 | static unsigned long loops_per_jiffy_ref = 0; |
| 205 | static unsigned long cpu_khz_ref = 0; |
| 206 | |
| 207 | static int |
| 208 | time_cpufreq_notifier(struct notifier_block *nb, unsigned long val, void *data) |
| 209 | { |
| 210 | struct cpufreq_freqs *freq = data; |
| 211 | |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 212 | if (!ref_freq) { |
| 213 | if (!freq->old){ |
| 214 | ref_freq = freq->new; |
Daniel Walker | df3624a | 2007-05-02 19:27:18 +0200 | [diff] [blame] | 215 | return 0; |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 216 | } |
| 217 | ref_freq = freq->old; |
| 218 | loops_per_jiffy_ref = cpu_data[freq->cpu].loops_per_jiffy; |
| 219 | cpu_khz_ref = cpu_khz; |
| 220 | } |
| 221 | |
| 222 | if ((val == CPUFREQ_PRECHANGE && freq->old < freq->new) || |
| 223 | (val == CPUFREQ_POSTCHANGE && freq->old > freq->new) || |
| 224 | (val == CPUFREQ_RESUMECHANGE)) { |
| 225 | if (!(freq->flags & CPUFREQ_CONST_LOOPS)) |
| 226 | cpu_data[freq->cpu].loops_per_jiffy = |
| 227 | cpufreq_scale(loops_per_jiffy_ref, |
| 228 | ref_freq, freq->new); |
| 229 | |
| 230 | if (cpu_khz) { |
| 231 | |
| 232 | if (num_online_cpus() == 1) |
| 233 | cpu_khz = cpufreq_scale(cpu_khz_ref, |
| 234 | ref_freq, freq->new); |
| 235 | if (!(freq->flags & CPUFREQ_CONST_LOOPS)) { |
| 236 | tsc_khz = cpu_khz; |
| 237 | set_cyc2ns_scale(cpu_khz); |
| 238 | /* |
| 239 | * TSC based sched_clock turns |
| 240 | * to junk w/ cpufreq |
| 241 | */ |
john stultz | 5a90cf2 | 2007-05-02 19:27:08 +0200 | [diff] [blame] | 242 | mark_tsc_unstable("cpufreq changes"); |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 243 | } |
| 244 | } |
| 245 | } |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 246 | |
| 247 | return 0; |
| 248 | } |
| 249 | |
| 250 | static struct notifier_block time_cpufreq_notifier_block = { |
| 251 | .notifier_call = time_cpufreq_notifier |
| 252 | }; |
| 253 | |
| 254 | static int __init cpufreq_tsc(void) |
| 255 | { |
Thomas Gleixner | 26a08eb | 2007-02-16 01:27:32 -0800 | [diff] [blame] | 256 | return cpufreq_register_notifier(&time_cpufreq_notifier_block, |
| 257 | CPUFREQ_TRANSITION_NOTIFIER); |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 258 | } |
john stultz | 539eb11 | 2006-06-26 00:25:10 -0700 | [diff] [blame] | 259 | core_initcall(cpufreq_tsc); |
| 260 | |
| 261 | #endif |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 262 | |
| 263 | /* clock source code */ |
| 264 | |
| 265 | static unsigned long current_tsc_khz = 0; |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 266 | |
| 267 | static cycle_t read_tsc(void) |
| 268 | { |
| 269 | cycle_t ret; |
| 270 | |
| 271 | rdtscll(ret); |
| 272 | |
| 273 | return ret; |
| 274 | } |
| 275 | |
| 276 | static struct clocksource clocksource_tsc = { |
| 277 | .name = "tsc", |
| 278 | .rating = 300, |
| 279 | .read = read_tsc, |
Jim Cromie | 7f9f303 | 2006-06-26 00:25:15 -0700 | [diff] [blame] | 280 | .mask = CLOCKSOURCE_MASK(64), |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 281 | .mult = 0, /* to be set */ |
| 282 | .shift = 22, |
Thomas Gleixner | 73b08d2 | 2007-02-16 01:27:36 -0800 | [diff] [blame] | 283 | .flags = CLOCK_SOURCE_IS_CONTINUOUS | |
| 284 | CLOCK_SOURCE_MUST_VERIFY, |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 285 | }; |
| 286 | |
john stultz | 5a90cf2 | 2007-05-02 19:27:08 +0200 | [diff] [blame] | 287 | void mark_tsc_unstable(char *reason) |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 288 | { |
Thomas Gleixner | 7e69f2b | 2007-02-16 01:27:42 -0800 | [diff] [blame] | 289 | if (!tsc_unstable) { |
| 290 | tsc_unstable = 1; |
Thomas Gleixner | d9a5c0a | 2007-03-24 23:02:49 +0100 | [diff] [blame] | 291 | tsc_enabled = 0; |
john stultz | 5a90cf2 | 2007-05-02 19:27:08 +0200 | [diff] [blame] | 292 | printk("Marking TSC unstable due to: %s.\n", reason); |
Thomas Gleixner | 7e69f2b | 2007-02-16 01:27:42 -0800 | [diff] [blame] | 293 | /* Can be called before registration */ |
| 294 | if (clocksource_tsc.mult) |
| 295 | clocksource_change_rating(&clocksource_tsc, 0); |
| 296 | else |
| 297 | clocksource_tsc.rating = 0; |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 298 | } |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 299 | } |
Thomas Gleixner | 7e69f2b | 2007-02-16 01:27:42 -0800 | [diff] [blame] | 300 | EXPORT_SYMBOL_GPL(mark_tsc_unstable); |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 301 | |
Jeff Garzik | 1855256 | 2007-10-03 15:15:40 -0400 | [diff] [blame] | 302 | static int __init dmi_mark_tsc_unstable(const struct dmi_system_id *d) |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 303 | { |
| 304 | printk(KERN_NOTICE "%s detected: marking TSC unstable.\n", |
| 305 | d->ident); |
Thomas Gleixner | 7e69f2b | 2007-02-16 01:27:42 -0800 | [diff] [blame] | 306 | tsc_unstable = 1; |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 307 | return 0; |
| 308 | } |
| 309 | |
| 310 | /* List of systems that have known TSC problems */ |
| 311 | static struct dmi_system_id __initdata bad_tsc_dmi_table[] = { |
| 312 | { |
| 313 | .callback = dmi_mark_tsc_unstable, |
| 314 | .ident = "IBM Thinkpad 380XD", |
| 315 | .matches = { |
| 316 | DMI_MATCH(DMI_BOARD_VENDOR, "IBM"), |
| 317 | DMI_MATCH(DMI_BOARD_NAME, "2635FA0"), |
| 318 | }, |
| 319 | }, |
| 320 | {} |
| 321 | }; |
| 322 | |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 323 | /* |
| 324 | * Make an educated guess if the TSC is trustworthy and synchronized |
| 325 | * over all CPUs. |
| 326 | */ |
Ingo Molnar | 95492e4 | 2007-02-16 01:27:34 -0800 | [diff] [blame] | 327 | __cpuinit int unsynchronized_tsc(void) |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 328 | { |
Ingo Molnar | 95492e4 | 2007-02-16 01:27:34 -0800 | [diff] [blame] | 329 | if (!cpu_has_tsc || tsc_unstable) |
| 330 | return 1; |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 331 | /* |
| 332 | * Intel systems are normally all synchronized. |
| 333 | * Exceptions must mark TSC as unstable: |
| 334 | */ |
Thomas Gleixner | 7e69f2b | 2007-02-16 01:27:42 -0800 | [diff] [blame] | 335 | if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) { |
| 336 | /* assume multi socket systems are not synchronized: */ |
| 337 | if (num_possible_cpus() > 1) |
| 338 | tsc_unstable = 1; |
| 339 | } |
| 340 | return tsc_unstable; |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 341 | } |
| 342 | |
Marcelo Tosatti | 07190a0 | 2007-02-16 01:27:44 -0800 | [diff] [blame] | 343 | /* |
| 344 | * Geode_LX - the OLPC CPU has a possibly a very reliable TSC |
| 345 | */ |
| 346 | #ifdef CONFIG_MGEODE_LX |
| 347 | /* RTSC counts during suspend */ |
| 348 | #define RTSC_SUSP 0x100 |
| 349 | |
| 350 | static void __init check_geode_tsc_reliable(void) |
| 351 | { |
Ingo Molnar | f97586b | 2007-10-17 18:04:34 +0200 | [diff] [blame^] | 352 | unsigned long res_low, res_high; |
Marcelo Tosatti | 07190a0 | 2007-02-16 01:27:44 -0800 | [diff] [blame] | 353 | |
Ingo Molnar | f97586b | 2007-10-17 18:04:34 +0200 | [diff] [blame^] | 354 | rdmsr_safe(MSR_GEODE_BUSCONT_CONF0, &res_low, &res_high); |
| 355 | if (res_low & RTSC_SUSP) |
Marcelo Tosatti | 07190a0 | 2007-02-16 01:27:44 -0800 | [diff] [blame] | 356 | clocksource_tsc.flags &= ~CLOCK_SOURCE_MUST_VERIFY; |
| 357 | } |
| 358 | #else |
| 359 | static inline void check_geode_tsc_reliable(void) { } |
| 360 | #endif |
| 361 | |
john stultz | 6bb74df | 2007-03-05 00:30:50 -0800 | [diff] [blame] | 362 | |
| 363 | void __init tsc_init(void) |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 364 | { |
john stultz | 6bb74df | 2007-03-05 00:30:50 -0800 | [diff] [blame] | 365 | if (!cpu_has_tsc || tsc_disable) |
| 366 | goto out_no_tsc; |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 367 | |
john stultz | 6bb74df | 2007-03-05 00:30:50 -0800 | [diff] [blame] | 368 | cpu_khz = calculate_cpu_khz(); |
| 369 | tsc_khz = cpu_khz; |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 370 | |
john stultz | 6bb74df | 2007-03-05 00:30:50 -0800 | [diff] [blame] | 371 | if (!cpu_khz) |
| 372 | goto out_no_tsc; |
| 373 | |
| 374 | printk("Detected %lu.%03lu MHz processor.\n", |
| 375 | (unsigned long)cpu_khz / 1000, |
| 376 | (unsigned long)cpu_khz % 1000); |
| 377 | |
| 378 | set_cyc2ns_scale(cpu_khz); |
| 379 | use_tsc_delay(); |
| 380 | |
| 381 | /* Check and install the TSC clocksource */ |
| 382 | dmi_check_system(bad_tsc_dmi_table); |
| 383 | |
| 384 | unsynchronized_tsc(); |
| 385 | check_geode_tsc_reliable(); |
| 386 | current_tsc_khz = tsc_khz; |
| 387 | clocksource_tsc.mult = clocksource_khz2mult(current_tsc_khz, |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 388 | clocksource_tsc.shift); |
john stultz | 6bb74df | 2007-03-05 00:30:50 -0800 | [diff] [blame] | 389 | /* lower the rating if we already know its unstable: */ |
| 390 | if (check_tsc_unstable()) { |
| 391 | clocksource_tsc.rating = 0; |
| 392 | clocksource_tsc.flags &= ~CLOCK_SOURCE_IS_CONTINUOUS; |
Thomas Gleixner | d9a5c0a | 2007-03-24 23:02:49 +0100 | [diff] [blame] | 393 | } else |
| 394 | tsc_enabled = 1; |
| 395 | |
john stultz | 6bb74df | 2007-03-05 00:30:50 -0800 | [diff] [blame] | 396 | clocksource_register(&clocksource_tsc); |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 397 | |
john stultz | 6bb74df | 2007-03-05 00:30:50 -0800 | [diff] [blame] | 398 | return; |
| 399 | |
| 400 | out_no_tsc: |
| 401 | /* |
| 402 | * Set the tsc_disable flag if there's no TSC support, this |
| 403 | * makes it a fast flag for the kernel to see whether it |
| 404 | * should be using the TSC. |
| 405 | */ |
| 406 | tsc_disable = 1; |
john stultz | 5d0cf41 | 2006-06-26 00:25:12 -0700 | [diff] [blame] | 407 | } |