From nobody Sun Apr 5 16:22:54 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 BE6213C5DD6 for ; Mon, 23 Mar 2026 17:25:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774286741; cv=none; b=riTBYWW+/nOSms8QCP+EGIubpCCx4kDUb2t6lEaYtNuHuRHPVOCgFJ3M3glTiFex0JtKCQs65E8Oh0Az4t+xvFDn5OPFPywvnKYV5xWRkpgEo3RkmTgG5Nuy3rHcgNwoA+bffhUmn9+RAtMm6mTigb8fdC92PvVCbaY6fwbm4Jg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774286741; c=relaxed/simple; bh=+l00fky33FJjUcCtct02e8xTnMZAOCOPGYXSQstRsV8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=IYqEgq7kO7HfS01JTe88nyKmQvzZIKJyxpzGLIwzPqShE746Amph5cQfSRL67lzUDnqRMHByQcPT1FY7YdVz0tesOctvNzD6g6/B/tEMPb/J4DNh0o7Eok4vzj4VYMH6SAZNGBfq/P8Xwlx2DvU2BcMmfuDNNlpHg1xdwy+lQ18= 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=T+NkKkKG; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=nGVcC8yr; arc=none smtp.client-ip=170.10.129.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="T+NkKkKG"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="nGVcC8yr" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774286739; 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=q1hC/ZzGEUORZ2zC8HhKM0IgI+bXqAEpeb3eJalR1xU=; b=T+NkKkKGdG6lhkUYLhCmUrjzhPsJyhvUO6ioZHkt0cdfnktTvORxUkH0xym+L5TmmmeYPG 6p8FLZ+8e6WZD6w3vrnLzPTSSHibrTpKZovKh3uOQqVmUYTiDMBdrCjKzddqzDoUxFXTcY utmXVlaUddTG2/c2BC/fKRWrsbTVVl4= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-205-1ZfsuNOwMOWYRHnW3EAW6w-1; Mon, 23 Mar 2026 13:25:37 -0400 X-MC-Unique: 1ZfsuNOwMOWYRHnW3EAW6w-1 X-Mimecast-MFC-AGG-ID: 1ZfsuNOwMOWYRHnW3EAW6w_1774286736 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-50b4661881eso6117391cf.0 for ; Mon, 23 Mar 2026 10:25:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1774286736; x=1774891536; 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=q1hC/ZzGEUORZ2zC8HhKM0IgI+bXqAEpeb3eJalR1xU=; b=nGVcC8yrd2dYyDb8MKnxP+N5TTHUmZwUlCLwRdTAT3XcQsVS0b4o+ERfVBr3MxZZ+y gPDHYa3N0dXxQMNdRjykhF8ylkhvrLunSIxcLQHh6v/CxCf5YrTfcPhJG7dHOGdozEsX rsqhFzOvj93YlOMPtCITv+B2wabXqDfLI81j8lRhzx0Zb37yW3ytQNeCFurdDlb0p74x 9PC73th7yH4W81tRzeog8HIFrVuFtABMpNnxfwQ8EQyVyLeU0Shfm0bLwpTlYBQ0QG+w iycc5JU4G38CC7wAWn7FOgQZ3zXJNIGxVKN1EoxnbRFc7HqUH2njL94NrKp7UByNYfEy Crcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774286736; x=1774891536; 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=q1hC/ZzGEUORZ2zC8HhKM0IgI+bXqAEpeb3eJalR1xU=; b=S/pjkDPOaQ6aehad1ZzSk3xeba9+YqLkjOIfOm4VAsPaenGjyT2rzVQNY0/GBEAUSA vDsc4ALLPnNMegUQF9POCrktaDT2ZrUZFAD3fpOn7mKqKgH5wdoDMg8OpyC0a4VAqoZz U1xRQaWt5accIIMXU/XVSMkNaCmzs4gbICyoOhqzwMCOoHyTfypDA3P9jRr+SANXuyiR O41wXhoBmMT0a5xviVzS4Tab2XU6ENCJoFCNS7Ex42uGj7FsjwdMo5aaIokcbLCGBUrG fCMqoivBypeZDJYL2ZgwYiTZg8eztizilNAX4QP8c4ZmZ01A0UdmzYWlSLeai8wkIMo+ F+EQ== X-Forwarded-Encrypted: i=1; AJvYcCWJFbI4s4P43F02tvdPWIc8vj79dTnv0jWGHvbXwe0IQmuUzbna6g+IAelNPgPhlvopHIcXAX3u2cZK3QU=@vger.kernel.org X-Gm-Message-State: AOJu0YxeXlBxrE0VfJ/C9ogCLSRErlZISq/wK5dnLLlqboJwBFYbCr4u SuuY2NIAVwRtb+TP8muiJQ6VBC/DPJuhhEH9bDlw4JKUmq2mwpZ4U1wWPFc2xONc/G4nIDr1DMZ /TCtClOFFICowjXpfWlR/6IwpEnt9qZByAfA1qGubLK2JX3PiaE8gIxdVs2lEYLcL8Q== X-Gm-Gg: ATEYQzyck3cv5D9ECcTmymvBe84ENlHRgjWWtdTwhWepbqvu957+chVkJiCpXAT8z6w JtUoch7SxfVRIcccpofcV7/8mH2w6Mw36YkJJb4E9gaBbqerj7K1R1VIJY0ZJGJ1P3/2XFVwJMJ SRfdYUm0S601aEAOCKgR/zxcQGqpNkW51/oEcXqxfRU3d6XhlAQixvDgnSODITODHWMGMhhj36q 3zVmDTVxn3CVTfbf+6ch8/dpM4KF+i+xYo4zsKtdZdhYqKQUJPzd/VSn7EFsAXlbWzD6KLjmzEa Sp1zLGMoc7MFEJUBi+Kkft2Mkdhke86ixv39ovaFr15B6eDDDAiLzU8tL7AgTQGdaYRutx4jPQP 6DeghlyKBzN125WozyAVAGtYHO1Rz1lPFV05XHp+PmFad+nRgvZQE8R4JBl7g X-Received: by 2002:a05:622a:1e85:b0:50b:2fac:9597 with SMTP id d75a77b69052e-50b3743992emr212550381cf.22.1774286736595; Mon, 23 Mar 2026 10:25:36 -0700 (PDT) X-Received: by 2002:a05:622a:1e85:b0:50b:2fac:9597 with SMTP id d75a77b69052e-50b3743992emr212549821cf.22.1774286735944; Mon, 23 Mar 2026 10:25:35 -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-50b36e34f8bsm108249661cf.15.2026.03.23.10.25.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2026 10:25:35 -0700 (PDT) From: Brian Masney Date: Mon, 23 Mar 2026 13:24:52 -0400 Subject: [PATCH v7 1/8] clk: test: export clk_dummy_rate_ops and clk_dummy_context() for other tests 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: <20260323-clk-scaling-v7-1-8e7193dc9405@redhat.com> References: <20260323-clk-scaling-v7-0-8e7193dc9405@redhat.com> In-Reply-To: <20260323-clk-scaling-v7-0-8e7193dc9405@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=2492; i=bmasney@redhat.com; s=20250903; h=from:subject:message-id; bh=+l00fky33FJjUcCtct02e8xTnMZAOCOPGYXSQstRsV8=; b=owGbwMvMwCW2/dJd9di6A+2Mp9WSGDIPlreFyJQq1+tfrvd9O1/RymXLZOWde5dpTvfsMJK/v SnG+X5YRykLgxgXg6yYIsuSXKOCiNRVtvfuaLLAzGFlAhnCwMUpABP5Xsjwz6T9kFHGr0mX1t7y PsffM0EloWLulwPfexJfvw1/9LBKvInhf52ZhElk6Wbmt5U+YVutvJsj98nbTtXMOdyex2vkpl/ FAQA= X-Developer-Key: i=bmasney@redhat.com; a=openpgp; fpr=A46D32705865AA3DDEDC2904B7D2DD275D7EC087 Expose clk_dummy_rate_ops and clk_dummy_context() so that they can be used for other clk kunit tests. These will be used for the clk-divider tests. This export will be used by the upcoming clk-divider test suite. For consistency with clk-fixed-rate_test.c and drivers/clk/clk-gate_test.c, the divider tests will be setup as it's own separate kernel module. 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_test.c | 9 +++------ include/kunit/clk.h | 7 +++++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/clk/clk_test.c b/drivers/clk/clk_test.c index a268d7b5d4cb28ec1f029f828c31107f8e130556..b286297bb902a0c6c8a0469d0f7= 85009416ba9a5 100644 --- a/drivers/clk/clk_test.c +++ b/drivers/clk/clk_test.c @@ -15,6 +15,7 @@ #include #include #include +#include =20 #include "kunit_clk_assigned_rates.h" #include "clk_parent_data_test.h" @@ -25,11 +26,6 @@ static const struct clk_ops empty_clk_ops =3D { }; #define DUMMY_CLOCK_RATE_1 (142 * 1000 * 1000) #define DUMMY_CLOCK_RATE_2 (242 * 1000 * 1000) =20 -struct clk_dummy_context { - struct clk_hw hw; - unsigned long rate; -}; - static unsigned long clk_dummy_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { @@ -96,11 +92,12 @@ static u8 clk_dummy_single_get_parent(struct clk_hw *hw) return 0; } =20 -static const struct clk_ops clk_dummy_rate_ops =3D { +const struct clk_ops clk_dummy_rate_ops =3D { .recalc_rate =3D clk_dummy_recalc_rate, .determine_rate =3D clk_dummy_determine_rate, .set_rate =3D clk_dummy_set_rate, }; +EXPORT_SYMBOL_IF_KUNIT(clk_dummy_rate_ops); =20 static const struct clk_ops clk_dummy_maximize_rate_ops =3D { .recalc_rate =3D clk_dummy_recalc_rate, diff --git a/include/kunit/clk.h b/include/kunit/clk.h index f226044cc78d11564f7adb4cc2450934aab04ce6..b31d9a9055881ac95d3c69f0e5d= 0728d9fefed88 100644 --- a/include/kunit/clk.h +++ b/include/kunit/clk.h @@ -9,6 +9,13 @@ struct device_node; struct of_phandle_args; struct kunit; =20 +struct clk_dummy_context { + struct clk_hw hw; + unsigned long rate; +}; + +extern const struct clk_ops clk_dummy_rate_ops; + struct clk * clk_get_kunit(struct kunit *test, struct device *dev, const char *con_id); struct clk * --=20 2.53.0 From nobody Sun Apr 5 16:22:54 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 6FBAE3C8718 for ; Mon, 23 Mar 2026 17:25:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774286745; cv=none; b=k/DXXtUpAPDwaEWRz4OmyjQSTZeqj4awevlcGLiiTF70rQORC5fiFn4xpyEbY/BQN7EO33Xb9gWrt7X1L2giUsjrsIhP2jPkTNWPgWDSjwMWpKN8HhQex5HTB8OpOg1QOGDVfFnFcu28uFDEmyVSEojbUo6Yczz0ENTO3Yn8+i0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774286745; c=relaxed/simple; bh=CgZwb7h0Lrx3Ro3dOuYbsmKBBaRIB98siIpf9VE69j8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=RRDwpNnEqbtWB5R5BPeToJtjFXwD9hM65uFYm1wsUETVESQzGhNPgH254N5q7ZIEF8++v9O08xUhup6/jOrUrCgxUV2yEHaEMsyKnFd5eQ42RBnfGWZboGXF/koJ+ee4fUTeknGMtGNVpj19MXMyHXymEEu0A03DMiTCHm2+pa8= 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=ctiqItDG; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=g8w3ZXUW; arc=none smtp.client-ip=170.10.129.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="ctiqItDG"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="g8w3ZXUW" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774286742; 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=pupRNbhM9qW5q4wP02mhMBzXmq28/3Y+QgXeGlFMiVM=; b=ctiqItDGku0mJUjok7m/EbxNzuIRvU5R2u7XMaeWT+4Y8qhc22qegRgB6VXz5OU9Rzw5jn ehYgYZS9gtRDaDuAC0WZYzKSJvBy7NYIqxOu1YO1dBhCKmDrrGGuceaQP1dJWsZosVshT1 cinbCH+GoIePwHDEwiIeq5sui+mfua4= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-621-AujmxOYwMOqh3G8_lMeP-A-1; Mon, 23 Mar 2026 13:25:39 -0400 X-MC-Unique: AujmxOYwMOqh3G8_lMeP-A-1 X-Mimecast-MFC-AGG-ID: AujmxOYwMOqh3G8_lMeP-A_1774286738 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-5090e08dcfcso19600371cf.0 for ; Mon, 23 Mar 2026 10:25:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1774286738; x=1774891538; 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=pupRNbhM9qW5q4wP02mhMBzXmq28/3Y+QgXeGlFMiVM=; b=g8w3ZXUW47EW7OwdhCenOo2tDbLNcuzz07Rsclo8sGY13W8WvEdYeOzyf6BVNkA3ki dMwrBesOzX92y2WOKthc8iBoo2W+M3Ixuiv/EqMfLNDAe9OGu7h9cO/SuraNmbEF6nBE vYO8kVtNCl74FpR+XnPH+OogAahOpnaBeGiBfCmZ2VLKcG8tra0CckW1XIzw8dMsJk4r 7qkW8Zp5lM5Hyr3vipZQKplRbCA4bqb64rXmcB7kUfDS7m3krQKugfUKFJS9V/E0lxYS izKinkb8/0U05KgM7DQoQeUpW9qM7V710MWw8Y87+iBsQy//4dbFDVlsLS5PuIHklj4X KE3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774286738; x=1774891538; 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=pupRNbhM9qW5q4wP02mhMBzXmq28/3Y+QgXeGlFMiVM=; b=Qurwqg7p64ShgjPf9NXAmVJuZ5VEsLx2oYhxU3YvmaZoFDTJhC/x88GgIpQsLZqaD7 nADv2i0BJTJZ5SZNn2trDzIHB09hl9xx+D4ccmGhqCE27M3CP2xBJrWgNJgWPIkqPUjn o/U3E17p0ocNPmKOqTk08KDHCtR652A/V4WOvIctiXHl/aTRkR4qWeLsgQQ7nzQ17fp0 kgv8IiaqteYSj055ik8qZr3Rw+zzlgLybrFcfuvRJhRUJTqqS2XepnvT4SHILvUjuMUz p+oEtvR9JG9UOmiVQDJ0j2qyC1wEv1ErMzRx5Z75TC9s17OPENOgfOLhmnFeZkRxXY8S QHlw== X-Forwarded-Encrypted: i=1; AJvYcCUOfZF0O5mt0GR7zTwOEfjDTvcdiMsrz6y1J1b5PjhPtNENin9Lq13XXpdkaEYdHdZ0xI+eipIG8VEq7xg=@vger.kernel.org X-Gm-Message-State: AOJu0YymUtofMzRU26dmwI08DnebVGSc0iElHNzATiU0v7lKAl8RMzHA 3buw18GI8r8HGCyeRV4h1yo139/8T4RbJfhdpq+/wbVTHFY8NY0zxmoJOiQNNSHEboBIGByYxPV Sk9DsW7Xv11F4ZySSkowW7g3Z5RmKgMJC3+rhQhw6FA9A2K5R9IKstmCdwaYc8uzPmQ== X-Gm-Gg: ATEYQzwIy4CM+fB1nlpnTbD/h5obQJUESQXCCdbVis6Qovf8lhybG4bkJPSquaATnW2 KL5qFd0h/AaKdLNhYza2zLorLYz/GzySj3h9vb06rRvkq8wzxGnNrCTzc6EV7y6QtU+qLSxb6pp PEXao/Lf/67W3CFcsqUns4G5G8NiB/6TrhMYS450D5Uj/3YJpHuVFbWwalpY3voo7tcfoP/yeBw jubLy2+FJgg3IKXbxY540fo8pd/YKtgOV+6BOnb6MuESdPMt5JmjUkfG2FoOsuedn6OSqpz26AO 4zsMGC//9veyX6lOQwWWyD7wKO2osYYe2wT5eAXtcK6yR/HyODDQcYzclIi2O4mrYGf/6QNRWfq nXsQWQu/Ueu44heyrI8fOxW5O+o8HUur50h0QoTZo9zG/nxfrI92rgtteFd2T X-Received: by 2002:a05:622a:5c9:b0:509:2455:2b53 with SMTP id d75a77b69052e-50b37545ee8mr209673391cf.49.1774286738272; Mon, 23 Mar 2026 10:25:38 -0700 (PDT) X-Received: by 2002:a05:622a:5c9:b0:509:2455:2b53 with SMTP id d75a77b69052e-50b37545ee8mr209672921cf.49.1774286737627; Mon, 23 Mar 2026 10:25:37 -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-50b36e34f8bsm108249661cf.15.2026.03.23.10.25.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2026 10:25:37 -0700 (PDT) From: Brian Masney Date: Mon, 23 Mar 2026 13:24:53 -0400 Subject: [PATCH v7 2/8] clk: divider: introduce divider kunit tests 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: <20260323-clk-scaling-v7-2-8e7193dc9405@redhat.com> References: <20260323-clk-scaling-v7-0-8e7193dc9405@redhat.com> In-Reply-To: <20260323-clk-scaling-v7-0-8e7193dc9405@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=10994; i=bmasney@redhat.com; s=20250903; h=from:subject:message-id; bh=CgZwb7h0Lrx3Ro3dOuYbsmKBBaRIB98siIpf9VE69j8=; b=owGbwMvMwCW2/dJd9di6A+2Mp9WSGDIPlrdl1V2do+MlynX/s2RngMx7+USWYu/wVZoa1p/Xz GeXcFzYUcrCIMbFICumyLIk16ggInWV7b07miwwc1iZQIYwcHEKwER05jIyrH7LuG3SRmOn4DKX mMXL5CpOlRxO70u6vPk3/2Ph2b/4dzL8D0mMd+pwlP/9mCtylr+3Jk+2R4xo2sILC+3yhBarf3/ MAQA= X-Developer-Key: i=bmasney@redhat.com; a=openpgp; fpr=A46D32705865AA3DDEDC2904B7D2DD275D7EC087 Introduce some kunit tests for the generic clk-divider.c implementation. This test suite demonstrates the current behavior of how a clock can unknowingly change the rate of it's siblings. Some boards are unknowingly dependent on this behavior, and per discussions at the 2025 Linux Plumbers Conference in Tokyo, we can't break the existing behavior. So let's add kunit tests with the current behavior so that we can be made aware if that functionality changes in the future. The tests in this commit use the following simplified clk tree with the initial state: parent 24 MHz / \ child1 child2 24 MHz 24 MHz child1 and child2 both divider-only clocks that have CLK_SET_RATE_PARENT set, and the parent is capable of achieving any rate. For consistency with clk-fixed-rate_test.c and drivers/clk/clk-gate_test.c, the divider tests are setup as it's own separate kernel module. 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/.kunitconfig | 1 + drivers/clk/Kconfig | 7 ++ drivers/clk/Makefile | 1 + drivers/clk/clk-divider_test.c | 226 +++++++++++++++++++++++++++++++++++++= ++++ 4 files changed, 235 insertions(+) diff --git a/drivers/clk/.kunitconfig b/drivers/clk/.kunitconfig index 8a0ea41934a2100e1bb1521ce3ad490baec76ec2..ea05b9a28c8000c647c76c4adf8= 13da97c500ab6 100644 --- a/drivers/clk/.kunitconfig +++ b/drivers/clk/.kunitconfig @@ -4,6 +4,7 @@ CONFIG_OF=3Dy CONFIG_OF_OVERLAY=3Dy CONFIG_COMMON_CLK=3Dy CONFIG_CLK_KUNIT_TEST=3Dy +CONFIG_CLK_DIVIDER_KUNIT_TEST=3Dy CONFIG_CLK_FIXED_RATE_KUNIT_TEST=3Dy CONFIG_CLK_GATE_KUNIT_TEST=3Dy CONFIG_CLK_FD_KUNIT_TEST=3Dy diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig index 8cc300b90b5fd9fb38ce94fcb1098810c3f52c36..ba4af56949e39249652fc414eb2= 3b44aee1d37f5 100644 --- a/drivers/clk/Kconfig +++ b/drivers/clk/Kconfig @@ -550,6 +550,13 @@ config CLK_KUNIT_TEST help Kunit tests for the common clock framework. =20 +config CLK_DIVIDER_KUNIT_TEST + tristate "Basic divider clk type KUnit test" if !KUNIT_ALL_TESTS + depends on KUNIT && CLK_KUNIT_TEST + default KUNIT_ALL_TESTS + help + KUnit tests for the basic divider clk type. + config CLK_FIXED_RATE_KUNIT_TEST tristate "Basic fixed rate clk type KUnit test" if !KUNIT_ALL_TESTS depends on KUNIT diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile index f52cf3ac64fcce7e20f3fd91f837c5096375521a..f11d37cb09423b914d7653fa4c3= fa17370430aa7 100644 --- a/drivers/clk/Makefile +++ b/drivers/clk/Makefile @@ -21,6 +21,7 @@ clk-test-y :=3D clk_test.o \ kunit_clk_hw_get_dev_of_node.dtbo.o \ kunit_clk_parent_data_test.dtbo.o obj-$(CONFIG_COMMON_CLK) +=3D clk-divider.o +obj-$(CONFIG_CLK_DIVIDER_KUNIT_TEST) +=3D clk-divider_test.o obj-$(CONFIG_COMMON_CLK) +=3D clk-fixed-factor.o obj-$(CONFIG_COMMON_CLK) +=3D clk-fixed-rate.o obj-$(CONFIG_CLK_FIXED_RATE_KUNIT_TEST) +=3D clk-fixed-rate-test.o diff --git a/drivers/clk/clk-divider_test.c b/drivers/clk/clk-divider_test.c new file mode 100644 index 0000000000000000000000000000000000000000..2a01b0201e9d919c36bb70eeb21= c9f4ae113254e --- /dev/null +++ b/drivers/clk/clk-divider_test.c @@ -0,0 +1,226 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Kunit tests for clk divider + */ +#include +#include +#include +#include + +#include +#include + +/* 4 ought to be enough for anybody */ +#define CLK_DUMMY_DIV_WIDTH 4 +#define CLK_DUMMY_DIV_FLAGS (CLK_DIVIDER_ONE_BASED | CLK_DIVIDER_ROUND_CLO= SEST) + +struct clk_dummy_div { + struct clk_hw hw; + unsigned int div; +}; + +static unsigned long clk_dummy_div_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct clk_dummy_div *div =3D container_of(hw, struct clk_dummy_div, hw); + + return divider_recalc_rate(hw, parent_rate, div->div, NULL, + CLK_DUMMY_DIV_FLAGS, CLK_DUMMY_DIV_WIDTH); +} + +static int clk_dummy_div_determine_rate(struct clk_hw *hw, + struct clk_rate_request *req) +{ + if (!(clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT) && req->best_parent_rat= e < req->rate) + return -EINVAL; + + return divider_determine_rate(hw, req, NULL, CLK_DUMMY_DIV_WIDTH, CLK_DUM= MY_DIV_FLAGS); +} + +static int clk_dummy_div_set_rate(struct clk_hw *hw, unsigned long rate, + unsigned long parent_rate) +{ + struct clk_dummy_div *div =3D container_of(hw, struct clk_dummy_div, hw); + + div->div =3D divider_get_val(rate, parent_rate, NULL, CLK_DUMMY_DIV_WIDTH, + CLK_DUMMY_DIV_FLAGS); + + return 0; +} + +static const struct clk_ops clk_dummy_div_ops =3D { + .recalc_rate =3D clk_dummy_div_recalc_rate, + .determine_rate =3D clk_dummy_div_determine_rate, + .set_rate =3D clk_dummy_div_set_rate, +}; + +struct clk_rate_change_divider_context { + struct clk_dummy_context parent; + struct clk_dummy_div child1, child2; + struct clk *parent_clk, *child1_clk, *child2_clk; +}; + +struct clk_rate_change_divider_test_param { + const char *desc; + const struct clk_ops *ops; + unsigned int extra_child_flags; +}; + +static const struct clk_rate_change_divider_test_param +clk_rate_change_divider_test_regular_ops_params[] =3D { + { + .desc =3D "regular_ops", + .ops =3D &clk_dummy_div_ops, + .extra_child_flags =3D 0, + }, +}; + +KUNIT_ARRAY_PARAM_DESC(clk_rate_change_divider_test_regular_ops, + clk_rate_change_divider_test_regular_ops_params, desc) + +static int clk_rate_change_divider_test_init(struct kunit *test) +{ + const struct clk_rate_change_divider_test_param *param =3D test->param_va= lue; + struct clk_rate_change_divider_context *ctx; + int ret; + + ctx =3D kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL); + if (!ctx) + return -ENOMEM; + test->priv =3D ctx; + + ctx->parent.hw.init =3D CLK_HW_INIT_NO_PARENT("parent", &clk_dummy_rate_o= ps, 0); + ctx->parent.rate =3D 24 * HZ_PER_MHZ; + ret =3D clk_hw_register_kunit(test, NULL, &ctx->parent.hw); + if (ret) + return ret; + + ctx->child1.hw.init =3D CLK_HW_INIT_HW("child1", &ctx->parent.hw, + param->ops, + CLK_SET_RATE_PARENT | param->extra_child_flags); + ctx->child1.div =3D 1; + ret =3D clk_hw_register_kunit(test, NULL, &ctx->child1.hw); + if (ret) + return ret; + + ctx->child2.hw.init =3D CLK_HW_INIT_HW("child2", &ctx->parent.hw, + param->ops, + CLK_SET_RATE_PARENT | param->extra_child_flags); + ctx->child2.div =3D 1; + ret =3D clk_hw_register_kunit(test, NULL, &ctx->child2.hw); + if (ret) + return ret; + + ctx->parent_clk =3D clk_hw_get_clk(&ctx->parent.hw, NULL); + ret =3D clk_prepare_enable(ctx->parent_clk); + if (ret) + return ret; + + ctx->child1_clk =3D clk_hw_get_clk(&ctx->child1.hw, NULL); + clk_prepare_enable(ctx->child1_clk); + if (ret) + return ret; + + ctx->child2_clk =3D clk_hw_get_clk(&ctx->child2.hw, NULL); + clk_prepare_enable(ctx->child2_clk); + if (ret) + return ret; + + return 0; +} + +static void clk_rate_change_divider_test_exit(struct kunit *test) +{ + struct clk_rate_change_divider_context *ctx =3D test->priv; + + clk_put(ctx->parent_clk); + clk_put(ctx->child1_clk); + clk_put(ctx->child2_clk); +} + +/* + * Test that, for a parent with two divider-only children with CLK_SET_RAT= E_PARENT set + * and one requests a rate compatible with the existing parent rate, the p= arent and + * sibling rates are not affected. + */ +static void clk_test_rate_change_divider_1(struct kunit *test) +{ + struct clk_rate_change_divider_context *ctx =3D test->priv; + int ret; + + KUNIT_ASSERT_EQ(test, clk_get_rate(ctx->parent_clk), 24 * HZ_PER_MHZ); + KUNIT_ASSERT_EQ(test, clk_get_rate(ctx->child1_clk), 24 * HZ_PER_MHZ); + KUNIT_EXPECT_EQ(test, ctx->child1.div, 1); + KUNIT_ASSERT_EQ(test, clk_get_rate(ctx->child2_clk), 24 * HZ_PER_MHZ); + KUNIT_EXPECT_EQ(test, ctx->child2.div, 1); + + ret =3D clk_set_rate(ctx->child1_clk, 6 * HZ_PER_MHZ); + KUNIT_ASSERT_EQ(test, ret, 0); + + KUNIT_EXPECT_EQ(test, clk_get_rate(ctx->parent_clk), 24 * HZ_PER_MHZ); + KUNIT_EXPECT_EQ(test, clk_get_rate(ctx->child1_clk), 6 * HZ_PER_MHZ); + KUNIT_EXPECT_EQ(test, ctx->child1.div, 4); + KUNIT_EXPECT_EQ(test, clk_get_rate(ctx->child2_clk), 24 * HZ_PER_MHZ); + KUNIT_EXPECT_EQ(test, ctx->child2.div, 1); +} + +/* + * Test that, for a parent with two divider-only children with CLK_SET_RAT= E_PARENT + * set and one requests a rate incompatible with the existing parent rate,= the + * sibling rate is also affected. This preserves existing behavior in the = clk + * core that some drivers may be unknowingly dependent on. + */ +static void clk_test_rate_change_divider_2_v1(struct kunit *test) +{ + struct clk_rate_change_divider_context *ctx =3D test->priv; + int ret; + + KUNIT_ASSERT_EQ(test, clk_get_rate(ctx->parent_clk), 24 * HZ_PER_MHZ); + KUNIT_ASSERT_EQ(test, clk_get_rate(ctx->child1_clk), 24 * HZ_PER_MHZ); + KUNIT_EXPECT_EQ(test, ctx->child1.div, 1); + KUNIT_ASSERT_EQ(test, clk_get_rate(ctx->child2_clk), 24 * HZ_PER_MHZ); + KUNIT_EXPECT_EQ(test, ctx->child2.div, 1); + + ret =3D clk_set_rate(ctx->child1_clk, 32 * HZ_PER_MHZ); + KUNIT_ASSERT_EQ(test, ret, 0); + + /* + * The last sibling rate change is the one that was successful, and + * wins. The parent, and two children are all changed to 32 MHz. This + * keeps the long-standing behavior of the clk core that some drivers + * may be unknowingly dependent on. + */ + KUNIT_EXPECT_EQ(test, clk_get_rate(ctx->parent_clk), 32 * HZ_PER_MHZ); + KUNIT_EXPECT_EQ(test, clk_get_rate(ctx->child1_clk), 32 * HZ_PER_MHZ); + KUNIT_EXPECT_EQ(test, ctx->child1.div, 1); + KUNIT_EXPECT_EQ(test, clk_get_rate(ctx->child2_clk), 32 * HZ_PER_MHZ); + KUNIT_EXPECT_EQ(test, ctx->child2.div, 1); +} + +static struct kunit_case clk_rate_change_divider_cases[] =3D { + KUNIT_CASE_PARAM(clk_test_rate_change_divider_1, + clk_rate_change_divider_test_regular_ops_gen_params), + KUNIT_CASE_PARAM(clk_test_rate_change_divider_2_v1, + clk_rate_change_divider_test_regular_ops_gen_params), + {} +}; + +/* + * Test suite that creates a parent with two divider-only children, and + * documents the behavior of what happens to the sibling clock when one ch= ild + * changes its rate. + */ +static struct kunit_suite clk_rate_change_divider_test_suite =3D { + .name =3D "clk-rate-change-divider", + .init =3D clk_rate_change_divider_test_init, + .exit =3D clk_rate_change_divider_test_exit, + .test_cases =3D clk_rate_change_divider_cases, +}; + +kunit_test_suites( + &clk_rate_change_divider_test_suite, +); + +MODULE_DESCRIPTION("Kunit tests for clk divider"); +MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING"); +MODULE_LICENSE("GPL"); --=20 2.53.0 From nobody Sun Apr 5 16:22:54 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 2608C3C7DEB for ; Mon, 23 Mar 2026 17:25:41 +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=1774286743; cv=none; b=Sc6gJFluZ9cEoLqFZrqbM1GWUnvQF/h/5d+GMcZH4l8OG+78kkHj9MTnAmvQb/58NDUZtLgkZI5RnuGVzG9VdDxCz911FFiOMLQpsDJTro6NMJYT8O/P78PLuj9MlvPHPGIHCdTCfkiLOmghfvi3Qj3VaK6ic2wfn+CHf3FLt58= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774286743; c=relaxed/simple; bh=6Hn+W3p9K8hX9s8hBstWGFWtJdnC5xLfXEUhWSlPJkw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QVTU0qi7YLuSqyGGjLLRHrUfcxgNKb1bTgUXzWsOQcQlFgNczZ8ZFTiiOMSCu3UBSI4TkDVtESzbtJjhtmEYTP7s5+guLXZc0HgggKOv+wWz6FBrUGANU++kTVhglNKhlCDCU1C3Zy27+El0SwvetqrCz2SXPII0UZxifkItNlE= 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=QPZAqhbq; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=aYUzyoX1; 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="QPZAqhbq"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="aYUzyoX1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774286741; 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=0wEqBpiQa/bVt9oxxXdYY2tbaf0jiNQNtHenrP9Zr9A=; b=QPZAqhbqVOBODbTWbgdouTfyC1q+v4qD9z6dU14KbkAAVsoR2mmz3niqKEKZToqHoPmsgq IEwnOb/la/gUWDYLbnJm7HipIbQYSZ/ILwbRh7836Y3OXub122Ct0zTWsoKTUEINY6blXm FFm684zW+y/roJr5umO4khVFg99k7n0= 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-84-OrTNcJ_dOcG9P7A7eWY6Uw-1; Mon, 23 Mar 2026 13:25:40 -0400 X-MC-Unique: OrTNcJ_dOcG9P7A7eWY6Uw-1 X-Mimecast-MFC-AGG-ID: OrTNcJ_dOcG9P7A7eWY6Uw_1774286739 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-50b4fe4ff7bso179406661cf.0 for ; Mon, 23 Mar 2026 10:25:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1774286739; x=1774891539; 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=0wEqBpiQa/bVt9oxxXdYY2tbaf0jiNQNtHenrP9Zr9A=; b=aYUzyoX1qWlNV1ol7cISTdcqCdcj9Zp2wO/JUYBok20IIpgi3Dudx0rqIfZPeFpcqV KfgIAF5+ueVZLLxh4aX+3kJn5Y46VBpQqkmOF1+eXpuQSP8fbmWVXg6OGuo8RfUfz69Z bn1ne7u5Us5YRYs1gTNQJsNldCmLBQ6VL1eQTdqc+1Xp4N28HDTl9A50KSO4geNDLbHG cF5tmRdM5A3g0KgjzLbRIqhbQwEaOl920doRJ8DF8zrwk0QwiZ+5byoszr/MXF2GDuiw qxx9WoRcCyEPQ/B/cSHfCUexDFgP3MH2rT/dqa0P8oeD6b8QtXeei5ls9+RALXDndc7u c7Gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774286739; x=1774891539; 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=0wEqBpiQa/bVt9oxxXdYY2tbaf0jiNQNtHenrP9Zr9A=; b=ewNIu/ZHGUSBmXns1T9NyPU5Hy4Q6mkEV3kAsrqjg1ApOpJmeACyBv97wAU9hKNmQn pyvTOzJLlXydFqagfMi6+Z6aBE4nU61RX4Y6eOTU1JNC7mec3TD/hblRBYist7TwHTgj RUMQ2IQu5pafTmq7xs9QeMH03xMjCOo7TJAVUCCE4cc6RQ1VYmHQLuSGm3eDMHbn/HKM eYStlaHKb0w5q2XStNuKE//PLVxtnDhnmok//UNAz27ASjsr2bGkKP0AfWIw9l1keIDc nosNGTPrM1nte19n455IzZiFWgfbDkxEZSVxrgSHDB2+3NMWItg6vWCa1skxrmmgycsZ 4iVQ== X-Forwarded-Encrypted: i=1; AJvYcCWt7EVlDORCJ5xtTzGk3Ki9VdT2FV8c2Ev6C0mzf2C/9iAIi8gk6PKc9BDKBj53Ns1UVT5G2imWLuspseQ=@vger.kernel.org X-Gm-Message-State: AOJu0YyWJsjzDSLf+xXqcdNVkOtPvR3WlPA/mzcEP6jiVdpNTnIZ4Y1o xyYK5vvRLhU2igxbSDVPL4OfDcbkbLPSHA+rYrsFhjjKbSMxy7lUUVoVchrsQ9qjFb+4nQrl4pZ +ZUjMdRLM9xIP9zVkaP//vxdk6NPJ7lL3cEGASaH/2RYfOLnQaOH9cPbGahdf/eBsCg== X-Gm-Gg: ATEYQzz1NupNUxFVDWMDQrO9/mE6qWFhhZhxlI22sSGYWofxtpdKLjBrc6hjOIh2k/r clSXxLbpLWyG9DQJ2FTEno06tTzrTNfEWNRfuvF+q85z02qK+nc13DHeVuCmK6jWjVMOh6f3IoV Ys7DqdTxqGxZHG1aAkBkOO4DO4wGQ+wV6ZAJGgJyTkLTGQVYHSvNG/5lKRtQDWi/Wk7mm4QFVJC BtEfXRsLqtBDFV+b79YG8ZJVVCSw00h4CnJbOezgRSsL1+B11TKSkCP7k4Ya5Qy3y9hKwqevQY8 GKnM+hj0wUxHBKiewuXLKmMFq7cSnC+XWfRxciNdXp9mbQdL1ZnPybmZB8ZgFD0OXF8vj27tUVA w/iHC7XhRXWg2DaANSn8lH+RdCz9dDFXRVCcPhNX267+d4UpJfsa0ai9eO+og X-Received: by 2002:a05:622a:454:b0:4ee:1bdb:a547 with SMTP id d75a77b69052e-50b6ed78949mr6346491cf.14.1774286739530; Mon, 23 Mar 2026 10:25:39 -0700 (PDT) X-Received: by 2002:a05:622a:454:b0:4ee:1bdb:a547 with SMTP id d75a77b69052e-50b6ed78949mr6346071cf.14.1774286739079; Mon, 23 Mar 2026 10:25:39 -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-50b36e34f8bsm108249661cf.15.2026.03.23.10.25.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2026 10:25:38 -0700 (PDT) From: Brian Masney Date: Mon, 23 Mar 2026 13:24:54 -0400 Subject: [PATCH v7 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: <20260323-clk-scaling-v7-3-8e7193dc9405@redhat.com> References: <20260323-clk-scaling-v7-0-8e7193dc9405@redhat.com> In-Reply-To: <20260323-clk-scaling-v7-0-8e7193dc9405@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=3842; i=bmasney@redhat.com; s=20250903; h=from:subject:message-id; bh=6Hn+W3p9K8hX9s8hBstWGFWtJdnC5xLfXEUhWSlPJkw=; b=owGbwMvMwCW2/dJd9di6A+2Mp9WSGDIPlreX/JrC4KeS9/6MCM/inac2P1sbZpI55d2F9yK7c 0ozj1x+1VHKwiDGxSArpsiyJNeoICJ1le29O5osMHNYmUCGMHBxCsBEVm9j+F942/BMvvSymsfa dtui2dasmLfu2LVaVbclBXfjp7u3LOdj+F+pefjTnOULv59paOMpTDzMICtx2fu1SNTnucsDqxo 4ZvADAA== 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 | 49 ++++++++++++++++++++++++++++++++++++++++= ++++ include/linux/clk-provider.h | 2 ++ 2 files changed, 51 insertions(+) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index 47093cda9df32223c1120c3710261296027c4cd3..f1afd6c93eba49b9fc6c5c0e1db= 11d46c79069e9 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,54 @@ 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; + + 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 (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 From nobody Sun Apr 5 16:22:54 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 34A8A3C73CB for ; Mon, 23 Mar 2026 17:25:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774286745; cv=none; b=H7SdCligM3jAesjlxNd9+hiYbue7NGLTzV78ywqI9/rczPON6FncpRTNQSS/js8Iwycfzk1sZQSqXTAR80OMlTw/vrUiAcw1LK+j1BVzrHdLJW1QEswxuCUNpnYkNjrMXettq3X/Eio+Bh40mPmFWQvQVSLO7g7eFhcg67/TG/w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774286745; c=relaxed/simple; bh=sdglBIrVf9XMFJdnwd7fyg9fFtXfQnVciJoWpfDXV38=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jpmBo/8+ZV2xQoDpYjOLPFuXVeUCm5HqReKtnmbDWM2mN+cYkOx8eoOvajaylYRbUidAg8Ufs1Gzhue2SGAqgyFTdGv2uToWxPpfa3r188bgpfZXVB2iKopUUj2AfZhzzqdmcbBoXpw0fNqtXjH16fzKvhd/N69MfQhI8HEQlsc= 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=Ct0ExBVH; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=hyBS9JKo; arc=none smtp.client-ip=170.10.129.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="Ct0ExBVH"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="hyBS9JKo" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774286743; 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=KTykAjUDSJWq2f3i10F+kRt97VvDrBvWNt+eUgSz3Ow=; b=Ct0ExBVHQCfm8n+wL/Wc2RiK44Afv1DfHZ7Qwf6hjEvNHw5pS0+SlS5XuETIIY3isvw8GJ cXM/ONRjezilJm6TWDaXwj7DhFMCWvMDcG8aqrUwGVI/klPBaiGgJV2drUyxu8r7oYpONm zLk+zcqeY5cbY0IAIVrqppqwd3fUYhk= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-347-s11yZFbnPgCkx9SyhOnP0g-1; Mon, 23 Mar 2026 13:25:42 -0400 X-MC-Unique: s11yZFbnPgCkx9SyhOnP0g-1 X-Mimecast-MFC-AGG-ID: s11yZFbnPgCkx9SyhOnP0g_1774286741 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-5090cc6a7d2so264474571cf.2 for ; Mon, 23 Mar 2026 10:25:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1774286741; x=1774891541; 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=KTykAjUDSJWq2f3i10F+kRt97VvDrBvWNt+eUgSz3Ow=; b=hyBS9JKofQNjY8Y5k2GfRUwLMiqgAKpvKd8mS+vR511lz1wWKEm/wnSJQicjDWLPij HfCyB9ySdKQPcpZEs0KGfWDZ9mpOOcJvulrmi4fWxHWwd7gLLYjepGGbDzFiJ/h/v1sz 8lw6CQEPe9Bqri30hcJ0ygu9druYnWBZ9ANrIkrZmyrctQvmwllwBG0Qw8rTRyvoRUq3 OGYl0I7aMDeQMpZ7u4joj5+yG9htmfrNK06teBo//y4hHSdLE0a9gPmyZPmcytwLhPoW 70vnDY1JPopGhj6b/3YBpy8+36ZqYJc5GmWmp5cK01dl9X5QTtzWy/jIxcIi7bDKbzcw 1w3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774286741; x=1774891541; 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=KTykAjUDSJWq2f3i10F+kRt97VvDrBvWNt+eUgSz3Ow=; b=baxOoSiD4UY0HS9Undg5ZQ9y2Z4URl1+Jwl0qseEdz7oUOMYINSNKWi895GjPzISgJ Tc0dB0TWk7K0JguwT0m3W8mZrCX5z7ADqUJncJlbUF8Ed3I3GoWrTruHuPHiHOXTJ49L zh75GbHRuuXBg3MCFcuQsgzzqfTAepranbpyBbCMjZaEYYgG4WpPP7i1a9vvFpejmGNv I82TzSRb4+4xKXsctJFkjrEKUfSBcxaysq2KiRYp7pf5WGthIaDwoOgXaLquF0Y3xB97 Obsvi/04u7ixEX65rxpf4C2FTBiMS7wd/L0P2xqPYbCZeLo/8mZYHDljEWjkeoc4gicj 1DKQ== X-Forwarded-Encrypted: i=1; AJvYcCUlBlbvs4uV2to9YixWQyTzH1qJkVY/ciXip05eeTZVbviwoQX2QFENZouXuXdzcxBxlazzDAznii4eP5c=@vger.kernel.org X-Gm-Message-State: AOJu0YwSZsG56nB48Dpqzpg3uLF2jGK5o6fFEiXINT1D0Gzsh3v5IwPV rrxhtfUCjG4fWmRGLqXFx34PUB/u/4rs9tk73qSK/jN0zS4vE806AjubRQWizXG93do8kK6i8vE IuI7Mi+6bi+Y4gmhQWfTmdXu2xYL0yz8ae7+3jD0o2oo1AbTX6mBbP6AbgnE0Jt+3Hg== X-Gm-Gg: ATEYQzxdoxeceIHQt8JtZ/tmfak25ZnvbvfMpb6Le4kK9BJ3CE5B4xZWhj6bpU36mWd 64nyzKLMp4W8+3y4f+ZYKDLhF5s+yXCuCSnMDdGbqm81jubtEAuoz+/DWnzWzz6UJGnhKLCiaT6 2LPZwmJGc6CRcfOfMG6GLTuKODjNkE9EZZHX9d8EcDQ6jOG9Jdlf1IPm0fWzB4dTUhj3I+6rDog uYU2WWQAuMr4SI2HilBztej+mfMir0H43LqhGS5p/WQI8DtcTu+1aJ3pTKvKlEN2bonw/NQ06xy 8+M1bOGuROzYv1wMWm+6KMF3ndbzaeKu7UAMSMsw+M2zS80ZVZ9uO54A4k+6gj2x/5pukPt0pGx /eLGvwUFMoyggUJXS4ojH4sK3Z+dPWYGtKie5kHZ5rorkkCPB5rqEeUdGrOtj X-Received: by 2002:ac8:59d5:0:b0:50b:559e:fb09 with SMTP id d75a77b69052e-50b559f063fmr90674201cf.11.1774286741284; Mon, 23 Mar 2026 10:25:41 -0700 (PDT) X-Received: by 2002:ac8:59d5:0:b0:50b:559e:fb09 with SMTP id d75a77b69052e-50b559f063fmr90673591cf.11.1774286740676; Mon, 23 Mar 2026 10:25:40 -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-50b36e34f8bsm108249661cf.15.2026.03.23.10.25.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2026 10:25:40 -0700 (PDT) From: Brian Masney Date: Mon, 23 Mar 2026 13:24:55 -0400 Subject: [PATCH v7 4/8] clk: divider: test: introduce additional test case for parent rate change 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: <20260323-clk-scaling-v7-4-8e7193dc9405@redhat.com> References: <20260323-clk-scaling-v7-0-8e7193dc9405@redhat.com> In-Reply-To: <20260323-clk-scaling-v7-0-8e7193dc9405@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=5709; i=bmasney@redhat.com; s=20250903; h=from:subject:message-id; bh=sdglBIrVf9XMFJdnwd7fyg9fFtXfQnVciJoWpfDXV38=; b=owGbwMvMwCW2/dJd9di6A+2Mp9WSGDIPlnc4Xbb6dWF/8pq5jOvSmEvD7SY0uueslZaR0Zh3X 8n83SGdjlIWBjEuBlkxRZYluUYFEamrbO/d0WSBmcPKBDKEgYtTACZy/xojw881i96Ehj9tPb3k 1LMVF5NfP5Rce0vWjo2TaeIOh/S/AY4M/5Ndsp3nLH9f9SctYEmjY5q5b3W4gdsss0MfTtxcnlz GwAcA X-Developer-Key: i=bmasney@redhat.com; a=openpgp; fpr=A46D32705865AA3DDEDC2904B7D2DD275D7EC087 Add a test case where the parent clk rate is changed to a rate that's acceptable to both children, however the sibling clk rate is affected. The tests in this commit use the following simplified clk tree with the initial state: parent 24 MHz / \ child1 child2 24 MHz 24 MHz child1 and child2 both divider-only clocks that have CLK_SET_RATE_PARENT set, and the parent is capable of achieving any rate. child1 requests 32 MHz, and the tree should end up with the state: parent 96 MHz / \ child1 child2 32 MHz 24 MHz However, child2 ends up with it's parent rate due to the way the clk core currently handles rate changes. parent 96 MHz / \ child1 child2 32 MHz 96 MHz ^^^^^^ Incorrect. Should be 24 MHz. Let's document this behavior with a kunit test since some boards are unknowingly dependent on this behavior. 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-divider_test.c | 70 ++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 70 insertions(+) diff --git a/drivers/clk/clk-divider_test.c b/drivers/clk/clk-divider_test.c index 2a01b0201e9d919c36bb70eeb21c9f4ae113254e..95a55835a29065fede0426f1c15= ec158e8a703c1 100644 --- a/drivers/clk/clk-divider_test.c +++ b/drivers/clk/clk-divider_test.c @@ -54,6 +54,26 @@ static const struct clk_ops clk_dummy_div_ops =3D { .set_rate =3D clk_dummy_div_set_rate, }; =20 +static int clk_dummy_div_lcm_determine_rate(struct clk_hw *hw, + struct clk_rate_request *req) +{ + struct clk_hw *parent_hw =3D clk_hw_get_parent(hw); + + if (!(clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT) && req->best_parent_rat= e < req->rate) + return -EINVAL; + + req->best_parent_rate =3D clk_hw_get_children_lcm(parent_hw, hw, req->rat= e); + req->best_parent_hw =3D parent_hw; + + return divider_determine_rate(hw, req, NULL, CLK_DUMMY_DIV_WIDTH, CLK_DUM= MY_DIV_FLAGS); +} + +static const struct clk_ops clk_dummy_div_lcm_ops =3D { + .recalc_rate =3D clk_dummy_div_recalc_rate, + .determine_rate =3D clk_dummy_div_lcm_determine_rate, + .set_rate =3D clk_dummy_div_set_rate, +}; + struct clk_rate_change_divider_context { struct clk_dummy_context parent; struct clk_dummy_div child1, child2; @@ -78,6 +98,18 @@ clk_rate_change_divider_test_regular_ops_params[] =3D { KUNIT_ARRAY_PARAM_DESC(clk_rate_change_divider_test_regular_ops, clk_rate_change_divider_test_regular_ops_params, desc) =20 +static const struct clk_rate_change_divider_test_param +clk_rate_change_divider_test_lcm_ops_v1_params[] =3D { + { + .desc =3D "lcm_ops_v1", + .ops =3D &clk_dummy_div_lcm_ops, + .extra_child_flags =3D 0, + }, +}; + +KUNIT_ARRAY_PARAM_DESC(clk_rate_change_divider_test_lcm_ops_v1, + clk_rate_change_divider_test_lcm_ops_v1_params, desc) + static int clk_rate_change_divider_test_init(struct kunit *test) { const struct clk_rate_change_divider_test_param *param =3D test->param_va= lue; @@ -197,11 +229,49 @@ static void clk_test_rate_change_divider_2_v1(struct = kunit *test) KUNIT_EXPECT_EQ(test, ctx->child2.div, 1); } =20 +/* + * Test that, for a parent with two divider-only children with CLK_SET_RAT= E_PARENT + * set and one requests a rate incompatible with the existing parent rate,= the + * sibling rate is also affected. This preserves existing behavior in the = clk + * core that some drivers may be unknowingly dependent on. This test + * demonstrates that even if the clk provider picks a parent rate that's + * suitable for both children, the child's rate change also affects the + * sibling's rate with the v1 rate negotiation logic. + */ +static void clk_test_rate_change_divider_3_v1(struct kunit *test) +{ + struct clk_rate_change_divider_context *ctx =3D test->priv; + int ret; + + KUNIT_ASSERT_EQ(test, clk_get_rate(ctx->parent_clk), 24 * HZ_PER_MHZ); + KUNIT_ASSERT_EQ(test, clk_get_rate(ctx->child1_clk), 24 * HZ_PER_MHZ); + KUNIT_EXPECT_EQ(test, ctx->child1.div, 1); + KUNIT_ASSERT_EQ(test, clk_get_rate(ctx->child2_clk), 24 * HZ_PER_MHZ); + KUNIT_EXPECT_EQ(test, ctx->child2.div, 1); + + ret =3D clk_set_rate(ctx->child1_clk, 32 * HZ_PER_MHZ); + KUNIT_ASSERT_EQ(test, ret, 0); + + /* + * With LCM-based coordinated rate changes, the parent should be at + * 96 MHz (LCM of 32 and 24), child1 at 32 MHz, and child2 at 24 MHz. + * However, the clk core by default will clobber the sibling clk rate, + * so the sibling gets the parent rate of 96 MHz. + */ + KUNIT_EXPECT_EQ(test, clk_get_rate(ctx->parent_clk), 96 * HZ_PER_MHZ); + KUNIT_EXPECT_EQ(test, clk_get_rate(ctx->child1_clk), 32 * HZ_PER_MHZ); + KUNIT_EXPECT_EQ(test, ctx->child1.div, 3); + KUNIT_EXPECT_EQ(test, clk_get_rate(ctx->child2_clk), 96 * HZ_PER_MHZ); + KUNIT_EXPECT_EQ(test, ctx->child2.div, 1); +} + static struct kunit_case clk_rate_change_divider_cases[] =3D { KUNIT_CASE_PARAM(clk_test_rate_change_divider_1, clk_rate_change_divider_test_regular_ops_gen_params), KUNIT_CASE_PARAM(clk_test_rate_change_divider_2_v1, clk_rate_change_divider_test_regular_ops_gen_params), + KUNIT_CASE_PARAM(clk_test_rate_change_divider_3_v1, + clk_rate_change_divider_test_lcm_ops_v1_gen_params), {} }; =20 --=20 2.53.0 From nobody Sun Apr 5 16:22:54 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 691453C73D3 for ; Mon, 23 Mar 2026 17:25:46 +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=1774286748; cv=none; b=isC/04glpKzkCvUugd4ntc1SBjs3+8tXk9XEwmcEQQucnCMIXrIZRQB8a77LoSEnOMjsT/kFS6n/CxgIeqBI4g5Pa8e6Neg3sYWUtPyrrmv/RYkiRgrLKKhQFOONkKTVP8pOT0rQChxlekZ8eu5YSebO6WXQmLiVEzM+kGxSxQU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774286748; c=relaxed/simple; bh=Vb1zqZZDcPSmNYKZywOXTmBgHYJOa04VcbDUF/lQWGc=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=W5YkVX0pcft9Hrh+8sBFHD6TQ2LRQtND030jcjMh7iLz5xxsZuEHzblLCz+pdYG8MN0PH2fxc4bji85YjVDOcmlumN5KdoSuiMaTcHxaRo7PmrSeD994U+o15hXppqxjoK9e9JUN9ahv+HItzjh0gdVYOk+HXw/1l2HLIiXqobk= 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=OnDJWAxn; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=Yv7Bk9xE; 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="OnDJWAxn"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="Yv7Bk9xE" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774286745; 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=3zIp/d5/hztf4MB9KAZJz0xahQcJa2jv/x4ruis54xg=; b=OnDJWAxnQupS61vYjzak46WOFZYB6DYIZxvZlWfZv92Aj4jd6Dor1FWphNKe9a1jzhC7GN T5ywBb4zD4K29L+WmZWEdd/hLUC5oJ0CT9V2XwO+1yF7MmGlPiHXx58E3TcSyxaCfcMoI8 oW/oz190zylhJZDDcVMVpWsO0Ekcg6M= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-596-ctZkf3E2O9yh6Nm5NPkGmg-1; Mon, 23 Mar 2026 13:25:43 -0400 X-MC-Unique: ctZkf3E2O9yh6Nm5NPkGmg-1 X-Mimecast-MFC-AGG-ID: ctZkf3E2O9yh6Nm5NPkGmg_1774286743 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-50b5f675be9so111241111cf.0 for ; Mon, 23 Mar 2026 10:25:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1774286743; x=1774891543; 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=3zIp/d5/hztf4MB9KAZJz0xahQcJa2jv/x4ruis54xg=; b=Yv7Bk9xE+vh6J1CPof8eXfFa0UBNlgfNMoqq+EctFsa9fzOFmC1+mO/EVVYnlPk7Sl g+yy+kcIuI49ljzL7yuJOtUkwnse6NqpevUG5kydgWmOQxCaehG+p7HRoQEsVC9vgoqH j57yVXsZftqMMJ32PMbvyxrHDkiy36JtfkDO16esDAGhtFa/UvI4An/51KJNQVoF3b7/ UQiRCHIzCACF5dhPJ+oaWERySDC9dCr3Bx0XraXm4UmpMwlqAn+e6M4vNj4/EjkdqfF0 eNqcB+lvtKNQzkCDVYxBZFMc+z8S554Ppg0+vgSpM/NmsP2f2vNVyh9kJHjQUkEEftcc 2Y9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774286743; x=1774891543; 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=3zIp/d5/hztf4MB9KAZJz0xahQcJa2jv/x4ruis54xg=; b=TZW3hf05vt0QoSc5wlngpOXFVRMc4WYMJpkDhso2PEN0LRApZjnpwFO8aQ6LpBO6mv 6WVWraXCOtWZdbShBemKCpHNxwk3RUtw6OOISGbbZypa6Bgmp+0w7HJpM2CkHq2eOyQI RdEksMlZ43a2ur6go7XeOROuUo11oLpXvH9fQsSOGx0EAm9rBdAbcmfdS3OFpm1wXur/ P/0fo8KgptAIoMXCJRtknaSTFS730QvdiJ1YpQamVJfwaLp6Pkbbiu3isABnpjhqGk7t L29IAOapOeWIL6GLgAu7X8LwWFjoU62ucAz03D4uzBnzL0SflW5GS4XwKuzSvrUPcv02 MTdg== X-Forwarded-Encrypted: i=1; AJvYcCVC5Qrv4476r4sFLt3jJBEMYKkp5z2KT2wZ06YxMTTx4T9yMLRDQwc0kHLs8wkOAIibrTrpYFthWUeE+yU=@vger.kernel.org X-Gm-Message-State: AOJu0YzD8/kIqlFeYmQzYZWVt4bVcfibKWCZ7xKoqz/WycPQ64nuFf3C 1vvCAoAJ3Qsc+lneCenBoNEkfA7bjGo5w3acwmaYA7239H9HEkCSvwnB3Xk4/SBKBWPJaKFdLZ1 HqbjtIH7bVZ0o9GIzeIOv3DkzNpAQTcccoRbZkgzbAEWfRreAhWqxCuelXqRoq4P/2w== X-Gm-Gg: ATEYQzz8gFbqTqULi+2tBqeylMsA5oHXlnJd1zt1+yT6G6Q9rt8xJH9OEjmUlF7RZo/ iSnxNVRIXwAV8PK4tsTr6rbgk3ki8jNGng+irZDQMxPWGNJ2sIB0c5eP7KYDh01z7FgWXy5TxtQ gtQ50jnKw0s4kZN6X6GY98eFPdqeT147qTu7/W3q33UHKciHiO3j+tCcfGR5cDaGxqhbBO6KdWD 1nNT+qkeJ79WxiAXP8KFYyEsiGq1/IPKrcZaDJkK3Lm98ZVkOJTKZBqVbU61Rfw5K8W14R5ATmY VEeJe5K7Rg/tYdg30a5wz+ECxQUuCb4TFQ/sA/iNhgjp+mML+qtPG7w7r4AJ50WRCSHAhrKWl8E 9aFTD/WZ6LHyXKU3EqrbIXwngimHS2G/pP9rqWYH1fO4/8/hWH8AINjfe2+Ll X-Received: by 2002:a05:622a:1113:b0:50b:5276:ed6c with SMTP id d75a77b69052e-50b52770899mr103573491cf.68.1774286743086; Mon, 23 Mar 2026 10:25:43 -0700 (PDT) X-Received: by 2002:a05:622a:1113:b0:50b:5276:ed6c with SMTP id d75a77b69052e-50b52770899mr103572851cf.68.1774286742392; Mon, 23 Mar 2026 10:25:42 -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-50b36e34f8bsm108249661cf.15.2026.03.23.10.25.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2026 10:25:41 -0700 (PDT) From: Brian Masney Date: Mon, 23 Mar 2026 13:24:56 -0400 Subject: [PATCH v7 5/8] clk: introduce new flag CLK_V2_RATE_NEGOTIATION for sensitive clocks 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: <20260323-clk-scaling-v7-5-8e7193dc9405@redhat.com> References: <20260323-clk-scaling-v7-0-8e7193dc9405@redhat.com> In-Reply-To: <20260323-clk-scaling-v7-0-8e7193dc9405@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=7222; i=bmasney@redhat.com; s=20250903; h=from:subject:message-id; bh=Vb1zqZZDcPSmNYKZywOXTmBgHYJOa04VcbDUF/lQWGc=; b=owGbwMvMwCW2/dJd9di6A+2Mp9WSGDIPlnds2GVt/Uc628/nzqfmc7MuzvgXuvK+Vc66htaaG yw9ayQMOkpZGMS4GGTFFFmW5BoVRKSusr13R5MFZg4rE8gQBi5OAZjIoQiG/55XU5ZL9d3qXzuz wdHFleOSbtJCy5bvMevZJbiWczZYyzP8ZrV4d3qFVuGvNc13ma9LTn1cWhQ5a37HHv23bi7lZxY J8wEA X-Developer-Key: i=bmasney@redhat.com; a=openpgp; fpr=A46D32705865AA3DDEDC2904B7D2DD275D7EC087 As demonstrated by the kunit tests, clk_calc_subtree() in the clk core can overwrite a sibling clk with the parent rate. Clocks that are used for some subsystems like DRM and sound are particularly sensitive to this issue. I consider this to be a logic bug in the clk subsystem, however this functionality has existed since the clk core was introduced with commit b2476490ef11 ("clk: introduce the common clock framework"), and some boards are unknowingly dependent on this behavior. Let's add support for a v2 rate negotiation logic that addresses the logic error. Clks can opt into this new behavior by adding the flag CLK_V2_RATE_NEGOTIATION. 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 | 58 ++++++++++++++++++++++++++++++++++------= ---- include/linux/clk-provider.h | 3 +++ 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c index f1afd6c93eba49b9fc6c5c0e1db11d46c79069e9..514f2e2eb62a09df4f797b0207a= a9b1448ddaf3d 100644 --- a/drivers/clk/clk.c +++ b/drivers/clk/clk.c @@ -887,6 +887,31 @@ unsigned long clk_hw_get_children_lcm(struct clk_hw *h= w, struct clk_hw *requesti } EXPORT_SYMBOL_GPL(clk_hw_get_children_lcm); =20 +/** + * clk_has_v2_rate_negotiation - Check if a clk should use v2 rate negotia= tion + * @core: The clock core to check + * + * This function recursively checks if the clk or any of its descendants h= ave + * the CLK_V2_RATE_NEGOTIATION flag set. + * + * Returns: true if the v2 logic should be used; false otherwise + */ +bool clk_has_v2_rate_negotiation(const struct clk_core *core) +{ + struct clk_core *child; + + if (core->flags & CLK_V2_RATE_NEGOTIATION) + return true; + + hlist_for_each_entry(child, &core->children, child_node) { + if (clk_has_v2_rate_negotiation(child)) + return true; + } + + return false; +} +EXPORT_SYMBOL_GPL(clk_has_v2_rate_negotiation); + /* * __clk_mux_determine_rate - clk_ops::determine_rate implementation for a= mux type clk * @hw: mux type clk to determine rate on @@ -2294,7 +2319,8 @@ static int __clk_speculate_rates(struct clk_core *cor= e, } =20 static void clk_calc_subtree(struct clk_core *core, unsigned long new_rate, - struct clk_core *new_parent, u8 p_index) + struct clk_core *new_parent, u8 p_index, + struct clk_core *initiating_clk) { struct clk_core *child; =20 @@ -2307,8 +2333,12 @@ static void clk_calc_subtree(struct clk_core *core, = unsigned long new_rate, new_parent->new_child =3D core; =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); + if (child !=3D initiating_clk && clk_has_v2_rate_negotiation(child)) + child->new_rate =3D child->rate; + else + child->new_rate =3D clk_recalc(child, new_rate); + + clk_calc_subtree(child, child->new_rate, NULL, 0, initiating_clk); } } =20 @@ -2317,7 +2347,8 @@ static void clk_calc_subtree(struct clk_core *core, u= nsigned long new_rate, * changed. */ static struct clk_core *clk_calc_new_rates(struct clk_core *core, - unsigned long rate) + unsigned long rate, + struct clk_core *initiating_clk) { struct clk_core *top =3D core; struct clk_core *old_parent, *parent; @@ -2365,7 +2396,7 @@ static struct clk_core *clk_calc_new_rates(struct clk= _core *core, return NULL; } else { /* pass-through clock with adjustable parent */ - top =3D clk_calc_new_rates(parent, rate); + top =3D clk_calc_new_rates(parent, rate, initiating_clk); new_rate =3D parent->new_rate; goto out; } @@ -2390,10 +2421,10 @@ static struct clk_core *clk_calc_new_rates(struct c= lk_core *core, =20 if ((core->flags & CLK_SET_RATE_PARENT) && parent && best_parent_rate !=3D parent->rate) - top =3D clk_calc_new_rates(parent, best_parent_rate); + top =3D clk_calc_new_rates(parent, best_parent_rate, initiating_clk); =20 out: - clk_calc_subtree(core, new_rate, parent, p_index); + clk_calc_subtree(core, new_rate, parent, p_index, initiating_clk); =20 return top; } @@ -2441,7 +2472,7 @@ static struct clk_core *clk_propagate_rate_change(str= uct clk_core *core, * walk down a subtree and set the new rates notifying the rate * change on the way */ -static void clk_change_rate(struct clk_core *core) +static void clk_change_rate(struct clk_core *core, struct clk_core *initia= ting_clk) { struct clk_core *child; struct hlist_node *tmp; @@ -2510,7 +2541,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->new_rate, initiating_clk); =20 /* * Use safe iteration, as change_rate can actually swap parents @@ -2520,12 +2551,12 @@ static void clk_change_rate(struct clk_core *core) /* Skip children who will be reparented to another clock */ if (child->new_parent && child->new_parent !=3D core) continue; - clk_change_rate(child); + clk_change_rate(child, initiating_clk); } =20 /* handle the new child who might not be in core->children yet */ if (core->new_child) - clk_change_rate(core->new_child); + clk_change_rate(core->new_child, initiating_clk); =20 clk_pm_runtime_put(core); } @@ -2581,7 +2612,7 @@ static int clk_core_set_rate_nolock(struct clk_core *= core, return -EBUSY; =20 /* calculate new rates and get the topmost changed clock */ - top =3D clk_calc_new_rates(core, req_rate); + top =3D clk_calc_new_rates(core, req_rate, core); if (!top) return -EINVAL; =20 @@ -2600,7 +2631,7 @@ static int clk_core_set_rate_nolock(struct clk_core *= core, } =20 /* change the rates */ - clk_change_rate(top); + clk_change_rate(top, core); =20 core->req_rate =3D req_rate; err: @@ -3587,6 +3618,7 @@ static const struct { ENTRY(CLK_IS_CRITICAL), ENTRY(CLK_OPS_PARENT_ENABLE), ENTRY(CLK_DUTY_CYCLE_PARENT), + ENTRY(CLK_V2_RATE_NEGOTIATION), #undef ENTRY }; =20 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index 2699b9759e13d0c1f0b54f4fa4f7f7bdd42e8dde..e0fc0bd347e5920e999ac96dbed= 9fc247f9443fa 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -32,6 +32,8 @@ #define CLK_OPS_PARENT_ENABLE BIT(12) /* duty cycle call may be forwarded to the parent clock */ #define CLK_DUTY_CYCLE_PARENT BIT(13) +/* clock participates in v2 rate negotiation */ +#define CLK_V2_RATE_NEGOTIATION BIT(14) =20 struct clk; struct clk_hw; @@ -1432,6 +1434,7 @@ void clk_hw_set_rate_range(struct clk_hw *hw, unsigne= d 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); +bool clk_has_v2_rate_negotiation(const struct clk_core *core); =20 static inline void __clk_hw_set_clk(struct clk_hw *dst, struct clk_hw *src) { --=20 2.53.0 From nobody Sun Apr 5 16:22:54 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 0BCD53C9447 for ; Mon, 23 Mar 2026 17:25:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774286749; cv=none; b=DbjbbCNMzf976ncQ5pniBe7JRxzKGUHrp3zL8qh3WWToHbYumwL7KeHiYu3x/5merq1bZY40AjJYyhs4XgMuVVpcm3xXfmYC0YbZZN6u005CmSMRxxTpEdG5nHDl+ck7tZ1hlFGCSvkRWbDAyQPIz/9g0Gk61m5jAvTihuIOy9U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774286749; c=relaxed/simple; bh=3Wx9iN4TAJNUNIOuDPx1ojQxxrOnjyC9d13DLRzCvF0=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=QB3Fa4BNZiM9MoTtrBDonskN9d5lV3VsoYbW5b8x5BFBLqS389e+kW24VxOqyz4cVd/8nA1iJRuY7iWa7akMNmb/oBTraY8PQ+nF1Pn1wq2HJTqusrAvpQXeq5oQv0HilEiViEyOexX+MD03wRIKSqCgfsnUk8x6pxoWmK7aPXo= 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=B55pQHHw; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=Y9l7pSzy; arc=none smtp.client-ip=170.10.129.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="B55pQHHw"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="Y9l7pSzy" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774286747; 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=TbzwY54CQAGeSGXdTg/v3Czq6hzBLavF0xp2Hme/bBk=; b=B55pQHHwC7Vxcx76aaBoL1J/hyV6Y5WmY3vAtmOG9JLsFrd37iFdtDGktucQHtOyXQmya5 GOCrY98Sny8Jg50scrnmSaQfKAK5C1OKgIBOd5JnBMbYs2aG/5KX1YtPf6S4rYx5T4teBk BW3YOytY2x2FVINEdW6Nx48ouZ7pyD8= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-591---I4vEu_OfiP2Kc5aDzBbg-1; Mon, 23 Mar 2026 13:25:45 -0400 X-MC-Unique: --I4vEu_OfiP2Kc5aDzBbg-1 X-Mimecast-MFC-AGG-ID: --I4vEu_OfiP2Kc5aDzBbg_1774286745 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-5093b92f327so327317221cf.1 for ; Mon, 23 Mar 2026 10:25:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1774286745; x=1774891545; 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=TbzwY54CQAGeSGXdTg/v3Czq6hzBLavF0xp2Hme/bBk=; b=Y9l7pSzy5FCJ9If+QBhkP1gKAQkSOH7ALojuLir0sXtcTblB3VzWBVuulhFvbjDeqd uZq3UnJSFpcxRwBqyXtn8HztZwIyceJiuUQdlHAR5nZfeBfroNERR7FOFVwqGYcmH+v4 xCFuddsGsUS/hpQYX35LhaParaBR4lAoH7GTOpXy4GCqiFOOsgIXzm5OXJYcB5GyMDRi CM4Ve5cx27LW2CMaOx1juzNbMRTF5lN5ux8Wq2/ire/j2Acm+32M/KPwBqZgTjHAxHvJ p+BpT41IKre31nJM+jviqEDMzYh1I7URKJDAj0I26wz4gla15zlhIHN2GR8yMxTgE3gr OVOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774286745; x=1774891545; 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=TbzwY54CQAGeSGXdTg/v3Czq6hzBLavF0xp2Hme/bBk=; b=AYHMD3fiCx5q4eVv8asV8fDgJzWTK7HGqIptMfCGP2kQ61zcOxsMW+YZv59/GrUlaD 4Ymd3KECaVEM19Qz546hBg1dny+F9H8C6x8dP4+2ShmRDazj0UP+L2exwkuuV0lEcULT R8mDZpKPRh+Rlonfisledu5jJ6736e5JtxAsx2g/SA1kzIbbQ/tw/dYEIhQZkKALa+Gz JwkqqyJV8Nny8aDoJPgv0InUfgOWswbhAznY6O2pPDHR+LG2D83awKrMvzkCh7JOf8Md uoONj7SWcEmtwPJ8RFGtbg5o9m6hlU29EBSnpQMmGGOJYEKYcVWiQ7nbzZgp7gzTE0+J jEng== X-Forwarded-Encrypted: i=1; AJvYcCVKPXSc7LkEzxjMqwhqSpmwDFIajbxqUTVTwPUZDUVL+ZvYXT47iMrl+MPxJQLH3uAo58wkEmVzr36oXQk=@vger.kernel.org X-Gm-Message-State: AOJu0YyltMlI4Mnho5fJCbJMMGf9/6Ws2b0Lk7FW7xGHUafL5JdYBfAO 2HXrpBrJBvX5kgpXX7bFImqLM/uqFBAdt/Fs4WlIj/CqLpQnDgb5LdK9oq0xn2McANW/j/nh05C pnJHLCItpxbKAsl9jwsfsI46ritBqS5bfd0Hob3fbEUtKsLlE8fYCyEMxa+2ZHm7YZw== X-Gm-Gg: ATEYQzzbbfYs+nIetya4CbCAvl2VrBeYgh0khWhPs1/D6xRaV1oasQ0dz6IAc0RcTO5 t2o0pPWztFuH3p6BaaTDPVPIkiKmOxWeeSA4H8A/ZHfhDCIgJ9m9tFnHpVUwXHZXeE+m372zway Gc1vOzCEgmVEIW6aL9AR0UKolzZfP0ud3jc/61C0xt2IH1Ij8Ic2Mysqhbm9+EXLi28yqaE90QO +ECiiOyHv3INzyJqZoysA0P3fVdbwC6vJwcPT/0a91IlWQ54XITZfTrq1lDTnaPN4lJFgwTM804 GQ45lN7KnEfBtIofHCYN1TOtCBgwbmP4vkROpBkb9ip06hPudq9etqx/rLUaTcrWm5Jb2AI5sFq xxIDa3HpQSzZpMPd6w4KHIkGSuDyEJZaMl1TpC0A5Q0bE4RYAAGcxp41ipCE0 X-Received: by 2002:ac8:7e8d:0:b0:50b:37ff:727e with SMTP id d75a77b69052e-50b37ff7412mr200892861cf.44.1774286744575; Mon, 23 Mar 2026 10:25:44 -0700 (PDT) X-Received: by 2002:ac8:7e8d:0:b0:50b:37ff:727e with SMTP id d75a77b69052e-50b37ff7412mr200892241cf.44.1774286743960; Mon, 23 Mar 2026 10:25:43 -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-50b36e34f8bsm108249661cf.15.2026.03.23.10.25.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2026 10:25:43 -0700 (PDT) From: Brian Masney Date: Mon, 23 Mar 2026 13:24:57 -0400 Subject: [PATCH v7 6/8] clk: divider: enable optional support for v2 rate negotiation 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: <20260323-clk-scaling-v7-6-8e7193dc9405@redhat.com> References: <20260323-clk-scaling-v7-0-8e7193dc9405@redhat.com> In-Reply-To: <20260323-clk-scaling-v7-0-8e7193dc9405@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=2590; i=bmasney@redhat.com; s=20250903; h=from:subject:message-id; bh=3Wx9iN4TAJNUNIOuDPx1ojQxxrOnjyC9d13DLRzCvF0=; b=owGbwMvMwCW2/dJd9di6A+2Mp9WSGDIPlnc2mp0yKew7Z+kpW3Xf98Cp0+9W6V38r2ooWx34/ d1RTqugjlIWBjEuBlkxRZYluUYFEamrbO/d0WSBmcPKBDKEgYtTACbyOJORYUotY9/V398dTFZX 7vviuN8r0smdyW7fSg01l3ezPh/zOsPIMId99Yp9O7b+lS+bUBc6S39t9a5tch33WqQK42xOPk1 K4QUA X-Developer-Key: i=bmasney@redhat.com; a=openpgp; fpr=A46D32705865AA3DDEDC2904B7D2DD275D7EC087 If the v2 rate negotiation logic is enabled in this portion of the clk subtree, then use the Lowest Common Multiple (LCM) of all of the child rates to determine what the parent rate should be. Make this change for clk_divider_bestdiv (used by clk_divider_determine_rate), and divider_ro_determine_rate. Note that the v2 rate negotiation logic is disabled by default, unless a clk in this portion of the subtree has the flag CLK_V2_RATE_NEGOTIATION. This change was tested on a Thinkpad x13s laptop. Some clks used this new code, however this needs to be tested on more real systems. Reviewed-by: Maxime Ripard 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-divider.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c index 45e7ebde4a8b4d6572aa9d867a6f12f6caf8aae4..17646a06420e099b5fa3ec99d92= 175356c65afa0 100644 --- a/drivers/clk/clk-divider.c +++ b/drivers/clk/clk-divider.c @@ -315,6 +315,19 @@ static int clk_divider_bestdiv(struct clk_hw *hw, stru= ct clk_hw *parent, return bestdiv; } =20 + if (clk_has_v2_rate_negotiation(parent->core)) { + unsigned long lcm_rate; + + lcm_rate =3D clk_hw_get_children_lcm(parent, hw, rate); + if (lcm_rate > 0) { + *best_parent_rate =3D lcm_rate; + bestdiv =3D _div_round(table, lcm_rate, rate, flags); + bestdiv =3D bestdiv =3D=3D 0 ? 1 : bestdiv; + bestdiv =3D bestdiv > maxdiv ? maxdiv : bestdiv; + return bestdiv; + } + } + /* * The maximum divider we can use without overflowing * unsigned long in rate * i below @@ -377,8 +390,19 @@ int divider_ro_determine_rate(struct clk_hw *hw, struc= t clk_rate_request *req, if (!req->best_parent_hw) return -EINVAL; =20 - req->best_parent_rate =3D clk_hw_round_rate(req->best_parent_hw, - req->rate * div); + if (clk_has_v2_rate_negotiation(req->best_parent_hw->core)) { + unsigned long lcm_rate; + + lcm_rate =3D clk_hw_get_children_lcm(req->best_parent_hw, hw, req->rate= ); + if (lcm_rate > 0) + req->best_parent_rate =3D lcm_rate; + else + req->best_parent_rate =3D clk_hw_round_rate(req->best_parent_hw, + req->rate * div); + } else { + req->best_parent_rate =3D clk_hw_round_rate(req->best_parent_hw, + req->rate * div); + } } =20 req->rate =3D DIV_ROUND_UP_ULL((u64)req->best_parent_rate, div); --=20 2.53.0 From nobody Sun Apr 5 16:22:54 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 5B6723CBE6F for ; Mon, 23 Mar 2026 17:25:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774286755; cv=none; b=gLJ9gJcCKcyjFiu+PvgSGU8kA0D9nMtamGUowrZ7TMN4MOb8Xf6CfZ4AeSvpc8p+7SF26uoCduXcYq7fr8ZQ50D+T+6ECdwECyun1yc8WAtExxMHRxkOUChBVPHAe+cL/7/koW0ApSbNmrB/t1AMzNcctF3lKCvaRoc4P9Z0sFA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774286755; c=relaxed/simple; bh=xpGnRJHb7iFtNaWnVivX5OL5Ase55p/rrd+OZZm4p/o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pqF73O3cXZjMt9vkEQugvKV3SPYbWptX7KMpEOA4sLc/GcFHSnw5EniB5GyhHVgOtS0YJ+voEWPN5TcXQRRBvT0T9oCenlDelmrVwpSAtegTt1LF/3Fr6uj3KxciLdoVorEb2GOlVXLda/OCX/tWUzu3iOx3xXXrbnylrhT27Ak= 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=QbozP16Q; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=KM4XDQR2; arc=none smtp.client-ip=170.10.129.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="QbozP16Q"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="KM4XDQR2" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774286753; 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=34oVGrWJiWoSUSC15rXIzEcw5Hsg90ZuipTla97gnAM=; b=QbozP16QpSdXlzl0Jh9jzph6uHel0qNJKN0X0GRBtHnO50PrWFZ/mvoMQTSzto7G+YF//c hwIm6GJDyzb1u/q1vF+8PY1iDd7B2mO15xjrfsF4JMICZ2cPoxtZBDvwfIqwVsKYh9Bgvu dyWmHpu9Lmh1u6kqs0VRBHr7YuYCFn4= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-451-hEANyIinNPKa0D3SpIRDuA-1; Mon, 23 Mar 2026 13:25:52 -0400 X-MC-Unique: hEANyIinNPKa0D3SpIRDuA-1 X-Mimecast-MFC-AGG-ID: hEANyIinNPKa0D3SpIRDuA_1774286752 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-509219f94b0so36113931cf.3 for ; Mon, 23 Mar 2026 10:25:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1774286752; x=1774891552; 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=34oVGrWJiWoSUSC15rXIzEcw5Hsg90ZuipTla97gnAM=; b=KM4XDQR23dXkDE/2xRR+Rv4ARzW3Id0e7lPIJANipnx5GznH13S3qaBhmEp9VWR6ig geJCU+NVC587RZ8aEu5h0jbSXgMt/GUoUf15YGr9/kMbqSM5XQj0xIbsi98e0+uKkn2L EZQCp7S2hainBDXvrkrHMHEZeOrQIdxytFiYFeqHIWtNSGVWrevz7r5jWlb1fppdj5WX UkFOdohjzm0eHb9VSQvw+nrsjn2CNUZtaxjJSWjbKakYioe69HjSrw+t2l/OxNSkhtpZ q6IGRUXwCTfjYLj0s4lcua8oSjMiY2FTF+jhE2ChqFdto7jeQWUCVogH4eLuYaXaZJNI QZbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774286752; x=1774891552; 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=34oVGrWJiWoSUSC15rXIzEcw5Hsg90ZuipTla97gnAM=; b=WBeQG+JgiwIPzITLL+wxMjs4eSJylWEOicRxYbDvQJvmC69IZmcF8T/ab6yqJHrpRT R/JUSn7uIVwV7u2+aMWvYTP71XEn9wcq0OPKyujyBNtukIKfkGWFtopfBgjg/v/aph1l bDLj6bN1+g5PQs7meyZJ9HXROWgIxwBz8jnQ+6hl3U5QjAoHT8oGB2GNVrugIQGlNFRX r0n1/6EeNPBu8ZifhURS1x5HxaodcWdvDJm0A0JWljBBbFvx9oiW2xoi4P6VgYbZ3wUd L3U6RsEZ71ziigIv002UOPpzBf9khetL7qQeqU9Ue0ke6rH3zl0Ag7g4zp7H37yhvjHN 52hg== X-Forwarded-Encrypted: i=1; AJvYcCWKyP5+0G8i1uIOUaGcrZ99gmIhEVnc7eyIKwIQz/oCtax7z7AXDafIPoQELHr0cFmXONiBytEbYrPrpZk=@vger.kernel.org X-Gm-Message-State: AOJu0YxnJYNya7Tu3yk44pkoyPhYRCGRuxwNn8LcyOybYqZKphAq6gHU 2dd3M5f4XAjDtcR9rFFtMVZyH7UbZCRN/tXiAZGvE2gxJGdzY1tL1CBpYiKUYpmpg28mO4/QETi ulX1YuAUR7ZewIG6a8ro5EoGGQ8g3j1l0mmiB4k/W3Vuml1dLOt0GV+seYXd6IQaRIA== X-Gm-Gg: ATEYQzxjjo15qokY8s3Oym2ymJMlq8//1deETYNEWBXa5UpXL6z3xfVanN88g0GTdEp KTL3xJrhvYR+YNLXpfUdB3MB3htU1qo01oUL5rJwLFpqO52ucM4nxYnIOBoIndA/oo1xdbpwBYo p+TNZ7QjCs1Y0P2/eZJOTQ0DyTm4ozMBOgkBaS4r2M5O82fqoo4NO/BeGCWuTl42kpJ+EyTYu4R 2WRDI54mAFkue5MNnSHncsRAkEQCGvQlTpAW242kiqqZJmIyMAfXF+Znh5HMLvPOR0xb9ERjv0b QFUg1oT3rKPDaBie1Ha0Jcw2Be6XWQ2UnJLe8VoHZxjmI/RW8xBHPowRv0lkky9hCdH4dtKyP9/ yBjoTn9i6McVtzNkfjnllJLOwJJuFLrF2CvrboRe1/cYKh0Cz3Sq/w3vp6Be5 X-Received: by 2002:a05:622a:1aaa:b0:50b:4dc9:347d with SMTP id d75a77b69052e-50b4dc94b6cmr116972461cf.22.1774286746745; Mon, 23 Mar 2026 10:25:46 -0700 (PDT) X-Received: by 2002:a05:622a:1aaa:b0:50b:4dc9:347d with SMTP id d75a77b69052e-50b4dc94b6cmr116971871cf.22.1774286746000; Mon, 23 Mar 2026 10:25:46 -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-50b36e34f8bsm108249661cf.15.2026.03.23.10.25.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2026 10:25:45 -0700 (PDT) From: Brian Masney Date: Mon, 23 Mar 2026 13:24:58 -0400 Subject: [PATCH v7 7/8] clk: divider: test: introduce additional test case showing v2 rate change + LCM parent 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: <20260323-clk-scaling-v7-7-8e7193dc9405@redhat.com> References: <20260323-clk-scaling-v7-0-8e7193dc9405@redhat.com> In-Reply-To: <20260323-clk-scaling-v7-0-8e7193dc9405@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=4963; i=bmasney@redhat.com; s=20250903; h=from:subject:message-id; bh=xpGnRJHb7iFtNaWnVivX5OL5Ase55p/rrd+OZZm4p/o=; b=owGbwMvMwCW2/dJd9di6A+2Mp9WSGDIPlneVrBf/anbxvLrp4fWXtaXPbHPpk1uQ+983Mirm5 M6fyg4iHaUsDGJcDLJiiixLco0KIlJX2d67o8kCM4eVCWQIAxenAEykiZXhfyDPpICi5rtNFU/y ZG9++SojKlKuoV7fXash830X2+Jl4YwMe/MZr91KfrCH66DAQZY2iUOsJVdXXGVf+Gyd5I9shgO ebAA= X-Developer-Key: i=bmasney@redhat.com; a=openpgp; fpr=A46D32705865AA3DDEDC2904B7D2DD275D7EC087 Add a test case that uses the clk divider with the v2 rate negotiation logic, plus the Lowest Common Multiple (LCM) to calculate the optimal parent rate. The test ensures that the parent clk rate is set to a rate that's acceptable to both children, and the sibling clock is not affected. The test in this commit use the following simplified clk tree with the initial state: parent 24 MHz / \ child1 child2 24 MHz 24 MHz child1 and child2 both divider-only clocks that have CLK_SET_RATE_PARENT set, and the parent is capable of achieving any rate. child1 requests 32 MHz, and the tree ends up with the correct state: parent 96 MHz / \ child1 child2 32 MHz 24 MHz 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-divider_test.c | 54 ++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 54 insertions(+) diff --git a/drivers/clk/clk-divider_test.c b/drivers/clk/clk-divider_test.c index 95a55835a29065fede0426f1c15ec158e8a703c1..a16c04d5d8a86952b42750d326f= 88754fbc91eb7 100644 --- a/drivers/clk/clk-divider_test.c +++ b/drivers/clk/clk-divider_test.c @@ -110,6 +110,18 @@ clk_rate_change_divider_test_lcm_ops_v1_params[] =3D { KUNIT_ARRAY_PARAM_DESC(clk_rate_change_divider_test_lcm_ops_v1, clk_rate_change_divider_test_lcm_ops_v1_params, desc) =20 +static const struct clk_rate_change_divider_test_param +clk_rate_change_divider_test_regular_ops_v2_params[] =3D { + { + .desc =3D "regular_ops_v2", + .ops =3D &clk_dummy_div_ops, + .extra_child_flags =3D CLK_V2_RATE_NEGOTIATION, + }, +}; + +KUNIT_ARRAY_PARAM_DESC(clk_rate_change_divider_test_regular_ops_v2, + clk_rate_change_divider_test_regular_ops_v2_params, desc) + static int clk_rate_change_divider_test_init(struct kunit *test) { const struct clk_rate_change_divider_test_param *param =3D test->param_va= lue; @@ -196,6 +208,11 @@ static void clk_test_rate_change_divider_1(struct kuni= t *test) KUNIT_EXPECT_EQ(test, ctx->child2.div, 1); } =20 +static inline bool __clk_has_v2_negotiation(struct clk *clk) +{ + return clk_hw_get_flags(__clk_get_hw(clk)) & CLK_V2_RATE_NEGOTIATION; +} + /* * Test that, for a parent with two divider-only children with CLK_SET_RAT= E_PARENT * set and one requests a rate incompatible with the existing parent rate,= the @@ -265,6 +282,39 @@ static void clk_test_rate_change_divider_3_v1(struct k= unit *test) KUNIT_EXPECT_EQ(test, ctx->child2.div, 1); } =20 +/* + * Test that, for a parent with two divider-only children with CLK_SET_RAT= E_PARENT + * set and one requests a rate incompatible with the existing parent rate,= the + * sibling rate is not affected, and maintains it's rate when the v2 rate + * negotiation logic is used. + */ +static void clk_test_rate_change_divider_4_v2(struct kunit *test) +{ + struct clk_rate_change_divider_context *ctx =3D test->priv; + int ret; + + KUNIT_ASSERT_EQ(test, clk_get_rate(ctx->parent_clk), 24 * HZ_PER_MHZ); + KUNIT_ASSERT_EQ(test, clk_get_rate(ctx->child1_clk), 24 * HZ_PER_MHZ); + KUNIT_EXPECT_EQ(test, ctx->child1.div, 1); + KUNIT_ASSERT_EQ(test, clk_get_rate(ctx->child2_clk), 24 * HZ_PER_MHZ); + KUNIT_EXPECT_EQ(test, ctx->child2.div, 1); + KUNIT_ASSERT_TRUE(test, __clk_has_v2_negotiation(ctx->child1_clk)); + KUNIT_ASSERT_TRUE(test, __clk_has_v2_negotiation(ctx->child2_clk)); + + ret =3D clk_set_rate(ctx->child1_clk, 32 * HZ_PER_MHZ); + KUNIT_ASSERT_EQ(test, ret, 0); + + /* + * With LCM-based parent + v2 rate changes, the parent should be at + * 96 MHz (LCM of 32 and 24), child1 at 32 MHz, and child2 at 24 MHz. + */ + KUNIT_EXPECT_EQ(test, clk_get_rate(ctx->parent_clk), 96 * HZ_PER_MHZ); + KUNIT_EXPECT_EQ(test, clk_get_rate(ctx->child1_clk), 32 * HZ_PER_MHZ); + KUNIT_EXPECT_EQ(test, ctx->child1.div, 3); + KUNIT_EXPECT_EQ(test, clk_get_rate(ctx->child2_clk), 24 * HZ_PER_MHZ); + KUNIT_EXPECT_EQ(test, ctx->child2.div, 4); +} + static struct kunit_case clk_rate_change_divider_cases[] =3D { KUNIT_CASE_PARAM(clk_test_rate_change_divider_1, clk_rate_change_divider_test_regular_ops_gen_params), @@ -272,6 +322,10 @@ static struct kunit_case clk_rate_change_divider_cases= [] =3D { clk_rate_change_divider_test_regular_ops_gen_params), KUNIT_CASE_PARAM(clk_test_rate_change_divider_3_v1, clk_rate_change_divider_test_lcm_ops_v1_gen_params), + KUNIT_CASE_PARAM(clk_test_rate_change_divider_1, + clk_rate_change_divider_test_regular_ops_v2_gen_params), + KUNIT_CASE_PARAM(clk_test_rate_change_divider_4_v2, + clk_rate_change_divider_test_regular_ops_v2_gen_params), {} }; =20 --=20 2.53.0 From nobody Sun Apr 5 16:22:54 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 378623CAE7B for ; Mon, 23 Mar 2026 17:25:51 +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=1774286752; cv=none; b=q7qvtlZXhqI8CsrF2yVm9gtvP1fMw7Ge/H4u+35BjzDLsFMIE9yZ1mPfLa03+zXJVaXGPTvWhnBlXzodzqHIDG/spnIlgt6PAE9NuZ5fUDfMN0KrSng9VoKSwySgc/cH15eo85+br8zfxXRpJImKssYC/jew6DdTYPkBStJsTP8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774286752; c=relaxed/simple; bh=WDIE7lt2EMyOXFUD9TIulldMehjU0ziYiCpz80CIxbU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=FJGIVOkdueDuSX/tsLblHu4PTGQe7fS5bmPF18j7oZDguEhJ518wInhBOOZytSHX6vkUSzr5PhBwrRBrLQYC4PFs7rKFXDYztC3xnp0bB8ZbCoC4pAv48c06YxAN2p7AsriffNRTxWJ6N6y3xxX0dhWX+mkLv7AfApDSlYtSuzs= 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=CnRirpEQ; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=hFHirqAD; 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="CnRirpEQ"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="hFHirqAD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774286750; 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=z3ukp7lwYjI/rsNx0zgB5rYQ+pIaxNH93AMrhUusdCA=; b=CnRirpEQq4inVDZWRIIG0mSKQSmZKc+WSESa4diewVYhtpwrOJBG0RkfehTwXazjHbhNqP 9gGhrfNARPNRYv3UwRM9v15WbL1fZc9OKs485N49ICEXP2jEIKD9jlBcH0wzwWnVNxfT2l js3daZwE/xv1/whuC5vuqVJR0tXOivw= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-612-9ey77zizPF-W9pMxBJEApA-1; Mon, 23 Mar 2026 13:25:49 -0400 X-MC-Unique: 9ey77zizPF-W9pMxBJEApA-1 X-Mimecast-MFC-AGG-ID: 9ey77zizPF-W9pMxBJEApA_1774286748 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-5090e08dcfcso19609731cf.0 for ; Mon, 23 Mar 2026 10:25:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1774286748; x=1774891548; 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=z3ukp7lwYjI/rsNx0zgB5rYQ+pIaxNH93AMrhUusdCA=; b=hFHirqADkLZ9z1GG0koNOIfTZdub0UGxFX7RzMWtla66a/Ps47/F5PqWKehxtWmXdp bFQFul0Garw+Er2pMyBZAhGTmdondlK8j4J6OZgLv15f5t0WXmW8PVe0+BBFThOeBjhn Q7rflFApGEatx+2sLCV3Xhhg0GOE0xcZye8KDIywz42NVzCRafD22/E8iSILMlWSo4EI RcLtUTHd+7TawMbLKzGp+lekfovScP/nXdbit2rtLXAkDISs1s/KBtMKazP4kJIrpxIA ubF9gmsGykDCU1eFmnSAjLpxvqdAvKy/zKUJLf/RCZ07K088x9mzCfKusuWfUaF2Kl9k xKKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774286748; x=1774891548; 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=z3ukp7lwYjI/rsNx0zgB5rYQ+pIaxNH93AMrhUusdCA=; b=kWp7h3INn0aaYGKeXkNjExE4gMe1Dlqs/+WA8gfTAlf+yXrUoxqZyNY6CeE6MFs6t2 OHq59umxJZjlSX5m9lnxr+ba5zFQp2qL5aSiCyYFqM9blGMoT5AYH7NPv1y/3kVB/+7c VSkJUDhi+WwA0a0STBSAIIS9PQmz5HXlP9r8CfdOG5tfKjdu/CeOaikYh6PkYgIVYNuL Ah7lKZya9HJCnv8eckKU5EzIeyTDfYo2GU9F0yHybXi0CRmQxqUd1tB3lVrMPLQqGh+m ZukbovUuURu5hqmtHrotxhBDlLEZqt9U9bWf5oXI887G9ie2MI4Y560oZaL0mMsBcLKm CQJw== X-Forwarded-Encrypted: i=1; AJvYcCVWq5IR/V0fPM8oLhL8P8JMA7aBJGWKue43gOwx6bGZQvqlidrYH1hnTvO8wTpI0kKJdoh3f/4NVHxZZfE=@vger.kernel.org X-Gm-Message-State: AOJu0YxEfiSX90JtNcOkovLMJYn++7Xu5XFW7WgIzrsJl61O+l459j/i dJAqfydfO/msMDoCm/sZd2EAQBAoFU/6PUpfwgWxAD8QnZorqm6GVCRiOxPoksz/CWVZjNDQawm 49ZHXClp8uygVJ8qXBTYqBZeij/VKosJy+Y2pp7sYQQ2M2p+rVTEH3Ra8dfAMcvVwow== X-Gm-Gg: ATEYQzwJg1hj2sZUeP7jB7la53aHWe7kOfBCXmB7yUhMMNmHd+beT/jfw1peFUDZG9P Zrk06R6fl+H0DJbQo6o22FaxjE/BmEpp0YNRKxfIpePTGuIT1xof3JcXY68WOmQ4A1yktQCo5b4 DTl+F+fRn2DdsyCVmk6t6e7CEsJRUHi99BcIlBtMqhJl+edTMICL/R4y20HTxA5y7rPx/31LnrY S0B9SM2OBLJcBXR+ik0dOAX4bpKJxihUbpTwktLi1+1d5ek4aDE9EgyEHvA9qFn5QCeXonlP+DW boJ49lvlOywyoFC+iiyqD5TxPiHteX6iIo4d7PYb183rxbJNt8hKJs3PDUax6qqd9kzf4X99G36 eG5MDmdFcycw4XbC20KXZu0kJU8sA9kOfxwIjDdf98csXHrtMkE5wiMQi0a1W X-Received: by 2002:a05:622a:1b91:b0:50b:3895:facc with SMTP id d75a77b69052e-50b38964598mr190997811cf.14.1774286748525; Mon, 23 Mar 2026 10:25:48 -0700 (PDT) X-Received: by 2002:a05:622a:1b91:b0:50b:3895:facc with SMTP id d75a77b69052e-50b38964598mr190997271cf.14.1774286747947; Mon, 23 Mar 2026 10:25:47 -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-50b36e34f8bsm108249661cf.15.2026.03.23.10.25.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2026 10:25:47 -0700 (PDT) From: Brian Masney Date: Mon, 23 Mar 2026 13:24:59 -0400 Subject: [PATCH v7 8/8] clk: divider: test: mark some tests as supporting only v1 negotiation 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: <20260323-clk-scaling-v7-8-8e7193dc9405@redhat.com> References: <20260323-clk-scaling-v7-0-8e7193dc9405@redhat.com> In-Reply-To: <20260323-clk-scaling-v7-0-8e7193dc9405@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=2824; i=bmasney@redhat.com; s=20250903; h=from:subject:message-id; bh=WDIE7lt2EMyOXFUD9TIulldMehjU0ziYiCpz80CIxbU=; b=owGbwMvMwCW2/dJd9di6A+2Mp9WSGDIPlnd7nekL2qX8bduML9Myd8kVr5HjsOVqK7KZxF29k rlZa411RykLgxgXg6yYIsuSXKOCiNRVtvfuaLLAzGFlAhnCwMUpABPpEWL4K/78FOOH2VHrQj+u Upsw6VKjbPkOA56bPlKvJI1/feTt72H4p1jnZVS79fZtlqqAm6tSlVaureJJenehqH12x6e6Bwc TmAE= X-Developer-Key: i=bmasney@redhat.com; a=openpgp; fpr=A46D32705865AA3DDEDC2904B7D2DD275D7EC087 Mark the tests that only support v1 negotiation to make it clear exactly which behavior is under test. 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-divider_test.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/clk/clk-divider_test.c b/drivers/clk/clk-divider_test.c index a16c04d5d8a86952b42750d326f88754fbc91eb7..646307f1d78a08130a8a552b578= 74e21b07f7b4a 100644 --- a/drivers/clk/clk-divider_test.c +++ b/drivers/clk/clk-divider_test.c @@ -54,6 +54,15 @@ static const struct clk_ops clk_dummy_div_ops =3D { .set_rate =3D clk_dummy_div_set_rate, }; =20 +/* + * clk-divider.c has support for v2 rate negotiation, and setting the pare= nt + * based on the LCM, however we need to be able to test just setting the p= arent + * rate based on the LCM, and not set the v2 rate negotiation flag. This i= s to + * demonstrate existing behavior in the clk core when a parent rate that's + * suitable for all children is selected, a sibling will still have it's r= ate + * negatively affected. Some boards may be unknowingly dependent on this + * behavior, and we want to ensure this behavior stays the same. + */ static int clk_dummy_div_lcm_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) { @@ -197,6 +206,7 @@ static void clk_test_rate_change_divider_1(struct kunit= *test) KUNIT_EXPECT_EQ(test, ctx->child1.div, 1); KUNIT_ASSERT_EQ(test, clk_get_rate(ctx->child2_clk), 24 * HZ_PER_MHZ); KUNIT_EXPECT_EQ(test, ctx->child2.div, 1); + /* This test is expected to work with both v1 and v2 rate negotiation. */ =20 ret =3D clk_set_rate(ctx->child1_clk, 6 * HZ_PER_MHZ); KUNIT_ASSERT_EQ(test, ret, 0); @@ -229,6 +239,8 @@ static void clk_test_rate_change_divider_2_v1(struct ku= nit *test) KUNIT_EXPECT_EQ(test, ctx->child1.div, 1); KUNIT_ASSERT_EQ(test, clk_get_rate(ctx->child2_clk), 24 * HZ_PER_MHZ); KUNIT_EXPECT_EQ(test, ctx->child2.div, 1); + KUNIT_ASSERT_TRUE(test, !__clk_has_v2_negotiation(ctx->child1_clk)); + KUNIT_ASSERT_TRUE(test, !__clk_has_v2_negotiation(ctx->child2_clk)); =20 ret =3D clk_set_rate(ctx->child1_clk, 32 * HZ_PER_MHZ); KUNIT_ASSERT_EQ(test, ret, 0); @@ -265,6 +277,8 @@ static void clk_test_rate_change_divider_3_v1(struct ku= nit *test) KUNIT_EXPECT_EQ(test, ctx->child1.div, 1); KUNIT_ASSERT_EQ(test, clk_get_rate(ctx->child2_clk), 24 * HZ_PER_MHZ); KUNIT_EXPECT_EQ(test, ctx->child2.div, 1); + KUNIT_ASSERT_TRUE(test, !__clk_has_v2_negotiation(ctx->child1_clk)); + KUNIT_ASSERT_TRUE(test, !__clk_has_v2_negotiation(ctx->child2_clk)); =20 ret =3D clk_set_rate(ctx->child1_clk, 32 * HZ_PER_MHZ); KUNIT_ASSERT_EQ(test, ret, 0); --=20 2.53.0