From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (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 0C04B2095D9CB for ; Fri, 4 Aug 2017 01:27:14 -0700 (PDT) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Aug 2017 01:29:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,320,1498546800"; d="scan'208";a="133496053" Received: from shwdeopenpsi068.ccr.corp.intel.com ([10.239.9.12]) by orsmga005.jf.intel.com with ESMTP; 04 Aug 2017 01:29:25 -0700 From: Star Zeng To: edk2-devel@lists.01.org Cc: Star Zeng , Heyi Guo , Ruiyu Ni , Laszlo Ersek Date: Fri, 4 Aug 2017 16:29:23 +0800 Message-Id: <1501835363-61956-1-git-send-email-star.zeng@intel.com> X-Mailer: git-send-email 2.7.0.windows.1 Subject: [PATCH] MdeModulePkg SerialDxe: Process timeout consistently in SerialRead 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: , X-List-Received-Date: Fri, 04 Aug 2017 08:27:14 -0000 https://lists.01.org/pipermail/edk2-devel/2017-July/012385.html reported the timeout processing in SerialRead is not consistent. Since SerialPortPoll only checks the status of serial port and returns immediately, and SerialPortRead does not really implement a time out mechanism and will always wait for enough input, it will cause below results: 1. If there is no serial input at all, this interface will return timeout immediately without any waiting; 2. If there is A characters in serial port FIFO, and caller requires A+1 characters, it will wait until a new input is coming and timeout will not really occur. This patch is to update SerialRead() to check SerialPortPoll() and read data through SerialPortRead() one byte by one byte, and check timeout against mSerialIoMode.Timeout if no input. Cc: Heyi Guo Cc: Ruiyu Ni Cc: Laszlo Ersek Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Star Zeng --- MdeModulePkg/Universal/SerialDxe/SerialIo.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Universal/SerialDxe/SerialIo.c b/MdeModulePkg/Universal/SerialDxe/SerialIo.c index d2383e56dd8f..43d33dba0c2a 100644 --- a/MdeModulePkg/Universal/SerialDxe/SerialIo.c +++ b/MdeModulePkg/Universal/SerialDxe/SerialIo.c @@ -465,11 +465,25 @@ SerialRead ( ) { UINTN Count; + UINTN TimeOut; Count = 0; - if (SerialPortPoll ()) { - Count = SerialPortRead (Buffer, *BufferSize); + while (Count < *BufferSize) { + TimeOut = 0; + while (TimeOut < mSerialIoMode.Timeout) { + if (SerialPortPoll ()) { + break; + } + gBS->Stall (10); + TimeOut += 10; + } + if (TimeOut >= mSerialIoMode.Timeout) { + break; + } + SerialPortRead (Buffer, 1); + Count++; + Buffer = (VOID *) ((UINT8 *) Buffer + 1); } if (Count != *BufferSize) { -- 2.7.0.windows.1