From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (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 62564209589CB for ; Fri, 4 Aug 2017 02:23:19 -0700 (PDT) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga104.jf.intel.com with ESMTP; 04 Aug 2017 02:25:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,320,1498546800"; d="scan'208";a="886369072" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by FMSMGA003.fm.intel.com with ESMTP; 04 Aug 2017 02:25:31 -0700 Received: from fmsmsx102.amr.corp.intel.com (10.18.124.200) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 4 Aug 2017 02:25:31 -0700 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by FMSMSX102.amr.corp.intel.com (10.18.124.200) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 4 Aug 2017 02:25:30 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.146]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.188]) with mapi id 14.03.0319.002; Fri, 4 Aug 2017 17:25:28 +0800 From: "Zeng, Star" To: "Ni, Ruiyu" , "edk2-devel@lists.01.org" CC: Heyi Guo , Laszlo Ersek , "Zeng, Star" Thread-Topic: [PATCH] MdeModulePkg SerialDxe: Process timeout consistently in SerialRead Thread-Index: AQHTDPvN3Byx3yphxkaF5cqSQ//BT6JzY5SAgACIfBA= Date: Fri, 4 Aug 2017 09:25:28 +0000 Message-ID: <0C09AFA07DD0434D9E2A0C6AEB0483103B8F9EEF@shsmsx102.ccr.corp.intel.com> References: <1501835363-61956-1-git-send-email-star.zeng@intel.com> <734D49CCEBEEF84792F5B80ED585239D5B9CC46A@SHSMSX104.ccr.corp.intel.com> In-Reply-To: <734D49CCEBEEF84792F5B80ED585239D5B9CC46A@SHSMSX104.ccr.corp.intel.com> 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: [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:23:19 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Thanks for the comments. EFI_TIMER_PERIOD_MICROSECONDS is used for timer event according to its defi= nition, and its unit is 100ns. But the unit of mSerialIoMode.Timeout and gBS->Stall() is 1us. +1 may cause more polling of SerialPortPoll(). How about keeping using +10?= :) Thanks, Star -----Original Message----- From: Ni, Ruiyu=20 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 i= n SerialRead Star, 3 minor comments below. Thanks/Ray > -----Original Message----- > From: Zeng, Star > Sent: Friday, August 4, 2017 4:29 PM > To: edk2-devel@lists.01.org > Cc: Zeng, Star ; Heyi Guo ;=20 > Ni, Ruiyu ; Laszlo Ersek > Subject: [PATCH] MdeModulePkg SerialDxe: Process timeout consistently=20 > in SerialRead >=20 > https://lists.01.org/pipermail/edk2-devel/2017-July/012385.html > reported the timeout processing in SerialRead is not consistent. >=20 > Since SerialPortPoll only checks the status of serial port and returns=20 > immediately, and SerialPortRead does not really implement a time out=20 > mechanism and will always wait for enough input, it will cause below resu= lts: > 1. If there is no serial input at all, this interface will return=20 > timeout immediately without any waiting; 2. If there is A characters=20 > 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 > This patch is to update SerialRead() to check SerialPortPoll() and=20 > read data through SerialPortRead() one byte by one byte, and check=20 > timeout against mSerialIoMode.Timeout if no input. >=20 > 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(-) >=20 > 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; >=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); 1. can you use EFI_TIMER_PERIOD_MICROSECONDS(1)? > + TimeOut +=3D 10; 2. TImeOut++? > + } > + if (TimeOut >=3D mSerialIoMode.Timeout) { 3. if (TimeOut =3D=3D ...) { ? > + break; > + } > + SerialPortRead (Buffer, 1); > + Count++; > + Buffer =3D (VOID *) ((UINT8 *) Buffer + 1); > } >=20 > if (Count !=3D *BufferSize) { > -- > 2.7.0.windows.1