3 #include <gpxe/timer.h>
7 #include <bits/timer2.h>
11 #define rdtsc(low,high) \
12 __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high))
14 #define rdtscll(val) \
15 __asm__ __volatile__ ("rdtsc" : "=A" (val))
18 /* Measure how many clocks we get in one microsecond */
19 static inline uint64_t calibrate_tsc(void)
26 i386_timer2_udelay(USECS_IN_MSEC);
29 return (rdtsc_end - rdtsc_start) / USECS_IN_MSEC;
32 static uint32_t clocks_per_usec = 0;
34 /* We measure time in microseconds. */
35 static tick_t rdtsc_currticks(void)
39 /* Read the Time Stamp Counter */
42 return clocks / clocks_per_usec;
45 static int rdtsc_ts_init(void)
48 struct cpuinfo_x86 cpu_info;
50 get_cpuinfo(&cpu_info);
51 if (cpu_info.features & X86_FEATURE_TSC) {
52 clocks_per_usec= calibrate_tsc();
53 if (clocks_per_usec) {
54 DBG("RDTSC ticksource installed. CPU running at %ld Mhz\n",
60 DBG("RDTSC ticksource not available on this machine.\n");
64 struct timer rdtsc_ts __timer (01) = {
65 .init = rdtsc_ts_init,
66 .udelay = generic_currticks_udelay,
67 .currticks = rdtsc_currticks,