From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 54AED21AEB0DB for ; Fri, 4 Aug 2017 02:51:04 -0700 (PDT) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Aug 2017 02:53:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,320,1498546800"; d="scan'208";a="119683227" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga002.jf.intel.com with ESMTP; 04 Aug 2017 02:53:16 -0700 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 4 Aug 2017 02:53:16 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.151]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.188]) with mapi id 14.03.0319.002; Fri, 4 Aug 2017 17:53:15 +0800 From: "Ni, Ruiyu" To: "Zeng, Star" , "edk2-devel@lists.01.org" CC: Heyi Guo , Laszlo Ersek Thread-Topic: [PATCH] MdeModulePkg SerialDxe: Process timeout consistently in SerialRead Thread-Index: AQHTDPvNgsJugB0K0kKXGX7XOdF+VKJz6Vow//99ygCAAI2Z4A== Date: Fri, 4 Aug 2017 09:53:15 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5B9CC583@SHSMSX104.ccr.corp.intel.com> References: <1501835363-61956-1-git-send-email-star.zeng@intel.com> <734D49CCEBEEF84792F5B80ED585239D5B9CC46A@SHSMSX104.ccr.corp.intel.com> <0C09AFA07DD0434D9E2A0C6AEB0483103B8F9EEF@shsmsx102.ccr.corp.intel.com> In-Reply-To: <0C09AFA07DD0434D9E2A0C6AEB0483103B8F9EEF@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: [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 09:51:04 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable I thought unit of Stall is 100ns. Then no issues now. Reviewed-by: Ruiyu Ni Thanks/Ray > -----Original Message----- > From: Zeng, Star > Sent: Friday, August 4, 2017 5:25 PM > To: Ni, Ruiyu ; edk2-devel@lists.01.org > Cc: Heyi Guo ; Laszlo Ersek ; > Zeng, Star > Subject: RE: [PATCH] MdeModulePkg SerialDxe: Process timeout consistently > in SerialRead >=20 > Thanks for the comments. >=20 > EFI_TIMER_PERIOD_MICROSECONDS is used for timer event according to its > definition, and its unit is 100ns. > But the unit of mSerialIoMode.Timeout and gBS->Stall() is 1us. >=20 > +1 may cause more polling of SerialPortPoll(). How about keeping using > ++10? :) >=20 >=20 > Thanks, > Star > -----Original Message----- > From: Ni, Ruiyu > Sent: Friday, August 4, 2017 5:13 PM > To: Zeng, Star ; edk2-devel@lists.01.org > Cc: Heyi Guo ; Laszlo Ersek > Subject: RE: [PATCH] MdeModulePkg SerialDxe: Process timeout consistently > in SerialRead >=20 > Star, > 3 minor comments below. >=20 > Thanks/Ray >=20 > > -----Original Message----- > > From: Zeng, Star > > Sent: Friday, August 4, 2017 4:29 PM > > To: edk2-devel@lists.01.org > > Cc: Zeng, Star ; Heyi Guo ; > > Ni, Ruiyu ; Laszlo Ersek > > Subject: [PATCH] MdeModulePkg SerialDxe: Process timeout consistently > > in SerialRead > > > > 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 re= sults: > > 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 =3D 0; > > > > - if (SerialPortPoll ()) { > > - Count =3D SerialPortRead (Buffer, *BufferSize); > > + while (Count < *BufferSize) { > > + TimeOut =3D 0; > > + while (TimeOut < mSerialIoMode.Timeout) { > > + if (SerialPortPoll ()) { > > + break; > > + } > > + gBS->Stall (10); > 1. can you use EFI_TIMER_PERIOD_MICROSECONDS(1)? >=20 > > + TimeOut +=3D 10; > 2. TImeOut++? >=20 > > + } > > + if (TimeOut >=3D mSerialIoMode.Timeout) { > 3. if (TimeOut =3D=3D ...) { ? >=20 > > + break; > > + } > > + SerialPortRead (Buffer, 1); > > + Count++; > > + Buffer =3D (VOID *) ((UINT8 *) Buffer + 1); > > } > > > > if (Count !=3D *BufferSize) { > > -- > > 2.7.0.windows.1