From: Paolo Bonzini <pbonzini@redhat.com>
To: edk2-devel@lists.01.org
Cc: Laszlo Ersek <lersek@redhat.com>
Subject: [PATCH] OvmfPkg: PlatformDebugLibIoPort: save on I/O port accesses when the debug port is not in use
Date: Wed, 15 Nov 2017 18:30:52 +0100 [thread overview]
Message-ID: <20171115173052.1503-1-pbonzini@redhat.com> (raw)
When SEV is enabled, every debug message printed by OVMF to the
QEMU debug port traps from the guest to QEMU character by character
because "REP OUTSB" cannot be used by IoWriteFifo8. Furthermore,
when OVMF is built with the DEBUG_VERBOSE bit (value 0x00400000)
enabled in "gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel", then the
OvmfPkg/IoMmuDxe driver, and the OvmfPkg/Library/BaseMemEncryptSevLib
library instance that is built into it, produce a huge amount of
log messages. Therefore, in SEV guests, the boot time impact is huge
(about 45 seconds _additional_ time spent writing to the debug port).
While these messages are very useful for analyzing guest behavior,
most of the time the user won't be capturing the OVMF debug log.
In fact libvirt does not provide a method for configuring log capture;
users that wish to do this (or are instructed to do this) have to resort
to <qemu:arg>.
The debug console device provides a handy detection mechanism; when read,
it returns 0xE9 (which is very much unlike the 0xFF that is returned by
an unused port). Use it to skip the possibly expensive OUT instructions
when the debug I/O port isn't plugged anywhere.
Contributed-under: TianoCore Contribution Agreement 1.0
Cc: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c b/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c
index 5435767c1c..06d6169dc8 100644
--- a/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c
+++ b/OvmfPkg/Library/PlatformDebugLibIoPort/DebugLib.c
@@ -29,6 +29,16 @@
//
#define MAX_DEBUG_MESSAGE_LENGTH 0x100
+//
+// The constant value that is read from the debug I/O port
+//
+#define BOCHS_DEBUG_PORT_MAGIC 0xE9
+
+//
+// Set to TRUE if the debug I/O port is enabled
+//
+static BOOLEAN mDebugIoPortFound = FALSE;
+
/**
This constructor function does not have to do anything.
@@ -41,6 +51,7 @@ PlatformDebugLibIoPortConstructor (
VOID
)
{
+ mDebugIoPortFound = IoRead8 (PcdGet16 (PcdDebugIoPort)) == BOCHS_DEBUG_PORT_MAGIC;
return EFI_SUCCESS;
}
@@ -77,9 +88,9 @@ DebugPrint (
ASSERT (Format != NULL);
//
- // Check driver debug mask value and global mask
+ // Do nothing if the global mask disables this message or the driver is inactive
//
- if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0) {
+ if ((ErrorLevel & GetDebugPrintErrorLevel ()) == 0 || !mDebugIoPortFound) {
return;
}
@@ -138,7 +149,9 @@ DebugAssert (
//
// Send the print string to the debug I/O port
//
- IoWriteFifo8 (PcdGet16 (PcdDebugIoPort), Length, Buffer);
+ if (mDebugIoPortFound) {
+ IoWriteFifo8 (PcdGet16 (PcdDebugIoPort), Length, Buffer);
+ }
//
// Generate a Breakpoint, DeadLoop, or NOP based on PCD settings
--
2.14.3
next reply other threads:[~2017-11-15 17:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-15 17:30 Paolo Bonzini [this message]
2017-11-16 0:43 ` [PATCH] OvmfPkg: PlatformDebugLibIoPort: save on I/O port accesses when the debug port is not in use Laszlo Ersek
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20171115173052.1503-1-pbonzini@redhat.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox