aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNikesh Oswal <Nikesh.Oswal@wolfsonmicro.com>2015-10-21 09:16:14 -0400
committerMark Brown <broonie@kernel.org>2015-11-16 04:44:59 -0500
commit6399aea629b02a23364efcb6eea1319b8e9d1abf (patch)
tree279b4753273ad1b976fe789d5a63d10bd9d2e7fd
parent8005c49d9aea74d382f474ce11afbbc7d7130bec (diff)
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: Nikesh Oswal <Nikesh.Oswal@wolfsonmicro.com> Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--drivers/base/regmap/regcache-rbtree.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/drivers/base/regmap/regcache-rbtree.c b/drivers/base/regmap/regcache-rbtree.c
index 56486d92c4e7..353f60236ce0 100644
--- a/drivers/base/regmap/regcache-rbtree.c
+++ b/drivers/base/regmap/regcache-rbtree.c
@@ -413,8 +413,8 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
413 max = reg + max_dist; 413 max = reg + max_dist;
414 414
415 /* look for an adjacent register to the one we are about to add */ 415 /* look for an adjacent register to the one we are about to add */
416 for (node = rb_first(&rbtree_ctx->root); node; 416 node = rbtree_ctx->root.rb_node;
417 node = rb_next(node)) { 417 while (node) {
418 rbnode_tmp = rb_entry(node, struct regcache_rbtree_node, 418 rbnode_tmp = rb_entry(node, struct regcache_rbtree_node,
419 node); 419 node);
420 420
@@ -425,6 +425,11 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
425 new_base_reg = min(reg, base_reg); 425 new_base_reg = min(reg, base_reg);
426 new_top_reg = max(reg, top_reg); 426 new_top_reg = max(reg, top_reg);
427 } else { 427 } else {
428 if (max < base_reg)
429 node = node->rb_left;
430 else
431 node = node->rb_right;
432
428 continue; 433 continue;
429 } 434 }
430 435