Received: by 10.223.185.116 with SMTP id b49csp6562756wrg; Wed, 28 Feb 2018 11:32:29 -0800 (PST) X-Google-Smtp-Source: AH8x225E5qKNQIWAMAappelSshGweu2QsVUIfIB5CNUIXtFumNEi7GcWVl9XOsNC4ecGsfBEzTUg X-Received: by 2002:a17:902:7786:: with SMTP id o6-v6mr18654146pll.2.1519846349119; Wed, 28 Feb 2018 11:32:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519846349; cv=none; d=google.com; s=arc-20160816; b=y8uT9BTeHz8WGzSbAo+ctqgzzvDf+Rzz4eaMkjj0amks+bBrNsBLd84ep2DR1DjWJK ftMAeQGpGu8IHxzMAGMcUR1JTn2NwiPx3i/bV3yH4ALYxwLcugQBxakD3Nubp8pzDcFJ nMJQCza1/UuG1u1BlDAckX7TgGcoB+d5KPQRWH94Lwgak2YGkjPzLD29HVDGSjyNN1ag iGbAufYSPGnlAT2zJt1xr8uaMqp6FcBqU4QuW8EEtz8EuSqu43eOrxTk4r8/WBrdujda XKl26kQe/XRzRpE1QyHaEzE8rG6OvFJuoo0kDji8ycxYPDKFoRXRdsEF9vSYBcFjtiLj Nxzw== 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:dkim-signature :arc-authentication-results; bh=CQku/lWsHYxaAHe7t/DB75cX1EP3cm078EwFa9z6O8E=; b=wFeqx6ziZTVqaQb/ohw4ahfIaq/K0G7rOwtSUBvHRd2+Hf4DkdNLPdXZEK49Ih533l RCjwaaoV2s64DI2AjKa7fj8oWbfhGFnbilY+YmAnstpCjec73REvgidf7VfDjjSXJl8h tqhb2sOtxDuNYY6QWXVr5zqdNLq0g9wXjCIqPFJHC4PLKPpo9rj9QpSGppKd7nc22yIf x1lZmdJMrov+y6Cx8tUwIK8jwhW6gyWujQAe1MrgKskQCq0zQBOx173F4i2BVo5DECtf J+9ajXcs2D/HPFgMsBwFcE2No5mlMFgVXiJzqwzwzNLdF2Jm65L8AfopacclvmrXY+Bz g6yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Oyst+KgU; 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 e87si1644502pfd.352.2018.02.28.11.32.13; Wed, 28 Feb 2018 11:32:29 -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=Oyst+KgU; 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 S933629AbeB1Tbd (ORCPT + 99 others); Wed, 28 Feb 2018 14:31:33 -0500 Received: from mail-qt0-f195.google.com ([209.85.216.195]:34660 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933330AbeB1Tbb (ORCPT ); Wed, 28 Feb 2018 14:31:31 -0500 Received: by mail-qt0-f195.google.com with SMTP id l25so4499806qtj.1; Wed, 28 Feb 2018 11:31:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=CQku/lWsHYxaAHe7t/DB75cX1EP3cm078EwFa9z6O8E=; b=Oyst+KgUbvJaxq98QuB13euFn6jWq5mVfCXUOgIF9wFFL7AZmdci0Qm1NGXa8z+o+D xZVmSm+WfQox9Ww3TckOvS81tONehYdw4yh7+RXbLJYgZMW12RomoBF50KaFT4W83uat 7TUnT+Z9ZouIKb5aU59hOhKENnfI+0NnlZ7FQupdzA1Oh/s87TTLs41yDWiXBT4z7lc9 mfEoS8+celG8n0dw1z01xsqVNIC7I3jgvFnnO1n2t8lfTEN8L6SfyE2+CPmUJU2/tHo1 j4tpMXuGuCrcKEMeOjU6ipFeAqMdBYusaYqBXYh8N1yj9igke8TdPGa3dyTIa2DSgFnK idcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=CQku/lWsHYxaAHe7t/DB75cX1EP3cm078EwFa9z6O8E=; b=hfmkL2C8W7omR8/Z9qJb/d8QPYEGgfgySBfFq3oq1aZTjXfvm8FVtMXRlrlTULGJC1 hkpX1UiVdcYm4mFh9Bjr+4zX/eEeCZEhwO4DGBTSu5JYoEi5b3009FHjRwyJXAnBsrRM 0pt7EV5pk/tVCdXdtGhG4F6fnZFKly/LhmNPOFf4SNKVCovDtPSZAifCiZKzPNDMQe1o uLl4YeskA2ICZYxFb9LZkNbMIiS5W5WY6OS22JnvUPBeVdJM/C/K1y4h4O1aGGCSGOfH Vc2MJEAZeyUilqFzt6iai6rDMvo/WjjFYFolnvwsWD3JucMP639L/MK0zxUhdR+89jnc A2cw== X-Gm-Message-State: APf1xPDxuN7szkw62OQ1t58xsVa7azW3caYXfVcdVkSyuyJonLxxMyk1 DOHDFA/9/b40jajkGy1H356EM3yr/S0LHj8Z+OE= X-Received: by 10.237.59.232 with SMTP id s37mr30334594qte.83.1519846290646; Wed, 28 Feb 2018 11:31:30 -0800 (PST) MIME-Version: 1.0 Received: by 10.12.195.80 with HTTP; Wed, 28 Feb 2018 11:31:29 -0800 (PST) In-Reply-To: <1519844656-16443-2-git-send-email-frowand.list@gmail.com> References: <1519844656-16443-1-git-send-email-frowand.list@gmail.com> <1519844656-16443-2-git-send-email-frowand.list@gmail.com> From: Andy Shevchenko Date: Wed, 28 Feb 2018 21:31:29 +0200 Message-ID: Subject: Re: [PATCH v4 1/2] of: cache phandle nodes to reduce cost of of_find_node_by_phandle() To: Frank Rowand Cc: Rob Herring , cpandya@codeaurora.org, devicetree , Linux Kernel Mailing List 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 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? Using radix_tree() I suppose allows to dynamically extend or shrink the cache which would work with DT overlays. -- With Best Regards, Andy Shevchenko