From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-002e3701.pphosted.com (mx0a-002e3701.pphosted.com [148.163.147.86]) by mx.groups.io with SMTP id smtpd.web11.12785.1599066303117599778 for ; Wed, 02 Sep 2020 10:05:03 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=hpw6h/DQ; spf=pass (domain: hpe.com, ip: 148.163.147.86, mailfrom: prvs=051440aaa7=patrick.henz@hpe.com) Received: from pps.filterd (m0150242.ppops.net [127.0.0.1]) by mx0a-002e3701.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 082GwMKY001366; Wed, 2 Sep 2020 17:05:02 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : content-type : content-transfer-encoding : mime-version; s=pps0720; bh=C1ZLzy3ASgH3oZHdgVMbbXCDYDVnZus+PAK05oBtX78=; b=hpw6h/DQcUpu7mISR5LuTEydOtSP1xIUUyC4AJv6F6D8l0ZWAIjR4Un3nQZL42inHdM2 WUViQdGX9tCeJjJkkHdvNy8GIz25iURgfrR5YiPUfXDHKoHqQkfVsXMXYPtVPd9W5yDd ywFyM62g4UvxSimkt60zpeyf2Uq1O8cfb80hHWvLBk+wfCp0Z/a5OwaS2cx0zSt72jDr Aikm8xnSlN86NHTYxNsikbV+g1p3g7CO0djVnt9OH3mgt8hj10fYY1O9AoiTdbP5hDGl KJ0kza3E4uS252w94WOs1gmHWEKfWPBow2lxE277T/nMXGu5QIhMUlHqM/bwEGF/wZZd Cw== Received: from g9t5009.houston.hpe.com (g9t5009.houston.hpe.com [15.241.48.73]) by mx0a-002e3701.pphosted.com with ESMTP id 33a5vsmw2v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 02 Sep 2020 17:05:02 +0000 Received: from G1W8106.americas.hpqcorp.net (g1w8106.austin.hp.com [16.193.72.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by g9t5009.houston.hpe.com (Postfix) with ESMTPS id C276A63; Wed, 2 Sep 2020 17:05:01 +0000 (UTC) Received: from G4W9334.americas.hpqcorp.net (16.208.32.120) by G1W8106.americas.hpqcorp.net (16.193.72.61) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 2 Sep 2020 17:05:01 +0000 Received: from G9W9210.americas.hpqcorp.net (2002:10dc:429b::10dc:429b) by G4W9334.americas.hpqcorp.net (2002:10d0:2078::10d0:2078) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 2 Sep 2020 17:05:01 +0000 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (15.241.52.11) by G9W9210.americas.hpqcorp.net (16.220.66.155) with Microsoft SMTP Server (TLS) id 15.0.1497.2 via Frontend Transport; Wed, 2 Sep 2020 17:05:01 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZU/G+RJBkE0eXGu8Vr9tqbacVanTxfb7u3al+AIk05lKxVt3x34tPph+5kMeHFUTc1g+NZGHhjoyiM82JCOpPA3sWUR64ENhmOUqfYYX71NF7g3YGlW9jiKNHyeGOGVgNMaPnH30ywoYKYq4k3dFfEot5Fh+FJul27+gqi7uwuyK64E/XcTa3wx8xt3g9PmwMmkslzedN+OTVaLl+UZF3tzQ2er73sq+YILPU533+BwFJWtgbIi3AIElqx8eLJQryRwuI5xPVOU7pYWbWBpy9xksBM9GS9c0X+UGBhPFTspF+VObvUy9WxC1KkMrhVRmr4t/7yL/+3sR+jXHZD9Oeg== 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=C1ZLzy3ASgH3oZHdgVMbbXCDYDVnZus+PAK05oBtX78=; b=GTtp/GHjEYkJLnhutFlQB0UFrV//HppbEHwwZlnHtVe5IMnrr76NEECzIeSZ09+SORjkKVU40/3yJCcEtdkkKYFPZxlWb3zKL3Sz1zuyilItMCm+wFpwYRlmJB8pc0pDFqbIlxXW60IyKvzfX12VruKUiVU3v9S6doQYs7AKB25bgOsEr52aInkBk9ytdp5qvkh3P3NQdBFq7v/6TRi0awYRXSU6nlhB7K4UkfB7crrc9abNwdZBeFYvPZUxANFyG/4CTcO4E01OwB/+Kv6/5z+bouEWPTVDa1msAhX1w3xyB0/H4GxmPSc+lFpzjU0cwz7cMx4ft6AHPeMvUqb6dQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=hpe.com; dmarc=pass action=none header.from=hpe.com; dkim=pass header.d=hpe.com; arc=none Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=hpe.com; Received: from TU4PR8401MB0478.NAMPRD84.PROD.OUTLOOK.COM (2a01:111:e400:7709::19) by TU4PR8401MB0400.NAMPRD84.PROD.OUTLOOK.COM (2a01:111:e400:770a::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3326.22; Wed, 2 Sep 2020 17:05:00 +0000 Received: from TU4PR8401MB0478.NAMPRD84.PROD.OUTLOOK.COM ([fe80::4968:3a88:e4a6:5cea]) by TU4PR8401MB0478.NAMPRD84.PROD.OUTLOOK.COM ([fe80::4968:3a88:e4a6:5cea%8]) with mapi id 15.20.3348.015; Wed, 2 Sep 2020 17:05:00 +0000 From: patrick.henz@hpe.com To: CC: Patrick Henz , Jian J Wang , Hao A Wu , Ray Ni Subject: [PATCH v2 1/1] MdeModulePkg/XhciDxe: Fix Broken Timeouts Date: Wed, 2 Sep 2020 12:04:40 -0500 Message-ID: X-Mailer: git-send-email 2.28.0 In-Reply-To: References: X-ClientProxiedBy: SN4PR0501CA0025.namprd05.prod.outlook.com (2603:10b6:803:40::38) To TU4PR8401MB0478.NAMPRD84.PROD.OUTLOOK.COM (2a01:111:e400:7709::19) X-MS-Exchange-MessageSentRepresentingType: 1 Received: from 255.255.255.255 (255.255.255.255) by SN4PR0501CA0025.namprd05.prod.outlook.com (2603:10b6:803:40::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3348.7 via Frontend Transport; Wed, 2 Sep 2020 17:04:59 +0000 X-Mailer: git-send-email 2.28.0 X-Originating-IP: [76.17.188.158] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 1635aee5-4fab-4456-2861-08d84f62537d X-MS-TrafficTypeDiagnostic: TU4PR8401MB0400: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4125; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0QcOFapI6o17/nO1WDXN1zynD8dvZT+UVMD29yJBNl7mJD7t2jcKLAIZP7WDpcQjX5BDBvsqo7wn/ZPeruO3l/XyP8fNu9YVGqA/DShOIoXFvpHA8NF8EAmJE184XKZt825u1pZAgPc0EsKRpK5Qa0xH9vbQ83YBPHYBpM6GYIyksYQIwOHokv6xgQMRqrydOVsz2BnjWJnq9QBCNkoYU95O95j/4IBnASYFxaempTpMdEx/4DfqDuKQqEgurq7oCTr+XnXcgmunDsJOcOK1nwSsovZrpl4MRtqydmSLjqf8JQA0KQRccIwZrkhjv2hdtFnDPgNbJAo/7rMLUmLmbfVil0CHQ0D6AmQeTB3qllZ366Rih3UuTHd34aavC2PGyon8tRPo3ePCOSt7wQ21WA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:TU4PR8401MB0478.NAMPRD84.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(366004)(376002)(136003)(39860400002)(346002)(396003)(9686003)(186003)(66946007)(66476007)(2616005)(956004)(52116002)(36756003)(66556008)(6916009)(5660300002)(26005)(316002)(16576012)(8676002)(6486002)(86362001)(54906003)(83380400001)(4326008)(2906002)(8936002)(6666004)(478600001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: T5uTe2gXzBPQJUkHsHwg4o6YzHUpPF35onwZTEmhAjQ+6v010C5ac49zkq13wAGnfPpbO1IGSEtiBeU6Xm9wddRumZ1RhZNHd2e3c5XGLB779Oen/UTUco51596wJdQRLsXPGE2CrhmgKw26gCCDVWuEhytJJUnhIeZ3SHCwxJkq3F5rPz4Yvk9zEzyRyULwDe988G9JbfCYUcmAmVMQy/zznj0Y1JI1QnegmtqWTSk69pnYlHN7viuCzRS4l+QigBLzaH+DvDfE3vt2vaZ8yACbJRPhvVfKYu6V0IuH0/MIcLZw4U3fNKwSVgPQ1r3MPeyNRovK1zP0Ajy8TFiOec84fYudS/M3Bgb6Urrzgd8F7voCttVvqOSAwHXDi0VRe9jFTcXjiMTgLxcJR9wqGwLGtJAFyYawKVlsbPuTUtkMg5DzvZ5jHftSWwa42tAvY1LPb/OKvGPMQXoNYiUOkaQiiuPKqy/Pect9w/Lvk0ZKc3NBoyEUMxtN66NrnhYaScLfYhG4onFz0xnGJgX2FSj5P6Ab6A6YSGN6MT2uG/YOG41/d55EAkD+1//dGe9CmwUUd4Gxd3LoDsZWL/h2weAgpr2jDvKC0feGOLOG6UqdzjfmZmzj1itrmLXaqVny9Q7bPu06aj0tx7LTu73iJA== X-MS-Exchange-CrossTenant-Network-Message-Id: 1635aee5-4fab-4456-2861-08d84f62537d X-MS-Exchange-CrossTenant-AuthSource: TU4PR8401MB0478.NAMPRD84.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2020 17:05:00.0485 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 105b2061-b669-4b31-92ac-24d304d195dc X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 78QkUeL+Hs9hRfQn9Ov5ykLNQu5bd70IBdF3tEPj5TT7QwujcuZcpR2cGG5OaivNJfmz8ZdipJPdsDYmPGC82g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: TU4PR8401MB0400 X-OriginatorOrg: hpe.com X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-09-02_11:2020-09-02,2020-09-02 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 bulkscore=0 malwarescore=0 spamscore=0 impostorscore=0 lowpriorityscore=0 priorityscore=1501 clxscore=1015 suspectscore=0 phishscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009020162 Content-Type: text/plain Content-Transfer-Encoding: 8bit From: Patrick Henz REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2948 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 | 35 ++++++++++++++++--- MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 43 +++++++++++++++++++----- 2 files changed, 65 insertions(+), 13 deletions(-) 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; - Loop = Timeout * XHC_1_MILLISECOND; + TimeoutEvent = NULL; - for (Index = 0; Index < Loop; Index++) { + if (Timeout == 0) { + goto TIMEOUT; + } + + Status = gBS->CreateEvent ( + EVT_TIMER, + TPL_CALLBACK, + NULL, + NULL, + &TimeoutEvent + ); + + if (!EFI_ERROR (Status)) { + Status = gBS->SetTimer (TimeoutEvent, + TimerRelative, + EFI_TIMER_PERIOD_MILLISECONDS(Timeout)); + } + + if (EFI_ERROR(Status)) { + goto TIMEOUT; + } + + do { if (XHC_REG_BIT_IS_SET (Xhc, Offset, Bit) == WaitToSet) { return EFI_SUCCESS; } gBS->Stall (XHC_1_MICROSECOND); + } while (EFI_ERROR(gBS->CheckEvent (TimeoutEvent))); + +TIMEOUT: + if (TimeoutEvent != NULL) { + gBS->CloseEvent (TimeoutEvent); } 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 = EFI_SUCCESS; + Finished = FALSE; + TimeoutEvent = NULL; + + if (Timeout == 0) { + goto DONE; + } if (CmdTransfer) { SlotId = 0; @@ -1291,29 +1299,46 @@ XhcExecTransfer ( ASSERT (Dci < 32); } - Status = EFI_SUCCESS; - Loop = Timeout * XHC_1_MILLISECOND; - if (Timeout == 0) { - Loop = 0xFFFFFFFF; + TimerStatus = gBS->CreateEvent ( + EVT_TIMER, + TPL_CALLBACK, + NULL, + NULL, + &TimeoutEvent + ); + + if (!EFI_ERROR (TimerStatus)) { + TimerStatus = gBS->SetTimer (TimeoutEvent, + TimerRelative, + EFI_TIMER_PERIOD_MILLISECONDS(Timeout)); + } + + if (EFI_ERROR (TimerStatus)) { + goto DONE; } XhcRingDoorBell (Xhc, SlotId, Dci); - for (Index = 0; Index < Loop; Index++) { + do { Finished = XhcCheckUrbResult (Xhc, Urb); if (Finished) { break; } gBS->Stall (XHC_1_MICROSECOND); - } + } while (EFI_ERROR(gBS->CheckEvent (TimeoutEvent))); - if (Index == Loop) { +DONE: + if (!Finished) { Urb->Result = EFI_USB_ERR_TIMEOUT; Status = EFI_TIMEOUT; } else if (Urb->Result != EFI_USB_NOERROR) { Status = EFI_DEVICE_ERROR; } + if (TimeoutEvent != NULL) { + gBS->CloseEvent (TimeoutEvent); + } + return Status; } -- 2.28.0