Re: [PATCH v4 2/2] of: add early boot allocation of of_find_node_by_phandle() cache
Hi Frank, I love your patch! Yet something to improve: [auto build test ERROR on robh/for-next] [also build test ERROR on v4.16-rc3 next-20180302] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system] url: https://github.com/0day-ci/linux/commits/frowand-list-gmail-com/of-cache-phandle-nodes-to-reduce-cost-of-of_find_node_by_phandle/20180303-090055 base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next config: tile-allmodconfig (attached as .config) compiler: tilegx-linux-gcc (GCC) 7.2.0 reproduce: wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross ARCH=tile All errors (new ones prefixed by >>): drivers//of/base.c: In function 'of_core_init': >> drivers//of/base.c:187:2: error: implicit declaration of function >> 'memblock_free'; did you mean 'ptlock_free'? >> [-Werror=implicit-function-declaration] memblock_free(__pa(phandle_cache), size); ^ ptlock_free cc1: some warnings being treated as errors vim +187 drivers//of/base.c 178 179 void __init of_core_init(void) 180 { 181 unsigned long flags; 182 struct device_node *np; 183 phys_addr_t size; 184 185 raw_spin_lock_irqsave(_lock, flags); 186 size = (phandle_cache_mask + 1) * sizeof(*phandle_cache); > 187 memblock_free(__pa(phandle_cache), size); 188 phandle_cache = NULL; 189 raw_spin_unlock_irqrestore(_lock, flags); 190 191 of_populate_phandle_cache(); 192 193 /* Create the kset, and register existing nodes */ 194 mutex_lock(_mutex); 195 of_kset = kset_create_and_add("devicetree", NULL, firmware_kobj); 196 if (!of_kset) { 197 mutex_unlock(_mutex); 198 pr_err("failed to register existing nodes\n"); 199 return; 200 } 201 for_each_of_allnodes(np) 202 __of_attach_node_sysfs(np); 203 mutex_unlock(_mutex); 204 205 /* Symlink in /proc as required by userspace ABI */ 206 if (of_root) 207 proc_symlink("device-tree", NULL, "/sys/firmware/devicetree/base"); 208 } 209 --- 0-DAY kernel test infrastructureOpen Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation .config.gz Description: application/gzip
Re: [PATCH v4 2/2] of: add early boot allocation of of_find_node_by_phandle() cache
Hi Frank, I love your patch! Yet something to improve: [auto build test ERROR on robh/for-next] [also build test ERROR on v4.16-rc3 next-20180302] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system] url: https://github.com/0day-ci/linux/commits/frowand-list-gmail-com/of-cache-phandle-nodes-to-reduce-cost-of-of_find_node_by_phandle/20180303-090055 base: https://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git for-next config: tile-allmodconfig (attached as .config) compiler: tilegx-linux-gcc (GCC) 7.2.0 reproduce: wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross ARCH=tile All errors (new ones prefixed by >>): drivers//of/base.c: In function 'of_core_init': >> drivers//of/base.c:187:2: error: implicit declaration of function >> 'memblock_free'; did you mean 'ptlock_free'? >> [-Werror=implicit-function-declaration] memblock_free(__pa(phandle_cache), size); ^ ptlock_free cc1: some warnings being treated as errors vim +187 drivers//of/base.c 178 179 void __init of_core_init(void) 180 { 181 unsigned long flags; 182 struct device_node *np; 183 phys_addr_t size; 184 185 raw_spin_lock_irqsave(_lock, flags); 186 size = (phandle_cache_mask + 1) * sizeof(*phandle_cache); > 187 memblock_free(__pa(phandle_cache), size); 188 phandle_cache = NULL; 189 raw_spin_unlock_irqrestore(_lock, flags); 190 191 of_populate_phandle_cache(); 192 193 /* Create the kset, and register existing nodes */ 194 mutex_lock(_mutex); 195 of_kset = kset_create_and_add("devicetree", NULL, firmware_kobj); 196 if (!of_kset) { 197 mutex_unlock(_mutex); 198 pr_err("failed to register existing nodes\n"); 199 return; 200 } 201 for_each_of_allnodes(np) 202 __of_attach_node_sysfs(np); 203 mutex_unlock(_mutex); 204 205 /* Symlink in /proc as required by userspace ABI */ 206 if (of_root) 207 proc_symlink("device-tree", NULL, "/sys/firmware/devicetree/base"); 208 } 209 --- 0-DAY kernel test infrastructureOpen Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation .config.gz Description: application/gzip
[PATCH v4 2/2] of: add early boot allocation of of_find_node_by_phandle() cache
From: Frank RowandThe 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 --- The previous version of this patch was a standalone patch: [PATCH] of: add early boot allocation of of_find_node_by_phandle() cache that was dependent on patch 1/2 of this series. Changes from previous versions: - no changes 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 e71d157d7149..eeaa270a5135 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 @@ -134,6 +136,29 @@ static void of_populate_phandle_cache(void) raw_spin_unlock_irqrestore(_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) { @@ -153,7 +178,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(_lock, flags); + size = (phandle_cache_mask + 1) * sizeof(*phandle_cache); + memblock_free(__pa(phandle_cache), size); + phandle_cache = NULL; + raw_spin_unlock_irqrestore(_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
[PATCH v4 2/2] of: add early boot allocation of of_find_node_by_phandle() cache
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 --- The previous version of this patch was a standalone patch: [PATCH] of: add early boot allocation of of_find_node_by_phandle() cache that was dependent on patch 1/2 of this series. Changes from previous versions: - no changes 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 e71d157d7149..eeaa270a5135 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 @@ -134,6 +136,29 @@ static void of_populate_phandle_cache(void) raw_spin_unlock_irqrestore(_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) { @@ -153,7 +178,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(_lock, flags); + size = (phandle_cache_mask + 1) * sizeof(*phandle_cache); + memblock_free(__pa(phandle_cache), size); + phandle_cache = NULL; + raw_spin_unlock_irqrestore(_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