From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 4D5FE7803D7 for ; Tue, 31 Oct 2023 01:41:40 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=y/J0EKUPcOT8PbRcfn7iOkkTJwXiqC9r67pXSDqdJ2s=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:From:To:CC:Subject:Thread-Topic:Thread-Index:Date:Message-ID:References:In-Reply-To:Accept-Language:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1698716499; v=1; b=XD9GUZrVHywuDH5Vn9RCVUnOok6s+QzRoSrvsGFPbMrGIXdbMz6hPQFXVBuf5YA/SUDoqR+8 gpL3coDVfocgM/19b2wS+66TEC0GNEzY9m/hMwYKJb6yPC/ObwRKtgk6cYrrDrtrDtPRuCdN3Ak DIa5iuQ1WyqzLcISetnrr6hA= X-Received: by 127.0.0.2 with SMTP id PdALYY7687511xJ1MdeDyThl; Mon, 30 Oct 2023 18:41:39 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) by mx.groups.io with SMTP id smtpd.web10.177443.1698716497799961508 for ; Mon, 30 Oct 2023 18:41:38 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="9720767" X-IronPort-AV: E=Sophos;i="6.03,264,1694761200"; d="scan'208";a="9720767" X-Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Oct 2023 18:41:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10879"; a="760466176" X-IronPort-AV: E=Sophos;i="6.03,264,1694761200"; d="scan'208";a="760466176" X-Received: from fmsmsx602.amr.corp.intel.com ([10.18.126.82]) by orsmga002.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 30 Oct 2023 18:41:35 -0700 X-Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Mon, 30 Oct 2023 18:41:34 -0700 X-Received: from fmsmsx602.amr.corp.intel.com (10.18.126.82) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Mon, 30 Oct 2023 18:41:34 -0700 X-Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx602.amr.corp.intel.com (10.18.126.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34 via Frontend Transport; Mon, 30 Oct 2023 18:41:34 -0700 X-Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.100) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.34; Mon, 30 Oct 2023 18:41:31 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=i607usEf/fYrri/X87HYaXDiCtdff9b6cjtKoLzbIIgWe1q9Ib+5oRH59TbUzwQDfO2db1xjlqNOu7qJpp9WxEC/5AWYCfONwYN3hX275GJsizn/47PmDMeXRDzU9wQRq1sAdMIcjjj85QmxUcMA5UBYoleIJOIdDKGITyBR+bc5ilBUnN5dGEWqEilAzkdZCIbZtTuOXXG3Cks5a+wL+ai2EQRmzq0sdFi8DIQ2V7ic0d0g9IcKLy/dZSVerAF2daBKsnWDFHw+Kj9cefxa4LnuvshtC/FQzC8uY5tF87DG6F6+hlowCa2T9RL8Zp5x9wI0XOemjHyim6XYevwAxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=J+tKiiyrJ35a8ighqA1ij7RixOFQvW7BhUNI8iW+tmA=; b=FpxZw7KKfj6Zw3B7F5DNwL6PvUfOvTGoWsv1NBzBhZhSlAqWy7Ogd0TPqkCot8NwuACCwVLI9riMqHOdp3XPozqyms1Ae9XLxazvEGyBHCMcIJQi4V3sqMgz6xTO/NvlGdKV5gRjW6A+MJROnK13WiLZcuJMRGQYmR3X0+acXSNXR9tIZMGYMqBfPcnyPKdib45631r2p7hYyRYkenOJBdxl+TSAMb//Ejjjqu1cXI3UT9Ls2nouT22FCPoLGvRZEZATYB1shpCpza7+FYniz/Fni9frrKggC0WvMg7O6o6vjEUYaVzfhn8royiO5xvbrdXGAjdioUZbYr1IIiJ7VQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none X-Received: from DM6PR11MB4025.namprd11.prod.outlook.com (2603:10b6:5:197::31) by IA1PR11MB7318.namprd11.prod.outlook.com (2603:10b6:208:426::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.26; Tue, 31 Oct 2023 01:41:27 +0000 X-Received: from DM6PR11MB4025.namprd11.prod.outlook.com ([fe80::fd1c:5b02:8fe:2ee2]) by DM6PR11MB4025.namprd11.prod.outlook.com ([fe80::fd1c:5b02:8fe:2ee2%4]) with mapi id 15.20.6933.021; Tue, 31 Oct 2023 01:41:27 +0000 From: "Wu, Hao A" To: "devel@edk2.groups.io" , "Henz, Patrick" , Michael Brown CC: "Kinney, Michael D" , "Gao, Liming" Subject: Re: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use Performance Timer for XHCI Timeouts Thread-Topic: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use Performance Timer for XHCI Timeouts Thread-Index: AQHZr32iafvIU0JyA0+vZWQmCs2v8a/TT1yggBEKMoCAADEbgIB+990AgABRwgA= Date: Tue, 31 Oct 2023 01:41:27 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DM6PR11MB4025:EE_|IA1PR11MB7318:EE_ x-ms-office365-filtering-correlation-id: c1842ca4-e0d0-41a0-648d-08dbd9b27f91 x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: t7XP7xtbMdded25SEZj8R+oNeQ6a1jbuVJ8KNPtcWKIiuwr5TRGWkyQcVYlaJ2TOI/+NXSPRjvdkOmXRycw471Gc9khth0UYsabvCR6ZZO6yxtX9gT+fM2z9OyIQi2qfoAcBI475nWg/Veaj78vObTZvjfgRwoXh7eDvvRt3aZI6zpBuNKHjXInj57lAySd+ZzCDj7ZJFHE5tB2sDZ1Fl4mvFCRIhryCpjixi46/xGgzJl+zkm5OKemWcoPtrqHDF+c50eG7DgXWXJvu7IGeLjPjI6IsWA8IwzUYKK+RnjUwro69UjHvr0YqNWPYk80UgdpwqO9y3Ee4rgNsQSox+fEu4OZSqbqYopgdoUUQ8KAscIWHZHPhrkcS9OrUPZAwYlChDYatQnWTLpOor5vqLU3XJfb9oararwCl6j559fAQtHFfx2iIzDS62D+whj1xde4VFW/gKySTLKGAhPa/f36zr1tVCf1fkLp0LZkkxfCGV+P3A2wXfEjI8q60ttELQtUs2iTRbYEEjEKxAqt0Lcx9l9eO8YHcxSurCw0uoYc63avWi9HvleQgLIka38XCPUSq6ZyAseYlDlCMGTCD+RaHPXbtMON3vgox80xhPlT61SlQadmOHkbnBbYT9B+tNwydbzxm1kcaff11PSqBQQ== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?GYie2yiPp8hbYuuPt3bhEKlUrPrkQBdScxtsJbJ0PL02eL9VbWu4Hznh08Vn?= =?us-ascii?Q?oTaUCA6XZQWajR6NvAgoOOAXT6hKmGTnLBtnRQmA0jV7qKfb8nmf/JnEiRkb?= =?us-ascii?Q?w50cSItyVuzZwlQ+el2lXZO1FfglQDXn3KBINE1J92jjPccIE+HK9Y7XWXDD?= =?us-ascii?Q?8bYdsHJNVc2IWo0P9LWAagoT9qpAUaQ1Ikms4+xStpkfx4LrE4H4kgGICcUI?= =?us-ascii?Q?MLHf+jJU3OEIAUctit5UUC0hpG9VSLUFPEEae6SoA2UhWqO9gLeQheQ9q8fr?= =?us-ascii?Q?YPFDGCVFXKeAKmyzmXJ2nFYPgbZJAlEiutbLrjlNJmexSRViTaT+vodIWEee?= =?us-ascii?Q?vc0KG70MrNPX2wscNMLMKymL65cH80aUaFheM11mCP8anuN1OvxT/bPYLV3F?= =?us-ascii?Q?Oa2JbSQJ+9B+KCRiHMmbzCLG0l0+R7p4ilQ73wYCPkhw69eQbnki9Rjc/Kfo?= =?us-ascii?Q?RiKqJCX3k9H3WvDypKi9lLvHrUGqKGqg0t/7ArthO/ehBwhClntS/eVipJ+p?= =?us-ascii?Q?mUCPVJhyj3ec8PrHT5tPj+Yvfab16XQGfvy7M1RnIQLktUoh2hU6x1J3b3eb?= =?us-ascii?Q?APQUmAld+XIics9TdwRPTpdB29Q4f0qm68MB1Jeg1JdUhUaqKbuQwg7rlRIn?= =?us-ascii?Q?AmVE7Aa6bW6LyWXKDQVwFVCWlH4kiD+mpYMrvkccsfKvir9tIfnW4eS6UKv5?= =?us-ascii?Q?EzgtxNhg2RtAvpGxqljgC5BUecwhjN3dLluPBpFqnekos7eK2lRB+Cjv3BCF?= =?us-ascii?Q?nwcscUuJXGEmEMcBcD68s4hfIxShc8Vn81OfKneISB+gyrrEnKmr2jjmT2Tv?= =?us-ascii?Q?6cnWUbjdU+BMdGj4keE01qf4zv4fHl0gNkJjNIoeuZWCWzAM9wx1m7rL4JyE?= =?us-ascii?Q?8RySWlfb90+LG74Sa2U0IxZ/ImgWPsagQ0kb9UbV8zidtEerzz92So6GHUzw?= =?us-ascii?Q?Sv8T9gEbYf8JVmIcBRUBraIDIg7HB447PABCqZnGEMH7C0EXPqvl03837JJ6?= =?us-ascii?Q?wIQvZyL2avE88J0xuIjvsP+G9x/ZlZDVGtfJv65hi1of+tgdoJqhCvGkJb23?= =?us-ascii?Q?DAAXsTRd0DD8eRey1D9FRfVOjLhox7fSTXXjuEJz2+czxj6T9sviXr8S0OLY?= =?us-ascii?Q?Pk5aKmQp1lamidOHR8JiRcxKg+Qx28AhEUf3nqldGip6dOZeGQTM74OzlEeF?= =?us-ascii?Q?rXUKwTWVXhv6Q5E8z2lR+ghfIQz6zTeBnY6ftdK+7KDWsXCZdq9UweAR17LT?= =?us-ascii?Q?FLliX2IBsl0GXPpOK065701JMzyC9CXauy0GFw/t4/K5DW+ArFohQR1Tp7GX?= =?us-ascii?Q?VmIdMNTt/CxR+4vGqtD49Q33ucaaE+KHHZuM/H6WkfmYJk2nn7RKkU6BpnyD?= =?us-ascii?Q?z4psd5bOmNuwBMH2tS3mkmJIvd3HHy79o51ab5bUSSccHbtxqmZmFlZV3mQ5?= =?us-ascii?Q?xFoDbxE9issXnnUiex/4o14g1jex97eM/OXECyQu49ix5uRWVSSGRyccYCIc?= =?us-ascii?Q?0/+fPK3/V9Fr2w1OBQOGjxDZsGzKaWF3hcYb7VOR3Y1ETGttkPuvdd4zsvDz?= =?us-ascii?Q?CBnyJXZdwvWcMOMlGpoJy7pnNUpkvDCzQmzVSP2z?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR11MB4025.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c1842ca4-e0d0-41a0-648d-08dbd9b27f91 X-MS-Exchange-CrossTenant-originalarrivaltime: 31 Oct 2023 01:41:27.0419 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: DAp/nTdxe44ycjT2/P2dkDXVChp672Y31I5TFa1uogMTTYe25KcWfDWhXCvmBgWJbvoA6nzo/NMMB4oYiJj4Tg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR11MB7318 X-OriginatorOrg: intel.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,hao.a.wu@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: Zj87yGZYf9nWqa1RTzZSIVaUx7686176AA= Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=XD9GUZrV; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}"); dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io (Add MdePkg maintainers for their feedbacks) Sorry that I do not have strong opinion on this one. Some of my thoughts are: * If you find the to-be-added APIs can be used in serveral places to reduce repetative codes, then it will be worthwhile to add new library APIs. * TimerLib has many instance implementations, my take is that many post-mem instances use library level global variable to store information like tim= er frequency to avoid calculating it every time. For pre-mem instances, such caching is not feasible. I think it will be t= he API consumer's responsibility to limit the usage of these APIs for perfor= mance consideration. Best Regards, Hao Wu > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Henz, > Patrick > Sent: Tuesday, October 31, 2023 4:36 AM > To: Wu, Hao A ; devel@edk2.groups.io; Michael Brown > > Subject: Re: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use Performance > Timer for XHCI Timeouts >=20 > My changes have been in for a little over a month now, I've been looking = into > updating the TimerLib API but I'm questioning if it still makes sense to = go down > that path. The functions I had implemented, XhcGetElapsedTicks () and > XhcConvertTimeToTicks (), now rely heavily on the use of global variables= for > caching return values from GetPerformanceCounterProperties. As-is these > functions won't work for all instances of TimerLib, specifically if the i= nstance is > used before memory (RAM) is available. I could implement the functions as > they originally were, but I wouldn't be able to replace the Xhc functions > without adding additional parameters to said TimerLib functions (e.g. add= ing > Frequency, StartValue, StopValue to ConvertTimeToTicks), which feels clun= ky > to me. Would a new library make sense here? Something that sits between > the driver and the TimerLib library? Or do we just leave things as they > currently are? >=20 > Thanks, > Patrick Henz >=20 > -----Original Message----- > From: Wu, Hao A > Sent: Thursday, August 10, 2023 8:43 PM > To: Henz, Patrick ; devel@edk2.groups.io; Michael > Brown > Subject: RE: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use Performance > Timer for XHCI Timeouts >=20 > My personal preference is to do this as two steps. > Address the issue in XhciDxe first. Then add new TimerLib API to replace = all > driver/library internal implementations. >=20 > Best Regards, > Hao Wu >=20 > > -----Original Message----- > > From: Henz, Patrick > > Sent: Friday, August 11, 2023 6:45 AM > > To: devel@edk2.groups.io; Wu, Hao A ; Michael > > Brown > > Subject: RE: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use > > Performance Timer for XHCI Timeouts > > > > I can certainly make that change. > > > > For what it's worth I have been working on adding the new function, > > GetElapsedTicks, to the various implementations of TimerLib. I've > > finished up testing, I would just need to clean up the commits for a > > patch. Should I move forward with that, or would we rather I just add > > XhcGetElapsedTime to XhciDxe for the time being? > > > > Thanks, > > Patrick Henz > > > > -----Original Message----- > > From: devel@edk2.groups.io On Behalf Of Wu, > Hao > > A > > Sent: Sunday, July 30, 2023 9:57 PM > > To: devel@edk2.groups.io; Henz, Patrick ; > > Michael Brown > > Subject: Re: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use > > Performance Timer for XHCI Timeouts > > > > For the 2 occurrences of in XhcWaitOpRegBit & XhcExecTransfer: > > TimeoutTime =3D XHC_MICROSECOND_TO_NANOSECOND (Timeout * > > XHC_1_MILLISECOND); How about changing them to: > > TimeoutTime =3D XHC_MICROSECOND_TO_NANOSECOND ((UINT64) > Timeout > > * XHC_1_MILLISECOND); to address possible overflow during "Timeout * > > XHC_1_MILLISECOND"? > > > > For extending XhcGetElapsedTime as a TimerLib API, I am fine to put it > > in XhciDxe at this moment. > > If package maintainers suggest to make it as a public library API, my > > take is that this should be done in a separate commit. > > > > Best Regards, > > Hao Wu > > > > > -----Original Message----- > > > From: devel@edk2.groups.io On Behalf Of Henz, > > > Patrick > > > Sent: Thursday, July 6, 2023 4:16 AM > > > To: devel@edk2.groups.io > > > Cc: Henz, Patrick > > > Subject: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use Performance > > > Timer for XHCI Timeouts > > > > > > REF:INVALID URI REMOVED > > > bu > > > g.cgi?id=3D2948__;!!NpxR!kyFQM5IkKYAG9CRBO4xphwBnzi_jhb2oU- > > NKbMjOV-lctg5 > > > _B3K1Lcta452Gx-1twRt8At3cueAYDq_n$ > > > > > > XhciDxe uses the timer functionality provided by the boot services > > > table to detect timeout conditions. This breaks the driver's > > > ExitBootServices call back, as CoreExitBootServices halts the timer > > > before signaling the ExitBootServices event. If the host controller > > > fails to halt in the call back, the timeout condition will never > > > occur and the boot gets stuck in an indefinite spin loop. Use the > > > free running timer provided by TimerLib to calculate timeouts, > > > avoiding the potential hang. > > > > > > Signed-off-by: Patrick Henz > > > Reviewed-by: > > > --- > > > MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 56 +++++++++++++++++++ > > > MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h | 22 ++++++++ > > > MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf | 2 + > > > MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c | 67 +++++++++-------------= - > > > MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 68 > > > +++++++++--------------- > > > 5 files changed, 129 insertions(+), 86 deletions(-) > > > > > > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c > > > b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c > > > index 62682dd27c..1dcbe20512 100644 > > > --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c > > > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c > > > @@ -1,6 +1,7 @@ > > > /** @file > > > > > > The XHCI controller driver. > > > > > > > > > > > > +(C) Copyright 2023 Hewlett Packard Enterprise Development LP
> > > > > > Copyright (c) 2011 - 2022, Intel Corporation. All rights > > > reserved.
> > > > > > SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > > > > > @@ -2294,3 +2295,58 @@ XhcDriverBindingStop ( > > > > > > > > > return EFI_SUCCESS; > > > > > > } > > > > > > + > > > > > > +/** > > > > > > + Computes and returns the elapsed time in nanoseconds since > > > > > > + PreviousTick. The value of PreviousTick is overwritten with the > > > > > > + current performance counter value. > > > > > > + > > > > > > + @param PreviousTick Pointer to PreviousTick count. > > > > > > + @return The elapsed time in nanoseconds since PreviousCount. > > > > > > + PreviousCount is overwritten with the current performance > > > > > > + counter value. > > > > > > +**/ > > > > > > +UINT64 > > > > > > +XhcGetElapsedTime ( > > > > > > + IN OUT UINT64 *PreviousTick > > > > > > + ) > > > > > > +{ > > > > > > + UINT64 StartValue; > > > > > > + UINT64 EndValue; > > > > > > + UINT64 CurrentTick; > > > > > > + UINT64 Delta; > > > > > > + > > > > > > + GetPerformanceCounterProperties (&StartValue, &EndValue); > > > > > > + > > > > > > + CurrentTick =3D GetPerformanceCounter (); > > > > > > + > > > > > > + // > > > > > > + // Determine if the counter is counting up or down > > > > > > + // > > > > > > + if (StartValue < EndValue) { > > > > > > + // > > > > > > + // Counter counts upwards, check for an overflow condition > > > > > > + // > > > > > > + if (*PreviousTick > CurrentTick) { > > > > > > + Delta =3D (EndValue - *PreviousTick) + CurrentTick; > > > > > > + } else { > > > > > > + Delta =3D CurrentTick - *PreviousTick; > > > > > > + } > > > > > > + } else { > > > > > > + // > > > > > > + // Counter counts downwards, check for an underflow condition > > > > > > + // > > > > > > + if (*PreviousTick < CurrentTick) { > > > > > > + Delta =3D (StartValue - CurrentTick) + *PreviousTick; > > > > > > + } else { > > > > > > + Delta =3D *PreviousTick - CurrentTick; > > > > > > + } > > > > > > + } > > > > > > + > > > > > > + // > > > > > > + // Set PreviousTick to CurrentTick > > > > > > + // > > > > > > + *PreviousTick =3D CurrentTick; > > > > > > + > > > > > > + return GetTimeInNanoSecond (Delta); > > > > > > +} > > > > > > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h > > > b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h > > > index ca223bd20c..77feb66647 100644 > > > --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h > > > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h > > > @@ -2,6 +2,7 @@ > > > > > > > > > Provides some data structure definitions used by the XHCI host > > > controller driver. > > > > > > > > > > > > +(C) Copyright 2023 Hewlett Packard Enterprise Development LP
> > > > > > Copyright (c) 2011 - 2017, Intel Corporation. All rights > > > reserved.
> > > > > > Copyright (c) Microsoft Corporation.
> > > > > > SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > @@ -26,6 +27,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent > > > #include > > > > > > #include > > > > > > #include > > > > > > +#include > > > > > > > > > > > > #include > > > > > > > > > > > > @@ -37,6 +39,10 @@ typedef struct _USB_DEV_CONTEXT > > USB_DEV_CONTEXT; > > > #include "ComponentName.h" > > > > > > #include "UsbHcMem.h" > > > > > > > > > > > > +// > > > > > > +// Converts a count from microseconds to nanoseconds > > > > > > +// > > > > > > +#define XHC_MICROSECOND_TO_NANOSECOND(Time) ((UINT64)(Time) > * > > > 1000) > > > > > > // > > > > > > // The unit is microsecond, setting it as 1us. > > > > > > // > > > > > > @@ -720,4 +726,20 @@ XhcAsyncIsochronousTransfer ( > > > IN VOID *Context > > > > > > ); > > > > > > > > > > > > +/** > > > > > > + Computes and returns the elapsed time in nanoseconds since > > > > > > + PreviousTick. The value of PreviousTick is overwritten with the > > > > > > + current performance counter value. > > > > > > + > > > > > > + @param PreviousTick Pointer to PreviousTick count. > > > > > > + before calling this function. > > > > > > + @return The elapsed time in nanoseconds since PreviousCount. > > > > > > + PreviousCount is overwritten with the current performance > > > > > > + counter value. > > > > > > +**/ > > > > > > +UINT64 > > > > > > +XhcGetElapsedTime ( > > > > > > + IN OUT UINT64 *PreviousTick > > > > > > + ); > > > > > > + > > > > > > #endif > > > > > > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf > > > b/MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf > > > index 5865d86822..18ef87916a 100644 > > > --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf > > > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf > > > @@ -3,6 +3,7 @@ > > > # It implements the interfaces of monitoring the status of all > > > ports and transferring > > > > > > # Control, Bulk, Interrupt and Isochronous requests to those > > > attached usb LS/FS/HS/SS devices. > > > > > > # > > > > > > +# (C) Copyright 2023 Hewlett Packard Enterprise Development LP
> > > > > > # Copyright (c) 2011 - 2018, Intel Corporation. All rights > > > reserved.
> > > > > > # > > > > > > # SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > @@ -54,6 +55,7 @@ > > > BaseMemoryLib > > > > > > DebugLib > > > > > > ReportStatusCodeLib > > > > > > + TimerLib > > > > > > > > > > > > [Guids] > > > > > > gEfiEventExitBootServicesGuid ## SOMETIMES_CONSUME= S ## > > > Event > > > > > > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c > > > b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c > > > index 5700fc5fb8..2499698715 100644 > > > --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c > > > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c > > > @@ -2,6 +2,7 @@ > > > > > > > > > The XHCI register operation routines. > > > > > > > > > > > > +(C) Copyright 2023 Hewlett Packard Enterprise Development LP
> > > > > > Copyright (c) 2011 - 2017, Intel Corporation. All rights > > > reserved.
> > > > > > SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > > > > > @@ -417,15 +418,14 @@ XhcClearOpRegBit ( > > > Wait the operation register's bit as specified by Bit > > > > > > to become set (or clear). > > > > > > > > > > > > - @param Xhc The XHCI Instance. > > > > > > - @param Offset The offset of the operation registe= r. > > > > > > - @param Bit The bit of the register to wait for= . > > > > > > - @param WaitToSet Wait the bit to set or clear. > > > > > > - @param Timeout The time to wait before abort (in m= illisecond, > > > ms). > > > > > > + @param Xhc The XHCI Instance. > > > > > > + @param Offset The offset of the operation register. > > > > > > + @param Bit The bit of the register to wait for. > > > > > > + @param WaitToSet Wait the bit to set or clear. > > > > > > + @param Timeout The time to wait before abort (in millisecond= , ms). > > > > > > > > > > > > - @retval EFI_SUCCESS The bit successfully changed by hos= t > > controller. > > > > > > - @retval EFI_TIMEOUT The time out occurred. > > > > > > - @retval EFI_OUT_OF_RESOURCES Memory for the timer event could > not > > > be allocated. > > > > > > + @retval EFI_SUCCESS The bit successfully changed by host controll= er. > > > > > > + @retval EFI_TIMEOUT The time out occurred. > > > > > > > > > > > > **/ > > > > > > EFI_STATUS > > > > > > @@ -437,54 +437,35 @@ XhcWaitOpRegBit ( > > > IN UINT32 Timeout > > > > > > ) > > > > > > { > > > > > > - EFI_STATUS Status; > > > > > > - EFI_EVENT TimeoutEvent; > > > > > > - > > > > > > - TimeoutEvent =3D NULL; > > > > > > + UINT64 TimeoutTime; > > > > > > + UINT64 ElapsedTime; > > > > > > + UINT64 TimeDelta; > > > > > > + UINT64 CurrentTick; > > > > > > > > > > > > if (Timeout =3D=3D 0) { > > > > > > return EFI_TIMEOUT; > > > > > > } > > > > > > > > > > > > - Status =3D gBS->CreateEvent ( > > > > > > - EVT_TIMER, > > > > > > - TPL_CALLBACK, > > > > > > - NULL, > > > > > > - NULL, > > > > > > - &TimeoutEvent > > > > > > - ); > > > > > > - > > > > > > - if (EFI_ERROR (Status)) { > > > > > > - goto DONE; > > > > > > - } > > > > > > - > > > > > > - Status =3D gBS->SetTimer ( > > > > > > - TimeoutEvent, > > > > > > - TimerRelative, > > > > > > - EFI_TIMER_PERIOD_MILLISECONDS (Timeout) > > > > > > - ); > > > > > > - > > > > > > - if (EFI_ERROR (Status)) { > > > > > > - goto DONE; > > > > > > - } > > > > > > + TimeoutTime =3D XHC_MICROSECOND_TO_NANOSECOND (Timeout * > > > XHC_1_MILLISECOND); > > > > > > + ElapsedTime =3D 0; > > > > > > + CurrentTick =3D GetPerformanceCounter (); > > > > > > > > > > > > do { > > > > > > if (XHC_REG_BIT_IS_SET (Xhc, Offset, Bit) =3D=3D WaitToSet) { > > > > > > - Status =3D EFI_SUCCESS; > > > > > > - goto DONE; > > > > > > + return EFI_SUCCESS; > > > > > > } > > > > > > > > > > > > gBS->Stall (XHC_1_MICROSECOND); > > > > > > - } while (EFI_ERROR (gBS->CheckEvent (TimeoutEvent))); > > > > > > - > > > > > > - Status =3D EFI_TIMEOUT; > > > > > > + TimeDelta =3D XhcGetElapsedTime (&CurrentTick); > > > > > > + // Ensure that ElapsedTime is always incremented to avoid > > > + indefinite > > > hangs > > > > > > + if (TimeDelta =3D=3D 0) { > > > > > > + TimeDelta =3D XHC_MICROSECOND_TO_NANOSECOND > > > (XHC_1_MICROSECOND); > > > > > > + } > > > > > > > > > > > > -DONE: > > > > > > - if (TimeoutEvent !=3D NULL) { > > > > > > - gBS->CloseEvent (TimeoutEvent); > > > > > > - } > > > > > > + ElapsedTime +=3D TimeDelta; > > > > > > + } while (ElapsedTime < TimeoutTime); > > > > > > > > > > > > - return Status; > > > > > > + return EFI_TIMEOUT; > > > > > > } > > > > > > > > > > > > /** > > > > > > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c > > > b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c > > > index 298fb88b81..5177886e52 100644 > > > --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c > > > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c > > > @@ -2,6 +2,7 @@ > > > > > > > > > XHCI transfer scheduling routines. > > > > > > > > > > > > +(C) Copyright 2023 Hewlett Packard Enterprise Development LP
> > > > > > Copyright (c) 2011 - 2020, Intel Corporation. All rights > > > reserved.
> > > > > > Copyright (c) Microsoft Corporation.
> > > > > > Copyright (C) 2022 Advanced Micro Devices, Inc. All rights > > > reserved.
> > > > > > @@ -1273,15 +1274,14 @@ EXIT: > > > /** > > > > > > Execute the transfer by polling the URB. This is a synchronous ope= ration. > > > > > > > > > > > > - @param Xhc The XHCI Instance. > > > > > > - @param CmdTransfer The executed URB is for cmd transfe= r or > not. > > > > > > - @param Urb The URB to execute. > > > > > > - @param Timeout The time to wait before abort, in m= illisecond. > > > > > > + @param Xhc The XHCI Instance. > > > > > > + @param CmdTransfer The executed URB is for cmd transfer or = not. > > > > > > + @param Urb The URB to execute. > > > > > > + @param Timeout The time to wait before abort, in millis= econd. > > > > > > > > > > > > - @return EFI_DEVICE_ERROR The transfer failed due to transfer > error. > > > > > > - @return EFI_TIMEOUT The transfer failed due to time out= . > > > > > > - @return EFI_SUCCESS The transfer finished OK. > > > > > > - @retval EFI_OUT_OF_RESOURCES Memory for the timer event could > not > > > be allocated. > > > > > > + @return EFI_DEVICE_ERROR The transfer failed due to transfer erro= r. > > > > > > + @return EFI_TIMEOUT The transfer failed due to time out. > > > > > > + @return EFI_SUCCESS The transfer finished OK. > > > > > > > > > > > > **/ > > > > > > EFI_STATUS > > > > > > @@ -1296,12 +1296,14 @@ XhcExecTransfer ( > > > UINT8 SlotId; > > > > > > UINT8 Dci; > > > > > > BOOLEAN Finished; > > > > > > - EFI_EVENT TimeoutEvent; > > > > > > + UINT64 TimeoutTime; > > > > > > + UINT64 ElapsedTime; > > > > > > + UINT64 TimeDelta; > > > > > > + UINT64 CurrentTick; > > > > > > BOOLEAN IndefiniteTimeout; > > > > > > > > > > > > Status =3D EFI_SUCCESS; > > > > > > Finished =3D FALSE; > > > > > > - TimeoutEvent =3D NULL; > > > > > > IndefiniteTimeout =3D FALSE; > > > > > > > > > > > > if (CmdTransfer) { > > > > > > @@ -1319,34 +1321,14 @@ XhcExecTransfer ( > > > > > > > > > if (Timeout =3D=3D 0) { > > > > > > IndefiniteTimeout =3D TRUE; > > > > > > - goto RINGDOORBELL; > > > > > > - } > > > > > > - > > > > > > - Status =3D gBS->CreateEvent ( > > > > > > - EVT_TIMER, > > > > > > - TPL_CALLBACK, > > > > > > - NULL, > > > > > > - NULL, > > > > > > - &TimeoutEvent > > > > > > - ); > > > > > > - > > > > > > - if (EFI_ERROR (Status)) { > > > > > > - goto DONE; > > > > > > } > > > > > > > > > > > > - Status =3D gBS->SetTimer ( > > > > > > - TimeoutEvent, > > > > > > - TimerRelative, > > > > > > - EFI_TIMER_PERIOD_MILLISECONDS (Timeout) > > > > > > - ); > > > > > > - > > > > > > - if (EFI_ERROR (Status)) { > > > > > > - goto DONE; > > > > > > - } > > > > > > - > > > > > > -RINGDOORBELL: > > > > > > XhcRingDoorBell (Xhc, SlotId, Dci); > > > > > > > > > > > > + TimeoutTime =3D XHC_MICROSECOND_TO_NANOSECOND (Timeout * > > > XHC_1_MILLISECOND); > > > > > > + ElapsedTime =3D 0; > > > > > > + CurrentTick =3D GetPerformanceCounter (); > > > > > > + > > > > > > do { > > > > > > Finished =3D XhcCheckUrbResult (Xhc, Urb); > > > > > > if (Finished) { > > > > > > @@ -1354,22 +1336,22 @@ RINGDOORBELL: > > > } > > > > > > > > > > > > gBS->Stall (XHC_1_MICROSECOND); > > > > > > - } while (IndefiniteTimeout || EFI_ERROR (gBS->CheckEvent > > > (TimeoutEvent))); > > > > > > + TimeDelta =3D XhcGetElapsedTime (&CurrentTick); > > > > > > + // Ensure that ElapsedTime is always incremented to avoid > > > + indefinite > > > hangs > > > > > > + if (TimeDelta =3D=3D 0) { > > > > > > + TimeDelta =3D XHC_MICROSECOND_TO_NANOSECOND > > > (XHC_1_MICROSECOND); > > > > > > + } > > > > > > > > > > > > -DONE: > > > > > > - if (EFI_ERROR (Status)) { > > > > > > - Urb->Result =3D EFI_USB_ERR_NOTEXECUTE; > > > > > > - } else if (!Finished) { > > > > > > + ElapsedTime +=3D TimeDelta; > > > > > > + } while (IndefiniteTimeout || ElapsedTime < TimeoutTime); > > > > > > + > > > > > > + if (!Finished) { > > > > > > Urb->Result =3D EFI_USB_ERR_TIMEOUT; > > > > > > Status =3D EFI_TIMEOUT; > > > > > > } else if (Urb->Result !=3D EFI_USB_NOERROR) { > > > > > > Status =3D EFI_DEVICE_ERROR; > > > > > > } > > > > > > > > > > > > - if (TimeoutEvent !=3D NULL) { > > > > > > - gBS->CloseEvent (TimeoutEvent); > > > > > > - } > > > > > > - > > > > > > return Status; > > > > > > } > > > > > > > > > > > > -- > > > 2.34.1 > > > > > > > > > > > > -=3D-=3D-=3D-=3D-=3D-=3D > > > Groups.io Links: You receive all messages sent to this group. > > > View/Reply Online (#106668): > > > INVALID URI REMOVED > > > 06 > > > 668__;!!NpxR!kyFQM5IkKYAG9CRBO4xphwBnzi_jhb2oU-NKbMjOV- > > lctg5_B3K1Lcta4 > > > 52Gx-1twRt8At3cuWxQsO18$ Mute This Topic: > > > https://groups.io/mt/99972791/1768737 > > > NpxR!kyFQM5IkKYAG9CRBO4xphwBnzi_jhb2oU-NKbMjOV- > > lctg5_B3K1Lcta452Gx-1tw > > > Rt8At3cubh2HDyk$ Group Owner: devel+owner@edk2.groups.io > > > Unsubscribe: > > > https://edk2.groups.io/g/devel/unsub > > > !N > > > pxR!kyFQM5IkKYAG9CRBO4xphwBnzi_jhb2oU-NKbMjOV- > > lctg5_B3K1Lcta452Gx-1twR > > > t8At3cuWYMMXVU$ [hao.a.wu@intel.com] -=3D-=3D-=3D-=3D-=3D-=3D > > > > > > > > > > > > > > > >=20 >=20 >=20 >=20 >=20 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#110354): https://edk2.groups.io/g/devel/message/110354 Mute This Topic: https://groups.io/mt/99972791/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-