* [PATCH] clk: make clk_core_lookup faster by using clk name hash
@ 2021-10-05 6:59 Mark-PK Tsai
2021-10-15 0:44 ` Stephen Boyd
0 siblings, 1 reply; 3+ messages in thread
From: Mark-PK Tsai @ 2021-10-05 6:59 UTC (permalink / raw)
To: mturquette, sboyd
Cc: mark-pk.tsai, yj.chiang, matthias.bgg, linux-clk, linux-kernel,
linux-arm-kernel, linux-mediatek
Compare hash value before strcmp the full name to make
clk_core_lookup faster.
It make clk driver probe 30 percent faster on the platform
have 1483 registered clks and average clock name length 20.
Signed-off-by: Mark-PK Tsai <mark-pk.tsai@mediatek.com>
---
drivers/clk/clk.c | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 65508eb89ec9..d5f65fda3db8 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -89,6 +89,7 @@ struct clk_core {
struct hlist_node debug_node;
#endif
struct kref ref;
+ unsigned int hash;
};
#define CREATE_TRACE_POINTS
@@ -292,16 +293,17 @@ struct clk_hw *clk_hw_get_parent(const struct clk_hw *hw)
EXPORT_SYMBOL_GPL(clk_hw_get_parent);
static struct clk_core *__clk_lookup_subtree(const char *name,
+ unsigned int hash,
struct clk_core *core)
{
struct clk_core *child;
struct clk_core *ret;
- if (!strcmp(core->name, name))
+ if (hash == core->hash && !strcmp(core->name, name))
return core;
hlist_for_each_entry(child, &core->children, child_node) {
- ret = __clk_lookup_subtree(name, child);
+ ret = __clk_lookup_subtree(name, hash, child);
if (ret)
return ret;
}
@@ -313,20 +315,22 @@ static struct clk_core *clk_core_lookup(const char *name)
{
struct clk_core *root_clk;
struct clk_core *ret;
+ unsigned int hash;
if (!name)
return NULL;
+ hash = full_name_hash(NULL, name, strlen(name));
/* search the 'proper' clk tree first */
hlist_for_each_entry(root_clk, &clk_root_list, child_node) {
- ret = __clk_lookup_subtree(name, root_clk);
+ ret = __clk_lookup_subtree(name, hash, root_clk);
if (ret)
return ret;
}
/* if not found, then search the orphan tree */
hlist_for_each_entry(root_clk, &clk_orphan_list, child_node) {
- ret = __clk_lookup_subtree(name, root_clk);
+ ret = __clk_lookup_subtree(name, hash, root_clk);
if (ret)
return ret;
}
@@ -3827,6 +3831,7 @@ __clk_register(struct device *dev, struct device_node *np, struct clk_hw *hw)
goto fail_name;
}
+ core->hash = full_name_hash(NULL, core->name, strlen(core->name));
if (WARN_ON(!init->ops)) {
ret = -EINVAL;
goto fail_ops;
--
2.18.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] clk: make clk_core_lookup faster by using clk name hash
2021-10-05 6:59 [PATCH] clk: make clk_core_lookup faster by using clk name hash Mark-PK Tsai
@ 2021-10-15 0:44 ` Stephen Boyd
2021-10-18 3:38 ` Chen-Yu Tsai
0 siblings, 1 reply; 3+ messages in thread
From: Stephen Boyd @ 2021-10-15 0:44 UTC (permalink / raw)
To: Mark-PK Tsai, mturquette
Cc: mark-pk.tsai, yj.chiang, matthias.bgg, linux-clk, linux-kernel,
linux-arm-kernel, linux-mediatek
Quoting Mark-PK Tsai (2021-10-04 23:59:49)
> Compare hash value before strcmp the full name to make
> clk_core_lookup faster.
>
> It make clk driver probe 30 percent faster on the platform
> have 1483 registered clks and average clock name length 20.
Why is clk_core_lookup() a fast path for you?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] clk: make clk_core_lookup faster by using clk name hash
2021-10-15 0:44 ` Stephen Boyd
@ 2021-10-18 3:38 ` Chen-Yu Tsai
0 siblings, 0 replies; 3+ messages in thread
From: Chen-Yu Tsai @ 2021-10-18 3:38 UTC (permalink / raw)
To: Stephen Boyd
Cc: Mark-PK Tsai, Michael Turquette, yj.chiang, Matthias Brugger,
linux-clk, LKML,
moderated list:ARM/FREESCALE IMX / MXC ARM ARCHITECTURE,
moderated list:ARM/Mediatek SoC support
On Fri, Oct 15, 2021 at 8:44 AM Stephen Boyd <sboyd@kernel.org> wrote:
>
> Quoting Mark-PK Tsai (2021-10-04 23:59:49)
> > Compare hash value before strcmp the full name to make
> > clk_core_lookup faster.
> >
> > It make clk driver probe 30 percent faster on the platform
> > have 1483 registered clks and average clock name length 20.
>
> Why is clk_core_lookup() a fast path for you?
Maybe because the Mediatek clock driver still does global clk name matching
to resolve parents?
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-10-18 3:38 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-05 6:59 [PATCH] clk: make clk_core_lookup faster by using clk name hash Mark-PK Tsai
2021-10-15 0:44 ` Stephen Boyd
2021-10-18 3:38 ` Chen-Yu Tsai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).