Received: by 2002:a05:7412:ba23:b0:fa:4c10:6cad with SMTP id jp35csp366019rdb; Thu, 18 Jan 2024 06:06:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IEuSk9Quxnf2mfiiAeA8keH9pcV3YGLYIajsDZlIaZOUVjbsakVfImWwkzPY7OXEHaoxw7w X-Received: by 2002:a17:903:189:b0:1d5:eebf:2447 with SMTP id z9-20020a170903018900b001d5eebf2447mr1042745plg.109.1705586811565; Thu, 18 Jan 2024 06:06:51 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705586811; cv=pass; d=google.com; s=arc-20160816; b=TZFjGM3gdCP/JwWN0U9l0v4fyF/HMoR3vBDoyRboxggRqHYDcrCV6MFhDIl18HMs+p uxEUiEI5beas8Qq+f3q7k3Ltm/9xekkZ9v5zAR5uG/bjLFJkiPwbUlG6xaSymZeUv6X9 ki4e/+r6vvNCDBgEynfOPaqVZDAdN6+mcabP3SpV0KPlCoyEeVLRUX+9GptlG1gkru+o qHndvFBwL/P5Y9xyTiwxOBulrQpHOhzYoFMJWb/W47aWiWg3D/Iw1bWd+gS2918Ww49f +cmjBZJ+VRGs37OZIiFP1EOiphNz/yvItAREH2eKULL/QdVewlApsFo3rtbOyEBY5TET +lOw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:references:in-reply-to:subject:cc:to:from:message-id :date:dkim-signature; bh=Ul2G8TNp2gv7sQwBWp3kj+LDWPzgLHs/viYbHLkrJrM=; fh=KHEDJX/Z02cKYuV1YTaKeoZxSrGuIoLuEjHT/r1MzBc=; b=KXRYrS1WRWaLVb143niRaJ2eGglEfKXEeWmOVilUWY9NTR2JBa4Y0ElQC6YHc4oako 64N9VH5NqmebW7/UJFnQm3TgqXDqY98CtRfFA7RpuVLm2A1GuDuUt3FcSqApqzf/9qfv i8jc8Y/wYrRjIDW1TTQx89WBJDehq10rTQ/IO1iB/aYcG78zLnEFZt5yMVuH6K9+kgmL it4B8ySq2T5hGtd3i7JseRhatN4ZGLfaP++gMCCBNjgE2ZURM8d4t0/cpmAjp9He9/6I Ixor/7QOrtbtU+bxnqmDsn17tYSc+Q0HKvHop/RmSMSSDIvw1VBa4CMdqlel3mj9Euyj yiEQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aeM1B0J2; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-30175-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30175-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id l12-20020a170903120c00b001d46a313b41si1584937plh.353.2024.01.18.06.06.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jan 2024 06:06:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-30175-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aeM1B0J2; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-30175-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-30175-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 2964DB26370 for ; Thu, 18 Jan 2024 14:00:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 581792576A; Thu, 18 Jan 2024 14:00:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aeM1B0J2" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 79DAA25759 for ; Thu, 18 Jan 2024 14:00:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705586420; cv=none; b=imPbJCd4yaxTzMgPaHM7YTprseHz8ZwjhxJPnDPVrLiJ5MqI/wTho9kZ4xl2QroohDX9sgvf6slxKkig/AlF2aVyAk0G3mv0KOrD3KkbrtBPb7iG+xJnRuC+sXQLFmfPl0d9cFGxnJiR6x+KGGjDUeSZvsQjGsRquZ5JaPqY/rg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705586420; c=relaxed/simple; bh=oePAFFYODLX4qKuT+hCCpKcLhpD+k+lB3GJAV7/Ee3I=; h=Received:DKIM-Signature:Received:Date:Message-ID:From:To:Cc: Subject:In-Reply-To:References:User-Agent:MIME-Version: Content-Type:X-SA-Exim-Connect-IP:X-SA-Exim-Rcpt-To: X-SA-Exim-Mail-From:X-SA-Exim-Scanned; b=YJKh4wT+wGg8BYCaQPKaVtnZddv+3Pj2xzOQnFOLab47OYmL4PZg6UwID9D7WzMiqwn7dwGA2nBhaytzfW1DGn1+VyjlT7uWwzt7HJxtoLv/qAPb32BY56iJLkX2WACuljbZ0Mef4O0WDL5VNyD4um7l3UTgaLnA/ZHnsgy86uE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aeM1B0J2; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1F62C433F1; Thu, 18 Jan 2024 14:00:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1705586420; bh=oePAFFYODLX4qKuT+hCCpKcLhpD+k+lB3GJAV7/Ee3I=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=aeM1B0J20cbeQQNXCaZYaGpdGrfTjZA7w/rSw+wgQTLOMuEDK6L+Ukg+Sgb3/JSJA hAlpHZDyGPIdHRDRIBo6Y8L8FBJMdIG23sEdQugEWqb/NNDkMfRGbXkbWhlP0jIOsD bQybv1OQBW1JI2UKxQhzqqQdV85Z+DGLOMAn90i0vgwkOvvwSY0Uz7Ak9XS2lRrB68 nX3ZYqnozKJSFtyeYFQPI9pgP+twQv8aYRz3ft6IS9ELPy70t8WZz/Y3Wr+xIgOkb4 ukG9Fe24G9lyL4NQtl2qxxbMk9QuF0E9ubeHPHIYzmXYg0/nAj4LJmaDkGriiigjBj dNVpWXmcbYc5A== Received: from sofa.misterjones.org ([185.219.108.64] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rQSwL-00CiGO-Bx; Thu, 18 Jan 2024 14:00:17 +0000 Date: Thu, 18 Jan 2024 14:00:15 +0000 Message-ID: <871qaeyc5s.wl-maz@kernel.org> From: Marc Zyngier To: Dawei Li Cc: tglx@linutronix.de, sdonthineni@nvidia.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, set_pte_at@outlook.com Subject: Re: [PATCH 1/4] irqchip/gic-v3: Implement read polling with dedicated API In-Reply-To: <20240118112739.2000497-2-dawei.li@shingroup.cn> References: <20240118112739.2000497-1-dawei.li@shingroup.cn> <20240118112739.2000497-2-dawei.li@shingroup.cn> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/28.2 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: dawei.li@shingroup.cn, tglx@linutronix.de, sdonthineni@nvidia.com, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, set_pte_at@outlook.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Thu, 18 Jan 2024 11:27:36 +0000, Dawei Li wrote: > > Kernel provide read*_poll_* API family to support looping based polling > code pattern like below: > while (...) > { > val = op(addr); > condition = cond(val); > if (condition) > break; > > /* Maybe some timeout handling stuff */ > > cpu_relax(); > udelay(); > } > > As such, use readl_relaxed_poll_timeout_atomic() to implement atomic > register polling logic in gic-v3. > > Signed-off-by: Dawei Li > --- > drivers/irqchip/irq-gic-v3.c | 27 ++++++++------------------- > 1 file changed, 8 insertions(+), 19 deletions(-) > > diff --git a/drivers/irqchip/irq-gic-v3.c b/drivers/irqchip/irq-gic-v3.c > index 98b0329b7154..b9d9375a3434 100644 > --- a/drivers/irqchip/irq-gic-v3.c > +++ b/drivers/irqchip/irq-gic-v3.c > @@ -19,6 +19,7 @@ > #include > #include > #include > +#include > > #include > #include > @@ -251,17 +252,11 @@ static inline void __iomem *gic_dist_base(struct irq_data *d) > > static void gic_do_wait_for_rwp(void __iomem *base, u32 bit) > { > - u32 count = 1000000; /* 1s! */ > + u32 val; > > - while (readl_relaxed(base + GICD_CTLR) & bit) { > - count--; > - if (!count) { > - pr_err_ratelimited("RWP timeout, gone fishing\n"); > - return; > - } > - cpu_relax(); > - udelay(1); > - } > + if (readl_relaxed_poll_timeout_atomic(base + GICD_CTLR, > + val, !(val & bit), 1, 1000000) == -ETIMEDOUT) If you are doing this, please use a constant such as USEC_PER_SEC for the timeout. And fix the alignment of the second line so that the parameters are aligned vertically. > + pr_err_ratelimited("RWP timeout, gone fishing\n"); > } > > /* Wait for completion of a distributor change */ > @@ -279,7 +274,6 @@ static void gic_redist_wait_for_rwp(void) > static void gic_enable_redist(bool enable) > { > void __iomem *rbase; > - u32 count = 1000000; /* 1s! */ > u32 val; > > if (gic_data.flags & FLAGS_WORKAROUND_GICR_WAKER_MSM8996) > @@ -301,14 +295,9 @@ static void gic_enable_redist(bool enable) > return; /* No PM support in this redistributor */ > } > > - while (--count) { > - val = readl_relaxed(rbase + GICR_WAKER); > - if (enable ^ (bool)(val & GICR_WAKER_ChildrenAsleep)) > - break; > - cpu_relax(); > - udelay(1); > - } > - if (!count) > + if (readl_relaxed_poll_timeout_atomic(rbase + GICR_WAKER, > + val, enable ^ (bool)(val & GICR_WAKER_ChildrenAsleep), > + 1, 1000000) == -ETIMEDOUT) > pr_err_ratelimited("redistributor failed to %s...\n", > enable ? "wakeup" : "sleep"); > } Same thing here. M. -- Without deviation from the norm, progress is not possible.