提交 6399aea6 编写于 作者: N Nikesh Oswal 提交者: Mark Brown

regmap: rbtree: When adding a reg do a bsearch for target node

A binary search is much more efficient rather than iterating
over the rbtree in ascending order which the current code is
doing.

During initialisation the reg defaults are written to the
cache in a large chunk and these are always sorted in the
ascending order so for this situation ideally we should have
iterated the rbtree in descending order.

But at runtime the drivers may write into the cache in any
random order so this patch selects to use a bsearch to give
an optimal runtime performance and also at initialisation
time when reg defaults are written the performance of binary
search would be much better than iterating in ascending order
which the current code was doing.
Signed-off-by: NNikesh Oswal <Nikesh.Oswal@wolfsonmicro.com>
Signed-off-by: NMark Brown <broonie@kernel.org>
上级 8005c49d
...@@ -413,8 +413,8 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg, ...@@ -413,8 +413,8 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
max = reg + max_dist; max = reg + max_dist;
/* look for an adjacent register to the one we are about to add */ /* look for an adjacent register to the one we are about to add */
for (node = rb_first(&rbtree_ctx->root); node; node = rbtree_ctx->root.rb_node;
node = rb_next(node)) { while (node) {
rbnode_tmp = rb_entry(node, struct regcache_rbtree_node, rbnode_tmp = rb_entry(node, struct regcache_rbtree_node,
node); node);
...@@ -425,6 +425,11 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg, ...@@ -425,6 +425,11 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
new_base_reg = min(reg, base_reg); new_base_reg = min(reg, base_reg);
new_top_reg = max(reg, top_reg); new_top_reg = max(reg, top_reg);
} else { } else {
if (max < base_reg)
node = node->rb_left;
else
node = node->rb_right;
continue; continue;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册