regmap: Add maple tree based register cache
authorMark Brown <broonie@kernel.org>
Thu, 30 Mar 2023 00:10:24 +0000 (01:10 +0100)
committerMark Brown <broonie@kernel.org>
Mon, 3 Apr 2023 11:53:44 +0000 (12:53 +0100)
commitf033c26de5a5734625d2dd1dc196745fae186f1b
tree5a1bd87f6a41de78def3d2209eafb1c575c73842
parent05933e2d44607767ecb4937a33df4e882bdf9ad3
regmap: Add maple tree based register cache

The current state of the art for sparse register maps is the
rbtree cache.  This works well for most applications but isn't
always ideal for sparser register maps since the rbtree can get
deep, requiring a lot of walking.  Fortunately the kernel has a
data structure intended to address this very problem, the maple
tree.  Provide an initial implementation of a register cache
based on the maple tree to start taking advantage of it.

The entries stored in the maple tree are arrays of register
values, with the maple tree keys holding the register addresses.
We store data in host native format rather than device native
format as we do for rbtree, this will be a benefit for devices
where we don't marshal data within regmap and simplifies the code
but will result in additional CPU overhead when syncing the cache
on devices where we do marshal data in regmap.

This should work well for a lot of devices, though there's some
additional areas that could be looked at such as caching the
last accessed entry like we do for rbtree and trying to minimise
the maple tree level locking. We should also use bulk writes
rather than single register writes when resyncing the cache where
possible, even if we don't store in device native format.

Very small register maps may continue to to better with rbtree
longer term.

Signed-off-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20230325-regcache-maple-v3-2-23e271f93dc7@kernel.org
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/base/regmap/Makefile
drivers/base/regmap/internal.h
drivers/base/regmap/regcache-maple.c [new file with mode: 0644]
drivers/base/regmap/regcache.c
drivers/base/regmap/regmap-kunit.c
include/linux/regmap.h