From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 3A1DF20958992 for ; Tue, 18 Jul 2017 01:57:03 -0700 (PDT) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Jul 2017 01:58:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,377,1496127600"; d="scan'208";a="1196707358" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by fmsmga002.fm.intel.com with ESMTP; 18 Jul 2017 01:58:56 -0700 Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 18 Jul 2017 01:58:56 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.151]) by shsmsx102.ccr.corp.intel.com ([169.254.2.146]) with mapi id 14.03.0319.002; Tue, 18 Jul 2017 16:58:54 +0800 From: "Ni, Ruiyu" To: "Zeng, Star" , Heyi Guo , "edk2-devel@lists.01.org" , "Laszlo Ersek (lersek@redhat.com)" Thread-Topic: [edk2] MdeModulePkg/SerialDxe: Inconsistent timeout processing in SerialRead Thread-Index: AQHS/rR5LQUjFwwZLk+lMPdzYOESGqJYvxmAgACLiGA= Date: Tue, 18 Jul 2017 08:58:53 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5B9BA295@SHSMSX104.ccr.corp.intel.com> References: <0C09AFA07DD0434D9E2A0C6AEB0483103B8F41C6@shsmsx102.ccr.corp.intel.com> In-Reply-To: <0C09AFA07DD0434D9E2A0C6AEB0483103B8F41C6@shsmsx102.ccr.corp.intel.com> Accept-Language: en-US, zh-CN 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:57:03 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Star, Your change looks good. Thanks/Ray > -----Original Message----- > From: Zeng, Star > Sent: Tuesday, July 18, 2017 4:39 PM > To: Heyi Guo ; edk2-devel@lists.01.org; Ni, Ruiyu > ; Laszlo Ersek (lersek@redhat.com) > > Cc: Zeng, Star > Subject: RE: [edk2] MdeModulePkg/SerialDxe: Inconsistent timeout > processing in SerialRead >=20 > Gary, > SerialDxe is a wrapper of SerialPortLib to produce serial io protocol. > If let SerialDxe to handle the TimeOut, seemingly it can only check > SerialPortPoll() and read data by SerialPortRead() one byte by one byte, = for > example like below. > Do you have any proposed patch? >=20 > Ray and Laszlo, > Do you have any comments? >=20 >=20 > =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(-) >=20 > diff --git a/MdeModulePkg/Universal/SerialDxe/SerialIo.c > b/MdeModulePkg/Universal/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 >=20 >=20 > 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 >=20 > Hi Folks, >=20 > In SerialRead function in MdeModulePkg/Universal/SerialDxe/SerialIo.c, > it seems the timeout processing in SerialRead is not consistent. >=20 > 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: >=20 > 1. If there is no serial input at all, this interface will return timeout > immediately without any waiting; >=20 > 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. >=20 > As SerialPortLib is a simple library implementation, I think it is better= to > improve SerialIoDxe driver instead of SerialPortLib. >=20 > Please let me know your comments about this. >=20 > Thanks and regards, >=20 > Gary (Heyi Guo) >=20 > EFI_STATUS > EFIAPI > SerialRead ( > IN EFI_SERIAL_IO_PROTOCOL *This, > IN OUT UINTN *BufferSize, > OUT VOID *Buffer > ) > { > UINTN Count; >=20 > Count =3D 0; >=20 > if (SerialPortPoll ()) { > Count =3D SerialPortRead (Buffer, *BufferSize); > } >=20 > if (Count !=3D *BufferSize) { > *BufferSize =3D Count; > return EFI_TIMEOUT; > } >=20 > return EFI_SUCCESS; > } >=20 > _______________________________________________ > edk2-devel mailing list > edk2-devel@lists.01.org > https://lists.01.org/mailman/listinfo/edk2-devel