From nobody Sun May 5 14:06:40 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 1510018614342138.61646466192997; Mon, 6 Nov 2017 17:36:54 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id EB3FC2035D114; Mon, 6 Nov 2017 17:32:51 -0800 (PST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) (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 A240F203555F7 for ; Mon, 6 Nov 2017 17:32:50 -0800 (PST) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Nov 2017 17:36:49 -0800 Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.9.31]) by orsmga004.jf.intel.com with ESMTP; 06 Nov 2017 17:36:47 -0800 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=192.55.52.115; helo=mga14.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,355,1505804400"; d="scan'208";a="146702825" From: Star Zeng To: edk2-devel@lists.01.org Date: Tue, 7 Nov 2017 09:36:45 +0800 Message-Id: <1510018605-84896-1-git-send-email-star.zeng@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 Subject: [edk2] [PATCH V2] 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 Compare against the original parameters Suggested-by: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Star Zeng V2: Compare against the original parameters Reviewed-by: Laszlo Ersek Tested-by: Julien Grall --- MdeModulePkg/Universal/SerialDxe/SerialIo.c | 45 +++++++++++++++++++++++++= ++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Universal/SerialDxe/SerialIo.c b/MdeModulePkg/Uni= versal/SerialDxe/SerialIo.c index ebcd92726314..5be77e7acfb0 100644 --- a/MdeModulePkg/Universal/SerialDxe/SerialIo.c +++ b/MdeModulePkg/Universal/SerialDxe/SerialIo.c @@ -280,12 +280,51 @@ SerialSetAttributes ( IN EFI_STOP_BITS_TYPE StopBits ) { - EFI_STATUS Status; - EFI_TPL Tpl; + EFI_STATUS Status; + EFI_TPL Tpl; + UINT64 OriginalBaudRate; + UINT32 OriginalReceiveFifoDepth; + UINT32 OriginalTimeout; + EFI_PARITY_TYPE OriginalParity; + UINT8 OriginalDataBits; + EFI_STOP_BITS_TYPE OriginalStopBits; =20 + // + // Preserve the original input values in case + // SerialPortSetAttributes() updates the input/output parameters even on= error. + // + OriginalBaudRate =3D BaudRate; + OriginalReceiveFifoDepth =3D ReceiveFifoDepth; + OriginalTimeout =3D Timeout; + OriginalParity =3D Parity; + OriginalDataBits =3D DataBits; + OriginalStopBits =3D StopBits; 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 OriginalTimeout) && + (This->Mode->ReceiveFifoDepth =3D=3D OriginalReceiveFifoDepth) && + (This->Mode->BaudRate =3D=3D OriginalBaudRate) && + (This->Mode->DataBits =3D=3D (UINT32) OriginalDataBits) && + (This->Mode->Parity =3D=3D (UINT32) OriginalParity) && + (This->Mode->StopBits =3D=3D (UINT32) OriginalStopBits)) { + // + // Restore to the original input values. + // + BaudRate =3D OriginalBaudRate; + ReceiveFifoDepth =3D OriginalReceiveFifoDepth; + Timeout =3D OriginalTimeout; + Parity =3D OriginalParity; + DataBits =3D OriginalDataBits; + StopBits =3D OriginalStopBits; + 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