linux/drivers/of
Rob Herring 90dc0d1ce8 of: Rework and simplify phandle cache to use a fixed size
The phandle cache was added to speed up of_find_node_by_phandle() by
avoiding walking the whole DT to find a matching phandle. The
implementation has several shortcomings:

  - The cache is designed to work on a linear set of phandle values.
    This is true for dtc generated DTs, but not for other cases such as
    Power.
  - The cache isn't enabled until of_core_init() and a typical system
    may see hundreds of calls to of_find_node_by_phandle() before that
    point.
  - The cache is freed and re-allocated when the number of phandles
    changes.
  - It takes a raw spinlock around a memory allocation which breaks on
    RT.

Change the implementation to a fixed size and use hash_32() as the
cache index. This greatly simplifies the implementation. It avoids
the need for any re-alloc of the cache and taking a reference on nodes
in the cache. We only have a single source of removing cache entries
which is of_detach_node().

Using hash_32() removes any assumption on phandle values improving
the hit rate for non-linear phandle values. The effect on linear values
using hash_32() is about a 10% collision. The chances of thrashing on
colliding values seems to be low.

To compare performance, I used a RK3399 board which is a pretty typical
system. I found that just measuring boot time as done previously is
noisy and may be impacted by other things. Also bringing up secondary
cores causes some issues with measuring, so I booted with 'nr_cpus=1'.
With no caching, calls to of_find_node_by_phandle() take about 20124 us
for 1248 calls. There's an additional 288 calls before time keeping is
up. Using the average time per hit/miss with the cache, we can calculate
these calls to take 690 us (277 hit / 11 miss) with a 128 entry cache
and 13319 us with no cache or an uninitialized cache.

Comparing the 3 implementations the time spent in
of_find_node_by_phandle() is:

no cache:        20124 us (+ 13319 us)
128 entry cache:  5134 us (+ 690 us)
current cache:     819 us (+ 13319 us)

We could move the allocation of the cache earlier to improve the
current cache, but that just further complicates the situation as it
needs to be after slab is up, so we can't do it when unflattening (which
uses memblock).

Reported-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Segher Boessenkool <segher@kernel.crashing.org>
Cc: Frank Rowand <frowand.list@gmail.com>
Acked-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Reviewed-by: Frank Rowand <frowand.list@gmail.com>
Tested-by: Frank Rowand <frowand.list@gmail.com>
Signed-off-by: Rob Herring <robh@kernel.org>
2019-12-24 14:17:52 -07:00
..
unittest-data of/unittest: Add dma-ranges address translation tests 2019-10-08 13:55:26 -05:00
address.c of: Make of_dma_get_range() work on bus nodes 2019-10-09 12:30:09 -05:00
base.c of: Rework and simplify phandle cache to use a fixed size 2019-12-24 14:17:52 -07:00
device.c dma-mapping: treat dev->bus_dma_mask as a DMA limit 2019-11-21 18:14:35 +01:00
dynamic.c of: Rework and simplify phandle cache to use a fixed size 2019-12-24 14:17:52 -07:00
fdt_address.c of: Use SPDX license tag for DT files 2018-01-08 08:22:45 -06:00
fdt.c Devicetree updates for v5.5: 2019-12-02 11:41:35 -08:00
irq.c of: irq: fix a trivial typo in a doc comment 2019-08-14 20:12:16 -06:00
Kconfig dma-mapping: improve selection of dma_declare_coherent availability 2019-02-20 07:26:35 -07:00
kobj.c of: overlay: add missing of_node_get() in __of_attach_node_sysfs 2018-11-08 22:10:53 -08:00
Makefile PCI: Move OF-related PCI functions into PCI core 2018-01-17 17:36:39 -06:00
of_mdio.c net: of_get_phy_mode: Change API to solve int/unit warnings 2019-11-04 11:21:25 -08:00
of_net.c net: of_get_phy_mode: Change API to solve int/unit warnings 2019-11-04 11:21:25 -08:00
of_numa.c of, numa: Validate some distance map rules 2018-11-08 12:44:34 -06:00
of_private.h of: Rework and simplify phandle cache to use a fixed size 2019-12-24 14:17:52 -07:00
of_reserved_mem.c of: reserved_mem: add missing of_node_put() for proper ref-counting 2019-10-23 15:15:05 -05:00
overlay.c of: Rework and simplify phandle cache to use a fixed size 2019-12-24 14:17:52 -07:00
pdt.c of: Remove struct device_node.type pointer 2019-01-10 16:24:44 -06:00
platform.c of/platform: Unconditionally pause/resume sync state during kernel init 2019-12-12 18:39:52 -06:00
property.c Devicetree updates for v5.5: 2019-12-02 11:41:35 -08:00
resolver.c of: resolver: Add of_node_put() before return and break 2019-08-12 16:52:24 -06:00
unittest.c of: unittest: fix memory leak in attach_node_and_children 2019-11-26 12:32:43 -07:00