From: cheloha Date: Thu, 25 Aug 2022 17:38:16 +0000 (+0000) Subject: amd64, i386: use delay_init() instead of writing delay_func by hand X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=da893f172441e856e26b2082d78d08217a8ba3e5;p=openbsd amd64, i386: use delay_init() instead of writing delay_func by hand 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@ --- diff --git a/sys/arch/amd64/amd64/lapic.c b/sys/arch/amd64/amd64/lapic.c index e8236556eae..cd5d580a5ad 100644 --- a/sys/arch/amd64/amd64/lapic.c +++ b/sys/arch/amd64/amd64/lapic.c @@ -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; } } diff --git a/sys/arch/amd64/amd64/tsc.c b/sys/arch/amd64/amd64/tsc.c index fd38dc6359d..276098f05bf 100644 --- a/sys/arch/amd64/amd64/tsc.c +++ b/sys/arch/amd64/amd64/tsc.c @@ -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 @@ -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 diff --git a/sys/arch/i386/i386/lapic.c b/sys/arch/i386/i386/lapic.c index c7de8ea91ce..86572f6ebe5 100644 --- a/sys/arch/i386/i386/lapic.c +++ b/sys/arch/i386/i386/lapic.c @@ -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; } } diff --git a/sys/dev/pv/pvbus.c b/sys/dev/pv/pvbus.c index cbe543ac312..85903647a82 100644 --- a/sys/dev/pv/pvbus.c +++ b/sys/dev/pv/pvbus.c @@ -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 @@ -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 }