Received: by 10.223.185.116 with SMTP id b49csp1390537wrg; Wed, 14 Feb 2018 16:45:59 -0800 (PST) X-Google-Smtp-Source: AH8x224iNkTjfKZsHd6VvJ0RaTYdKNPtLCLCHLAhRM/0G97TdhaVXkh5Z8VkdkKqHag6AY5+QaOy X-Received: by 2002:a17:902:6809:: with SMTP id h9-v6mr800452plk.46.1518655559652; Wed, 14 Feb 2018 16:45:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518655559; cv=none; d=google.com; s=arc-20160816; b=jsLkVdAL6S/MKx6cQL7Nz7RkT8MUSQ3oZ7qemXsUPae7yUA6s/fNsDIypyDWeNuBpo ZZcUZhtbc6whpdxh57A29vWB+sQo9Zn0K3pVq09zJBaAZisdMcM/LCCfMyKSOpLWcOlX Elq+dxspHFuu7sBuYY7eDGZJI/9x4b1PvvtIqrvYUcaSJ1k4r+edo0ype9IR2EEgfbCX Ach7X+8nhbpCNcv5xGPLLmvm8s+V1B6E5Qezes7JGM1AeOSHIwPR35/zINYwik1CDfMc Z6E4+JOifcTEiemitv9GC7GYjWrEu+fO8+hVIZAn+HuR5Qf74Bcrd3aFvjXoJ2pHEk68 zDGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=rXQqtkolZ1n/2/xSDUwh9ii3iOHN14gyot7TExQz/CI=; b=QUEn247IOQUSx7IbxXK9G/dIS0Mv+nxMSw09Xg9ly1D8Pik8KGSgkWHB9MmCq/nBvx ESqnQUov2eeOgW+FU1V0IsYLfRmLs6b+/J1R5mz4J+TKXBDsut4AHu3ax+s/ieDLMSbl OSO2BhYk2tEuTH7sA/WLSNkPDOejs5URZqaZQFtw3JOQUem2KDVGg7M4PPxdohZdfdo7 f5Tp40Wym0xQJapuoYk7LMmNckXxNFrrMUtGjxUFS3IgJ+9j+h1cuac0xdfnmtd5rVaO qd7WOyCne8YdtooKaR+PRYroSFQmHWZ0MxsRmR4YBY8LzWom+o5pwGetrETAVVopNfex pJCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MSQZucqE; 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 69-v6si2203616plb.573.2018.02.14.16.45.45; Wed, 14 Feb 2018 16:45:59 -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=MSQZucqE; 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 S1032307AbeBOApH (ORCPT + 99 others); Wed, 14 Feb 2018 19:45:07 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:36885 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1032245AbeBOApE (ORCPT ); Wed, 14 Feb 2018 19:45:04 -0500 Received: by mail-pg0-f65.google.com with SMTP id o1so2944234pgn.4; Wed, 14 Feb 2018 16:45:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=rXQqtkolZ1n/2/xSDUwh9ii3iOHN14gyot7TExQz/CI=; b=MSQZucqEgAidjRMfi5KJa+98hssRtevhPwNAwss/NPde2qSxzQOd+xpoMeBILuDo0H Eva5Mlze+hW+MdqWBEx2ErhcRUo0ZQ+uG10zBveQngng18ztm9ScsZNn4I1BvJsnd7fJ YqgpSRxQRi/bZ+1ICQazeEiYVB9jR9QYJdwZaK3P3Xh7EbhSl9mBcSDymQf0vvzwBRH2 F67K4VuPuuvlqCsSfqCFefs89Clr7kLNjIkYglJAIkYyslhvhN8pAUMzUbvrAfNnI6su Lo/dOer46K2HP7xJ0pCELzhYPD/2pz8bMLTo2+K1d9u26KnEWpySSXQ5k0Lp21AEWSaI bPpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=rXQqtkolZ1n/2/xSDUwh9ii3iOHN14gyot7TExQz/CI=; b=UTH0Kxok4F3WBm2VdXUhfekZ0jn3H7wtHBO7JeipswzSq9AzMsT7DQd9gVQLEYE+7n rr4V8ocJLi4Skw3uUfK+Ox/4F52y0P86j8ETT9oHikBD9vcioKqXwDpdHcuVo9tONkhy xQBf1YTc1cCY3MJf429Ku0XGm64XFPxo0W5F/Yt/mAidV31JcmDfKQE0h6LlbCy7+ObG 06YMDNBVlfiKPyF2gf9NS+Gh06ITVwBvfP75/IrFqgtNz/C20T7WYCZsnUx6zRKTTh9h iA2McAW8dE3kWHDuu2jWuRBhX9q82G0C/IZAzG2k0uwZmGj7j8RYy4yY2TGLqf7CMcJp HROg== X-Gm-Message-State: APf1xPBileD/gFh0q96O2FMYUa/r6T3t3mXqxkFzCNMfffA4avgpN6zi FCtLz2xp1vOT6qpwrYC7BhkcxQ== X-Received: by 10.98.107.130 with SMTP id g124mr815354pfc.225.1518655504247; Wed, 14 Feb 2018 16:45:04 -0800 (PST) Received: from localhost.localdomain (c-73-93-215-6.hsd1.ca.comcast.net. [73.93.215.6]) by smtp.gmail.com with ESMTPSA id o87sm5398963pfj.86.2018.02.14.16.45.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 14 Feb 2018 16:45:03 -0800 (PST) From: frowand.list@gmail.com To: Rob Herring , cpandya@codeaurora.org Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] of: add early boot allocation of of_find_node_by_phandle() cache Date: Wed, 14 Feb 2018 16:44:25 -0800 Message-Id: <1518655465-10759-1-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; +} + #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) \ -- Frank Rowand