From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by mx.groups.io with SMTP id smtpd.web10.6197.1600910525420278887 for ; Wed, 23 Sep 2020 18:22:05 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=H6Dp6Cwe; spf=pass (domain: intel.com, ip: 134.134.136.31, mailfrom: hao.a.wu@intel.com) IronPort-SDR: KeF3tU9Aztk6dBhmW0Ac9kkgxv9a0bICEUxXHgHLtMFzrDWsVB3qzJGBtZ7i38dkIfApiWfPZy gSvRBcvnjgYQ== X-IronPort-AV: E=McAfee;i="6000,8403,9753"; a="222645923" X-IronPort-AV: E=Sophos;i="5.77,296,1596524400"; d="scan'208";a="222645923" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Sep 2020 18:22:04 -0700 IronPort-SDR: zyF+fveVg8e6VNWave3LDTqThbdUad+aEKkiOOvIFZQkyX5Ag4eFYknx7EI0xm7LoB1ZX+YEUn fIXWq9nZuvpg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.77,296,1596524400"; d="scan'208";a="382870915" Received: from fmsmsx602.amr.corp.intel.com ([10.18.126.82]) by orsmga001.jf.intel.com with ESMTP; 23 Sep 2020 18:22:04 -0700 Received: from fmsmsx606.amr.corp.intel.com (10.18.126.86) 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.1713.5; Wed, 23 Sep 2020 18:22:03 -0700 Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx606.amr.corp.intel.com (10.18.126.86) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5 via Frontend Transport; Wed, 23 Sep 2020 18:22:03 -0700 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.108) 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.1713.5; Wed, 23 Sep 2020 18:22:01 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WDVm1X+w35LCDKYfYml643uiLr4gNZDOiysCGiWdarFWWqlqzgMieq63N14XXUZdfaYGo0Ew1msiKmhU28vbsXmJHmocT/uOfgn8lK9bytS39ELpBE24uTglgidRm0sFtqk0L7LJbM6taYS+899GKwacgxmohlNTW+HmplIR8iIOVARsO44HMGv4Vz75dQotgqu/nm2/nKfawyHjRsUTXa3/nMCuthUfbFLwrQYPcRLbE4QHKP8WEywm9gvAzGlUSAUHKZnKI5iKpTGdL6UGzqWyehGh1FHRJu7jZuBmiZ9fzY11ra5KdDNxfN687e7Pr7X7q9hxAeSmLmUACxvyXQ== 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=fg5zscVBwF9en3a6UgVZC65N242Ud41E6wA/hV1wt68=; b=UTsBZo1nJsC0UkNtmFUW1cyqxS0WAUg8wJtrBRs2SwPOQunX7BRT2KB6/wTugq8n5FrfLGoCXS/xVRuKbo1t5I7c26xXUZH0JdRrPsmaSnMROr6maCxezKECqAwi7nYO413eE7pItpXPj0ZiZS899bUrTogfp61Fa/N8v1RcZuYtfZSWQe0xlufaepkMwGseFeANp1AWpqFg0SjmvcGpMdA35qvGLZpvkXkxsdS+V0IxSi11YwUe6I7pYSBT1ADEBx3syFkkKnqns4z7ooDdLT7VeOqs5NqvV07U0+AP9ceS14xUGpC2oiNbD3AAmw1/yRXmozoktMgmQnVOJklhtw== 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=fg5zscVBwF9en3a6UgVZC65N242Ud41E6wA/hV1wt68=; b=H6Dp6Cwegh4R6TK8a974l889bVULMkMUgMLUUcX7pCMp67TsG4tQg+/fgNfZPcQLUAQES/6ILwHK3T73ZM/ysTAWz9VB01Mgi4ogPewBu0wlibHOhCB9kvl45YmX6s9UvZTJtRje9QldcKNM6VX5M7UeMj0A/nOUKQetsWPlt+k= Received: from BN8PR11MB3666.namprd11.prod.outlook.com (2603:10b6:408:8c::19) by BN6PR11MB0068.namprd11.prod.outlook.com (2603:10b6:405:69::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3391.23; Thu, 24 Sep 2020 01:22:00 +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.020; Thu, 24 Sep 2020 01:22:00 +0000 From: "Wu, Hao A" 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 Thread-Topic: [edk2-devel] [PATCH v3 1/1] MdeModulePkg/XhciDxe: Fix Broken Timeouts Thread-Index: AQHWkeDlVw0kPFit8ky5Wda5lQp+S6l2/l+A Date: Thu, 24 Sep 2020 01:22:00 +0000 Message-ID: References: <82fc5045fc091b111edeb45c58b64e6e13599b47.1600889280.git.patrick.henz@hpe.com> In-Reply-To: <82fc5045fc091b111edeb45c58b64e6e13599b47.1600889280.git.patrick.henz@hpe.com> 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: 3828962b-8110-49b9-0821-08d860283c89 x-ms-traffictypediagnostic: BN6PR11MB0068: 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: YR0OG4Gucj1gCvcg1dQS6/Ndwi0FAO47ltpYbTX2mg0KHjCPOCVzCIU5tctdrYV1lIPc/a83gJtAPoR93NgIGwyBTXpizKkEKsUlc6KMNA2RJHGEhMRHTspnUqxEBftQGc14f+m7SVWiwU3O5g84DQ2I4Z06/0UFjTzsgnOt1GGPVrOYPDyk2OB2/LGA5O6WkDEcfsFjp/eyuM7OpJ3ojRwJrCqqkLOM3PVfA6BtAkpjIbdcbXFlRSWsdoGBoe79JnHHIbPQkIQtO12ZiPm02Edu9igf4lKUN9OU4Zy3GgaSCEnZA84qran7V+OLOeDm3sg6+RU4I8Qq+6TqohZDMMw8XJZmk0xzh1hRomD6ZLDCrflfopbyxzE97+58RRBQazNW126YAwzECtWdyoHrdw== 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)(366004)(136003)(346002)(396003)(39860400002)(376002)(2906002)(8936002)(186003)(64756008)(86362001)(66476007)(66946007)(66556008)(55016002)(107886003)(54906003)(316002)(66446008)(9686003)(6506007)(110136005)(4326008)(71200400001)(83380400001)(26005)(966005)(5660300002)(7696005)(33656002)(52536014)(478600001)(53546011)(8676002)(76116006);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: whSBpwuTI18bsLfGnQrOVuVZkWrpylHPk91BfxsihwLoiHA7ipHZx7aZQ/A7XCDaoNOaVicc7/auPViLptkwBhatn/L1ZczzzBRWC/oKfYC3PTIt5ZohADm8It8VDaT+JNRUMVqNGUnSOa70fpQanx2XchLOb2nuZKeMjPcGQW46dempXWpR09ckTyD1gQBzWHB8TmC6SVK9eI/Kxrgn4aBpwm1GFne0SHP2DOp2JqhtY4iM621i90vH36I2ZuAECHlk8Ni2586uFfIQ625UYcfRyPLC6bbWEbS39Lu3dhNOLcsEshClRLJU2iGp/OnX80oLBLyRJxKZFtOwGOgrntQMtrOv3eZZrlD4+u/gKOj1mRkfH/TAF46aCHHNFBcVDRyoz7HXpwpUjC2XM+dmO5EDo+pPlb2hPsg78d+BMR2jvD1QPey6YbneTCvukTb9cudqX5rJucyNKG6MlAvHl5XI9rgzgqwlkie3Xuw3KS/HkuootkJJ832QmmEIKVxmF4W8pGyPkucGmF92l00HaEVqlReI0pzTdbgq9fCBwSTS1Qg6aShC6YPBBv+nvIMbDGkTwM7WDNeY4i0NM6EQntRvpCHa/JdQ5bXEd3S2jmQFOiS2dY3Uf6SqMtlbDdtWimxgZQQlwNp8iotbOLzAmA== 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: 3828962b-8110-49b9-0821-08d860283c89 X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Sep 2020 01:22:00.1218 (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: RgoPharvdYfrUCx+bK14qw0xd+vE6/w4EYlVxnXuWonTQQ6Q6JEs3jsgX2yR9CohCJGahl1Nd5i5ZZxiN67DTA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR11MB0068 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 Reviewed-by: Hao A Wu Best Regards, Hao Wu > -----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 >=20 > From: Patrick Henz >=20 > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D2948 >=20 > Timeouts in the XhciDxe driver are taking longer than expected due to th= e > 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. >=20 > 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(-) >=20 > 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). >=20 > - @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, m= s). > + @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 mill= isecond, > ms). >=20 > - @retval EFI_SUCCESS The bit successfully changed by host controller. > - @retval EFI_TIMEOUT The time out occurred. > + @retval EFI_SUCCESS The bit successfully changed by host c= ontroller. > + @retval EFI_TIMEOUT The time out occurred. > + @retval EFI_OUT_OF_RESOURCES Memory for the timer event could not > be allocated. >=20 > **/ > EFI_STATUS > @@ -442,20 +443,52 @@ XhcWaitOpRegBit ( > IN UINT32 Timeout > ) > { > - UINT32 Index; > - UINT64 Loop; > + EFI_STATUS Status; > + EFI_EVENT TimeoutEvent; >=20 > - Loop =3D Timeout * XHC_1_MILLISECOND; > + TimeoutEvent =3D NULL; >=20 > - 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; > } >=20 > gBS->Stall (XHC_1_MICROSECOND); > + } while (EFI_ERROR(gBS->CheckEvent (TimeoutEvent))); > + > + Status =3D EFI_TIMEOUT; > + > +DONE: > + if (TimeoutEvent !=3D NULL) { > + gBS->CloseEvent (TimeoutEvent); > } >=20 > - return EFI_TIMEOUT; > + return Status; > } >=20 > /** > 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 operat= ion. >=20 > - @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 milliseco= nd. > + @param Xhc The XHCI Instance. > + @param CmdTransfer The executed URB is for cmd transfer o= r not. > + @param Urb The URB to execute. > + @param Timeout The time to wait before abort, in mill= isecond. >=20 > - @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 er= ror. > + @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. >=20 > **/ > 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; >=20 > if (CmdTransfer) { > SlotId =3D 0; > @@ -1291,29 +1297,56 @@ XhcExecTransfer ( > ASSERT (Dci < 32); > } >=20 > - Status =3D EFI_SUCCESS; > - Loop =3D Timeout * XHC_1_MILLISECOND; > if (Timeout =3D=3D 0) { > - Loop =3D 0xFFFFFFFF; > + IndefiniteTimeout =3D TRUE; > + goto RINGDOORBELL; > } >=20 > + 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); >=20 > - 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))); >=20 > - 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; > } >=20 > + if (TimeoutEvent !=3D NULL) { > + gBS->CloseEvent (TimeoutEvent); > + } > + > return Status; > } >=20 > -- > 2.28.0 >=20 >=20 >=20 >=20 >=20