From patchwork Tue Aug 20 12:15:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhongqiu Han X-Patchwork-Id: 13770046 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 45E5518E76E; Tue, 20 Aug 2024 12:15:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724156141; cv=none; b=pBkW5/ePPh5WVVw6UtHMDcSFeop5tlapIG5jiIPfy8Y41dirb2NsQKF15hmqkhBJWae36orSHgWVDcEmApALTs6gZKGPD7DI2q4whMHDb3yjZA3pPP7FZNc8BTSVd2PBxyMe1IYMT3zCEJyH6cTMeH2TjF5NsyRt4DLCugRKmhA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724156141; c=relaxed/simple; bh=8zJhHVbMjE3Xkm9dt/qt0GiFzBTzwByZQAz6eCkn4HU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CIivjJuYa7BVozps1m4geayDrGK4GreZAYP8+5/9sN2LHIiIX5JKIwGZPjKliBZZ4kiv2s6XEINBzPp3ajFtowTDuV649m7eIYD9Gs5J64G9h0NAdyZydCkoPVwJkDhb0oP1w/F0T471sWoR1GGEvqHVgfE1Uli27QRksp6xD9U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=QclY7f9j; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="QclY7f9j" Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47K74Pp8013240; Tue, 20 Aug 2024 12:15:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= aP5KX24UJ/vW0xetZirucPnqfr8HBBYCQbmFG+U/ZlY=; b=QclY7f9jKoqADfxE UG1376jrcfeYZnn1UkbUtw1ujQiiVzsvIFvivNZQUOD16eFR2xsjunYW7n1eVXvM Y5L2+sqHiXhd6tyFpca3MCyfH0DJWTJnvoPrbr6Z6wKNEXuzFjyGu31d5J9u+SvG 9trVeoo9utlS6vwwoZRMu7zO9esDtmwvVWN0Cy7RR0l7+1gFo7D76B7AzhM5JMHI /xD49opVnltEtANBwE7gEjAx1LSFkLLgQqiBm0iIiPM6iMwCBX6sj23baVdqlDWX EzeezzhXNrkF3sHfs7JaumEuE2+9JizsrgKlCrg9EM24eoiFsIqx5o45GAwnkBL8 HHSdSw== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 414pe5gxdk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Aug 2024 12:15:36 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA04.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 47KCFLQN009369 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Aug 2024 12:15:22 GMT Received: from zhonhan-gv.qualcomm.com (10.80.80.8) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Tue, 20 Aug 2024 05:15:20 -0700 From: Zhongqiu Han To: , , CC: , , Subject: [PATCH 1/2] usb: dwc3: core: Call cpu_relax() in registers polling busy loops Date: Tue, 20 Aug 2024 20:15:00 +0800 Message-ID: <20240820121501.3593245-2-quic_zhonhan@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240820121501.3593245-1-quic_zhonhan@quicinc.com> References: <20240820121501.3593245-1-quic_zhonhan@quicinc.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: YHhRBb7PrubpZgOHvQg7EzUJPFXSHZv5 X-Proofpoint-GUID: YHhRBb7PrubpZgOHvQg7EzUJPFXSHZv5 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-20_09,2024-08-19_03,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 suspectscore=0 mlxscore=0 lowpriorityscore=0 adultscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 spamscore=0 mlxlogscore=688 phishscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2407110000 definitions=main-2408200091 Busy loops that poll on a register should call cpu_relax(). On some architectures, it can lower CPU power consumption or yield to a hyperthreaded twin processor. It also serves as a compiler barrier, see Documentation/process/volatile-considered-harmful.rst. In addition, if something goes wrong in the busy loop at least it can prevent things from getting worse. Signed-off-by: Zhongqiu Han --- drivers/usb/dwc3/core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 734de2a8bd21..498f08dbbdb5 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -2050,6 +2050,8 @@ static int dwc3_get_num_ports(struct dwc3 *dwc) if (!offset) break; + cpu_relax(); + val = readl(base + offset); major_revision = XHCI_EXT_PORT_MAJOR(val); From patchwork Tue Aug 20 12:15:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhongqiu Han X-Patchwork-Id: 13770044 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0107118B48D; Tue, 20 Aug 2024 12:15:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724156133; cv=none; b=PY8teVmEw0tnPyhtIUXtocGR8eMhS58Y5HTEhfc/wSM5wgxh/OU3TtDcdoKlXIX7N3Gkleje/h4YE+b6thvRJ01NkAOK+X0uG9JPRn4MSr0vxQ5RVcPlzOFfmgGoWbwLJM22xnYkodPXeuYHG9ThrCoNF+nL/OAXq4CYqZpr+Cw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724156133; c=relaxed/simple; bh=Z4xe6jEfZ5KTh4rfWb/uoY/IdUUslSwwWSaZcLRO2+s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ta8twJTrE+5xByKRu6G7SKduud9j3H1w0BNfCAdW5Cs6r2kBk1m5a2+iDKHM+Z4YWBvcjjR+ZSvqxVy/eH68XoSw/ca5n2skPSrrehDbrxmUIHKVnqZ44oC/zTa85pwxZdwPNM+Jc5zpknllHXJQDGb1YQO2POgNSp6ynBs/NjA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=ouWqtsTe; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="ouWqtsTe" Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 47K8vs5m001126; Tue, 20 Aug 2024 12:15:27 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= k/GEw8BgJg/67/FhttEOkHwMmg1WkEY4jXTADC+q3qc=; b=ouWqtsTeCWdLWMcm ZKVVML3XRAWcMsS2RH0/X3mlJvAKFj5AZex98vMcAAzwSlAW4+ScQoyEVs/paLmp tSLXCBVP6WBaGV81aBlEVnhQ5Q2088Ust8brMBcn707Z3kyLxd7IrI4uqd/d6WMO 2nxm85dbmN7cnH7AO4oUK2Pp1zABdLI27gfA2IMNWHNtGRo4hGIzeVCxmNXns/L/ PW2lekaV3MLgdJfurogerayx2asH8aSOktSGrSc9SWyqBWSv4UMh+FwsuLe4L1Tg NMdv42sjOVCv6O1KVjqulJ4AehfPRob7BT8TEeTLAciKozNBrZvQrEiHTW/QGzQ6 1ERFQQ== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 412jtryr6d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Aug 2024 12:15:26 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA04.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 47KCFORn009427 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 20 Aug 2024 12:15:24 GMT Received: from zhonhan-gv.qualcomm.com (10.80.80.8) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Tue, 20 Aug 2024 05:15:22 -0700 From: Zhongqiu Han To: , , CC: , , Subject: [PATCH 2/2] usb: xhci: ext-caps: Use cpu_relax() when polling registers Date: Tue, 20 Aug 2024 20:15:01 +0800 Message-ID: <20240820121501.3593245-3-quic_zhonhan@quicinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240820121501.3593245-1-quic_zhonhan@quicinc.com> References: <20240820121501.3593245-1-quic_zhonhan@quicinc.com> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: otxIxkeyCTZiGiB6Kk47urf640p35LmK X-Proofpoint-GUID: otxIxkeyCTZiGiB6Kk47urf640p35LmK X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-08-20_09,2024-08-19_03,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 clxscore=1011 suspectscore=0 bulkscore=0 mlxlogscore=506 mlxscore=0 impostorscore=0 malwarescore=0 lowpriorityscore=0 adultscore=0 priorityscore=1501 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2407110000 definitions=main-2408200091 It is considered good practice to call cpu_relax() in busy loops, see Documentation/process/volatile-considered-harmful.rst. This can lower CPU power consumption or yield to a hyperthreaded twin processor and also serve as a compiler barrier. In addition, if something goes wrong in the busy loop at least it can prevent things from getting worse. Signed-off-by: Zhongqiu Han --- drivers/usb/host/xhci-ext-caps.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/usb/host/xhci-ext-caps.h b/drivers/usb/host/xhci-ext-caps.h index 96eb36a58738..25d148d60ab0 100644 --- a/drivers/usb/host/xhci-ext-caps.h +++ b/drivers/usb/host/xhci-ext-caps.h @@ -144,6 +144,8 @@ static inline int xhci_find_next_ext_cap(void __iomem *base, u32 start, int id) if (offset != start && (id == 0 || XHCI_EXT_CAPS_ID(val) == id)) return offset; + cpu_relax(); + next = XHCI_EXT_CAPS_NEXT(val); offset += next << 2; } while (next);