Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp4321199pxb; Tue, 5 Oct 2021 00:02:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySBKcukfujXMXhgEDFQDXD9iWR+C61IOpk05dFL4bI9npElexqUbCtB87O6Hv6ZhpodUzZ X-Received: by 2002:a05:6402:4cb:: with SMTP id n11mr23808219edw.233.1633417333165; Tue, 05 Oct 2021 00:02:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633417333; cv=none; d=google.com; s=arc-20160816; b=MZBokjtenKJ9gfMFnKvUOAldoMQI+Qk1mA+e+tMoUrJH9/2FMC1TL7x0EuA8Zca7Zr KDljaBcAjFq8QMY+20s7q7q6cc3dxhex99AJEueci49twyHGgidFxfoYCT+iYseS3faL sHg6LeYw4TJhFUO4o/3YZNWvMUYsHIikmEC0lfe2wgJLrIcCkoYtwigO5VCVgr9Nljc/ ZkGHgyo33Nwu9LaeHaE3bgbzQaR9EwjZ/GY7Tsebv8a0zsaOLn3efGX2+2QqILnPJSMz uTks/gFrIeRtgnYYf4MR4i86AzkQlyUsw4CEiSlp6I8rqbZ3mX6BPdNSxYe6SVoelyy4 Lz0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=1Y5TOY9Yqs/DyqG4K+etqXGf/Z3UTCNvSypf+tZpp/k=; b=EQUKbx0dI5dNCBVZuIO8VegrZPOd+gl9d7Nu8d4x67zGUuNkcFD9LNOEtLQfPLg0sV TzXA+FT/Jp+6pWw4g3grIGmRWtU2iC6n152aQR3QiqvsJQDqlPEM+xcJJxINZeF0Uyhf 8VrIowDZtm5Qxby5Wvg7D0Ezq4K52/DRbqttHtxBlsI3BxRsmeeVds4hS0Oag0qSTRDO N0JlA/KtIeJgHmOB4BIWwE0vBsEvH1RKZiVYIV48WqpGP118UP3jnZKcrDRNz0cf1w8D fVNgzKsv59084yyARHVtw/secPpZlrtGPbZB6QlsYsAk7hMsztnlb9LP2EfYepdOQ2g6 VmUw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h3si8912705ede.192.2021.10.05.00.01.49; Tue, 05 Oct 2021 00:02:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232460AbhJEHCO (ORCPT + 99 others); Tue, 5 Oct 2021 03:02:14 -0400 Received: from mailgw01.mediatek.com ([60.244.123.138]:53540 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S231816AbhJEHCO (ORCPT ); Tue, 5 Oct 2021 03:02:14 -0400 X-UUID: be0b5d5e78f24b48875d241a10957d00-20211005 X-UUID: be0b5d5e78f24b48875d241a10957d00-20211005 Received: from mtkcas07.mediatek.inc [(172.21.101.84)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 4802693; Tue, 05 Oct 2021 15:00:20 +0800 Received: from mtkexhb02.mediatek.inc (172.21.101.103) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.3; Tue, 5 Oct 2021 15:00:19 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkexhb02.mediatek.inc (172.21.101.103) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 5 Oct 2021 15:00:19 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Tue, 5 Oct 2021 15:00:18 +0800 From: Mark-PK Tsai To: , CC: , , , , , , Subject: [PATCH] clk: make clk_core_lookup faster by using clk name hash Date: Tue, 5 Oct 2021 14:59:49 +0800 Message-ID: <20211005065948.10092-1-mark-pk.tsai@mediatek.com> X-Mailer: git-send-email 2.18.0 MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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