Received: by 10.223.176.5 with SMTP id f5csp1922850wra; Wed, 31 Jan 2018 13:45:04 -0800 (PST) X-Google-Smtp-Source: AH8x227MWj64WsI4IxLRspaWEcoRkuBukFrQOy16gttnGVHJl9iiOoptHYLIAAvdV66kmbQOqain X-Received: by 10.98.252.82 with SMTP id e79mr34853159pfh.159.1517435103938; Wed, 31 Jan 2018 13:45:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517435103; cv=none; d=google.com; s=arc-20160816; b=xcTordn0YH+9FJ7ykkqyfAsKhaZD+7BXHTmMO38dnfALsRVTUV1W1w8U0ZmmEG3E/3 DdDIN6ba1wPOLHN+9aRrapbm3JB91IeOEuvYvJiQcVIq8QsTipsJW2ZhaRTig5RXncXk lUI0wukgMLhFni7g5e2Vrt/17k7B3FqH7r/V42ewd9RQpOJwWJ7FKmXrOeW/ABT1IBjQ a5K18jZIsy+1b1hw9gFOavoXUn2lLT++/GOG+nlsOUHHfh8lIERjM1wey3Zf12NrUFHI JckryLvOxd26layoHiUjl6Uqa0Wrb/n23i4kLNeiHyX9T5dwJE/ka4IuI95Mi/yilOO6 saPQ== 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:references:cc:to:from:subject:dkim-signature :arc-authentication-results; bh=coOcIUJ9gNGoC4Ccm7hnFis7FJsdfx2c5kcwS6W2zgU=; b=CcbMZ1z4Zw6ZY29ECUEd6pN1apYh/w5a2vyd/TDl+jBY3iHh4m5Ai1MWnGTvkeVdZu XmnafAliv482+Rn04zkdPoqYR4h8u6OlaPxTWjHA2GJNPumdTRwQNJJYAhHk8ayXp82A Tre2fMOLfjFZp+aLJuSZHR8SfdRufRcXgSKPcS0kQ5DnxdriS/K20/mSu+MVirr63mtF FUmyJBuPvf8PDXDty7/ZqTSTNI6T9WBrBSpoZBMhxXc1WqG4gYYFHsY+blnvKhOFrR+P jHiN8kZWe69CFpd8IMb0vGcNlobvGLuAK7pAAQLNPDgV137EUeJ5i+LzErbR5ri4IFE8 y6Bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Ar1EpTA+; 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=NONE 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 g14-v6si4393080plj.292.2018.01.31.13.44.48; Wed, 31 Jan 2018 13:45:03 -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=Ar1EpTA+; 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=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753309AbeAaVnc (ORCPT + 99 others); Wed, 31 Jan 2018 16:43:32 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:43862 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752098AbeAaVna (ORCPT ); Wed, 31 Jan 2018 16:43:30 -0500 Received: by mail-pg0-f66.google.com with SMTP id n17so11144632pgf.10; Wed, 31 Jan 2018 13:43:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:from:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=coOcIUJ9gNGoC4Ccm7hnFis7FJsdfx2c5kcwS6W2zgU=; b=Ar1EpTA+CSaSl7V3p/9+mKT73qWwPi83+5SX0TXBYKxKBmx4ZLP0EaN+3SfYEwxIYb g7dhVxElzT0uCg/GjXVn/DujBkahHSCET2hAc2/sU8WU7rq/Z94TpRJpoMfI7rCH/9W1 8F+XwkBn2Gbdlui6t0A835Mw8cLyRjCVZGyI91EpcvgFjqPXEfJgpFQFcdVn28yoL7K/ TDvaxTULF+zIeSAdB4WfM+jn1k0htdxCcb3vbSyY5byzKVlcIgCkVbIz35HEPdzfW4HK QMFHm1Gr9pfiwJVdTNcXXntJax9z8ZezMqLXCWLj3KY6jWSs+IoVqB3UxhJwgDS7Fbi6 uEJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=coOcIUJ9gNGoC4Ccm7hnFis7FJsdfx2c5kcwS6W2zgU=; b=Wv5iXR3L7pjvVacWJilGyIfJQe7/8jYtsye5gAKwhpNFY2Cp2TCGcOj9AG45TiMlrO 92geYBzaT/n/IJvIOnNLtoTqHcZPzXsWwtZ/cq/56d6HfbGbujQKVio2NKglHVWurmPu kwpm8PA1f6vDlbDG19Rj8oPqZW/UC9zYtpKfR+jwP3DSosVROVOdecS/zQy79MN1OAZq ZKYUFenyYHvYAC1ZjpXqGOyuRs+OF7D7LixMV0lXoHEVrJ7FxPAJwdSAHnXedcHm/hfh Booa8XRVCAys2IfhzWiQD1w3H1NuRLnISoeCbkQCN4GIuELYlj9kmNNyzHyIB3ZFcvri /rGA== X-Gm-Message-State: AKwxyte0aMLQZZVPGWVdQMA6zj4QAFcarDg2YuFZskUjvpXItLx6Q1h2 3recMFxEtAZreZYjBs9RVG0= X-Received: by 10.101.73.131 with SMTP id r3mr27192473pgs.76.1517435009461; Wed, 31 Jan 2018 13:43:29 -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 a28sm42025155pfe.70.2018.01.31.13.43.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 Jan 2018 13:43:28 -0800 (PST) Subject: Re: [PATCH] of: cache phandle nodes to decrease cost of of_find_node_by_phandle() From: Frank Rowand To: Rob Herring , cpandya@codeaurora.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org References: <1517429142-25727-1-git-send-email-frowand.list@gmail.com> Message-ID: <5dd35d8f-c430-237e-9863-2e73556f92ec@gmail.com> Date: Wed, 31 Jan 2018 13:43:27 -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: <1517429142-25727-1-git-send-email-frowand.list@gmail.com> 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 01/31/18 12:05, frowand.list@gmail.com 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. > > The cache is initialized in of_core_init(). > > The cache is freed via a late_initcall_sync(). > > Signed-off-by: Frank Rowand > --- > > Some of_find_by_phandle() calls may occur before the cache is > initialized or after it is freed. For example, for the qualcomm > qcom-apq8074-dragonboard, 11 calls occur before the initialization > and 80 occur after the cache is freed (out of 516 total calls.) > > > drivers/of/base.c | 85 ++++++++++++++++++++++++++++++++++++++++++++++--- > drivers/of/of_private.h | 5 +++ > drivers/of/resolver.c | 21 ------------ > 3 files changed, 86 insertions(+), 25 deletions(-) Some observations.... The size of the cache for a normal device tree would be a couple of words of overhead for the cache, plus one pointer per devicetree node that contains a phandle property. This will be less space than would be used by adding a hash field to each device node. It is also less space than was used by the older algorithm (long gone) that added a linked list through the nodes that contained a phandle property. This is assuming that the values of the phandle properties are the default ones created by the dtc compiler. In the case where a very large phandle property value is hand-coded in a devicetree source, the size of the cache is capped at one entry per node. In this case, a little bit of space will be wasted -- but this is just a sanity fallback, it should not be encountered, and can be fixed by fixing the devicetree source.