public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v6 0/7] clk: add support for v1 / v2 clock rate negotiation and kunit tests
@ 2026-03-13 16:43 Brian Masney
  2026-03-13 16:43 ` [PATCH v6 1/7] clk: test: introduce clk_dummy_div for a mock divider Brian Masney
                   ` (6 more replies)
  0 siblings, 7 replies; 26+ messages in thread
From: Brian Masney @ 2026-03-13 16:43 UTC (permalink / raw)
  To: Michael Turquette, Stephen Boyd, Maxime Ripard, Alberto Ruiz
  Cc: linux-clk, linux-kernel, Brian Masney

The Common Clock Framework is expected to keep a clock’s rate stable
after setting a new rate with:

    clk_set_rate(clk, NEW_RATE);

Clock consumers do not know about the clock hierarchy, sibling clocks,
or the type of clocks involved. However, several longstanding issues
affect how rate changes propagate through the clock tree when
CLK_SET_RATE_PARENT is involved, and the parent's clock rate is changed:

- A clock in some cases can unknowingly change a sibling clock's rate.

- No negotiation is done with the sibling clocks, so an inappropriate
  or less than ideal parent rate can be selected.

A selection of some real world examples of where this shows up is at
[1]. DRM needs to run at precise clock rates, and this issue shows up
there, however will also show up in other subsystems that require
precise clock rates, such as sound.

This series introduces kunit tests to illustrate the current behavior in
the clk core. As discussed at Linux Plumbers Conference 2025 in Tokyo,
it was suggested to move the negotiation logic into the clk providers
themselves so that only the clks with this issue can have their rate
preserved, and add some common helpers to the clk core.

How to test on real hardware
============================

I am interested in getting feedback about testing this patch on real
hardware, particularly for scenarios where CLK_SET_RATE_PARENT needs
to be removed like this:
https://lore.kernel.org/all/20260303115550.9279-1-mitltlatltl@gmail.com/

1) First ensure that your board uses divider_determine_rate() or
   divider_ro_determine_rate() from drivers/clk/clk-divider.c.

2) Boot the kernel with this patch set. There should be no change to the
   existing behavior, and everything should still function as is.

3) Now boot the kernel with the parameter clk_v2_rate_negotiation.
   Trigger the scenario where the clks get in a bad state, and it should
   not occur with this series.

Changes since v5:
https://lore.kernel.org/r/20260306-clk-scaling-v5-0-d21b84ee6f27@redhat.com
- Dropped all of the helpers, and complexity to the clk core. To solve
  this problem, we don't need to chain rate requests together.
- Add more unit tests
- Convert clk-divider.c so that there's a real user of this new API.
- This series no longer has the problem where large numbers of boards are
  moved over at once to the new v2 negotiation logic.

Changes since v4:
https://lore.kernel.org/linux-clk/20250923-clk-tests-docs-v4-0-9205cb3d3cba@redhat.com/
- Reworked based on feedback at Linux Plumbers [2] as described in two
  paragraphs above.
- Dropped gate and mux tests.

Changes since v3:
https://lore.kernel.org/r/20250812-clk-tests-docs-v3-0-054aed58dcd3@redhat.com
- Update clk_core struct members (Maxime)
- Add v2 rate negotiation logic and additional kunit tests
- Drop clk_dummy_rate_mhz() in kunit tests; use HZ_PER_MHZ

[1] https://lore.kernel.org/lkml/20230825-pll-mipi_keep_rate-v1-0-35bc43570730@oltmanns.dev/
    https://lore.kernel.org/linux-kernel/20230807-pll-mipi_set_rate_parent-v6-0-f173239a4b59@oltmanns.dev/
    https://lore.kernel.org/all/20241114065759.3341908-1-victor.liu@nxp.com/
    https://lore.kernel.org/linux-clk/20241121-ge-ian-debug-imx8-clk-tree-v1-0-0f1b722588fe@bootlin.com/

[2] Fixing Clock Tree Propagation in the Common Clk Framework
    https://www.youtube.com/watch?v=R8TytDzlcFs
    https://lpc.events/event/19/contributions/2152/

Link: https://lore.kernel.org/linux-clk/aUSWU7UymULCXOeF@redhat.com/
Link: https://lpc.events/event/19/contributions/2152/
Signed-off-by: Brian Masney <bmasney@redhat.com>
---
Brian Masney (7):
      clk: test: introduce clk_dummy_div for a mock divider
      clk: test: introduce test suite for sibling rate changes on a divider
      clk: introduce new helper clk_hw_get_children_lcm() to calculate LCM of all child rates
      clk: test: introduce additional test case showing sibling clock rate change
      clk: introduce new flag CLK_V2_RATE_NEGOTIATION for sensitive clocks
      clk: divider: enable optional support for v2 rate negotiation
      clk: test: introduce additional test case showing v2 rate change + LCM parent

 drivers/clk/clk-divider.c    |  28 +++-
 drivers/clk/clk.c            | 118 +++++++++++++++--
 drivers/clk/clk_test.c       | 300 +++++++++++++++++++++++++++++++++++++++++++
 include/linux/clk-provider.h |   5 +
 4 files changed, 436 insertions(+), 15 deletions(-)
---
base-commit: 6a2abc8018be1ce9a03470ebb1c526f814903452
change-id: 20260305-clk-scaling-b3b63cae7624

Best regards,
-- 
Brian Masney <bmasney@redhat.com>


^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2026-03-20 14:44 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-13 16:43 [PATCH v6 0/7] clk: add support for v1 / v2 clock rate negotiation and kunit tests Brian Masney
2026-03-13 16:43 ` [PATCH v6 1/7] clk: test: introduce clk_dummy_div for a mock divider Brian Masney
2026-03-16 12:09   ` Maxime Ripard
2026-03-13 16:43 ` [PATCH v6 2/7] clk: test: introduce test suite for sibling rate changes on a divider Brian Masney
2026-03-19  9:10   ` Maxime Ripard
2026-03-19 11:08     ` Brian Masney
2026-03-20 13:03       ` Maxime Ripard
2026-03-20 13:08         ` Brian Masney
2026-03-20 14:29           ` Maxime Ripard
2026-03-20 14:34             ` Brian Masney
2026-03-13 16:43 ` [PATCH v6 3/7] clk: introduce new helper clk_hw_get_children_lcm() to calculate LCM of all child rates Brian Masney
2026-03-19  9:16   ` Maxime Ripard
2026-03-13 16:43 ` [PATCH v6 4/7] clk: test: introduce additional test case showing sibling clock rate change Brian Masney
2026-03-19  9:22   ` Maxime Ripard
2026-03-19 15:14     ` Brian Masney
2026-03-13 16:43 ` [PATCH v6 5/7] clk: introduce new flag CLK_V2_RATE_NEGOTIATION for sensitive clocks Brian Masney
2026-03-19  9:35   ` Maxime Ripard
2026-03-19 10:35     ` Brian Masney
2026-03-20 14:31       ` Maxime Ripard
2026-03-20 14:33         ` Maxime Ripard
2026-03-20 14:44           ` Brian Masney
2026-03-13 16:43 ` [PATCH v6 6/7] clk: divider: enable optional support for v2 rate negotiation Brian Masney
2026-03-19  9:36   ` Maxime Ripard
2026-03-13 16:43 ` [PATCH v6 7/7] clk: test: introduce additional test case showing v2 rate change + LCM parent Brian Masney
2026-03-19  9:43   ` Maxime Ripard
2026-03-19 11:09     ` Brian Masney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox