From nobody Wed Dec 25 01:13:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 15095869040889.66288307155935; Wed, 1 Nov 2017 18:41:44 -0700 (PDT) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 67B932034A7B8; Wed, 1 Nov 2017 18:37:49 -0700 (PDT) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 43F7E21FCA27F for ; Wed, 1 Nov 2017 18:37:48 -0700 (PDT) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP; 01 Nov 2017 18:41:41 -0700 Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.9.31]) by fmsmga006.fm.intel.com with ESMTP; 01 Nov 2017 18:41:39 -0700 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.31; helo=mga06.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.44,331,1505804400"; d="scan'208";a="170778234" From: Star Zeng To: edk2-devel@lists.01.org Date: Thu, 2 Nov 2017 09:41:36 +0800 Message-Id: <1509586896-56444-1-git-send-email-star.zeng@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 Subject: [edk2] [PATCH] MdeModulePkg SerialDxe: Handle Timeout change more robustly X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ruiyu Ni , Laszlo Ersek , Star Zeng MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" https://lists.01.org/pipermail/edk2-devel/2017-October/016479.html reported "Xen Console input very slow in recent UEFI" that appears after 4cf3f37c87ba1f9d58072444bd735e40e4779e70 "MdeModulePkg SerialDxe: Process timeout consistently in SerialRead". Julien did more debugging and find out the following is happening in TerminalConInTimerHandler (MdeModulePkg/Universal/Console/TerminalDxe) when a character is received: 1) GetControl will return EFI_SERIAL_INPUT_BUFFER_EMPTY unset =3D> Entering in the loop to fetch character from the serial 2) GetOneKeyFromSerial() =3D> Return directly with the character read 3) Looping as the fifo is not full and no error 4) GetOneKeyFromSerial() -> SerialRead() =3D> No more character so SerialPortPoll() will return FALSE and loop until timeout =3D> Return EFI_TIMEOUT 5) Exiting the loop from TerminalConInTimerHandler 6) Characters are printed After some investigation, I found it is related to the Timeout value. The Timeout is 1000000 (1s) by default to follow UEFI spec. And the Terminal driver will recalculate and set the Timeout value based on the properties of UART in TerminalDriverBindingStart()/ TerminalConInTimerHandler(). SerialInTimeOut =3D 0; if (Mode->BaudRate !=3D 0) { // // According to BAUD rate to calculate the timeout value. // SerialInTimeOut =3D (1 + Mode->DataBits + Mode->StopBits) * 2 * 1000000 / (UINTN) Mode->BaudRate; } For example, based on the PCD values of PcdUartDefaultBaudRate, PcdUartDefaultDataBits and PcdUartDefaultStopBits, SerialInTimeOut =3D (1 + 8 + 1) * 2 * 1000000 / (UINTN) 115200 =3D 173 (us). When SerialDxe is used, TerminalDriverBindingStart()/TerminalConInTimerHandler() -> SerialIo->SetAttributes() -> SerialSetAttributes() -> SerialPortSetAttributes() Some implementations of SerialPortSetAttributes() could handle the input parameters and return RETURN_SUCCESS, for example BaseSerialPortLib16550, then Timeout value will be changed to 173 (us), no "slow down" will be observed. But some implementations of SerialPortSetAttributes() just return RETURN_UNSUPPORTED, for example XenConsoleSerialPortLib, then Timeout value will be not changed and kept 1000000 (1s), "slow down" will be observed. SerialPortLib instance can be enhanced to 1. Handle the input parameters and return status accordingly instead of just returning RETURN_UNSUPPORTED in SerialPortSetAttributes(). 2. Just return RETURN_SUCCESS instead of RETURN_UNSUPPORTED in SerialPortSetAttributes() if the instance does not care the input parameters at all. And SerialDxe can also be enhanced like this patch to be more robust to handle Timeout change. Cc: Julien Grall Cc: Laszlo Ersek Cc: Ruiyu Ni Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng Reviewed-by: Laszlo Ersek --- MdeModulePkg/Universal/SerialDxe/SerialIo.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/MdeModulePkg/Universal/SerialDxe/SerialIo.c b/MdeModulePkg/Uni= versal/SerialDxe/SerialIo.c index ebcd92726314..060ea56c2b1a 100644 --- a/MdeModulePkg/Universal/SerialDxe/SerialIo.c +++ b/MdeModulePkg/Universal/SerialDxe/SerialIo.c @@ -285,7 +285,21 @@ SerialSetAttributes ( =20 Status =3D SerialPortSetAttributes (&BaudRate, &ReceiveFifoDepth, &Timeo= ut, &Parity, &DataBits, &StopBits); if (EFI_ERROR (Status)) { - return Status; + // + // If it is just to set Timeout value and unsupported is returned, + // do not return error. + // + if ((Status =3D=3D EFI_UNSUPPORTED) && + (This->Mode->Timeout !=3D Timeout) && + (This->Mode->ReceiveFifoDepth =3D=3D ReceiveFifoDepth) && + (This->Mode->BaudRate =3D=3D BaudRate) && + (This->Mode->DataBits =3D=3D (UINT32) DataBits) && + (This->Mode->Parity =3D=3D (UINT32) Parity) && + (This->Mode->StopBits =3D=3D (UINT32) StopBits)) { + Status =3D EFI_SUCCESS; + } else { + return Status; + } } =20 // --=20 2.7.0.windows.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel