From nobody Thu Apr 2 15:39:01 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 AAA2337FF4C for ; Fri, 27 Mar 2026 19:32:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774639957; cv=none; b=FrQLSAazvykpJX5YwJJyhx10M6xSo26DxXfHU+IqrcPcO8UTgZXWR7+ulDzWiqHm7rhFMosBgBnYdiXNSglXOoIfQ4hsVpanc60PCPKMJGvrZcgQEcFJEvJbYJMRZSanrI/fBw7oMohNGsuymo5N8P2CvFa6iT64G2a2xhSU8MQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774639957; c=relaxed/simple; bh=zZuXuYzRXV1Ky5Xhgp7rZ3YFui3eWbaiq3f7MTmQQc0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=buc42zDSFG8cOalSQ2wPEsfjmt89f2VH2flz002ufrOI3uhVarJNXuiQcTfVgJrnANC+tDt4Y4SLgMYOCWx6u25tVogzueS9BgDhoxGIBnExe8vNtRaZLrcW5RGZrvvFGwAXVv+JB4tjxlI9vHfI4nIv54wr+YInYfkvaA5ckyo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=iR4oqZDn; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=qtkjBXwl; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="iR4oqZDn"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="qtkjBXwl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774639948; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bICn27k7AW7Sds/NN557RWHAZWLa14lZ1eS5gR80gvU=; b=iR4oqZDnesepHnz/Hzn3+M+NlPcHCYcAsOxy+eWnVPowEm/T/Wv26Z78lx4slzVxMeNpdV dqLpMai8zPuuxbe3kB5yIonT44EOtn6UIntyrMXqw6r63fI1b1+vhFLS11y9o7vuCq2vwZ EN+3jqIR2n5cm7yTypS+2FjEa3aOI8Y= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-452-TWNtRgKFPu6T9K72QbnhXQ-1; Fri, 27 Mar 2026 15:32:26 -0400 X-MC-Unique: TWNtRgKFPu6T9K72QbnhXQ-1 X-Mimecast-MFC-AGG-ID: TWNtRgKFPu6T9K72QbnhXQ_1774639946 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-50b802961ecso33779611cf.1 for ; Fri, 27 Mar 2026 12:32:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1774639946; x=1775244746; 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=bICn27k7AW7Sds/NN557RWHAZWLa14lZ1eS5gR80gvU=; b=qtkjBXwlCOhngMrBb74Kem324OblelTOyyb3TvYWoTDE+Tg4YhF29QYQcZuFGLBxSH VYeGsZSvGDSCfS5yr0pxgPEwoSKb/b2sV9/bOX5jUAEbl0LzitAOXyf3HbCaM/NoccAp DT3wmY99KfQCDcXTFZvm0nb8tND2h1NNfViGnTJhVwwTycZr2y4cxfSAVRhSbE1U9ZP6 Pn8XXO48U1NrcvJLDlO/4se0xR+OdDxm/bUG1pE0HSbWQ+UJTAn5o/O7Nnv+uKoDzwvV Ii97l/vV08zooh+LLg1x0saDojKbT3mfPuPvIhm03bMrVPPz7Kb4shcu9gPEeoagWvrm 39cA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774639946; x=1775244746; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=bICn27k7AW7Sds/NN557RWHAZWLa14lZ1eS5gR80gvU=; b=ZuwHuaFSkNAo7QwUKZXmm6lCbKhQ1tgeQVsbPAt2RWhpDUXl4oLybPT/PUPzx/h5+1 XXywv/2lHGCIh6ypXiDLbEjzYdZRMFicWZkKxJz0ObzAQvq/UZya9Z/1QW3lusrXCl/D IVCFYSjaABBQKTjcT1rVTcVdJOIX6idCC5WKBJDstKdOMb9oJicAoJYa4U0qACR8j7tJ BXCO978rmb3T9BD1eOGlCbAy4X6HpS0JZjsb6SvtGr4hJ5vOyq1Sqocyhz9G2OliIWBL 9SfxVxoG1KLw7EjGn2ZI1U7AXaCuUMpOWX4756V49kVT7eyxULvt1ggiUYFl9nnE/UtV M3vQ== X-Forwarded-Encrypted: i=1; AJvYcCXW7wQ5gkeS1xULor9dMZyLt66Tg7KSVBFNU13cf9nujaQ3rdl2qdD9OJfbv2BtPOvOYWNCOCGbowFpHFs=@vger.kernel.org X-Gm-Message-State: AOJu0Yzo0XLIgkg6bOczGzGJi9L4MCC6qTTy/deGJ2yedTv5/1xr3qYK R63MSS6tiXy0S+xcawJJWrNl/+6XOh+i1z28ZARJIiWolqkIJDFmj6cmvDTr0dPDCl6nyr4tX1Y zQ7ncYan9R/IYFZCetpNK31BCc+NaTEAkDOVnVX+YMpM0oXaueAY2OuK/AGHaXiZu1w== X-Gm-Gg: ATEYQzwv23x4GOpzbX5P3AdmehAqCqmZqocskrNH+H0Z4U1dL6flFvM1L8ot/nc0oHi SnKLziyjZHFBff4CUY9s4ioh+O7L224kKHSIMt0vwYpWJdhqXaE1w+aEmy6Ri4OhURMqNndxkdj j7QEHZGBnZmZ+zsGwyEYr5+mJUdgU+xygOTgTXlLhSY0XMyflY3hMnGovz6tgNvBkD/whpX1tJr zCho7T9huw6mfiZrDfTIZgbPRK5v5aBrOOLvl/JeEmAI3cM8sE1h/aIIc0ZAFiDo+EyWJ6iI3y4 VEfI5eyEsKYHHMR8LPQXUnSQOlsCRDXeaaFHmg97BNxsJpRkdWDmMoZL7aYC5ZDA4PEQZWbgtaM K7FZFyLsE8xoxJVCo26w8nvLAgkQ7aCxCUl1kDdPgWpF2vEDAYKB2VE2VKDVj X-Received: by 2002:ac8:7f12:0:b0:509:320:2de6 with SMTP id d75a77b69052e-50ba386455dmr52408511cf.25.1774639946166; Fri, 27 Mar 2026 12:32:26 -0700 (PDT) X-Received: by 2002:ac8:7f12:0:b0:509:320:2de6 with SMTP id d75a77b69052e-50ba386455dmr52408081cf.25.1774639945637; Fri, 27 Mar 2026 12:32:25 -0700 (PDT) Received: from [192.168.1.3] (c-73-183-52-120.hsd1.pa.comcast.net. [73.183.52.120]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-50bb2c678e9sm2037551cf.6.2026.03.27.12.32.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Mar 2026 12:32:25 -0700 (PDT) From: Brian Masney Date: Fri, 27 Mar 2026 15:31:58 -0400 Subject: [PATCH v8 3/8] clk: introduce new helper clk_hw_get_children_lcm() to calculate LCM of all child rates Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260327-clk-scaling-v8-3-86cd0aba3c5f@redhat.com> References: <20260327-clk-scaling-v8-0-86cd0aba3c5f@redhat.com> In-Reply-To: <20260327-clk-scaling-v8-0-86cd0aba3c5f@redhat.com> To: Michael Turquette , Stephen Boyd , Maxime Ripard , Alberto Ruiz , Brendan Higgins , David Gow , Rae Moar Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, Brian Masney X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3927; i=bmasney@redhat.com; s=20250903; h=from:subject:message-id; bh=zZuXuYzRXV1Ky5Xhgp7rZ3YFui3eWbaiq3f7MTmQQc0=; b=owGbwMvMwCW2/dJd9di6A+2Mp9WSGDKP3bYrWtjNd2nJh47cbSui93pPnLazdunJyznJv31rX 0YJ9ZZP7yhlYRDjYpAVU2RZkmtUEJG6yvbeHU0WmDmsTCBDGLg4BWAiS1wZ/gpd7dWOydvk5Se5 YcfCjZuLHGRkvM9wu63qfSrF6O4mdp7hr3DMgYVaKzXVH0e1Fa/ac26Sikxc8q75qc/sIy0XpK3 NZAIA X-Developer-Key: i=bmasney@redhat.com; a=openpgp; fpr=A46D32705865AA3DDEDC2904B7D2DD275D7EC087 Introduce a new helper that recursively walks through all children and their descendants, calculating the lowest common multiple (LCM) of their rates. For the requesting child, it uses the requested rate; for other enabled children, it uses their current rate. This is useful for determining what parent rate can satisfy all children through simple integer dividers. Link: https://lore.kernel.org/linux-clk/aUSWU7UymULCXOeF@redhat.com/ Link: https://lpc.events/event/19/contributions/2152/ Signed-off-by: Brian Masney --- drivers/clk/clk.c | 54 ++++++++++++++++++++++++++++++++++++++++= ++++ include/linux/clk-provider.h | 2 ++ 2 files changed, 56 insertions(+) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 47093cda9df32223c1120c3710261296027c4cd3..bb602c07df9a2b523a72e1e05cc= 3a27956e7198b 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -838,6 +839,59 @@ void clk_hw_set_rate_range(struct clk_hw *hw, unsigned= long min_rate, } EXPORT_SYMBOL_GPL(clk_hw_set_rate_range); =20 +/** + * clk_hw_get_children_lcm - Calculate LCM of all children's rates recursi= vely + * @hw: The parent clock hardware + * @requesting_hw: The child clock that is requesting a rate change (can b= e NULL) + * @requesting_rate: The target rate for the requesting clock + * + * This helper recursively walks through all children and their descendant= s, + * calculating the lowest common multiple (LCM) of their rates. For the + * requesting child, it uses the requested rate; for other enabled childre= n, it + * uses their current rate. This is useful for determining what parent rat= e can + * satisfy all children through simple integer dividers. + * + * Returns: The LCM of all non-zero rates found in the subtree, or 0 if no= valid rates. + */ +unsigned long clk_hw_get_children_lcm(struct clk_hw *hw, struct clk_hw *re= questing_hw, + unsigned long requesting_rate) +{ + unsigned long lcm_rate =3D 0; + unsigned long child_rate; + struct clk_core *child; + + lockdep_assert_held(&prepare_lock); + + hlist_for_each_entry(child, &hw->core->children, child_node) { + /* Use requesting rate for the requesting child, current rate for others= */ + if (child->hw =3D=3D requesting_hw) { + child_rate =3D requesting_rate; + } else { + if (!clk_hw_is_enabled(child->hw)) + continue; + + child_rate =3D clk_hw_get_rate(child->hw); + } + + if (child_rate =3D=3D 0) + continue; + + if (lcm_rate =3D=3D 0) + lcm_rate =3D child_rate; + else + lcm_rate =3D lcm(lcm_rate, child_rate); + + /* Recursively get LCM of this child's children */ + child_rate =3D clk_hw_get_children_lcm(child->hw, requesting_hw, + requesting_rate); + if (child_rate > 0) + lcm_rate =3D lcm(lcm_rate, child_rate); + } + + return lcm_rate; +} +EXPORT_SYMBOL_GPL(clk_hw_get_children_lcm); + /* * __clk_mux_determine_rate - clk_ops::determine_rate implementation for a= mux type clk * @hw: mux type clk to determine rate on diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 630705a47129453c241f1b1755f2c2f2a7ed8f77..2699b9759e13d0c1f0b54f4fa4f= 7f7bdd42e8dde 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -1430,6 +1430,8 @@ void clk_hw_get_rate_range(struct clk_hw *hw, unsigne= d long *min_rate, unsigned long *max_rate); void clk_hw_set_rate_range(struct clk_hw *hw, unsigned long min_rate, unsigned long max_rate); +unsigned long clk_hw_get_children_lcm(struct clk_hw *hw, struct clk_hw *re= questing_hw, + unsigned long requesting_rate); =20 static inline void __clk_hw_set_clk(struct clk_hw *dst, struct clk_hw *src) { --=20 2.53.0