1 #include <linux/sched.h>
2 #include <linux/init.h>
3 #include <linux/module.h>
4 #include <linux/timer.h>
6 unsigned int cpu_khz; /* TSC clocks / usec, not used here */
7 EXPORT_SYMBOL(cpu_khz);
9 EXPORT_SYMBOL(tsc_khz);
12 * TSC can be unstable due to cpufreq or due to unsynced TSCs
16 /* native_sched_clock() is called before tsc_init(), so
17 we must start with the TSC soft disabled to prevent
18 erroneous rdtsc usage on !cpu_has_tsc processors */
19 int tsc_disabled = -1;
22 * Scheduler clock - returns current time in nanosec units.
24 u64 native_sched_clock(void)
29 * Fall back to jiffies if there's no TSC available:
30 * ( But note that we still use it if the TSC is marked
31 * unstable. We do this because unlike Time Of Day,
32 * the scheduler clock tolerates small errors and it's
33 * very important for it to be as fast as the platform
36 if (unlikely(tsc_disabled)) {
37 /* No locking but a rare wrong value is not a big deal: */
38 return (jiffies_64 - INITIAL_JIFFIES) * (1000000000 / HZ);
41 /* read the Time Stamp Counter: */
44 /* return the value in ns */
45 return cycles_2_ns(this_offset);
48 /* We need to define a real function for sched_clock, to override the
49 weak default version */
50 #ifdef CONFIG_PARAVIRT
51 unsigned long long sched_clock(void)
53 return paravirt_sched_clock();
57 sched_clock(void) __attribute__((alias("native_sched_clock")));
60 int check_tsc_unstable(void)
64 EXPORT_SYMBOL_GPL(check_tsc_unstable);
67 int __init notsc_setup(char *str)
69 printk(KERN_WARNING "notsc: Kernel compiled with CONFIG_X86_TSC, "
70 "cannot disable TSC completely.\n");
76 * disable flag for tsc. Takes effect by clearing the TSC cpu flag
79 int __init notsc_setup(char *str)
81 setup_clear_cpu_cap(X86_FEATURE_TSC);
86 __setup("notsc", notsc_setup);