Received: by 10.223.185.116 with SMTP id b49csp1016790wrg; Fri, 16 Feb 2018 10:53:09 -0800 (PST) X-Google-Smtp-Source: AH8x227DkDAAQvFzYxcK4izj7cUhzjY9BO+SJlCl0ZmMgujDOX09rzFjR//kPcUSv6Bi2s9ExrlT X-Received: by 2002:a17:902:208:: with SMTP id 8-v6mr6706742plc.359.1518807189683; Fri, 16 Feb 2018 10:53:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518807189; cv=none; d=google.com; s=arc-20160816; b=XK9Puz79xgdyH6DXVCub9WVCjGDGq5vSXveLikadPUzPSVnpYd2vcth9A+qpNHaaD9 8CeCSyIA1FgmLR+UzuigOSnawXUK4rMf5IpWktDwNmTALdp+vqQ+Mz681tC1SHswTqA1 0z2Sz3FO3hQ/JEySAnYxmY+t+7xHg94MtMJhNasaqlm2LtTAAHZoDS6p8o7q83Tvyr33 yZPG5Ykrw79+FfKQKg0cvHEEYIDjiG+c7LcmzKUZm6tKLNBZ2jrJ0DA4TrW4yGM3moYc D2Vd8MYWPqc8BzR2HrsvAflk6U5zze/3V4Kh5kxqyzlRi0T4FxfR45VbIFV/sl+tGw7/ QBWg== 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:dmarc-filter :dkim-signature:dkim-signature:arc-authentication-results; bh=SXv+KDEYUuwNQ5DAwYPVaPenDM76F1A6PWnEvkwDEBc=; b=IWvs27ubq2nXOzqYuVgxuDly5X1iPxSduhoofTcFQ/NgCtkm+0vIGvbb3W6lShPEIy vX4PHLKFzktIG/DMnrGD7rxzhcEr9i/xRPeyydw7APMHxaRhOWu8GOcbV4stOnIWfdPQ bc3FBvbyMFVNzOFX8eZD4ofnTj0Mzpm4ckYRhWcg0jiPZHkxxfe1OUMapjGKWAF25LJ9 izij5D+E3lsOiACcOX0JP6LgZHEeJ8ciGiSqaUe2AKxjnQ0NveiH3b/nNhOY2zafD1Cs HFiC30bJZ9acm5eI+YqS8LmhtCG4bAiY1mEHYsG8Jzskj9YWc/bHF0Fex5nzRQx/ZnS7 X0Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=oM9iM0fx; dkim=pass header.i=@codeaurora.org header.s=default header.b=oM9iM0fx; 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 z28si4897299pfd.376.2018.02.16.10.52.55; Fri, 16 Feb 2018 10:53:09 -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=@codeaurora.org header.s=default header.b=oM9iM0fx; dkim=pass header.i=@codeaurora.org header.s=default header.b=oM9iM0fx; 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 S1757556AbeBPJIB (ORCPT + 99 others); Fri, 16 Feb 2018 04:08:01 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:50750 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757541AbeBPJIA (ORCPT ); Fri, 16 Feb 2018 04:08:00 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id DD954609D1; Fri, 16 Feb 2018 09:07:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1518772079; bh=y0/hd28QfAOIez+fa14E7JF5qUsmg/9gwD8FMEiUFzM=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=oM9iM0fxrzIr4bTeMq5UjIK+Dsho3rtLl17GU7AjJE88BYWQkjF7UeL0b/V4xBXcS trIL1UCONkYMTmrCUlphvX39FZAnhASludey8+HFFAYzVmsV+MjkPSHvYJBlOxYPWi WfzsrtnDs4SjqE1zv7DvMzHuB61lNYuchS6cikBs= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from [10.204.100.248] (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: cpandya@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id DE43960790; Fri, 16 Feb 2018 09:07:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1518772079; bh=y0/hd28QfAOIez+fa14E7JF5qUsmg/9gwD8FMEiUFzM=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=oM9iM0fxrzIr4bTeMq5UjIK+Dsho3rtLl17GU7AjJE88BYWQkjF7UeL0b/V4xBXcS trIL1UCONkYMTmrCUlphvX39FZAnhASludey8+HFFAYzVmsV+MjkPSHvYJBlOxYPWi WfzsrtnDs4SjqE1zv7DvMzHuB61lNYuchS6cikBs= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org DE43960790 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=cpandya@codeaurora.org Subject: Re: [PATCH] of: add early boot allocation of of_find_node_by_phandle() cache To: frowand.list@gmail.com, Rob Herring Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org References: <1518655465-10759-1-git-send-email-frowand.list@gmail.com> From: Chintan Pandya Message-ID: <25deaf48-6590-4ca2-e0db-adaef1f49c5d@codeaurora.org> Date: Fri, 16 Feb 2018 14:37:55 +0530 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <1518655465-10759-1-git-send-email-frowand.list@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed 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 2/15/2018 6:14 AM, frowand.list@gmail.com wrote: > From: Frank Rowand > > The initial implementation of the of_find_node_by_phandle() cache > allocates the cache using kcalloc(). Add an early boot allocation > of the cache so it will be usable during early boot. Switch over > to the kcalloc() based cache once normal memory allocation > becomes available. > > Signed-off-by: Frank Rowand > --- > > This patch is optional, to be added at Rob's discretion. The > extra complexity is not as much as I had feared, but the boot > speed up is also likely small. > > drivers/of/base.c | 33 +++++++++++++++++++++++++++++++++ > drivers/of/fdt.c | 2 ++ > drivers/of/of_private.h | 2 ++ > 3 files changed, 37 insertions(+) > > diff --git a/drivers/of/base.c b/drivers/of/base.c > index ab545dfa9173..d7b1ff1209e8 100644 > --- a/drivers/of/base.c > +++ b/drivers/of/base.c > @@ -16,9 +16,11 @@ > > #define pr_fmt(fmt) "OF: " fmt > > +#include > #include > #include > #include > +#include > #include > #include > #include > @@ -131,6 +133,29 @@ static void of_populate_phandle_cache(void) > raw_spin_unlock_irqrestore(&devtree_lock, flags); > } > > +void __init of_populate_phandle_cache_early(void) > +{ > + u32 cache_entries; > + struct device_node *np; > + u32 phandles = 0; > + size_t size; > + > + for_each_of_allnodes(np) > + if (np->phandle && np->phandle != OF_PHANDLE_ILLEGAL) > + phandles++; > + > + cache_entries = roundup_pow_of_two(phandles); > + phandle_cache_mask = cache_entries - 1; > + > + size = cache_entries * sizeof(*phandle_cache); > + phandle_cache = memblock_virt_alloc(size, 4); > + memset(phandle_cache, 0, size); > + > + for_each_of_allnodes(np) > + if (np->phandle && np->phandle != OF_PHANDLE_ILLEGAL) > + phandle_cache[np->phandle & phandle_cache_mask] = np; > +} There is a lot of code duplication in this function with of_populate_phandle_cache. Would you think of taking out common code or differ the function with extra bool parameter to say 'early' or 'not early'. > + > #ifndef CONFIG_MODULES > static int __init of_free_phandle_cache(void) > { > @@ -150,7 +175,15 @@ static int __init of_free_phandle_cache(void) > > void __init of_core_init(void) > { > + unsigned long flags; > struct device_node *np; > + phys_addr_t size; > + > + raw_spin_lock_irqsave(&devtree_lock, flags); > + size = (phandle_cache_mask + 1) * sizeof(*phandle_cache); > + memblock_free(__pa(phandle_cache), size); > + phandle_cache = NULL; > + raw_spin_unlock_irqrestore(&devtree_lock, flags); > > of_populate_phandle_cache(); > > diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c > index 84aa9d676375..cb320df23f26 100644 > --- a/drivers/of/fdt.c > +++ b/drivers/of/fdt.c > @@ -1264,6 +1264,8 @@ void __init unflatten_device_tree(void) > of_alias_scan(early_init_dt_alloc_memory_arch); > > unittest_unflatten_overlay_base(); > + > + of_populate_phandle_cache_early(); > } > > /** > diff --git a/drivers/of/of_private.h b/drivers/of/of_private.h > index fa70650136b4..6720448c84cc 100644 > --- a/drivers/of/of_private.h > +++ b/drivers/of/of_private.h > @@ -134,6 +134,8 @@ extern void __of_sysfs_remove_bin_file(struct device_node *np, > /* illegal phandle value (set when unresolved) */ > #define OF_PHANDLE_ILLEGAL 0xdeadbeef > > +extern void __init of_populate_phandle_cache_early(void); > + > /* iterators for transactions, used for overlays */ > /* forward iterator */ > #define for_each_transaction_entry(_oft, _te) \ > Chintan -- Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project