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.5207.1599099878947507335 for ; Wed, 02 Sep 2020 19:24:39 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=aiDwZEzy; spf=pass (domain: intel.com, ip: 192.55.52.88, mailfrom: hao.a.wu@intel.com) IronPort-SDR: nckUehftZIQ76hm0ijCsyG77qgfxGJloRxHU7KJGo5osfIXVvmTTdcy+Mwls51Ss8zr1jJyiz1 DdzGPTL9a1dw== X-IronPort-AV: E=McAfee;i="6000,8403,9732"; a="175557904" X-IronPort-AV: E=Sophos;i="5.76,384,1592895600"; d="scan'208";a="175557904" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Sep 2020 19:24:37 -0700 IronPort-SDR: E4z/hcZlKclLD1dBfijDNO7P6SBa/5ApZ5c7WcRcq9upUMzqx68D5xULHCy6vEBLcqgKYhmY5J FXaryj5MtbQw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,384,1592895600"; d="scan'208";a="502888708" Received: from fmsmsx604.amr.corp.intel.com ([10.18.126.84]) by fmsmga005.fm.intel.com with ESMTP; 02 Sep 2020 19:24:37 -0700 Received: from fmsmsx609.amr.corp.intel.com (10.18.126.89) 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; Wed, 2 Sep 2020 19:24:34 -0700 Received: from fmsmsx603.amr.corp.intel.com (10.18.126.83) by fmsmsx609.amr.corp.intel.com (10.18.126.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Wed, 2 Sep 2020 19:24:34 -0700 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx603.amr.corp.intel.com (10.18.126.83) 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, 2 Sep 2020 19:24:34 -0700 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.105) 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; Wed, 2 Sep 2020 19:24:31 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GcjwoZ2lVKF00uwAFy3Q/Y8Ak9h1zPfgeQNzaNmx0nmNMjJbygZT9LkiKfmCw0fz9B+UxcTYGtLK2J0GKN93Ww4xOmcNqTjJX+/n3X1/m831wACOEWEfAPK1OFk2Oj21JOE3NCD13IgjNAqnhj77nkRd5NmDO3uQBiF7KNS5DPa3b693ajEeNrJ0o9sMO3VWrnA4bKq9oAtqzD+fjcxK4teSGr9UpSRwgZJ+HccEJ6HgmurTAulsI5916D3JrVV5+OPhQ3phoRxHcIk5DF/U5S054oEzqCnRYGhKvhzCfD3NPSpG0Pjr5Z1GSibvEIB1/9uqAJNYb8gHW66Z99y5Wg== 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=HiiRIuEy8Q+JWMnq/iThQ6/prsxh8hlzi5/+d4yci2c=; b=EbQKf3UlfVW2CEkOAdcHJ7NyFCZoEEflEPWY8QGzOM5VNTm8hr0EU8nwwxlAmaLVGCO6b0njZ4zyZVY0InaR6WngZEsW+S6L3tkvQfLMHPBraYvfI/h/I5wqW34EGJR0SVkMcqtr/4RduikSFw/GPtve9OcmHUi33Kh0nG4wcn9XbmySIexczYb4U/CbqPIXpdxbhEG6alyV3Kt6fp29Y6dsf9ICzUW92IW647GhvcqqZYnrk9arSu2V9Zc5w+2UYQYRzeu4Pnh/X6AB6FNgHIhkdWuZd/Fpe61Y7jRVs5T9JAJL46hdEyNgHy4P4Yz1Yg0KEgxp04v5F3CAliCe9A== 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=HiiRIuEy8Q+JWMnq/iThQ6/prsxh8hlzi5/+d4yci2c=; b=aiDwZEzyoWDr9Sol0RTsnRjbbeNI486Ik1mfPuRJmNtq75ObFoFkWw+fIqoKpaFBVAtx335qdrZkJncS0FCPH7mlLzfPJEbOPUcjEXEzT7dQV0QvuTS+W6kfHEAiSLr4SQI/BHYLq/ppePkATPo4UZoiCyKjOyVVJTBYDYYd+Zk= Received: from DM6PR11MB3673.namprd11.prod.outlook.com (2603:10b6:5:145::26) by DM6PR11MB2620.namprd11.prod.outlook.com (2603:10b6:5:c8::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.15; Thu, 3 Sep 2020 02:24:30 +0000 Received: from DM6PR11MB3673.namprd11.prod.outlook.com ([fe80::5111:3ecb:21f:eeb6]) by DM6PR11MB3673.namprd11.prod.outlook.com ([fe80::5111:3ecb:21f:eeb6%7]) with mapi id 15.20.3326.025; Thu, 3 Sep 2020 02:24:30 +0000 From: "Wu, Hao A" To: "devel@edk2.groups.io" , "patrick.henz@hpe.com" , "Ni, Ray" CC: "Wang, Jian J" Subject: Re: [edk2-devel] [PATCH v2 1/1] MdeModulePkg/XhciDxe: Fix Broken Timeouts Thread-Topic: [edk2-devel] [PATCH v2 1/1] MdeModulePkg/XhciDxe: Fix Broken Timeouts Thread-Index: AQHWgUs82cadCyRNmkKDU4HvBxhYqqlWJO1A Date: Thu, 3 Sep 2020 02:24:30 +0000 Message-ID: References: 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: 6999315e-8b69-47b1-5a17-08d84fb07d12 x-ms-traffictypediagnostic: DM6PR11MB2620: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7219; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: D3hImTPbj6pG4/jp97SHt6f3r6AivPhOnm7ETgNswzUoXunvN6yeoHhXEhDaV5czZpUxTnkQ1hcUcOBBw9bZ4Tz6tKrvQkaSH14llzlzC4wHnTNGyrN65WWlapFxQJKNsyVlipbFLdQDtYI6MM5XQXCMKChKVxNoklGwyYAevNu8Mnz+IiUdWSwvmFFiuE2Izw7x6LHUxwqXRDananq2qToHZpRoZqsUcTeToe4SV+bF9KeoIKFE2mkdTKvqCvBQ4VstvAAaRqjpaxQvA7DcwpLKx5jkAOUq7uQRHimM2Zd1rNYg1xSgudaX0RjWqz079IW1Of56Tg+969BagUy+BBHavX5aLYTiDZc+JO1BUPdgUtOfQd0TDLBIMI1VInQk3dQBWMaSPzacEBouQZPtCw== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR11MB3673.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(39860400002)(396003)(376002)(346002)(136003)(366004)(33656002)(316002)(83380400001)(71200400001)(8936002)(52536014)(66946007)(8676002)(2906002)(66446008)(9686003)(966005)(5660300002)(86362001)(186003)(55016002)(66476007)(107886003)(66556008)(53546011)(64756008)(4326008)(478600001)(6506007)(6636002)(7696005)(110136005)(26005)(76116006);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: J2I2SSe9btLvESFjDUQZvjMgL6G6FqSWKd8MyY7FY+015MSzBJ50L+nL035tjHjwWPbYGIEIEs3Ib7xXxVAdOIQFDNQRkCh42sQKCdPOwAPraudimNJk/ISMCa236k0f8/fx42+U31XseBn/cCrb7pIwQkg1N0eoUc1b2e2SXM5VNQ7MwXzC90hwbWWBbzjfNvUp89giDyUGg4WWGL0maK9PnFSun3qXVZ00wtuif3jPmFZ9177u9lobE7rnePGrgIJ6MnreBv8bhABPQ6+uoyKAmGGJcIqav/mhU7YxfC5FOBCyd9HpwvyWftwkkFoqYcvH2SMgNNhuAcVuZ5IjFOu1Kz2uOwnY2GARfaf6GG7M3TS58nnP5+UP6lep4UOGOfmRIHWmDJqF9De+qZHp2dwupkfavnZDtuAbeQMrULTOkfjwIruIKhpBfKgWYQMAwB7YdbrlRlFh4XBOjiMpgFLGjPTdb7GVDEKi5Yw2EFYLv0bgkVPCAknScuwTnHML/9SRJ9GearVRpa3p89z15PhkupjKFe+/qYthKrRqySPI/9kGg/ExXBIl7LxZgCqhoAozDCBupthlq5ZUxeK6ui8/jB5FLEv7g+jR9A2z4W9Hp0Km4CZj+lrvcZ5Jo2e7IUIYbTL1d6hJZa75CfgzfA== MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR11MB3673.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6999315e-8b69-47b1-5a17-08d84fb07d12 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Sep 2020 02:24:30.2369 (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: 4QhTK1bPrLg1SIQ/4+MGmunwiOdfas8dNPwfdIj4GIR94q7P1+aEjq2aBdWeenMaRedcI+fooLdp/g+h4iWOCA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR11MB2620 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 Hello Patrick, a couple of inline comments below. Hello Ray, need your input on one thing below as well. > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of > patrick.henz@hpe.com > Sent: Thursday, September 3, 2020 1:05 AM > To: devel@edk2.groups.io > Cc: Patrick Henz ; Wang, Jian J > ; Wu, Hao A ; Ni, Ray > > Subject: [edk2-devel] [PATCH v2 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 | 35 ++++++++++++++++--- > MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 43 > +++++++++++++++++++----- > 2 files changed, 65 insertions(+), 13 deletions(-) >=20 > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c > b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c > index 42b773ab31be..33ac13504669 100644 > --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c > @@ -442,17 +442,44 @@ 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) { > + goto TIMEOUT; > + } > + > + Status =3D gBS->CreateEvent ( > + EVT_TIMER, > + TPL_CALLBACK, > + NULL, > + NULL, > + &TimeoutEvent > + ); > + > + if (!EFI_ERROR (Status)) { > + Status =3D gBS->SetTimer (TimeoutEvent, > + TimerRelative, > + EFI_TIMER_PERIOD_MILLISECONDS(Timeout)); > + } > + > + if (EFI_ERROR(Status)) { > + goto TIMEOUT; > + } Could you help to refine the return status for the case when CreateEvent o= r SetTimer calls fail? I think it will return EFI_TIMEOUT at this moment, which might confuse the= caller. You may need to modify the function description comment section for the ne= w return value also. A similar case applies to XhcExecTransfer() as well. > + > + do { > if (XHC_REG_BIT_IS_SET (Xhc, Offset, Bit) =3D=3D WaitToSet) { > return EFI_SUCCESS; > } >=20 > gBS->Stall (XHC_1_MICROSECOND); > + } while (EFI_ERROR(gBS->CheckEvent (TimeoutEvent))); > + > +TIMEOUT: > + if (TimeoutEvent !=3D NULL) { > + gBS->CloseEvent (TimeoutEvent); > } >=20 > return EFI_TIMEOUT; > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c > b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c > index ab8957c546ee..d6290b5fe33b 100644 > --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c > @@ -1273,11 +1273,19 @@ XhcExecTransfer ( > ) > { > EFI_STATUS Status; > - UINTN Index; > - UINT64 Loop; > UINT8 SlotId; > UINT8 Dci; > BOOLEAN Finished; > + EFI_EVENT TimeoutEvent; > + EFI_STATUS TimerStatus; > + > + Status =3D EFI_SUCCESS; > + Finished =3D FALSE; > + TimeoutEvent =3D NULL; > + > + if (Timeout =3D=3D 0) { > + goto DONE; > + } >=20 > if (CmdTransfer) { > SlotId =3D 0; > @@ -1291,29 +1299,46 @@ XhcExecTransfer ( > ASSERT (Dci < 32); > } >=20 > - Status =3D EFI_SUCCESS; > - Loop =3D Timeout * XHC_1_MILLISECOND; > - if (Timeout =3D=3D 0) { > - Loop =3D 0xFFFFFFFF; Ray and Patrick, the previous behavior when 'Timeout' is 0 for this functi= on is that it will do a 'psudo-indefinite' loop by setting the 'Loop' variable to the value of MAX_UINT32. But after the patch, the behavior got changed and the function will direct= ly return EFI_TIMEOUT when 'Timeout' is 0. This behavior change might impact the callers when they expecting a 'psudo= -indefinite' timeout. I think it would be better to keep the origin behavior, what is your thoug= ht? Best Regards, Hao Wu > + TimerStatus =3D gBS->CreateEvent ( > + EVT_TIMER, > + TPL_CALLBACK, > + NULL, > + NULL, > + &TimeoutEvent > + ); > + > + if (!EFI_ERROR (TimerStatus)) { > + TimerStatus =3D gBS->SetTimer (TimeoutEvent, > + TimerRelative, > + > + EFI_TIMER_PERIOD_MILLISECONDS(Timeout)); > + } > + > + if (EFI_ERROR (TimerStatus)) { > + goto DONE; > } >=20 > 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 (EFI_ERROR(gBS->CheckEvent (TimeoutEvent))); >=20 > - if (Index =3D=3D Loop) { > +DONE: > + 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