pc64: Make read_apic_timer() return remaining time in microseconds.
authorImre Vadász <imre@vdsz.com>
Sun, 27 Aug 2017 15:03:32 +0000 (17:03 +0200)
committerImre Vadász <imre@vdsz.com>
Mon, 4 Sep 2017 21:00:58 +0000 (23:00 +0200)
* This makes it easier to optionally use the TSC Deadline Mode in the lapic,
  since we no longer need or want to calibrate the lapic timer in that case.

sys/platform/pc64/apic/lapic.c
sys/platform/pc64/x86_64/mp_machdep.c

index 988288f..a415519 100644 (file)
@@ -698,18 +698,23 @@ set_apic_timer(int us)
 
 
 /*
- * Read remaining time in timer.
+ * Read remaining time in timer, in microseconds (rounded up).
  */
 int
 read_apic_timer(void)
 {
-#if 0
-       /** XXX FIXME: we need to return the actual remaining time,
-         *         for now we just return the remaining count.
-         */
-#else
-       return lapic->ccr_timer;
-#endif
+       uint64_t val;
+
+       val = lapic->ccr_timer;
+       if (val == 0)
+               return 0;
+       KKASSERT(lapic_cputimer_intr.freq > 0);
+       val *= 1000000;
+       val += (lapic_cputimer_intr.freq - 1);
+       val /= lapic_cputimer_intr.freq;
+       if (val > 0x7fffffff)
+               val = 0x7fffffff;
+       return val;
 }
 
 
index f06ead1..f87398b 100644 (file)
@@ -436,10 +436,6 @@ start_all_aps(u_int boot_addr)
                }
                if (smibest > 250000)
                        smibest = 0;
-               if (smibest) {
-                       smibest = smibest * (int64_t)1000000 /
-                                 get_apic_timer_frequency();
-               }
        }
        if (smibest)
                kprintf("SMI Frequency (worst case): %d Hz (%d us)\n",