+static u64
+emulate_tsc(void)
+{
+ int cnt, d;
+ u16 ebda_seg = get_ebda_seg();
+ u64 ret;
+ /* read timer 0 current count */
+ ret = GET_EBDA2(ebda_seg, tsc_8254);
+ /* readback mode has slightly shifted registers, works on all 8254, readback PIT0 latch */
+ outb(PM_SEL_READBACK | PM_READ_VALUE | PM_READ_COUNTER0, PORT_PIT_MODE);
+ cnt = (inb(PORT_PIT_COUNTER0) | (inb(PORT_PIT_COUNTER0) << 8));
+ d = GET_EBDA2(ebda_seg, last_tsc_8254) - cnt;
+ /* Determine the ticks count from last invocation of this function */
+ ret += (d > 0) ? d : (PIT_TICK_INTERVAL + d);
+ SET_EBDA2(ebda_seg, last_tsc_8254, cnt);
+ SET_EBDA2(ebda_seg, tsc_8254, ret);
+ return ret;
+}
+
+static u64
+get_tsc(void)
+{
+ if (unlikely(GET_GLOBAL(no_tsc)))
+ return emulate_tsc();
+ return rdtscll();
+}
+
+int
+check_tsc(u64 end)
+{
+ return (s64)(get_tsc() - end) > 0;
+}
+