From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 134.134.136.24, mailfrom: liming.gao@intel.com) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by groups.io with SMTP; Thu, 13 Jun 2019 09:22:07 -0700 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 13 Jun 2019 09:22:06 -0700 X-ExtLoop1: 1 Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by fmsmga001.fm.intel.com with ESMTP; 13 Jun 2019 09:22:06 -0700 Received: from fmsmsx152.amr.corp.intel.com (10.18.125.5) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.408.0; Thu, 13 Jun 2019 09:22:06 -0700 Received: from shsmsx105.ccr.corp.intel.com (10.239.4.158) by FMSMSX152.amr.corp.intel.com (10.18.125.5) with Microsoft SMTP Server (TLS) id 14.3.408.0; Thu, 13 Jun 2019 09:22:05 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.185]) by SHSMSX105.ccr.corp.intel.com ([169.254.11.72]) with mapi id 14.03.0439.000; Fri, 14 Jun 2019 00:22:03 +0800 From: "Liming Gao" To: Felix Polyudov , "devel@edk2.groups.io" , "Gao, Zhichao" CC: "Wang, Jian J" , "Wu, Hao A" , "Ni, Ray" , "Zeng, Star" , Sean Brogan , Michael Turner , Bret Barkelew , "Kinney, Michael D" , "Dong, Eric" , "Laszlo Ersek" , "Andrew Fish (afish@apple.com)" Subject: Re: [edk2-devel] [PATCH 0/6] Fix race condition and add event protocol Thread-Topic: [edk2-devel] [PATCH 0/6] Fix race condition and add event protocol Thread-Index: AQHVEe41MU5pQ7dhyUedn4AglpPO9qZ5tTqAgCApbVA= Date: Thu, 13 Jun 2019 16:22:03 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14E480BE4@SHSMSX104.ccr.corp.intel.com> References: <20190524050437.38616-1-zhichao.gao@intel.com> <9333E191E0D52B4999CE63A99BA663A00302C8EE0A@atlms1.us.megatrends.com> In-Reply-To: <9333E191E0D52B4999CE63A99BA663A00302C8EE0A@atlms1.us.megatrends.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiN2U2Zjc5NDgtNzY1YS00ZTljLThmMGQtOTNjM2ZjYzUzYWFjIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiSjNUMUJIdnh3M2pSYUZJY3kxSmRWTVIyRGVMMDNcL3hNc0pSRVVmWnFWcnFacEJ4R0htOXJzK1wvXC9leFlHS3h0SyJ9 dlp-product: dlpe-windows dlp-version: 11.0.600.7 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Return-Path: liming.gao@intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Felix: Sorry for the late response.=20 > -----Original Message----- > From: Felix Polyudov [mailto:Felixp@ami.com] > Sent: Friday, May 24, 2019 8:53 PM > To: devel@edk2.groups.io; Gao, Zhichao > Cc: Wang, Jian J ; Wu, Hao A = ; Ni, Ray ; Zeng, Star > ; Gao, Liming ; Sean Brogan <= sean.brogan@microsoft.com>; Michael Turner > ; Bret Barkelew ; Kinney, Michael D ; > Dong, Eric ; Laszlo Ersek ; Andr= ew Fish (afish@apple.com) > Subject: RE: [edk2-devel] [PATCH 0/6] Fix race condition and add event p= rotocol >=20 > I think there is a bigger problem with the idle event signaling by CoreW= aitForEvent. > On every iteration CoreWaitForEvent checks user events, and, if none is = signaled, the function signals special idle event. > This itself is not a problem. However, on many (most?) platforms CPU dri= ver installs idle event handler that calls CpuSleep > (f.i. refer to IdleLoopEventCallback in UefiCpuPkg/CpuDxe/CpuDxe.c and A= rmPkg/Drivers/CpuDxe/CpuDxe.c). > CpuSleep "places the CPU in a sleep state until an interrupt is received= ", which changes the nature of the WaitForEvent function arguably > violating the UEFI specification. >=20 > According to the UEFI specification: > "The list of events in the Event array are evaluated in order from first= to last, and this evaluation is repeated until an event is signaled or an > error is detected." >=20 > The sentence above implies continues evaluation (polling model). Here is repeat. It is not identical to polling model. A check per timer pe= riod is also a repeat implementation. So, it follows UEFI spec. > An idle event callback that sends CPU to a sleep state, converts WaitFor= Event from > a continues polling function into a poll-once-per-timer-period function = (timer is typically the only enabled HW interrupt), > which reduces quality of service provided by WaitForEvent and can lead t= o missed events. >=20 > For example, UEFI application that reads key strokes using gBS->WaitForE= vent(..)/ConIn->ReadKey(...) sequence > will be losing key strokes if they are coming faster than 18.2 keys per = second on a system based on legacy timer. This case may not be real case. Idle event is added since 2011 year @54cd1= 7e9842d82dae3cd78686e05c4dc37a3540d.=20 I don't get the real issue report. Have you meet with some real issue in t= he production? >=20 > So, should idle event support be removed from CoreWaitForEvent? >=20 I think we can still keep it. It is edk2 implementation. Thanks Liming > -----Original Message----- > From: devel@edk2.groups.io [mailto:devel@edk2.groups.io] On Behalf Of Ga= o, Zhichao > Sent: Friday, May 24, 2019 1:05 AM > To: devel@edk2.groups.io > Cc: Jian J Wang; Hao A Wu; Ray Ni; Star Zeng; Liming gao; Sean Brogan; M= ichael Turner; Bret Barkelew; Michael D Kinney; Eric Dong; > Laszlo Ersek > Subject: [edk2-devel] [PATCH 0/6] Fix race condition and add event proto= col >=20 > There is a race condition in CoreWaitForEvent function: > If an interrupt happens between CheckEvent and gIdleLoopEvent, > there would be a event pending during cpu sleep. > So it is required to check the gEventPending with the interrupt > disabled. > Implement a gEfiCpu2ProtocolGuid to fix that. The protocol include > one interface to enable interrupt and put the cpu to sleep. >=20 > Add a event protocol gEdkiiCommonEventProtocolGuid to support > all TPL event. It is require for PI drivers that use HW interrput. >=20 > Cc: Jian J Wang > Cc: Hao A Wu > cc: Ray Ni > Cc: Star Zeng > Cc: Liming gao > Cc: Sean Brogan > Cc: Michael Turner > Cc: Bret Barkelew > Cc: Michael D Kinney > Cc: Eric Dong > Cc: Laszlo Ersek >=20 > Sean Brogan (5): > MdeModulePkg: Add gEdkiiCommonEventProtocolGuid for event > MdePkg/BaseLib.h: Add EnableInterruptsAndSleep function declare > MdePkg/BaseLib: Implement EnableInterruptsAndSleep > MdePkg: Add gEfiCpu2ProtocolGuid and header file > MdeModulePkg/DxeMain: Implement common event protocol >=20 > Zhichao Gao (1): > UefiCpuPkg/CpuDxe: Implement Cpu2 protocol >=20 > MdeModulePkg/Core/Dxe/DxeMain.h | 64 ++++++++++- > MdeModulePkg/Core/Dxe/DxeMain.inf | 1 + > MdeModulePkg/Core/Dxe/DxeMain/DxeMain.c | 22 ++++ > .../Core/Dxe/DxeMain/DxeProtocolNotify.c | 1 + > MdeModulePkg/Core/Dxe/Event/Event.c | 102 ++++++++++++++++-- > MdeModulePkg/Core/Dxe/Event/Event.h | 2 +- > MdeModulePkg/Include/Protocol/CommonEvent.h | 18 ++++ > MdeModulePkg/MdeModulePkg.dec | 3 + > MdePkg/Include/Library/BaseLib.h | 11 ++ > MdePkg/Include/Protocol/Cpu2.h | 43 ++++++++ > .../Library/BaseLib/Ia32/EnableInterrupts.c | 18 +++- > .../BaseLib/Ia32/EnableInterrupts.nasm | 15 ++- > .../Library/BaseLib/X64/EnableInterrupts.nasm | 15 ++- > MdePkg/MdePkg.dec | 3 + > UefiCpuPkg/CpuDxe/CpuDxe.c | 40 ++++++- > UefiCpuPkg/CpuDxe/CpuDxe.h | 15 +++ > UefiCpuPkg/CpuDxe/CpuDxe.inf | 3 +- > 17 files changed, 358 insertions(+), 18 deletions(-) > create mode 100644 MdeModulePkg/Include/Protocol/CommonEvent.h > create mode 100644 MdePkg/Include/Protocol/Cpu2.h >=20 > -- > 2.21.0.windows.1 >=20 >=20 >=20 >=20 >=20 > Please consider the environment before printing this email. >=20 > The information contained in this message may be confidential and propri= etary to American Megatrends, Inc. This communication is > intended to be read only by the individual or entity to whom it is addre= ssed or by their designee. If the reader of this message is not the > intended recipient, you are on notice that any distribution of this mess= age, in any form, is strictly prohibited. Please promptly notify the > sender by reply e-mail or by telephone at 770-246-8600, and then delete = or destroy all copies of the transmission.