From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) (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 A146121CB0315 for ; Tue, 18 Jul 2017 01:37:13 -0700 (PDT) Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Jul 2017 01:39:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,377,1496127600"; d="scan'208";a="109189411" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by orsmga004.jf.intel.com with ESMTP; 18 Jul 2017 01:39:06 -0700 Received: from FMSMSX110.amr.corp.intel.com (10.18.116.10) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 18 Jul 2017 01:39:06 -0700 Received: from shsmsx104.ccr.corp.intel.com (10.239.4.70) by fmsmsx110.amr.corp.intel.com (10.18.116.10) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 18 Jul 2017 01:39:05 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.146]) by SHSMSX104.ccr.corp.intel.com ([10.239.4.70]) with mapi id 14.03.0319.002; Tue, 18 Jul 2017 16:39:04 +0800 From: "Zeng, Star" To: Heyi Guo , "edk2-devel@lists.01.org" , "Ni, Ruiyu" , "Laszlo Ersek (lersek@redhat.com)" CC: "Zeng, Star" Thread-Topic: [edk2] MdeModulePkg/SerialDxe: Inconsistent timeout processing in SerialRead Thread-Index: AQHS/rR5s7p0gE2FTESYuh+ovHOJ/KJZQQ+Q Date: Tue, 18 Jul 2017 08:39:03 +0000 Message-ID: <0C09AFA07DD0434D9E2A0C6AEB0483103B8F41C6@shsmsx102.ccr.corp.intel.com> References: In-Reply-To: Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: MdeModulePkg/SerialDxe: Inconsistent timeout processing 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: Tue, 18 Jul 2017 08:37:13 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Gary, SerialDxe is a wrapper of SerialPortLib to produce serial io protocol. If let SerialDxe to handle the TimeOut, seemingly it can only check SerialP= ortPoll() and read data by SerialPortRead() one byte by one byte, for examp= le like below. Do you have any proposed patch? Ray and Laszlo, Do you have any comments? =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D debf0d1b85e7a30defd29838abb20a44dd9ec69b MdeModulePkg/Universal/SerialDxe/SerialIo.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/MdeModulePkg/Universal/SerialDxe/SerialIo.c b/MdeModulePkg/Uni= versal/SerialDxe/SerialIo.c index d2383e56dd8f..b05603d7f3b5 100644 --- a/MdeModulePkg/Universal/SerialDxe/SerialIo.c +++ b/MdeModulePkg/Universal/SerialDxe/SerialIo.c @@ -465,11 +465,25 @@ SerialRead ( ) { UINTN Count; + UINTN TimeOut; =20 Count =3D 0; =20 - if (SerialPortPoll ()) { - Count =3D SerialPortRead (Buffer, *BufferSize); + while (Count < *BufferSize) { + TimeOut =3D 0; + while (TimeOut < mSerialIoMode.TimeOut) { + if (SerialPortPoll ()) { + break; + } + gBS->Stall (10); + TimeOut +=3D 10; + } + if (TimeOut >=3D mSerialIoMode.TimeOut) { + break; + } + SerialPortRead (Buffer, 1); + Count++; + Buffer =3D (VOID *) ((UINT8 *) Buffer + 1); } =20 if (Count !=3D *BufferSize) { =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Thanks, Star -----Original Message----- From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Heyi= Guo Sent: Monday, July 17, 2017 12:23 PM To: edk2-devel@lists.01.org Subject: [edk2] MdeModulePkg/SerialDxe: Inconsistent timeout processing in = SerialRead Hi Folks, In SerialRead function in MdeModulePkg/Universal/SerialDxe/SerialIo.c, it seems the timeout processing in SerialRead is not consistent. Since SerialPortPoll only checks the status of serial port and returns imme= diately, 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 i= mmediately without any waiting; 2. If there is A characters in serial port FIFO, and caller requires A+1 ch= aracters, it will wait until a new input is coming and timeout will not rea= lly occur. As SerialPortLib is a simple library implementation, I think it is better t= o improve SerialIoDxe driver instead of SerialPortLib. Please let me know your comments about this. Thanks and regards, Gary (Heyi Guo) EFI_STATUS EFIAPI SerialRead ( IN EFI_SERIAL_IO_PROTOCOL *This, IN OUT UINTN *BufferSize, OUT VOID *Buffer ) { UINTN Count; Count =3D 0; if (SerialPortPoll ()) { Count =3D SerialPortRead (Buffer, *BufferSize); } if (Count !=3D *BufferSize) { *BufferSize =3D Count; return EFI_TIMEOUT; } return EFI_SUCCESS; } _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel