Re: [PATCH v2 2/2] clk: Use hashtable for global clk lookups
From: Stephen Boyd <sboyd@kernel.org>
Date: 2025-09-21 17:20:06
Also in:
linux-clk, lkml
Quoting Chen-Yu Tsai (2025-08-13 20:53:16)
A clk lookup using clk_core_lookup() is currently somewhat expensive
since it has to walk the whole clk tree to find a match. This is
extremely bad in the clk_core_init() function where it is used to look
for clk name conflicts, which is always the worst case of walking the
whole tree. Moreover, the number of clks checked increases as more
clks are registered, causing each subsequent clk registration becoming
slower.
Add a hashtable for doing clk lookups to replace the tree walk method.
On arm64 this increases kernel memory usage by 4 KB for the hashtable,
and 16 bytes (2 pointers) for |struct hlist_node| in each clk. On a
platform with around 800 clks, this reduces the time spent in
clk_core_lookup() significantly:
| PID 0 | kworker |
| before | after | before | after |
-------------------------------------------Applied to clk-next Can you send a followup that adds a unit test for clk_core_lookup()? We don't want __clk_lookup() to continue being used, so maybe we can add a test only exported function like clk_hw_lookup() that uses clk_core_lookup() underneath while grabbing the prepare lock. It can make sure a registered clk_hw is found and a non-registered name isn't found and assert that the not yet registered name isn't found.