Received: by 10.223.185.116 with SMTP id b49csp6577603wrg; Wed, 28 Feb 2018 11:47:28 -0800 (PST) X-Google-Smtp-Source: AH8x225SE3z5DpC8S5TFbw+RCfGwg6Ij8ff9Ff2kt+Vjfr8G80sa/UfQ1zRDUEJDXp0SkWFKniCA X-Received: by 10.101.89.6 with SMTP id f6mr15193842pgu.22.1519847248440; Wed, 28 Feb 2018 11:47:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519847248; cv=none; d=google.com; s=arc-20160816; b=XsuHkm7z3HuUgfXiTZK4it7AmsSEoYKg8CjTmZw1/KFqXdklfD7/Nu5bpmIbJNIyH/ G/y2WhsqvD5upRk7j+OU9mn3rH+Lo5I5PmqzAHn61VZ2faat19CU0sqN3AxIlVBdiuTm rT7M/NXThAEN7onmUe35e6hDXom9XxKgW1pA+Q1Py3HrVdBusF/OrsCH9KhFxwp0brVm nBoKeATuG9ak6ovmCQQtpOhg9et447XxJlGa1Gf0U8LUSLlIkTLmxZ9myBjev0agwuj2 rmVJ6JmvEkOfn6v6PGc+EhPVYyaeWFfMvu+oDDJZELCiTmKfEuUVHJlBJpKjbYQ1gZqU NqIw== 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=dqSZRWhlOaAmMhMWazCVgMGbU9NFXMzpSNFiGYds/wk=; b=pjgzn+AQSo1a693+F+FhICtNqWXxbBiWvSuVa3FIZcpSla/g+JpvYuU4Z88/hn6JwZ sF/Zgg/9YTuFbnaPNZufpmLiSNNDRa5J6ZmaOF2ykCqa5FQpiHTZTdoqrMP5PntB9b0z go2iw3cAzfPMt1vLSXQnij/kmB/Y9+biz+VLdcf0BwjgPWZ62uOJqH8CVfEnEtDVMn/e +5HmFprmAFSSBJYQ9NkNPRsUKIiZ/Pfpq4Fuijana443+3MWVXZFuAQyelc4WDqP5pmK YzaP3Y2XPTnsiew6TP7VJJziLr78/rFBHztoRE6JNRG5NYIffO8EAA2Ie+4R79aLz6Ij TyPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Fa6wmN5h; 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 k23-v6si1784872pls.42.2018.02.28.11.47.13; Wed, 28 Feb 2018 11:47:28 -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=Fa6wmN5h; 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 S933996AbeB1To4 (ORCPT + 99 others); Wed, 28 Feb 2018 14:44:56 -0500 Received: from mail-pf0-f193.google.com ([209.85.192.193]:35457 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932351AbeB1Toy (ORCPT ); Wed, 28 Feb 2018 14:44:54 -0500 Received: by mail-pf0-f193.google.com with SMTP id y186so1432551pfb.2; Wed, 28 Feb 2018 11:44:54 -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=dqSZRWhlOaAmMhMWazCVgMGbU9NFXMzpSNFiGYds/wk=; b=Fa6wmN5hGX9jmnrULAgHBUIrJpiEchUghaoVtUit9afVVfedHs51WBA3PBQzriLrYD LSYkpaxHsHUP0S+ryYrQokl7EBZu2rtRVMV/6lo4VVmoifpam0heXr8DuwO3XGc0txW7 ZgAaL+HVIv4oU6GH1P0ZFXAY4nwsOc1+KYrqgvuQPoMKI0o6GR/M7MgOBhnaMLce7/HL Oi4DtKc6NfK0VIhxv24JG2en3SG4D0JhWhnyXUUgzsvj+ko4E5Czygbw+TOmhiEGGK/X XUXHP647CPjxPBdvcwtEep3pzZWM13hf/MU3u51YRYhiGUIHKDOu5SPLSjBPeTFFmLQ1 /KRA== 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=dqSZRWhlOaAmMhMWazCVgMGbU9NFXMzpSNFiGYds/wk=; b=grS9OG4rz6naaM0a/NIfKdUobpmN5b5ZkPTyvCsSlblNu/jATQlplwWpJo3/IItb2c Ov7reRof4s12DuhBGQZXxDZ1WnYnTPn6KuFfJmS/UqASO1Yg5rv9EFyZ2FfNVke9KOsz EahRFm8BWwaYX8c+Sjc1NINFCFoF4AE2NOXAqiJ/PJ+oWX3/Ny0cS7ha9PNbnmBRV8gx 2zLJlYWJ5amFrnrkgmIagUEWjyQJthwIc2ww4myutCVo1Ey+Y2/SC6L9hO/Ah58mngOf rjVyV8npSNXsJ2KhwVBl1XEFL2gRsW61aDKP7/QPr1KafGAmuF2L0lEAZ/GFLXc42FKr pe8w== X-Gm-Message-State: APf1xPBttmiM3V89+VTC1gAe8MkuU1/OXxn3VAi7Hjve0ShLCF80Mno5 OM620WmFPCZnX8RonbZ4HhBC+/5D X-Received: by 10.98.156.16 with SMTP id f16mr18955856pfe.180.1519847093653; Wed, 28 Feb 2018 11:44:53 -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 f11sm5011146pfa.166.2018.02.28.11.44.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 28 Feb 2018 11:44:53 -0800 (PST) Subject: Re: [PATCH v4 1/2] of: cache phandle nodes to reduce cost of of_find_node_by_phandle() To: Andy Shevchenko Cc: Rob Herring , cpandya@codeaurora.org, devicetree , Linux Kernel Mailing List References: <1519844656-16443-1-git-send-email-frowand.list@gmail.com> <1519844656-16443-2-git-send-email-frowand.list@gmail.com> From: Frank Rowand Message-ID: Date: Wed, 28 Feb 2018 11:44:51 -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/28/18 11:31, Andy Shevchenko wrote: > On Wed, Feb 28, 2018 at 9:04 PM, wrote: > >> 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() if modules are not >> enabled. >> >> If the devicetree is created by the dtc compiler, with all phandle >> property values auto generated, then the size required by the cache >> could be 4 * (1 + number of phandles) bytes. This results in an O(1) >> node lookup cost for a given phandle value. Due to a concern that the >> phandle property values might not be consistent with what is generated >> by the dtc compiler, a mask has been added to the cache lookup algorithm. >> To maintain the O(1) node lookup cost, the size of the cache has been >> increased by rounding the number of entries up to the next power of >> two. >> >> The overhead of finding the devicetree node containing a given phandle >> value has been noted by several people in the recent past, in some cases >> with a patch to add a hashed index of devicetree nodes, based on the >> phandle value of the node. One concern with this approach is the extra >> space added to each node. This patch takes advantage of the phandle >> property values auto generated by the dtc compiler, which begin with >> one and monotonically increase by one, resulting in a range of 1..n >> for n phandle values. This implementation should also provide a good >> reduction of overhead for any range of phandle values that are mostly >> in a monotonic range. >> >> Performance measurements by Chintan Pandya >> of several implementations of patches that are similar to this one >> suggest an expected reduction of boot time by ~400ms for his test >> system. If the cache size was decreased to 64 entries, the boot >> time was reduced by ~340 ms. The measurements were on a 4.9.73 kernel >> for arch/arm64/boot/dts/qcom/sda670-mtp.dts, contains 2371 nodes and >> 814 phandle values. > > The question is why O(1) is so important? O(log(n)) wouldn't work? O(1) is not critical. It was just a nice side result. > Using radix_tree() I suppose allows to dynamically extend or shrink > the cache which would work with DT overlays. The memory usage of the phandle cache in this patch is fairly small. The memory overhead of a radix_tree() would not be justified.