Skip to content

clk: Improve clock range handling

Maxime Ripard dri-devel linux-clk linux-tegra 5 versions – Applied

Status from this message: Applied to drm/drm-misc (drm-misc-next).

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v7 Latest12 patches 9 repliesApplied
  2. v612 patches 16 repliesSuperseded
  3. v511 patches 0 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v410 patches20 repliesSuperseded
v310 patches5 repliesSuperseded

Changes in v7 from the cover letter

- Removed unused header
- Used more fitting KUNIT macros
- Enhanced some comments
- Reworded a commit message

Patches in v7 Applied

#Subject and filesSizeRepliesApplied
1/12clk: Fix clk_hw_get_clk() when dev is NULLdrivers/clk/clk.c+2 -10 replies
2/12clk: Introduce Kunit Tests for the frameworkdrivers/clk/.kunitconfig drivers/clk/Kconfig drivers/clk/Makefile +1 more+796 -00 replies
3/12clk: Enforce that disjoints limits are invaliddrivers/clk/clk.c+24 -00 replies
4/12clk: Always clamp the rounded ratedrivers/clk/clk.c drivers/clk/clk_test.c+34 -180 replies
5/12clk: Use clamp instead of open-coding our owndrivers/clk/clk.c+1 -50 replies
6/12clk: Always set the rate on clk_set_range_ratedrivers/clk/clk.c drivers/clk/clk_test.c+49 -544 replies
7/12clk: Add clk_drop_rangedrivers/clk/clk_test.c include/linux/clk.h+13 -20 replies
8/12clk: bcm: rpi: Add variant structuredrivers/clk/bcm/clk-raspberrypi.c+46 -160 replies
9/12clk: bcm: rpi: Set a default minimum ratedrivers/clk/bcm/clk-raspberrypi.c+26 -00 replies
10/12clk: bcm: rpi: Run some clocks at the minimum rate alloweddrivers/clk/bcm/clk-raspberrypi.c+37 -00 replies
11/12drm/vc4: Add logging and commentsdrivers/gpu/drm/vc4/vc4_kms.c+11 -01 reply
12/12drm/vc4: hdmi: Remove clock rate initializationdrivers/gpu/drm/vc4/vc4_hdmi.c+0 -131 reply

Reviews trailers per patch

2 of 12 patches have a Reviewed-by or Acked-by.

PatchDaniel LatypovDmitry OsipenkoThomas Zimmermann
1/12
2/12T-b
3/12
4/12
5/12
6/12T-b
7/12
8/12
9/12
10/12
11/12A-b
12/12A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v7 thread

Cover letter [PATCH v7 00/12] clk: Improve clock range handling

Hi,

This is a follow-up of the discussion here:
https://lore.kernel.org/linux-clk/20210319150355.xzw7ikwdaga2dwhv@gilmour/

and here:
https://lore.kernel.org/all/[email protected]/

While the initial proposal implemented a new API to temporarily raise and lower clock rates based on consumer workloads, Stephen suggested an alternative approach implemented here.

The main issue that needed to be addressed in our case was that in a situation where we would have multiple calls to clk_set_rate_range, we would end up with a clock at the maximum of the minimums being set. This would be expected, but the issue was that if one of the users was to relax or drop its requirements, the rate would be left unchanged, even though the ideal rate would have changed.

So something like

clk_set_rate(user1_clk, 1000);
clk_set_min_rate(user1_clk, 2000);
clk_set_min_rate(user2_clk, 3000);
clk_set_min_rate(user2_clk, 1000);

Would leave the clock running at 3000Hz, while the minimum would now be 2000Hz.

This was mostly due to the fact that the core only triggers a rate change in clk_set_rate_range() if the current rate is outside of the boundaries, but not if it's within the new boundaries.

That series changes that and will trigger a rate change on every call, with the former rate being tried again. This way, providers have a chance to follow whatever policy they see fit for a given clock each time the boundaries change.

This series also implements some kunit tests, first to test a few rate related functions in the CCF, and then extends it to make sure that behaviour has some test coverage.

Let me know what you think
Maxime

Changes from v6:
- Removed unused header
- Used more fitting KUNIT macros
- Enhanced some comments
- Reworded a commit message

Changes from v5:
- Changed clk_hw_create_clk for clk_hw_get_clk since the former isn't exported to modules.
- Added fix for clk_hw_get_clk

Changes from v4:
- Rename the test file
- Move all the tests to the first patch, and fix them up as fixes are done
- Improved the test conditions
- Added more tests
- Improved commit messages
- Fixed a regression where two disjoints clock ranges would now be accepted

Changes from v3:
- Renamed the test file and Kconfig option
- Add option to .kunitconfig
- Switch to kunit_kzalloc
- Use KUNIT_EXPECT_* instead of KUNIT_ASSERT_* where relevant
- Test directly relevant calls instead of going through a temporary variable
- Switch to more precise KUNIT_ASSERT_* macros where relevant

Changes from v2:
- Rebased on current next
- Rewrote the whole thing according to Stephen reviews
- Implemented some kunit tests

Changes from v1:
- Return NULL in clk_request_start if clk pointer is NULL
- Test for clk_req pointer in clk_request_done
- Add another user in vc4
- Rebased on top of v5.15-rc1

Maxime Ripard (12):
clk: Fix clk_hw_get_clk() when dev is NULL
clk: Introduce Kunit Tests for the framework
clk: Enforce that disjoints limits are invalid
clk: Always clamp the rounded rate
clk: Use clamp instead of open-coding our own
clk: Always set the rate on clk_set_range_rate
clk: Add clk_drop_range
clk: bcm: rpi: Add variant structure
clk: bcm: rpi: Set a default minimum rate
clk: bcm: rpi: Run some clocks at the minimum rate allowed drm/vc4: Add logging and comments
drm/vc4: hdmi: Remove clock rate initialization

 drivers/clk/.kunitconfig          |   1 +
 drivers/clk/Kconfig               |   7 +
 drivers/clk/Makefile              |   1 +
 drivers/clk/bcm/clk-raspberrypi.c | 125 ++++-
 drivers/clk/clk.c                 |  76 ++-
 drivers/clk/clk_test.c            | 795 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/vc4/vc4_hdmi.c    |  13 -
 drivers/gpu/drm/vc4/vc4_kms.c     |  11 +
 include/linux/clk.h               |  11 +
 9 files changed, 985 insertions(+), 55 deletions(-)
 create mode 100644 drivers/clk/clk_test.c
Signature · 1 line
2.35.1