From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) (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 EB68C21D1B2A6 for ; Fri, 4 Aug 2017 02:10:33 -0700 (PDT) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Aug 2017 02:12:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,320,1498546800"; d="scan'208";a="886364976" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by FMSMGA003.fm.intel.com with ESMTP; 04 Aug 2017 02:12:46 -0700 Received: from fmsmsx156.amr.corp.intel.com (10.18.116.74) 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:12:46 -0700 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by fmsmsx156.amr.corp.intel.com (10.18.116.74) with Microsoft SMTP Server (TLS) id 14.3.319.2; Fri, 4 Aug 2017 02:12:45 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.151]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.122]) with mapi id 14.03.0319.002; Fri, 4 Aug 2017 17:12:44 +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 Date: Fri, 4 Aug 2017 09:12:43 +0000 Message-ID: <734D49CCEBEEF84792F5B80ED585239D5B9CC46A@SHSMSX104.ccr.corp.intel.com> References: <1501835363-61956-1-git-send-email-star.zeng@intel.com> In-Reply-To: <1501835363-61956-1-git-send-email-star.zeng@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:10:34 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable 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 ; Ni, > Ruiyu ; Laszlo Ersek > Subject: [PATCH] MdeModulePkg SerialDxe: Process timeout consistently 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 > immediately, and SerialPortRead does not really implement a time out > 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 timeout > immediately without any waiting; 2. If there is A characters in serial po= rt 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 read d= ata > through SerialPortRead() one byte by one byte, and check 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