Received: by 10.74.127.91 with SMTP id w88csp136887ooc; Tue, 13 Feb 2018 17:08:16 -0800 (PST) X-Google-Smtp-Source: AH8x225FYqU+HupOpUuDUsf369jk/Eb01lOwLSKmJHz0cTCLDTtt/sfiAwM1nElyFBJs36YoLh88 X-Received: by 10.99.116.22 with SMTP id p22mr1769053pgc.132.1518570495982; Tue, 13 Feb 2018 17:08:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518570495; cv=none; d=google.com; s=arc-20160816; b=Sm6mcIE+ULrlc9Drj/rJCbdRTBvyhsvjK6XT/Iw67zrnVKB+Nn4wIG+XUqrFM4K6X/ NOs3fTlxpZLkrEmssqb4ulpMqMb08ii9CwzEOvZkEmWfT5BaTIAMAgfsxIw5+9qM9DEC zCpr7XXhrW/c49lrcF0vRlsb/85y38QGxBaTgJhishAbn1Mj3esGuhBihsRh1F2TGmPW 0yrjOPpf7Ps0MGIoAl0gf+ZuRfCgEAIxYT0Wet+p6tTOxGR+1rjOj2DegMNLYdpkXs5q Y7PBL8tuYWhlXpnzVRGEqfvOdKKnrxGpQgx2YF3B+RbUekSz3XYSbjUbY3gE6xbBAOMc v4RA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=TFN+6GZiAcKAVMCCxPFgIeNE/qJiSTSfAg6cU2qa4aI=; b=LJBHrK1Z47Ntu/tvuLOOcAetDB6/Zwn4UtR/Aw2kmIYTD+os4g5pzgRXelT+PXeV9z MxEqdREVtYmRmlmZ4M01f/QLUS81pLrLbuCTDcH1X2iUX7ILvi7pjyUfQKR0WIWTgfI8 WKq0O5+WnivF/WRWlZEA+/5ulAs65A9fjplBTJ816YLf7Mz7JME4/VNU36T0HJwfUxbJ fZko8iepSrA/0SRj8VPS6HZukn9OuYXzPF0Ea3Cr+PGsDdQyG092/E7xP28PlVSH8ieM p0J6CAj+IsSkxIZTN8hEQ5jlrofysNE8GYHQWSEgKDE/lU/VoAdddmiFXt0Dexx5l9BA NuMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=imipPigW; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z12si5437034pgs.167.2018.02.13.17.08.00; Tue, 13 Feb 2018 17:08:15 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=imipPigW; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966314AbeBNBHV (ORCPT + 99 others); Tue, 13 Feb 2018 20:07:21 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:36635 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966225AbeBNBHU (ORCPT ); Tue, 13 Feb 2018 20:07:20 -0500 Received: by mail-pg0-f65.google.com with SMTP id j9so1244836pgv.3; Tue, 13 Feb 2018 17:07:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=TFN+6GZiAcKAVMCCxPFgIeNE/qJiSTSfAg6cU2qa4aI=; b=imipPigWa8yGCVuLhxRgNWxtPalbZN8KiXAdMKsrzjy7yArd6xeyDupsI8T0g9Nhdo jDI62DhmCD7qx1wgDGGfMEjAxZM3/EK/GK7tDdApFEExzdvL7wFCQuLlsFP76cHWgGhH 2bLaaf114gBJGdDVWmBDLr86QPE2W50JUqAXkVGbXIXM2FJlUuxUz5bNIBceMARop9Mc Cqyg60HjFKgE+KCL2WhhW0hrIhrXxhSfOs4UjRmFeEA24HQK3aY1FTVZu8zEpoHA97e/ eJC47gdATqDa0/RqcO7nOEexN/hu1K6XdUz+P3aNIHKCFse7fXxwc6ud7mETjCUQDEwd pyJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=TFN+6GZiAcKAVMCCxPFgIeNE/qJiSTSfAg6cU2qa4aI=; b=f7yHSLabcWzeyfLs16p1/i9qzRWrRsFmucKhpDDW1PYlH+oRNrfSJfsI3PnuCXCbjY VdENruFCDkUr9f5ucn1stYEl4BSZtFX+inE2BVKnbpIQM7JfLeeFd+qIeBKVfIqygAMu oCnuszDaUgRIEcKSjcQ6AtL0DzX1Q9VyEbmXzqC+sBYkGDhz9ULM01atHq356JVJD87M x+4Uh3QVyMg3nPkBhGJowU1bSKAzm8YTlzeW7D6vjTBLcBOl9wCuTGELtA1J7oA4g+Jv unXIW66EQ2X023bXr6Ca2uo3wh5Ei2A8RLv1C06D2ajURXeyUCiU9iEYKMfDbcryUdF8 8osQ== X-Gm-Message-State: APf1xPBoDdfnH1KCk+7A8fcBbzNeJyg4DcUJ3tIMBBs98sky1nckhXiQ X4EBOPoDZmK193r219bQJ2Q= X-Received: by 10.101.77.67 with SMTP id j3mr2416025pgt.76.1518570439544; Tue, 13 Feb 2018 17:07:19 -0800 (PST) Received: from [192.168.1.70] (c-73-93-215-6.hsd1.ca.comcast.net. [73.93.215.6]) by smtp.gmail.com with ESMTPSA id f4sm6972397pfn.82.2018.02.13.17.07.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Feb 2018 17:07:19 -0800 (PST) Subject: Re: [PATCH v2] of: cache phandle nodes to reduce cost of of_find_node_by_phandle() To: Rob Herring Cc: Chintan Pandya , devicetree@vger.kernel.org, "linux-kernel@vger.kernel.org" References: <1518416868-8804-1-git-send-email-frowand.list@gmail.com> From: Frank Rowand Message-ID: <6e16f883-8aaf-c6af-10f3-3d96c8370bd6@gmail.com> Date: Tue, 13 Feb 2018 17:07:17 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/13/18 06:49, Rob Herring wrote: > 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. Will do. >> 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. Will change to say so. >> + 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. I'll mask. > Please capture somewhere what the assumptions are for the cache to > work (i.e. phandles were allocated contiguously from 0). Will do. > > Rob >