Received: by 10.223.185.116 with SMTP id b49csp3725033wrg; Tue, 13 Feb 2018 06:52:14 -0800 (PST) X-Google-Smtp-Source: AH8x227jdFPsgh5IwQPoR8KiNUeB49VMVyQCt/3vrTN0Q/yzPTXsbgblgTNaTixmv6nsWjegXsXU X-Received: by 10.101.97.5 with SMTP id z5mr1180005pgu.270.1518533534029; Tue, 13 Feb 2018 06:52:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518533533; cv=none; d=google.com; s=arc-20160816; b=G69b3l992Gash6hI2Jv6MEnj9g+ktre9Vjng1C+tVwiLnBy8lUR8d+IswiDUvao+wE Fu25yJ15RmqD4YfaL/RYxIooqniUwg80PrjyER1VFFmmal3SZt7VAczqfI43QeggiLy2 1BpNpPbPRIcy5xT1yuL2fuRSDIQn7i+U2q0QTXooDhMXcG2XCoyWiQlGh9mro7WroCJ+ XBsPygi005V5k8i5UKq/vO/3WaxJW+G5BZpyucV/U1eKtos59S4eCupwBzCE4fPOTfps ijwhqmGTLcHSFnQ0ILWkgV53oLdcVvEJ9u3+gPY3kjRGc+6s6IkRmHpsXBB05EDJ2mfy BgfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dmarc-filter :arc-authentication-results; bh=UXhpu64q3XTlTCtplBmotZIl0peX1uh2pX2g2LYyciQ=; b=084LQUUNEdIBHnHM1JBRFHTJ/ce0PWwrzbPDRFCmtr8xDZt5Tq7aZq6hzweSRd2VJG q5tG5Bv3M/BjH3vv8nnjnexWp6fJF58YY2yUinOfDnTpa3rbXG56BtQRtPkhIjtvJX8r QgCO5mEtVCcVgQ34mQ3Ozum1yBOJucBg9OXYpa9OUCuPAOwWmHe7Xv2e1atOOBxxyrjz wafCZ9gPNE4YjtHJNexgF5dhkry1uognJ29xh6Jup3RQTcObjg6lJmGlWbvGQaZ3MD5p NyM2QgLTPfcRDJR86GscwFD1XZh+h0rTrfaKDRVNrzn48a0c7k+uwHbGWOupat/wSVLV EarQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a2-v6si23572plp.777.2018.02.13.06.51.59; Tue, 13 Feb 2018 06:52:13 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935418AbeBMOuD (ORCPT + 99 others); Tue, 13 Feb 2018 09:50:03 -0500 Received: from mail.kernel.org ([198.145.29.99]:58210 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933716AbeBMOuC (ORCPT ); Tue, 13 Feb 2018 09:50:02 -0500 Received: from mail-qt0-f170.google.com (mail-qt0-f170.google.com [209.85.216.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id E1FAC2178F; Tue, 13 Feb 2018 14:50:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E1FAC2178F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=robh+dt@kernel.org Received: by mail-qt0-f170.google.com with SMTP id d26so2284022qtj.4; Tue, 13 Feb 2018 06:50:01 -0800 (PST) X-Gm-Message-State: APf1xPDnnO0dCgNXYEq4sLA6moapVXr01pTSk78Pwt8ZK3n/BSljYIXU n+Yh3sXHI4HZNv24FDwZdigAMRJkhdcvShq5jw== X-Received: by 10.200.26.79 with SMTP id q15mr2157251qtk.174.1518533400921; Tue, 13 Feb 2018 06:50:00 -0800 (PST) MIME-Version: 1.0 Received: by 10.12.245.147 with HTTP; Tue, 13 Feb 2018 06:49:40 -0800 (PST) In-Reply-To: <1518416868-8804-1-git-send-email-frowand.list@gmail.com> References: <1518416868-8804-1-git-send-email-frowand.list@gmail.com> From: Rob Herring Date: Tue, 13 Feb 2018 08:49:40 -0600 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2] of: cache phandle nodes to reduce cost of of_find_node_by_phandle() To: Frank Rowand Cc: Chintan Pandya , devicetree@vger.kernel.org, "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 12, 2018 at 12:27 AM, wrote: > From: Frank Rowand > > Create a cache of the nodes that contain a phandle property. Use this > cache to find the node for a given phandle value instead of scanning > the devicetree to find the node. If the phandle value is not found > in the cache, of_find_node_by_phandle() will fall back to the tree > scan algorithm. Please add some data here as to what speed up we see. > The cache is initialized in of_core_init(). > > The cache is freed via a late_initcall_sync() if modules are not > enabled. > > Signed-off-by: Frank Rowand > --- > > Changes since v1: > - change short description from > of: cache phandle nodes to reduce cost of of_find_node_by_phandle() > - rebase on v4.16-rc1 > - reorder new functions in base.c to avoid forward declaration > - add locking around kfree(phandle_cache) for memory ordering > - add explicit check for non-null of phandle_cache in > of_find_node_by_phandle(). There is already a check for !handle, > which prevents accessing a null phandle_cache, but that dependency > is not obvious, so this check makes it more apparent. > - do not free phandle_cache if modules are enabled, so that > cached phandles will be available when modules are loaded > > drivers/of/base.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++--- > drivers/of/of_private.h | 5 +++ > drivers/of/resolver.c | 21 ----------- > 3 files changed, 94 insertions(+), 25 deletions(-) > > diff --git a/drivers/of/base.c b/drivers/of/base.c > index ad28de96e13f..b3597c250837 100644 > --- a/drivers/of/base.c > +++ b/drivers/of/base.c > @@ -91,10 +91,88 @@ int __weak of_node_to_nid(struct device_node *np) > } > #endif > > +static struct device_node **phandle_cache; > +static u32 max_phandle_cache; > + > +phandle live_tree_max_phandle(void) > +{ > + struct device_node *node; > + phandle max_phandle; > + unsigned long flags; > + > + raw_spin_lock_irqsave(&devtree_lock, flags); > + > + max_phandle = 0; > + for_each_of_allnodes(node) { > + if (node->phandle != OF_PHANDLE_ILLEGAL && > + node->phandle > max_phandle) > + max_phandle = node->phandle; > + } > + > + raw_spin_unlock_irqrestore(&devtree_lock, flags); > + > + return max_phandle; > +} > + > +static void of_populate_phandle_cache(void) > +{ > + unsigned long flags; > + phandle max_phandle; > + u32 nodes = 0; > + struct device_node *np; > + > + if (phandle_cache) > + return; > + > + max_phandle = live_tree_max_phandle(); > + > + raw_spin_lock_irqsave(&devtree_lock, flags); > + > + for_each_of_allnodes(np) > + nodes++; > + > + /* sanity cap for malformed tree */ Or any tree that doesn't match your assumptions. > + if (max_phandle > nodes) > + max_phandle = nodes; I fail to see how setting max_phandle to number of nodes helps you here. Either just bail out or mask the phandle values so this works with any contiguous range. Please capture somewhere what the assumptions are for the cache to work (i.e. phandles were allocated contiguously from 0). Rob