From: Chintan Pandya <cpandya-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
To: frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH] of: add early boot allocation of of_find_node_by_phandle() cache
Date: Fri, 16 Feb 2018 14:37:55 +0530 [thread overview]
Message-ID: <25deaf48-6590-4ca2-e0db-adaef1f49c5d@codeaurora.org> (raw)
In-Reply-To: <1518655465-10759-1-git-send-email-frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
On 2/15/2018 6:14 AM, frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:
> From: Frank Rowand <frank.rowand-7U/KSKJipcs@public.gmane.org>
>
> 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 <frank.rowand-7U/KSKJipcs@public.gmane.org>
> ---
>
> 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 <linux/bootmem.h>
> #include <linux/console.h>
> #include <linux/ctype.h>
> #include <linux/cpu.h>
> +#include <linux/memblock.h>
> #include <linux/module.h>
> #include <linux/of.h>
> #include <linux/of_device.h>
> @@ -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
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
WARNING: multiple messages have this Message-ID (diff)
From: Chintan Pandya <cpandya@codeaurora.org>
To: frowand.list@gmail.com, Rob Herring <robh+dt@kernel.org>
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] of: add early boot allocation of of_find_node_by_phandle() cache
Date: Fri, 16 Feb 2018 14:37:55 +0530 [thread overview]
Message-ID: <25deaf48-6590-4ca2-e0db-adaef1f49c5d@codeaurora.org> (raw)
In-Reply-To: <1518655465-10759-1-git-send-email-frowand.list@gmail.com>
On 2/15/2018 6:14 AM, frowand.list@gmail.com wrote:
> From: Frank Rowand <frank.rowand@sony.com>
>
> 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 <frank.rowand@sony.com>
> ---
>
> 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 <linux/bootmem.h>
> #include <linux/console.h>
> #include <linux/ctype.h>
> #include <linux/cpu.h>
> +#include <linux/memblock.h>
> #include <linux/module.h>
> #include <linux/of.h>
> #include <linux/of_device.h>
> @@ -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
next prev parent reply other threads:[~2018-02-16 9:07 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-15 0:44 [PATCH] of: add early boot allocation of of_find_node_by_phandle() cache frowand.list-Re5JQEeQqe8AvxtiuMwx3w
2018-02-15 0:44 ` frowand.list
[not found] ` <1518655465-10759-1-git-send-email-frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-02-15 0:55 ` Frank Rowand
2018-02-15 0:55 ` Frank Rowand
2018-02-16 9:07 ` Chintan Pandya [this message]
2018-02-16 9:07 ` Chintan Pandya
2018-02-16 22:32 ` Frank Rowand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=25deaf48-6590-4ca2-e0db-adaef1f49c5d@codeaurora.org \
--to=cpandya-sgv2jx0feol9jmxxk+q4oq@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=frowand.list-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.