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

Simon Burge <[email protected]>
Newsgroups gmane.os.netbsd.devel.kernel
Message-ID <[email protected]>
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.
> I propose the following approach:

Expanding on Martin's suggestion, I wonder if something like this
is better (completely untested!)?  This way we'd always have
inside_vm_guest() available to remove the #ifdef check from any
consumers and reduce clutter a little bit.

diff --git a/sys/arch/x86/include/cpu.h b/sys/arch/x86/include/cpu.h
index 6c26dc624b1..94c99946bc9 100644
--- a/sys/arch/x86/include/cpu.h
+++ b/sys/arch/x86/include/cpu.h
@@ -558,6 +558,12 @@ vm_guest_is_pvh(void)
         }
  }

+#define __HAVE_VIRTUAL_HOST_P
+static __inline bool __unused
+inside_vm_guest(void)
+{
+       return vm_guest != VM_GUEST_NO;
+}
+
  /* cpu_topology.c */
  void   x86_cpu_topology(struct cpu_info *);
diff --git a/sys/dev/ic/com.c b/sys/dev/ic/com.c
index 539b6597accd..f835e493184c 100644
--- a/sys/dev/ic/com.c
+++ b/sys/dev/ic/com.c
@@ -589,8 +589,15 @@ com_attach_subr(struct com_softc *sc)
                        break;
                }

+               if (!inside_vm_guest()) {
+                       /*
+                        * Wait for output to finish.  No need for
+                        * a delay on virtual machines.
+                        */
+                       delay(10000);
+               }
+
                /* Make sure the console is always "hardwired". */
-               delay(10000);                   /* wait for output to finish */
                if (is_console) {
                        SET(sc->sc_hwflags, COM_HW_CONSOLE);
                }
diff --git a/sys/sys/cpu.h b/sys/sys/cpu.h
index 0393f9c0058a..3f8a0d1ea684 100644
--- a/sys/sys/cpu.h
+++ b/sys/sys/cpu.h
@@ -50,6 +50,14 @@ void cpu_idle(void);
 #endif
 #endif

+#ifndef __HAVE_VIRTUAL_HOST_P
+static __inline bool __unused
+inside_vm_guest(void)
+{
+       return 0;
+}
+#endif /* !__HAVE_VIRTUAL_HOST_P */
+
 #ifndef cpu_need_resched
 void cpu_need_resched(struct cpu_info *, struct lwp *, int);
 #endif

Cheers,
Simon.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.