From nobody Sun Apr 5 18:11:34 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