amd64, i386: use delay_init() instead of writing delay_func by hand
authorcheloha <cheloha@openbsd.org>
Thu, 25 Aug 2022 17:38:16 +0000 (17:38 +0000)
committercheloha <cheloha@openbsd.org>
Thu, 25 Aug 2022 17:38:16 +0000 (17:38 +0000)
Now that we have delay_init(), use it in all the places where we
currently set delay_func by hand.

lapic_delay() is great: 3000.  hv_delay() is needed before we set up
lapic_delay() on Hyper-V guests: 4000.  tsc_delay() is better than
lapic_delay() and (probably?) hv_delay(): 5000.

We may bump hv_delay's quality value up over that of tsc_delay() in a
future patch.  It's a little ambiguous whether hv_delay() causes a VM
exit.

Idea and patch from jsg@.  With tons of input, research and advice
from jsg@.

Link: https://marc.info/?l=openbsd-tech&m=166053729104923&w=2
ok mlarkin@ jsg@

sys/arch/amd64/amd64/lapic.c
sys/arch/amd64/amd64/tsc.c
sys/arch/i386/i386/lapic.c
sys/dev/pv/pvbus.c

index e823655..cd5d580 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: lapic.c,v 1.60 2022/08/15 04:17:50 daniel Exp $       */
+/*     $OpenBSD: lapic.c,v 1.61 2022/08/25 17:38:16 cheloha Exp $      */
 /* $NetBSD: lapic.c,v 1.2 2003/05/08 01:04:35 fvdl Exp $ */
 
 /*-
@@ -592,8 +592,7 @@ skip_calibration:
                 * Now that the timer's calibrated, use the apic timer routines
                 * for all our timing needs..
                 */
-               if (delay_func == i8254_delay)
-                       delay_func = lapic_delay;
+               delay_init(lapic_delay, 3000);
                initclock_func = lapic_initclocks;
        }
 }
index fd38dc6..276098f 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: tsc.c,v 1.25 2022/08/12 02:20:36 cheloha Exp $        */
+/*     $OpenBSD: tsc.c,v 1.26 2022/08/25 17:38:16 cheloha Exp $        */
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * Copyright (c) 2016,2017 Reyk Floeter <reyk@openbsd.org>
@@ -109,7 +109,7 @@ tsc_identify(struct cpu_info *ci)
 
        tsc_frequency = tsc_freq_cpuid(ci);
        if (tsc_frequency > 0)
-               delay_func = tsc_delay;
+               delay_init(tsc_delay, 5000);
 }
 
 static inline int
index c7de8ea..86572f6 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: lapic.c,v 1.49 2022/08/15 04:17:50 daniel Exp $       */
+/*     $OpenBSD: lapic.c,v 1.50 2022/08/25 17:38:16 cheloha Exp $      */
 /* $NetBSD: lapic.c,v 1.1.2.8 2000/02/23 06:10:50 sommerfeld Exp $ */
 
 /*-
@@ -395,7 +395,7 @@ lapic_calibrate_timer(struct cpu_info *ci)
                 * Now that the timer's calibrated, use the apic timer routines
                 * for all our timing needs..
                 */
-               delay_func = lapic_delay;
+               delay_init(lapic_delay, 3000);
                initclock_func = lapic_initclocks;
        }
 }
index cbe543a..8590364 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: pvbus.c,v 1.24 2021/11/05 11:38:29 mpi Exp $  */
+/*     $OpenBSD: pvbus.c,v 1.25 2022/08/25 17:38:16 cheloha Exp $      */
 
 /*
  * Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org>
@@ -319,9 +319,8 @@ pvbus_hyperv(struct pvbus_hv *hv)
            HYPERV_VERSION_EBX_MINOR_S;
 
 #if NHYPERV > 0
-       if (hv->hv_features & CPUID_HV_MSR_TIME_REFCNT &&
-           delay_func == i8254_delay)
-               delay_func = hv_delay;
+       if (hv->hv_features & CPUID_HV_MSR_TIME_REFCNT)
+               delay_init(hv_delay, 4000);
 #endif
 }