tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: patch review: avoid com delay() in VMs



On Tue, 4 Feb 2025, Emile `iMil' Heitor wrote:

com_attach_subr() in sys/dev/ic/com.c has a delay(10000) waiting for
output to finish, this is very unlikely to be useful inside a virtual
machine and slows down boot time in such machine.

After several back-and-forths, thanks Martin, Simon and Taylor for
your help, here's a cleaner approach based on prop_dictionary_util,
avoiding #ifdefs:

ba0f8fc85baa9144d0a3e1194865b6995f67c1de Avoid delay(10000) for virtual machines
diff --git a/sys/arch/x86/x86/x86_autoconf.c b/sys/arch/x86/x86/x86_autoconf.c
index 835bb019175..6357967184b 100644
--- a/sys/arch/x86/x86/x86_autoconf.c
+++ b/sys/arch/x86/x86/x86_autoconf.c
@@ -602,6 +602,10 @@ device_register(device_t dev, void *aux)
 	(void)device_hyperv_register(dev, aux);
 #endif

+	if (device_is_a(dev, "com") && vm_guest > VM_GUEST_NO)
+		prop_dictionary_set_bool(device_properties(dev),
+		    "skip_attach_delay", true);
+
 	if (isaboot == NULL && pciboot == NULL)
 		return;

diff --git a/sys/dev/ic/com.c b/sys/dev/ic/com.c
index d271b594346..5e15ed17a1d 100644
--- a/sys/dev/ic/com.c
+++ b/sys/dev/ic/com.c
@@ -540,12 +540,14 @@ com_attach_subr(struct com_softc *sc)
 	prop_dictionary_t dict;
 	bool is_console = true;
 	bool force_console = false;
+	bool skip_attach_delay = false;

 	aprint_naive("\n");

 	dict = device_properties(sc->sc_dev);
 	prop_dictionary_get_bool(dict, "is_console", &is_console);
 	prop_dictionary_get_bool(dict, "force_console", &force_console);
+	prop_dictionary_get_bool(dict, "skip_attach_delay", &skip_attach_delay);
 	callout_init(&sc->sc_diag_callout, 0);
 	callout_init(&sc->sc_poll_callout, 0);
 	callout_setfunc(&sc->sc_poll_callout, com_intr_poll, sc);
@@ -589,8 +591,11 @@ com_attach_subr(struct com_softc *sc)
 			break;
 		}

+		/* No need for a delay on virtual machines. */
+		if (!skip_attach_delay)
+			delay(10000); /* wait for output to finish */
+
 		/* Make sure the console is always "hardwired". */
-		delay(10000);			/* wait for output to finish */
 		if (is_console) {
 			SET(sc->sc_hwflags, COM_HW_CONSOLE);
 		}

------------------------------------------------------------------------
Emile `iMil' Heitor <imil@{home.imil.net,NetBSD.org}> | https://imil.net



Home | Main Index | Thread Index | Old Index