From nobody Tue Apr 7 11:28:58 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 07C953C7DF2 for ; Fri, 13 Mar 2026 16:44:09 +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=1773420251; cv=none; b=hDfmXcriS6IO+clw7NHqFlfm108X3DjXYXXVwNCbfezLbQ9hOzr6LQxSDzsmtIFe8gOY5uoSBKDuccnuExrbw5daEVcckqMmu416rnJ3venHHUPLDs026sZ6j3RuW92A0cvLEfnI7ZJuaRbAqCyYXJbrHWDuKnhvIXWihyhB+fc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773420251; c=relaxed/simple; bh=e6VNEFE5OKDlGjgl9TvkE/uAdwoIcDCMi2TMuH/63MM=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fFmmlF+W+O+guBNkohupr9ZQ0w3TWcCn23YrJZibmoGjDYGiAjjMwSw6QboohPID/jUs2FFfH+6eApKkBDQoZVZLn23V++xPsM9dJ1Wcc6G2WegZmLP4SapIZH4ZI/Ku6rUh9gfr60Z7WtYV9zn+LHOLJzmcmuPb/JP2hb2xrQI= 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=DJvw8XG6; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=j3HYrhIf; 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="DJvw8XG6"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="j3HYrhIf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1773420249; 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=LDONcomQB2DLiXYCP0wRMGDkX6OSYJ9ENHojQAPp6Uk=; b=DJvw8XG6BtsR+V/haORIuftE9Of5nBn76OgNc4fOgPUMI5QWa7ziY8WAzeiI3LB6J1KMBW 7ieLZZqsACtBnWXpERbMwqER82EMmTPXztAq1crdzqk255jyPwsUWfDbXjLLwxTE8UWX3+ 3Mfz3i5/zYTo5h3mDK+w9cpUlH9CaRc= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-88-vvSkWQjjMvKmmOEvX7ZwNQ-1; Fri, 13 Mar 2026 12:44:08 -0400 X-MC-Unique: vvSkWQjjMvKmmOEvX7ZwNQ-1 X-Mimecast-MFC-AGG-ID: vvSkWQjjMvKmmOEvX7ZwNQ_1773420247 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-8cdb995a1bfso666784085a.1 for ; Fri, 13 Mar 2026 09:44:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1773420247; x=1774025047; 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=LDONcomQB2DLiXYCP0wRMGDkX6OSYJ9ENHojQAPp6Uk=; b=j3HYrhIflimqcgQuLjquds1f8tyAGuYUQlPNJIafBQpTlBb4z7Wn1b+IQCs6vkhZ7V OM2LzfD8n9XTVO8BNHraTflpIm46D2vtWrxaZ4wZI/zO/mscEGFAqZFyguGuClv6P2Ro YI0lkqL+hp5OI3GH+aiasFp6Grtymim1c0nkDJWMdNp/RcuFPZLildLMb3jwRzNtRWEq KPbaIokdZyloCLMC60jr9OXO4UTTe3mDJvy8wBEf7lniN5qS0yLMCwdr5R7jjO6/58HW Mw5wzl/WFP3RjBkJRIl4PXPyE9vGW1cAKM/EnbgCz7/W6kp4S0pJyDBNhSPXPLe6whsm l9pw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773420247; x=1774025047; 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=LDONcomQB2DLiXYCP0wRMGDkX6OSYJ9ENHojQAPp6Uk=; b=liq70u78w6ZUi/bnUZ/yzuVjf4MqTOc4g2CSssSH3XCNuqat+RmP5zMlQ35ii/CzvG y3EdoFBHgCGBx+R83rML4jP1bb2DEZYlJgqCfWnSW7hHK66T8e6q0Anyy4QFZYf13Rd1 WP3by02W75IZsc+XWTCsSNKz7KoUrphPrGFDJk8vTN3CyOAUPp4SldCI+5B9swrC+Zz+ 5Evn8cwD6J0pRbnWDOGyIkLvylp3Onalge+UPx46gtHngdLHbnR73ZyHZIjg6okLd+Oq +6q0GXCdfiNDxt+j5nNhl458D69VGfxTu/bfMzUIJ4laga6D30vSVDIZ3C757PFSw5lg sm9w== X-Forwarded-Encrypted: i=1; AJvYcCXgdyLxSd+igakLYQDDlnsZ2VhZjeVBJVg+54vDxq0Q1N7Y3q61d+kddtQduzQvPswF7mpK1Vcy7iCBYe4=@vger.kernel.org X-Gm-Message-State: AOJu0Yyj5pMKPv+QcVv9MOH4yZWETyyO3fZPX3GqH0xSyDlEf6KFrs5A XDXSU+WL0F2po23ZdCkVSgIRleG/cay9UJAXUcpzPVnW8gKy/SNQfiysdApYoV6a8mTmD7OERa8 AS2o+KZnchieZutsjnns1XAMBEZ9ILVcpmU7fUZoQuzTBZs6ZB+QDWAGpzmbMfwfnTZhOIcN1CA == X-Gm-Gg: ATEYQzxupRWZx9ebcsqkG89V3MEPIAIh9qgqVLHUT2SDowxRzpUPo6/kvo3Sj4dGCOI R5zFoPTPcEfMbOJ1ZPr8swYHZVVAfssgFK/iOK9ZIa6ylXGAD5vwHu15C3rwyeIksi/OYzYDr0n wp/8X78IWOasv+RA1chpABM65+zA/XmCM5idoLx4EfrN9bmUFs4uSO7WS6ygtIRBD/iZv/jMPef tU72zjK20Zw+xi3tsl5vKDDCK08ji+ArNLdip/SZw4VeaXiyxglvZgayfkS/32+ldtOWGEgAES0 HaavGJ57DwRB8KlBpf/cNnw+OJXweEnpDWgwmxBeZ1zoRgV8ACWB2eAKlNyK+E1AhD6kKfJeels I06US+iZFK23pMqPkqhZXEjrPDpvRHhNduFzrcyh4z4oAQz2RZVswrAiFMTU1 X-Received: by 2002:a05:620a:7e5:b0:8cd:c035:4fd2 with SMTP id af79cd13be357-8cdc035512amr158896785a.48.1773420247424; Fri, 13 Mar 2026 09:44:07 -0700 (PDT) X-Received: by 2002:a05:620a:7e5:b0:8cd:c035:4fd2 with SMTP id af79cd13be357-8cdc035512amr158893785a.48.1773420246970; Fri, 13 Mar 2026 09:44:06 -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 af79cd13be357-8cda215c2a9sm587964785a.46.2026.03.13.09.44.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Mar 2026 09:44:06 -0700 (PDT) From: Brian Masney Date: Fri, 13 Mar 2026 12:43:10 -0400 Subject: [PATCH v6 3/7] 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: <20260313-clk-scaling-v6-3-ce89968c5247@redhat.com> References: <20260313-clk-scaling-v6-0-ce89968c5247@redhat.com> In-Reply-To: <20260313-clk-scaling-v6-0-ce89968c5247@redhat.com> To: Michael Turquette , Stephen Boyd , Maxime Ripard , Alberto Ruiz Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Brian Masney X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3798; i=bmasney@redhat.com; s=20250903; h=from:subject:message-id; bh=e6VNEFE5OKDlGjgl9TvkE/uAdwoIcDCMi2TMuH/63MM=; b=owGbwMvMwCW2/dJd9di6A+2Mp9WSGDK32J36uUm3NURfuTvh+BHTEN15Qk/ittYecl5aaHeVc eK6dTx1HaUsDGJcDLJiiixLco0KIlJX2d67o8kCM4eVCWQIAxenAEzEfx/D/+ofYu/XrvdNqNMt ez318bu8R3//TePlKTXiejP/Xq90UDbDP4sPqX7aDOsef7GosTshFCn5I+hTSvvf297fdGQiAxy dWAA= 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 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 Reviewed-by: Maxime Ripard --- drivers/clk/clk.c | 48 ++++++++++++++++++++++++++++++++++++++++= ++++ include/linux/clk-provider.h | 2 ++ 2 files changed, 50 insertions(+) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 47093cda9df32223c1120c3710261296027c4cd3..051fe755e3bf1b0a06db254b92f= 8a02889456db9 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,53 @@ 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 children, it us= es their + * current rate. This is useful for determining what parent rate can satis= fy 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; + + 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 + 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