From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web12.10756.1601343095333393514 for ; Mon, 28 Sep 2020 18:31:35 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=hma1g7HL; spf=pass (domain: intel.com, ip: 192.55.52.88, mailfrom: hao.a.wu@intel.com) IronPort-SDR: MNmF/CfbKVTUKiHbAbWsEW+MGkNoldXMvtH8EUMwlCBQDoNx2u11Y8yMXyJsjRmJN5qmX1rtMV LGr2aLNp9C6g== X-IronPort-AV: E=McAfee;i="6000,8403,9758"; a="180249976" X-IronPort-AV: E=Sophos;i="5.77,316,1596524400"; d="scan'208";a="180249976" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Sep 2020 18:31:34 -0700 IronPort-SDR: LwNj9edkLHLRYyO7DwVbgprNEJrRgB1Xf2LMb0dRoVmfjef9ObzQTy45JTIIxaiWPH3T1pQHAj tEWRpL9RtgXw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,316,1596524400"; d="scan'208";a="324493196" Received: from fmsmsx604.amr.corp.intel.com ([10.18.126.84]) by orsmga002.jf.intel.com with ESMTP; 28 Sep 2020 18:31:33 -0700 Received: from fmsmsx607.amr.corp.intel.com (10.18.126.87) by fmsmsx604.amr.corp.intel.com (10.18.126.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Mon, 28 Sep 2020 18:31:30 -0700 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx607.amr.corp.intel.com (10.18.126.87) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5 via Frontend Transport; Mon, 28 Sep 2020 18:31:30 -0700 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (104.47.59.174) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.1713.5; Mon, 28 Sep 2020 18:31:28 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TzFagGBm/HQAc5iKHcjo2RsE4ecR7YrWtWm6BYdq3hOTHOjrNsiV8OQD5dGeq13O8k+XGTNyo7vR2Ld+gxsjd/5dPsMqPbs5jfMTuefVGesWTwHFwBSpHIr0PfncuRuKs8syDEAM+weKa+NLBIz1GBJNA3NDT4M3wVZa757/v1nUwpxp17ndkvJNkOWejoo0niy9BPvjvijPrP5NPxW1pEYX5gSer3q8RiWnhZfXgwaK1s55b+7GFe6vohkvFKVf5MBBihEtAi3oZlfxeI8vJo7yZvBZlRiifYW44A6ZjQU26yb7lmtpHXduv4FipLIe+UCKl8lHGzPdTsbmlMN/cA== 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-SenderADCheck; bh=ly9WmeHsQzW4X+hhBLNey7c90sYG/oOwxrGUwlTboZU=; b=aq0+RU49ELFw9W5yHm/83CBB1l1H8GxM2yTtl6VSXlY2b6h1CFMJCqLP7wHCJWU/iQpropUIuO901crMzvj94Nj1tG8RrG1cAen2pwrz2Scmq1G5CAT9GZlbqPwPuJmwg+9mR2YwrPr0CIE8KluM6d6uIXFbvhsdtcc54gl/OfRWTSa0AaPAX/o2IUhIfzLGqqzoAtIBDRvVbAp6lcVlndiQyT4WcX9RXcPdkv4yHjfMV4O9KcDrbyjAIaR4pi/Dqa0nsUwZMMT9E/knoACHZcqnmMgJuqWv0cJtA7fJesElZpuOaE4r6hj/wSYvHIq9TRoIFBBSD9g1qvGU4y5mVA== 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ly9WmeHsQzW4X+hhBLNey7c90sYG/oOwxrGUwlTboZU=; b=hma1g7HLkwo+lJbN138m8GzsG1vZUfEJ6Q13EFiZ84XK6cvQlfebRbj86grl2ewyqlReONOTDimvoqIs1uBiWn2Y0ZpFg4TCQb8+ddj1bHjVg+/zyMmVmLcj7xjm5QJMcCz75NhX1XYf7yo+4onymg6f+tbuaAlMNZgpTAJvNBY= Received: from BN8PR11MB3666.namprd11.prod.outlook.com (2603:10b6:408:8c::19) by BN8PR11MB3777.namprd11.prod.outlook.com (2603:10b6:408:8e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3412.26; Tue, 29 Sep 2020 01:31:26 +0000 Received: from BN8PR11MB3666.namprd11.prod.outlook.com ([fe80::c123:faac:1da3:f807]) by BN8PR11MB3666.namprd11.prod.outlook.com ([fe80::c123:faac:1da3:f807%5]) with mapi id 15.20.3412.029; Tue, 29 Sep 2020 01:31:26 +0000 From: "Wu, Hao A" To: "devel@edk2.groups.io" , "Wu, Hao A" , "patrick.henz@hpe.com" CC: "Wang, Jian J" , "Ni, Ray" Subject: Re: [edk2-devel] [PATCH v3 1/1] MdeModulePkg/XhciDxe: Fix Broken Timeouts Thread-Topic: [edk2-devel] [PATCH v3 1/1] MdeModulePkg/XhciDxe: Fix Broken Timeouts Thread-Index: AQHWkeDlVw0kPFit8ky5Wda5lQp+S6l2/l+AgAfd88A= Date: Tue, 29 Sep 2020 01:31:26 +0000 Message-ID: References: <82fc5045fc091b111edeb45c58b64e6e13599b47.1600889280.git.patrick.henz@hpe.com> In-Reply-To: Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-reaction: no-action dlp-version: 11.5.1.3 authentication-results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.198.147.218] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: d480276d-66a3-45af-d9e7-08d864176249 x-ms-traffictypediagnostic: BN8PR11MB3777: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: EF+KOos9cKWtLtqn6TMrCTrZE/7W0i7muDf/IKM+hlXVPQrP3gszCm/m5rczY1B9ctPGMhvlORzu2GIluHn8945inxSnTO7HXLigExbRKzEGB3P1MNqDvRdBN1VUxHlQzumpdGE9XvO7w9PifxZA6DE2L+c3krWn7rjp//t6Hv6ziEdu0pfPdHYLkPKFT53rz7gq6ETHTm07Lgsm0qfzSedw6TiV1faslIVNKW5y9m0h8iHAKpKnWrizhVmuSXYqTItPQvWKXxFvvLy11fwPW/0YHdqjKhCIafz9akj7bDI3EutS/204cRMLSxAMlq+7FWkWKpLvAPsRIdF5FloHxoG0cTACTX4VCA5+sC4xHnZN1vEBVdxAfvmYX/rfG1Xyf4xP1x/BmoqZZGAphaEYL03208BJDffvgQ2pugKJpZpqBvsMAjZJJEGD6RO8cuiFUNZzW+fz/0zaTjHaFyXLUg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BN8PR11MB3666.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(39860400002)(376002)(346002)(366004)(136003)(396003)(33656002)(8676002)(186003)(478600001)(83380400001)(71200400001)(316002)(5660300002)(7696005)(6506007)(8936002)(110136005)(53546011)(54906003)(26005)(55016002)(9686003)(2906002)(4326008)(107886003)(52536014)(966005)(86362001)(66476007)(66556008)(64756008)(66446008)(66946007)(76116006);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: 2QRL5kswtJ1yRJ6mrlnUa+2BhM3gUzUut1uSPTfysqYFhEbN+iKdEtvs8igzXG4DFd/C+GvitW2hxujPxy/+ItO42Z977Zg0kMlOCPK24cEoF+raL/iG9LkFERwADHu+uN78bJ+nZFxY7yBqO7D5XUlioG2F2gsT0BaEHmZPQoDUuicklCLosq1hXq4ICVKJQTKv4p9YxDm2GO+MjMw/Q/uWHNiRk+UoUXW7zWuruI2sPpnxBK87LQgyR/Fe8vR+CinIWiOGafZMpWOd1o0wwlxV7eemaHJ66RsxmAWc9OHvdx/UVTY22oll3c6/QFOOfUekw9douoAkRbFyS9V7EUMwkgphDHdWjA1a6q8HNBVTkF0+p12Mojb2TcbJJ0OX9Yoqhn2vx/5FlD+Cc+G4VOv1UuaT802HskbdQdhvUluMe5w0i/kgQTYt/dvsjN7vqJW1jBXSlbucVBdn4IhlLWIMModvYh//yfHU7EFpeBkVQwIiyt9G8qLTuj3jI3RwL/ocOuTYAqkuVn2ugfStaPXmdzJ+w742g+xj/k8qjjHeZS8HrEbb9ckNcUOT5/of1UP1DddsdlbOMp/kionP8B2F5i8zSE+KMeZKe17qDAzarBNsY5jUg8TqtR1nV6kduEg2mW6KHVzQfeKNOieVgw== MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: BN8PR11MB3666.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d480276d-66a3-45af-d9e7-08d864176249 X-MS-Exchange-CrossTenant-originalarrivaltime: 29 Sep 2020 01:31:26.6728 (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: tBxq8Bwmev4zHPLshZM6cblZ5cVBRfyU7/E08jjfg3jQyJvUbgnMFz4dXniOrEc47rPNo4lmdZVKVuVopNugzQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR11MB3777 Return-Path: hao.a.wu@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Merged via Pull request: https://github.com/tianocore/edk2/pull/968 Commit: 71dd80f14f2724ccc99dd7d349b7392adf114019 Best Regards, Hao Wu > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Wu, Hao > A > Sent: Thursday, September 24, 2020 9:22 AM > To: devel@edk2.groups.io; patrick.henz@hpe.com > Cc: Wang, Jian J ; Ni, Ray > Subject: Re: [edk2-devel] [PATCH v3 1/1] MdeModulePkg/XhciDxe: Fix > Broken Timeouts >=20 > Reviewed-by: Hao A Wu >=20 > Best Regards, > Hao Wu >=20 > > -----Original Message----- > > From: devel@edk2.groups.io On Behalf Of Henz, > > Patrick > > Sent: Thursday, September 24, 2020 3:36 AM > > To: devel@edk2.groups.io > > Cc: Patrick Henz ; Wang, Jian J > > ; Wu, Hao A ; Ni, Ray > > > > Subject: [edk2-devel] [PATCH v3 1/1] MdeModulePkg/XhciDxe: Fix Broken > > Timeouts > > > > From: Patrick Henz > > > > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D2948 > > > > Timeouts in the XhciDxe driver are taking longer than expected due to > > the timeout loops not accounting for code execution time. As en > > example, 5 second timeouts have been observed to take around 36 > > seconds to complete. > > Use SetTimer and Create/CheckEvent from Boot Services to determine > > when timeout occurred. > > > > Cc: Jian J Wang > > Cc: Hao A Wu > > Cc: Ray Ni > > Signed-off-by: Patrick Henz > > --- > > MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c | 59 +++++++++++++++++--- > -- > > MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 63 > ++++++++++++++++++-- > > ---- > > 2 files changed, 94 insertions(+), 28 deletions(-) > > > > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c > > b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c > > index 42b773ab31be..2bab09415b28 100644 > > --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c > > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c > > @@ -423,14 +423,15 @@ 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 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). > > + @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 mi= llisecond, > > ms). > > > > - @retval EFI_SUCCESS The bit successfully changed by host controlle= r. > > - @retval EFI_TIMEOUT The time out occurred. > > + @retval EFI_SUCCESS The bit successfully changed by host > controller. > > + @retval EFI_TIMEOUT The time out occurred. > > + @retval EFI_OUT_OF_RESOURCES Memory for the timer event could > not > > be allocated. > > > > **/ > > EFI_STATUS > > @@ -442,20 +443,52 @@ XhcWaitOpRegBit ( > > IN UINT32 Timeout > > ) > > { > > - UINT32 Index; > > - UINT64 Loop; > > + EFI_STATUS Status; > > + EFI_EVENT TimeoutEvent; > > > > - Loop =3D Timeout * XHC_1_MILLISECOND; > > + TimeoutEvent =3D NULL; > > > > - for (Index =3D 0; Index < Loop; Index++) { > > + 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; > > + } > > + > > + do { > > if (XHC_REG_BIT_IS_SET (Xhc, Offset, Bit) =3D=3D WaitToSet) { > > - return EFI_SUCCESS; > > + Status =3D EFI_SUCCESS; > > + goto DONE; > > } > > > > gBS->Stall (XHC_1_MICROSECOND); > > + } while (EFI_ERROR(gBS->CheckEvent (TimeoutEvent))); > > + > > + Status =3D EFI_TIMEOUT; > > + > > +DONE: > > + if (TimeoutEvent !=3D NULL) { > > + gBS->CloseEvent (TimeoutEvent); > > } > > > > - return EFI_TIMEOUT; > > + return Status; > > } > > > > /** > > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c > > b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c > > index ab8957c546ee..9cb115363c8b 100644 > > --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c > > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c > > @@ -1254,14 +1254,15 @@ XhcCheckUrbResult ( > > /** > > Execute the transfer by polling the URB. This is a synchronous oper= ation. > > > > - @param Xhc The XHCI Instance. > > - @param CmdTransfer The executed URB is for cmd transfer or n= ot. > > - @param Urb The URB to execute. > > - @param Timeout The time to wait before abort, in millise= cond. > > + @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 mi= llisecond. > > > > - @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. > > + @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. > > > > **/ > > EFI_STATUS > > @@ -1273,11 +1274,16 @@ XhcExecTransfer ( > > ) > > { > > EFI_STATUS Status; > > - UINTN Index; > > - UINT64 Loop; > > UINT8 SlotId; > > UINT8 Dci; > > BOOLEAN Finished; > > + EFI_EVENT TimeoutEvent; > > + BOOLEAN IndefiniteTimeout; > > + > > + Status =3D EFI_SUCCESS; > > + Finished =3D FALSE; > > + TimeoutEvent =3D NULL; > > + IndefiniteTimeout =3D FALSE; > > > > if (CmdTransfer) { > > SlotId =3D 0; > > @@ -1291,29 +1297,56 @@ XhcExecTransfer ( > > ASSERT (Dci < 32); > > } > > > > - Status =3D EFI_SUCCESS; > > - Loop =3D Timeout * XHC_1_MILLISECOND; > > if (Timeout =3D=3D 0) { > > - Loop =3D 0xFFFFFFFF; > > + 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); > > > > - for (Index =3D 0; Index < Loop; Index++) { > > + do { > > Finished =3D XhcCheckUrbResult (Xhc, Urb); > > if (Finished) { > > break; > > } > > gBS->Stall (XHC_1_MICROSECOND); > > - } > > + } while (IndefiniteTimeout || EFI_ERROR(gBS->CheckEvent > > + (TimeoutEvent))); > > > > - if (Index =3D=3D Loop) { > > +DONE: > > + if (EFI_ERROR(Status)) { > > + Urb->Result =3D EFI_USB_ERR_NOTEXECUTE; > > + } else 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.28.0 > > > > > > > > > > >=20 >=20 >=20 >=20 >=20