From nobody Mon Jan 5 11:08:07 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3FDF7E784B2 for ; Mon, 2 Oct 2023 09:24:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236085AbjJBJYB (ORCPT ); Mon, 2 Oct 2023 05:24:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236076AbjJBJXw (ORCPT ); Mon, 2 Oct 2023 05:23:52 -0400 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFDA991; Mon, 2 Oct 2023 02:23:48 -0700 (PDT) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-4060b623e64so17034395e9.0; Mon, 02 Oct 2023 02:23:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696238627; x=1696843427; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=0zfNZlxXcCTfNfmsz4BOltE66rgV2iaZsNlV7GrJxxA=; b=PUSHbJzyijUr1rpI8epmHVk+nCxLKUH1kzecaZs0XqrrYH6uG9pLmocoFRMqOtQ3D3 IXX8Dg+WyQ2OZTMe5gxIbFYprbKuMgBNGLtcaRlkrcVqdEZOg7PcfQ8SzgUSKrpvPV2g MbOXnFm9WSaFziC2IIzprhMEEnyCUURmraR3mqS0HTZfUTOyXXjMPHW6gS5FXOtDmWxS Srdu8j/1acXUS8MCfgf11gG5cGuf5QFQJ7x1D4GxSDIOm1kpCupxFWV53oCNdr1IrT6q BGVX5DMOVpNbNN36ICNFUgh2II3dErmikrxnaNAevAFGGX/HHaBbLM3dxC4V0YUp4mVE 2I6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696238627; x=1696843427; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0zfNZlxXcCTfNfmsz4BOltE66rgV2iaZsNlV7GrJxxA=; b=ZPj0cXgipgDPTcACLEWbNrw5HRed16snHb3/7f8O93HA3mU4TSko732Bseg409icUO tZfsejGZMWUX7EDYqCvsMcAcRlUS8sSiV4dDD4JoqctsuT6zfxhQEm690QYNPbpfhzFy c1+nxp5N3OtQgutGOdG89uutjQU8xCd7V0L0kvEBwVvVmhyqQPYsQWc8hySS7ej3AoHz vdigSHuGHQKAGDmKko5MP8xC+egyFMx04pOrxr8CKcvvW0yimvkx+vQIlzWbb7wXAhzo gfQrXYsjvmm7jP2zIIXAPLntWS5QpLGJEqa631cVEI+mh+YIxhHRGxixWWM/pBzZGPqP d0AQ== X-Gm-Message-State: AOJu0Yx1gfVSx/txVBRLBfwbtAYrL3poX2jwHPkqXDSZGFz4PTrQ+Goq xeQQNfdZNjSRqqy9TIHwLnqTurm1Pgw= X-Google-Smtp-Source: AGHT+IGwfzei/DJdHX7odp7l+Tnxd+hri1iomzAmP3bzlVoXIU31ZrWDGHFiUZ3WBrZH79yoCaEKmw== X-Received: by 2002:a05:600c:5022:b0:405:3f06:d2ef with SMTP id n34-20020a05600c502200b004053f06d2efmr9149200wmr.4.1696238626910; Mon, 02 Oct 2023 02:23:46 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id o30-20020a05600c511e00b003fef5e76f2csm6156589wms.0.2023.10.02.02.23.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 02:23:46 -0700 (PDT) From: Benjamin Bara Date: Mon, 02 Oct 2023 11:23:32 +0200 Subject: [PATCH RFC 1/4] clk: only set req_rate if it is set by consumer MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20231002-ccf-set-multiple-v1-1-2df5e9eb3738@skidata.com> References: <20231002-ccf-set-multiple-v1-0-2df5e9eb3738@skidata.com> In-Reply-To: <20231002-ccf-set-multiple-v1-0-2df5e9eb3738@skidata.com> To: Maxime Ripard , Michael Turquette , Stephen Boyd Cc: Frank Oltmanns , Adam Ford , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Bara X-Mailer: b4 0.12.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Benjamin Bara Currently, the req_rate is set during initialization and during re-parenting. Therefore, it is not clear whether the req_rate is really required by a consumer or just set by accident. Fix this by only setting the req_rate when it is really required (clk_set_rate() is called by consumer). Signed-off-by: Benjamin Bara --- drivers/clk/clk.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index c249f9791ae8..82f954121e4d 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -24,6 +24,8 @@ =20 #include "clk.h" =20 +#define CLK_RATE_UNSET -1UL + static DEFINE_SPINLOCK(enable_lock); static DEFINE_MUTEX(prepare_lock); =20 @@ -1832,7 +1834,6 @@ static unsigned long clk_recalc(struct clk_core *core, /** * __clk_recalc_rates * @core: first clk in the subtree - * @update_req: Whether req_rate should be updated with the new rate * @msg: notification type (see include/linux/clk.h) * * Walks the subtree of clks starting with clk and recalculates rates as it @@ -1842,8 +1843,7 @@ static unsigned long clk_recalc(struct clk_core *core, * clk_recalc_rates also propagates the POST_RATE_CHANGE notification, * if necessary. */ -static void __clk_recalc_rates(struct clk_core *core, bool update_req, - unsigned long msg) +static void __clk_recalc_rates(struct clk_core *core, unsigned long msg) { unsigned long old_rate; unsigned long parent_rate =3D 0; @@ -1857,8 +1857,6 @@ static void __clk_recalc_rates(struct clk_core *core,= bool update_req, parent_rate =3D core->parent->rate; =20 core->rate =3D clk_recalc(core, parent_rate); - if (update_req) - core->req_rate =3D core->rate; =20 /* * ignore NOTIFY_STOP and NOTIFY_BAD return values for POST_RATE_CHANGE @@ -1868,13 +1866,13 @@ static void __clk_recalc_rates(struct clk_core *cor= e, bool update_req, __clk_notify(core, msg, old_rate, core->rate); =20 hlist_for_each_entry(child, &core->children, child_node) - __clk_recalc_rates(child, update_req, msg); + __clk_recalc_rates(child, msg); } =20 static unsigned long clk_core_get_rate_recalc(struct clk_core *core) { if (core && (core->flags & CLK_GET_RATE_NOCACHE)) - __clk_recalc_rates(core, false, 0); + __clk_recalc_rates(core, 0); =20 return clk_core_get_rate_nolock(core); } @@ -2455,7 +2453,6 @@ static int clk_core_set_rate_nolock(struct clk_core *= core, /* change the rates */ clk_change_rate(top); =20 - core->req_rate =3D req_rate; err: clk_pm_runtime_put(core); =20 @@ -2485,6 +2482,7 @@ static int clk_core_set_rate_nolock(struct clk_core *= core, */ int clk_set_rate(struct clk *clk, unsigned long rate) { + unsigned long old_req_rate; int ret; =20 if (!clk) @@ -2493,6 +2491,9 @@ int clk_set_rate(struct clk *clk, unsigned long rate) /* prevent racing with updates to the clock topology */ clk_prepare_lock(); =20 + old_req_rate =3D clk->core->req_rate; + clk->core->req_rate =3D rate; + if (clk->exclusive_count) clk_core_rate_unprotect(clk->core); =20 @@ -2501,6 +2502,9 @@ int clk_set_rate(struct clk *clk, unsigned long rate) if (clk->exclusive_count) clk_core_rate_protect(clk->core); =20 + if (ret) + clk->core->req_rate =3D old_req_rate; + clk_prepare_unlock(); =20 return ret; @@ -2528,6 +2532,7 @@ EXPORT_SYMBOL_GPL(clk_set_rate); */ int clk_set_rate_exclusive(struct clk *clk, unsigned long rate) { + unsigned long old_req_rate; int ret; =20 if (!clk) @@ -2536,6 +2541,9 @@ int clk_set_rate_exclusive(struct clk *clk, unsigned = long rate) /* prevent racing with updates to the clock topology */ clk_prepare_lock(); =20 + old_req_rate =3D clk->core->req_rate; + clk->core->req_rate =3D rate; + /* * The temporary protection removal is not here, on purpose * This function is meant to be used instead of clk_rate_protect, @@ -2546,6 +2554,8 @@ int clk_set_rate_exclusive(struct clk *clk, unsigned = long rate) if (!ret) { clk_core_rate_protect(clk->core); clk->exclusive_count++; + } else { + clk->core->req_rate =3D old_req_rate; } =20 clk_prepare_unlock(); @@ -2723,7 +2733,7 @@ static void clk_core_reparent(struct clk_core *core, { clk_reparent(core, new_parent); __clk_recalc_accuracies(core); - __clk_recalc_rates(core, true, POST_RATE_CHANGE); + __clk_recalc_rates(core, POST_RATE_CHANGE); } =20 void clk_hw_reparent(struct clk_hw *hw, struct clk_hw *new_parent) @@ -2807,9 +2817,9 @@ static int clk_core_set_parent_nolock(struct clk_core= *core, =20 /* propagate rate an accuracy recalculation accordingly */ if (ret) { - __clk_recalc_rates(core, true, ABORT_RATE_CHANGE); + __clk_recalc_rates(core, ABORT_RATE_CHANGE); } else { - __clk_recalc_rates(core, true, POST_RATE_CHANGE); + __clk_recalc_rates(core, POST_RATE_CHANGE); __clk_recalc_accuracies(core); } =20 @@ -3706,7 +3716,7 @@ static void clk_core_reparent_orphans_nolock(void) __clk_set_parent_before(orphan, parent); __clk_set_parent_after(orphan, parent, NULL); __clk_recalc_accuracies(orphan); - __clk_recalc_rates(orphan, true, 0); + __clk_recalc_rates(orphan, 0); =20 /* * __clk_init_parent() will set the initial req_rate to @@ -3888,7 +3898,8 @@ static int __clk_core_init(struct clk_core *core) rate =3D parent->rate; else rate =3D 0; - core->rate =3D core->req_rate =3D rate; + core->rate =3D rate; + core->req_rate =3D CLK_RATE_UNSET; =20 /* * Enable CLK_IS_CRITICAL clocks so newly added critical clocks --=20 2.34.1 From nobody Mon Jan 5 11:08:07 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A3DFE7849A for ; Mon, 2 Oct 2023 09:24:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236102AbjJBJYD (ORCPT ); Mon, 2 Oct 2023 05:24:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236079AbjJBJXx (ORCPT ); Mon, 2 Oct 2023 05:23:53 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D17FB83; Mon, 2 Oct 2023 02:23:49 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-405524e6769so16967185e9.1; Mon, 02 Oct 2023 02:23:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696238628; x=1696843428; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=CWnc+dy+pgpvwPkAp+YPEAjlQNYnRW3rr6yrN5WtgHM=; b=ebkgnddL+rUXra5avqchX5dzdO9VJepU6B/wzyC1s0SmnJDDH4/mkGt1hEuz2h9QXg jaQKKpOTO9uoXkpR+rNbp6hTsyVkd2limfbdD49VrYZ9+ZrWvYRZJ+RA1+s9DymVEDaW WZiypRs39SAA0svCURfc3UrwtqO+ipGrI1f+rAg6yz0fZOHryXw+JuJDgSrNaFNwcfJr 8mxlN13S1zZ5cpyaVMVUJYy4gWrUDQll8og46PH4DXUyxjcYrq2KhhZ4pPgzUQEvCQdG yy4GlnrBoKKt1BjMtY6y+nw32qNDNW79rJrLKnME9T0QjVdqq7zTr8IvA+k7a0AwMWMO grGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696238628; x=1696843428; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CWnc+dy+pgpvwPkAp+YPEAjlQNYnRW3rr6yrN5WtgHM=; b=M2O8cTV8G9v7lEh/vBNp2jqxZcmZ5fKWvhi6q+/Ael+6c/+TWIgPYGKoAiXa4uT6Y+ JZjfkmfrwtP0nF4/c+Nf4kGenkE0d3T4PQR/uoB77qylpmNiQCGQ57KQotmlY9lEnnNQ 94J2s5ObhB7PZwiKD9gm6O0mt74BkbYRD3fNo1tHpXmwxjinLPHp7d+lk7gQkMAU7g0k lzJ1NFoUOlIUrd3FGukV+fpYl6TQ1wIdIFfwufUm1RV6n6JIsQ/cbTvYZDJOIKOrsCHr Yf2XcO05EWxawngsNHNZtaoru2BAnng1bFuJZHDb97GBEaYeiA8JNgYN8qtWGpRIywuL EFhw== X-Gm-Message-State: AOJu0YzCqEBk7AZw//hd4bniLmBaEZ54Q+WKYp+WeJnc3C1kd4D8UrPw y1M5JFfzpjBlOTOLTdOKIbZOvR7E7Tc= X-Google-Smtp-Source: AGHT+IEvprV74S3E0t1zQ5YloeRABiVyP75Q8xh4lMPOj/63ZR6M35ItZEnAIgtYfanunqc81pt4FA== X-Received: by 2002:a05:600c:3d8d:b0:405:d70d:1790 with SMTP id bi13-20020a05600c3d8d00b00405d70d1790mr8993263wmb.13.1696238627736; Mon, 02 Oct 2023 02:23:47 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id o30-20020a05600c511e00b003fef5e76f2csm6156589wms.0.2023.10.02.02.23.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 02:23:47 -0700 (PDT) From: Benjamin Bara Date: Mon, 02 Oct 2023 11:23:33 +0200 Subject: [PATCH RFC 2/4] clk: reset new_rates for next run MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20231002-ccf-set-multiple-v1-2-2df5e9eb3738@skidata.com> References: <20231002-ccf-set-multiple-v1-0-2df5e9eb3738@skidata.com> In-Reply-To: <20231002-ccf-set-multiple-v1-0-2df5e9eb3738@skidata.com> To: Maxime Ripard , Michael Turquette , Stephen Boyd Cc: Frank Oltmanns , Adam Ford , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Bara X-Mailer: b4 0.12.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Benjamin Bara During clk_set_rate(), new_rates are calculated for all clocks that are part of the changed clock subtree. These values are temporary and only valid during the current call. Therefore, reset them to prepare a clean state for the next call. Signed-off-by: Benjamin Bara --- drivers/clk/clk.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 82f954121e4d..5f183cba300c 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -2163,6 +2163,17 @@ static void clk_calc_subtree(struct clk_core *core, = unsigned long new_rate, } } =20 +static void clk_reset_temp_rates(struct clk_core *core) +{ + struct clk_core *child; + + core->new_rate =3D CLK_RATE_UNSET; + + hlist_for_each_entry(child, &core->children, child_node) { + clk_reset_temp_rates(child); + } +} + /* * calculate the new rates returning the topmost clock that has to be * changed. @@ -2244,7 +2255,9 @@ static struct clk_core *clk_calc_new_rates(struct clk= _core *core, top =3D clk_calc_new_rates(parent, best_parent_rate); =20 out: - clk_calc_subtree(core, new_rate, parent, p_index); + /* only set new_rates if we found a valid change path */ + if (top) + clk_calc_subtree(core, new_rate, parent, p_index); =20 return top; } @@ -2347,6 +2360,7 @@ static void clk_change_rate(struct clk_core *core) =20 trace_clk_set_rate_complete(core, core->new_rate); =20 + core->new_rate =3D CLK_RATE_UNSET; core->rate =3D clk_recalc(core, best_parent_rate); =20 if (core->flags & CLK_SET_RATE_UNGATE) { @@ -2361,7 +2375,7 @@ static void clk_change_rate(struct clk_core *core) __clk_notify(core, POST_RATE_CHANGE, old_rate, core->rate); =20 if (core->flags & CLK_RECALC_NEW_RATES) - (void)clk_calc_new_rates(core, core->new_rate); + (void)clk_calc_new_rates(core, core->rate); =20 /* * Use safe iteration, as change_rate can actually swap parents @@ -2437,8 +2451,10 @@ static int clk_core_set_rate_nolock(struct clk_core = *core, return -EINVAL; =20 ret =3D clk_pm_runtime_get(core); - if (ret) + if (ret) { + clk_reset_temp_rates(top); return ret; + } =20 /* notify that we are about to change rates */ fail_clk =3D clk_propagate_rate_change(top, PRE_RATE_CHANGE); @@ -2454,6 +2470,8 @@ static int clk_core_set_rate_nolock(struct clk_core *= core, clk_change_rate(top); =20 err: + clk_reset_temp_rates(top); + clk_pm_runtime_put(core); =20 return ret; @@ -3900,6 +3918,7 @@ static int __clk_core_init(struct clk_core *core) rate =3D 0; core->rate =3D rate; core->req_rate =3D CLK_RATE_UNSET; + core->new_rate =3D CLK_RATE_UNSET; =20 /* * Enable CLK_IS_CRITICAL clocks so newly added critical clocks --=20 2.34.1 From nobody Mon Jan 5 11:08:07 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34193E784AF for ; Mon, 2 Oct 2023 09:24:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236109AbjJBJYG (ORCPT ); Mon, 2 Oct 2023 05:24:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236082AbjJBJXx (ORCPT ); Mon, 2 Oct 2023 05:23:53 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63A5694; Mon, 2 Oct 2023 02:23:50 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-4066692ad35so16040885e9.1; Mon, 02 Oct 2023 02:23:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696238628; x=1696843428; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=eV+VLWmEsyaB+IunROtO6uT7xWMFypNTH9h9QU/Ea1c=; b=If5y+nlmGiqkkqGRabBrxpKSmtSrsDpgOqjBIaZw7shWiZHnf0T95I0yY9PHGXGFAN F8bc2u6dMG1lxB0WMyKYVbQ04ZaAQtr6+9D77uAQxa2rKHPBLvCS+1MzpkOcZdeFqogh DADVwOx4FUn4hW5GV9/yx+P5LlVD4YPpnwrg3DrG5h0bYwULtNxxn1WeF687FK4xlQ1h IIP7RexrzkZGMGletdD+OHHzPiUROzqnejcTPhGQD602UfWdajOvdUkVazq7p+6l9Vo8 3RVjq6zYDdnryOr+TRJN5x/0eVrPoiL0+FhW30W8UgLnxRIdqVqXZsbHXeZ5RwQ/hvYi W8Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696238628; x=1696843428; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eV+VLWmEsyaB+IunROtO6uT7xWMFypNTH9h9QU/Ea1c=; b=OPUfckOsAeQyEsYLOvtMjscXU/vVvETUh6Wis2rtomekEjigjT9C6g63kh/l2uwq7b /6Q8a0sy57utE1qRlQmcZ+/LoE+OTuJs2LVpkk48dqxfCfQl/kgIA29NiwG9moXBZohi Ma5oSuFjpXwlaxb82NrEgopZwQ57Rl9spe+fkJ1wO9WQO2F2e+jVR33wmpI8CH4RW85Y UOiDlvkgIlUpjtSQWgdBsl4wLjFkNOWv9VMeLXxhA4JMZ2ukLuanL4JcCQorLeq48pld jpyuaAOlo844JCETrYBGlfiTi/BP7KjpvZcSdwS5XLQesYxXo/SFpguxIMtRFxPeQaQQ 0wzw== X-Gm-Message-State: AOJu0YzZXm5rFe8/+AByLa53Ukq7ckkgbKSIjV4pd42UGoa7wdXlp2A9 ewfWqnWBaUxnazkD0POwGqWPGDAundY= X-Google-Smtp-Source: AGHT+IF2O0toKcnLPeXE1jxOs0n80mBAKKNdApkyD/rX1DNEYIT5N4voMKaDDHe4VgnM5u/hmeMwkA== X-Received: by 2002:a1c:7c11:0:b0:405:4a78:a890 with SMTP id x17-20020a1c7c11000000b004054a78a890mr9186760wmc.8.1696238628428; Mon, 02 Oct 2023 02:23:48 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id o30-20020a05600c511e00b003fef5e76f2csm6156589wms.0.2023.10.02.02.23.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 02:23:48 -0700 (PDT) From: Benjamin Bara Date: Mon, 02 Oct 2023 11:23:34 +0200 Subject: [PATCH RFC 3/4] clk: introduce req_rate_tmp MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20231002-ccf-set-multiple-v1-3-2df5e9eb3738@skidata.com> References: <20231002-ccf-set-multiple-v1-0-2df5e9eb3738@skidata.com> In-Reply-To: <20231002-ccf-set-multiple-v1-0-2df5e9eb3738@skidata.com> To: Maxime Ripard , Michael Turquette , Stephen Boyd Cc: Frank Oltmanns , Adam Ford , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Bara X-Mailer: b4 0.12.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Benjamin Bara A clock currently has a req_rate, which is required by the consumer, and a next_rate, which is the outcoming rate of the ongoing clk_set_rate() call. This commit introduces req_rate_tmp, which is a temporary required rate for the ongoing change. This means, the clock is an ancestor of the change trigger and a descendant of the top-most clock to change. This helps us to identify if the clock is changed "by accident" (new_rate set, req_rate_tmp not set). Signed-off-by: Benjamin Bara --- drivers/clk/clk.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 5f183cba300c..3e7dd97b71c3 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -68,6 +68,7 @@ struct clk_core { u8 new_parent_index; unsigned long rate; unsigned long req_rate; + unsigned long req_rate_tmp; unsigned long new_rate; struct clk_core *new_parent; struct clk_core *new_child; @@ -2168,6 +2169,7 @@ static void clk_reset_temp_rates(struct clk_core *cor= e) struct clk_core *child; =20 core->new_rate =3D CLK_RATE_UNSET; + core->req_rate_tmp =3D CLK_RATE_UNSET; =20 hlist_for_each_entry(child, &core->children, child_node) { clk_reset_temp_rates(child); @@ -2256,8 +2258,17 @@ static struct clk_core *clk_calc_new_rates(struct cl= k_core *core, =20 out: /* only set new_rates if we found a valid change path */ - if (top) + if (top) { + /* + * The current clock is an ancestor of the trigger and therefore + * is a clock which needs to be changed in this run. Clocks + * with new_rate set but req_rate_tmp unset are changed "by + * accident". On these clocks, the new_rate potentially + * conflicts with req_rate. + */ + core->req_rate_tmp =3D new_rate; clk_calc_subtree(core, new_rate, parent, p_index); + } =20 return top; } @@ -3917,7 +3928,7 @@ static int __clk_core_init(struct clk_core *core) else rate =3D 0; core->rate =3D rate; - core->req_rate =3D CLK_RATE_UNSET; + core->req_rate =3D core->req_rate_tmp =3D CLK_RATE_UNSET; core->new_rate =3D CLK_RATE_UNSET; =20 /* --=20 2.34.1 From nobody Mon Jan 5 11:08:07 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A04ABE784AF for ; Mon, 2 Oct 2023 09:24:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236114AbjJBJYJ (ORCPT ); Mon, 2 Oct 2023 05:24:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50618 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236084AbjJBJXy (ORCPT ); Mon, 2 Oct 2023 05:23:54 -0400 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 297179E; Mon, 2 Oct 2023 02:23:51 -0700 (PDT) Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-50307acd445so24788970e87.0; Mon, 02 Oct 2023 02:23:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696238629; x=1696843429; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=+WxI5UNOh/sMglL2XmJQroF7LkfgIlgVWztDdlKZGLc=; b=Ty7Gd6qcKHE9K/CCHgTbxFD7iuklgDrsqZ6NnZpvYGaeyYxmZzLcWwS2Y+aIwhLgt4 uAe+CjVFI4u4lS52Mw4y9+E1eJO/br9fMHzKFq064155hJeoIWtqYbjQ+BOLpKLFXyNs 1fLiXt8R6Zpr7KZussJaHLn8bj/Co+1qvdeJYkCdnHU8JKT4k0JjRuUsm4KIjJcs59Dz xAbzq76HuAuxuDfDaFr7N4irF4QB/3Yap5n21lOTuSOLrBeU9b0taNDtcvsmYfpAdrcc hxbmir8mYXWSlzMIvLxzl9Nz2tlcWz9Ua3DFzfMUiX8TYV+4izhHhIkLYNwGIL698Vk5 jbMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696238629; x=1696843429; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+WxI5UNOh/sMglL2XmJQroF7LkfgIlgVWztDdlKZGLc=; b=OmDbJvToDNkavsHj0THFyEH/B6lFnqprsmewDoDqYe+aRJSm2al7qpThVEEQpQcIAD 77YYlqqylAyzE1VfTNLoUutPKe3+l92QICJmYoAeh4/gyPopgU2H0ivlL3aTZArYvVN5 ioVskTosF7/Gys/7o3Te0CAh9pYm04MCqmDUMtm9wuvVc1F9SSgHOKOMuVieKUjONb+i h7n3HLTQcBL9Gq7RXG3aj1F5oO1jpC5I1i4exrDlsiB7FNKGbn40L2gmeppboVKPgMi+ Taf2Qx7932OaVjN/viN5JXMo9jmOjUYZ/adxKE8ftwzGmPIctJzRsjnE7ClW/hs/AbV4 kPWQ== X-Gm-Message-State: AOJu0YwewG4VxhbKvG515cnrPU4qSjpmwF+FAm1MuWlfl7cW2uCwYW7U pUbAy6q4fNeIYn5wON93nnUY6UbXJok= X-Google-Smtp-Source: AGHT+IE7TNaedcvmDzAjGdIITBA+OGMR+LGyhUSgwsbuDpFIgKXquyj34ELFm8dLaLHrZCmqoZ9LJQ== X-Received: by 2002:ac2:57c6:0:b0:505:70dd:d594 with SMTP id k6-20020ac257c6000000b0050570ddd594mr5124538lfo.49.1696238629036; Mon, 02 Oct 2023 02:23:49 -0700 (PDT) Received: from [127.0.1.1] ([91.230.2.244]) by smtp.gmail.com with ESMTPSA id o30-20020a05600c511e00b003fef5e76f2csm6156589wms.0.2023.10.02.02.23.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 02:23:48 -0700 (PDT) From: Benjamin Bara Date: Mon, 02 Oct 2023 11:23:35 +0200 Subject: [PATCH RFC 4/4] clk: consider rates when calculating subtree MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20231002-ccf-set-multiple-v1-4-2df5e9eb3738@skidata.com> References: <20231002-ccf-set-multiple-v1-0-2df5e9eb3738@skidata.com> In-Reply-To: <20231002-ccf-set-multiple-v1-0-2df5e9eb3738@skidata.com> To: Maxime Ripard , Michael Turquette , Stephen Boyd Cc: Frank Oltmanns , Adam Ford , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Benjamin Bara X-Mailer: b4 0.12.3 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Benjamin Bara With req_rate_tmp and new_rate, we can identify if a clock is changed by accident. Additionally, with req_rate, we are able to find out if a clock consumer requires a certain rate. This enables us to find "unwanted clock changes", meaning a clock is changed although its consumer is expecting its current rate. On such a finding, the "calculate new rates" process is started again, but this time for the affected clock. During every execution of this process, we identify the clocks which are required to be changed to get the requested rate. If a clock needs to be changed a second time, we found a conflict. There are various options to resolve the conflict, but for now we just error out. Signed-off-by: Benjamin Bara --- drivers/clk/clk.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++= --- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 3e7dd97b71c3..296d0fa510de 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -2145,7 +2145,10 @@ static int __clk_speculate_rates(struct clk_core *co= re, return ret; } =20 -static void clk_calc_subtree(struct clk_core *core, unsigned long new_rate, +static struct clk_core *clk_calc_new_rates(struct clk_core *core, + unsigned long rate); + +static int clk_calc_subtree(struct clk_core *core, unsigned long new_rate, struct clk_core *new_parent, u8 p_index) { struct clk_core *child; @@ -2160,8 +2163,28 @@ static void clk_calc_subtree(struct clk_core *core, = unsigned long new_rate, =20 hlist_for_each_entry(child, &core->children, child_node) { child->new_rate =3D clk_recalc(child, new_rate); - clk_calc_subtree(child, child->new_rate, NULL, 0); + + /* + * A new rate of a shared parent clock might clash with a + * required rate of a sibling. Ensure that the new rates are as + * close as possible to the required ones. During this process, + * the shared parent clock is not allowed to be changed again, + * meaning it should have found the optimal rate already in the + * initial clk_core_determine_round_nolock(). + */ + if (child->req_rate !=3D CLK_RATE_UNSET && + child->req_rate !=3D child->new_rate) { + pr_debug("%s: set back to req=3D%lu\n", child->name, + child->req_rate); + if (!clk_calc_new_rates(child, child->req_rate)) + return -EINVAL; + } + + if (clk_calc_subtree(child, child->new_rate, NULL, 0)) + return -EINVAL; } + + return 0; } =20 static void clk_reset_temp_rates(struct clk_core *core) @@ -2259,6 +2282,22 @@ static struct clk_core *clk_calc_new_rates(struct cl= k_core *core, out: /* only set new_rates if we found a valid change path */ if (top) { + /* + * If req_rate_tmp is set, the current clock is already required + * to be changed in this run. However, if the new rate is not + * the same as the temporary required one, the driver did not + * consider its active rate (which is required by at least one + * of its descendants from a previous run). + */ + if (core->req_rate_tmp !=3D CLK_RATE_UNSET && + core->req_rate_tmp !=3D new_rate) { + pr_warn("%s: %s: conflict: req=3D%lu new=3D%lu\n", __func__, + core->name, core->req_rate_tmp, new_rate); + pr_err(".{determine,round}_rate() of %s requires fix\n", + core->name); + return NULL; + } + /* * The current clock is an ancestor of the trigger and therefore * is a clock which needs to be changed in this run. Clocks @@ -2267,7 +2306,16 @@ static struct clk_core *clk_calc_new_rates(struct cl= k_core *core, * conflicts with req_rate. */ core->req_rate_tmp =3D new_rate; - clk_calc_subtree(core, new_rate, parent, p_index); + + /* + * Calculating the subtree potentially leads to a re-entrance + * into clk_calc_new_rates(). This is required to set accidently + * changed consumer-required clocks, back to their required + * rate. This can fail in case of a conflict (shared parent + * needs to be changed again). + */ + if (clk_calc_subtree(core, new_rate, parent, p_index)) + return NULL; } =20 return top; --=20 2.34.1