[SeaBIOS] [PATCH] qemu: avoid debug prints if debugcon is not enabled

Stefano Garzarella posted 1 patch 5 years, 4 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/seabios tags/patchew/20181202131013.199758-1-sgarzare@redhat.com
src/fw/paravirt.h |  3 +++
src/hw/serialio.c | 16 ++++++++++++++--
src/hw/serialio.h |  1 +
src/post.c        |  3 +++
4 files changed, 21 insertions(+), 2 deletions(-)
[SeaBIOS] [PATCH] qemu: avoid debug prints if debugcon is not enabled
Posted by Stefano Garzarella 5 years, 4 months ago
In order to speed up the boot phase, we can check the QEMU
debugcon device, and disable the writes if it is not recognized.

This patch allow us to save around 10 msec (time measured
between SeaBIOS entry point and "linuxboot" entry point)
when CONFIG_DEBUG_LEVEL=1 and debugcon is not enabled.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
---
 src/fw/paravirt.h |  3 +++
 src/hw/serialio.c | 16 ++++++++++++++--
 src/hw/serialio.h |  1 +
 src/post.c        |  3 +++
 4 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/src/fw/paravirt.h b/src/fw/paravirt.h
index a14d83e..f7e1d4c 100644
--- a/src/fw/paravirt.h
+++ b/src/fw/paravirt.h
@@ -49,6 +49,9 @@ static inline int runningOnKVM(void) {
 // QEMU_CFG_DMA ID bit
 #define QEMU_CFG_VERSION_DMA    2
 
+// QEMU debugcon read value
+#define QEMU_DEBUGCON_READBACK  0xe9
+
 int qemu_cfg_enabled(void);
 int qemu_cfg_dma_enabled(void);
 void qemu_preinit(void);
diff --git a/src/hw/serialio.c b/src/hw/serialio.c
index 319a85c..d9acd3c 100644
--- a/src/hw/serialio.c
+++ b/src/hw/serialio.c
@@ -103,11 +103,23 @@ serial_debug_flush(void)
 
 u16 DebugOutputPort VARFSEG = 0x402;
 
+void
+qemu_debug_postram_preinit(void)
+{
+    /* Check if the QEMU debug output port is active */
+    if (CONFIG_DEBUG_IO &&
+        inb(GET_GLOBAL(DebugOutputPort)) != QEMU_DEBUGCON_READBACK)
+        DebugOutputPort = 0;
+}
+
 // Write a character to the special debugging port.
 void
 qemu_debug_putc(char c)
 {
-    if (CONFIG_DEBUG_IO && runningOnQEMU())
+    u16 port;
+
+    if (CONFIG_DEBUG_IO && runningOnQEMU() &&
+        (port = GET_GLOBAL(DebugOutputPort)))
         // Send character to debug port.
-        outb(c, GET_GLOBAL(DebugOutputPort));
+        outb(c, port);
 }
diff --git a/src/hw/serialio.h b/src/hw/serialio.h
index 88296fe..31fbea3 100644
--- a/src/hw/serialio.h
+++ b/src/hw/serialio.h
@@ -24,6 +24,7 @@ void serial_debug_preinit(void);
 void serial_debug_putc(char c);
 void serial_debug_flush(void);
 extern u16 DebugOutputPort;
+void qemu_debug_postram_preinit(void);
 void qemu_debug_putc(char c);
 
 #endif // serialio.h
diff --git a/src/post.c b/src/post.c
index f93106a..650a314 100644
--- a/src/post.c
+++ b/src/post.c
@@ -332,6 +332,9 @@ handle_post(void)
     // Allow writes to modify bios area (0xf0000)
     make_bios_writable();
 
+    // Setup QEMU debug output port
+    qemu_debug_postram_preinit();
+
     // Now that memory is read/writable - start post process.
     dopost();
 }
-- 
2.19.2


_______________________________________________
SeaBIOS mailing list
SeaBIOS@seabios.org
https://mail.coreboot.org/mailman/listinfo/seabios
Re: [SeaBIOS] [PATCH] qemu: avoid debug prints if debugcon is not enabled
Posted by Kevin O'Connor 5 years, 4 months ago
On Sun, Dec 02, 2018 at 02:10:13PM +0100, Stefano Garzarella wrote:
> In order to speed up the boot phase, we can check the QEMU
> debugcon device, and disable the writes if it is not recognized.
> 
> This patch allow us to save around 10 msec (time measured
> between SeaBIOS entry point and "linuxboot" entry point)
> when CONFIG_DEBUG_LEVEL=1 and debugcon is not enabled.

Thanks.  In order to properly track reboots, the HaveRunPost variable
must always be the first global variable to be modified.  So, the qemu
debug init must come later in the boot.  How about the patch below
instead?

-Kevin


commit 75b42835134553c96f113e5014072c0caf99d092 (HEAD -> master)
Author: Stefano Garzarella <sgarzare@redhat.com>
Date:   Sun Dec 2 14:10:13 2018 +0100

    qemu: avoid debug prints if debugcon is not enabled
    
    In order to speed up the boot phase, we can check the QEMU
    debugcon device, and disable the writes if it is not recognized.
    
    This patch allow us to save around 10 msec (time measured
    between SeaBIOS entry point and "linuxboot" entry point)
    when CONFIG_DEBUG_LEVEL=1 and debugcon is not enabled.
    
    Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
    Signed-off-by: Kevin O'Connor <kevin@koconnor.net>

diff --git a/src/fw/paravirt.c b/src/fw/paravirt.c
index 0770c47..4fcd8f5 100644
--- a/src/fw/paravirt.c
+++ b/src/fw/paravirt.c
@@ -75,6 +75,9 @@ static void qemu_detect(void)
     if (!CONFIG_QEMU_HARDWARE)
         return;
 
+    // Setup QEMU debug output port
+    qemu_debug_preinit();
+
     // check northbridge @ 00:00.0
     u16 v = pci_config_readw(0, PCI_VENDOR_ID);
     if (v == 0x0000 || v == 0xffff)
diff --git a/src/fw/paravirt.h b/src/fw/paravirt.h
index a14d83e..f7e1d4c 100644
--- a/src/fw/paravirt.h
+++ b/src/fw/paravirt.h
@@ -49,6 +49,9 @@ static inline int runningOnKVM(void) {
 // QEMU_CFG_DMA ID bit
 #define QEMU_CFG_VERSION_DMA    2
 
+// QEMU debugcon read value
+#define QEMU_DEBUGCON_READBACK  0xe9
+
 int qemu_cfg_enabled(void);
 int qemu_cfg_dma_enabled(void);
 void qemu_preinit(void);
diff --git a/src/hw/serialio.c b/src/hw/serialio.c
index 319a85c..3163344 100644
--- a/src/hw/serialio.c
+++ b/src/hw/serialio.c
@@ -103,11 +103,23 @@ serial_debug_flush(void)
 
 u16 DebugOutputPort VARFSEG = 0x402;
 
+void
+qemu_debug_preinit(void)
+{
+    /* Check if the QEMU debug output port is active */
+    if (CONFIG_DEBUG_IO &&
+        inb(GET_GLOBAL(DebugOutputPort)) != QEMU_DEBUGCON_READBACK)
+        DebugOutputPort = 0;
+}
+
 // Write a character to the special debugging port.
 void
 qemu_debug_putc(char c)
 {
-    if (CONFIG_DEBUG_IO && runningOnQEMU())
+    if (!CONFIG_DEBUG_IO || !runningOnQEMU())
+        return;
+    u16 port = GET_GLOBAL(DebugOutputPort);
+    if (port)
         // Send character to debug port.
-        outb(c, GET_GLOBAL(DebugOutputPort));
+        outb(c, port);
 }
diff --git a/src/hw/serialio.h b/src/hw/serialio.h
index 88296fe..81fed30 100644
--- a/src/hw/serialio.h
+++ b/src/hw/serialio.h
@@ -24,6 +24,7 @@ void serial_debug_preinit(void);
 void serial_debug_putc(char c);
 void serial_debug_flush(void);
 extern u16 DebugOutputPort;
+void qemu_debug_preinit(void);
 void qemu_debug_putc(char c);
 
 #endif // serialio.h

_______________________________________________
SeaBIOS mailing list
SeaBIOS@seabios.org
https://mail.coreboot.org/mailman/listinfo/seabios
Re: [SeaBIOS] [PATCH] qemu: avoid debug prints if debugcon is not enabled
Posted by Stefano Garzarella 5 years, 4 months ago
On Tue, Dec 11, 2018 at 4:08 AM Kevin O'Connor <kevin@koconnor.net> wrote:
>
> On Sun, Dec 02, 2018 at 02:10:13PM +0100, Stefano Garzarella wrote:
> > In order to speed up the boot phase, we can check the QEMU
> > debugcon device, and disable the writes if it is not recognized.
> >
> > This patch allow us to save around 10 msec (time measured
> > between SeaBIOS entry point and "linuxboot" entry point)
> > when CONFIG_DEBUG_LEVEL=1 and debugcon is not enabled.
>
> Thanks.  In order to properly track reboots, the HaveRunPost variable
> must always be the first global variable to be modified.  So, the qemu
> debug init must come later in the boot.  How about the patch below
> instead?

Thanks for the explanation! It looks good!

Cheers,
Stefano

>
> -Kevin
>
>
> commit 75b42835134553c96f113e5014072c0caf99d092 (HEAD -> master)
> Author: Stefano Garzarella <sgarzare@redhat.com>
> Date:   Sun Dec 2 14:10:13 2018 +0100
>
>     qemu: avoid debug prints if debugcon is not enabled
>
>     In order to speed up the boot phase, we can check the QEMU
>     debugcon device, and disable the writes if it is not recognized.
>
>     This patch allow us to save around 10 msec (time measured
>     between SeaBIOS entry point and "linuxboot" entry point)
>     when CONFIG_DEBUG_LEVEL=1 and debugcon is not enabled.
>
>     Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
>     Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
>
> diff --git a/src/fw/paravirt.c b/src/fw/paravirt.c
> index 0770c47..4fcd8f5 100644
> --- a/src/fw/paravirt.c
> +++ b/src/fw/paravirt.c
> @@ -75,6 +75,9 @@ static void qemu_detect(void)
>      if (!CONFIG_QEMU_HARDWARE)
>          return;
>
> +    // Setup QEMU debug output port
> +    qemu_debug_preinit();
> +
>      // check northbridge @ 00:00.0
>      u16 v = pci_config_readw(0, PCI_VENDOR_ID);
>      if (v == 0x0000 || v == 0xffff)
> diff --git a/src/fw/paravirt.h b/src/fw/paravirt.h
> index a14d83e..f7e1d4c 100644
> --- a/src/fw/paravirt.h
> +++ b/src/fw/paravirt.h
> @@ -49,6 +49,9 @@ static inline int runningOnKVM(void) {
>  // QEMU_CFG_DMA ID bit
>  #define QEMU_CFG_VERSION_DMA    2
>
> +// QEMU debugcon read value
> +#define QEMU_DEBUGCON_READBACK  0xe9
> +
>  int qemu_cfg_enabled(void);
>  int qemu_cfg_dma_enabled(void);
>  void qemu_preinit(void);
> diff --git a/src/hw/serialio.c b/src/hw/serialio.c
> index 319a85c..3163344 100644
> --- a/src/hw/serialio.c
> +++ b/src/hw/serialio.c
> @@ -103,11 +103,23 @@ serial_debug_flush(void)
>
>  u16 DebugOutputPort VARFSEG = 0x402;
>
> +void
> +qemu_debug_preinit(void)
> +{
> +    /* Check if the QEMU debug output port is active */
> +    if (CONFIG_DEBUG_IO &&
> +        inb(GET_GLOBAL(DebugOutputPort)) != QEMU_DEBUGCON_READBACK)
> +        DebugOutputPort = 0;
> +}
> +
>  // Write a character to the special debugging port.
>  void
>  qemu_debug_putc(char c)
>  {
> -    if (CONFIG_DEBUG_IO && runningOnQEMU())
> +    if (!CONFIG_DEBUG_IO || !runningOnQEMU())
> +        return;
> +    u16 port = GET_GLOBAL(DebugOutputPort);
> +    if (port)
>          // Send character to debug port.
> -        outb(c, GET_GLOBAL(DebugOutputPort));
> +        outb(c, port);
>  }
> diff --git a/src/hw/serialio.h b/src/hw/serialio.h
> index 88296fe..81fed30 100644
> --- a/src/hw/serialio.h
> +++ b/src/hw/serialio.h
> @@ -24,6 +24,7 @@ void serial_debug_preinit(void);
>  void serial_debug_putc(char c);
>  void serial_debug_flush(void);
>  extern u16 DebugOutputPort;
> +void qemu_debug_preinit(void);
>  void qemu_debug_putc(char c);
>
>  #endif // serialio.h



-- 
Stefano Garzarella
Red Hat

_______________________________________________
SeaBIOS mailing list
SeaBIOS@seabios.org
https://mail.coreboot.org/mailman/listinfo/seabios
Re: [SeaBIOS] [PATCH] qemu: avoid debug prints if debugcon is not enabled
Posted by Kevin O'Connor 5 years, 4 months ago
On Tue, Dec 11, 2018 at 10:10:33AM +0100, Stefano Garzarella wrote:
> On Tue, Dec 11, 2018 at 4:08 AM Kevin O'Connor <kevin@koconnor.net> wrote:
> >
> > On Sun, Dec 02, 2018 at 02:10:13PM +0100, Stefano Garzarella wrote:
> > > In order to speed up the boot phase, we can check the QEMU
> > > debugcon device, and disable the writes if it is not recognized.
> > >
> > > This patch allow us to save around 10 msec (time measured
> > > between SeaBIOS entry point and "linuxboot" entry point)
> > > when CONFIG_DEBUG_LEVEL=1 and debugcon is not enabled.
> >
> > Thanks.  In order to properly track reboots, the HaveRunPost variable
> > must always be the first global variable to be modified.  So, the qemu
> > debug init must come later in the boot.  How about the patch below
> > instead?
> 
> Thanks for the explanation! It looks good!

Thanks.  I committed this change.

-Kevin

_______________________________________________
SeaBIOS mailing list
SeaBIOS@seabios.org
https://mail.coreboot.org/mailman/listinfo/seabios