linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] regmap: rbtree: When adding a reg do a bsearch for target node
@ 2015-10-21 13:16 Nikesh Oswal
  2015-10-22  8:44 ` Charles Keepax
  0 siblings, 1 reply; 2+ messages in thread
From: Nikesh Oswal @ 2015-10-21 13:16 UTC (permalink / raw)
  To: broonie, gregkh; +Cc: linux-kernel, patches, Nikesh.Oswal, Nikesh Oswal

From: Nikesh Oswal <Nikesh.Oswal@wolfsonmicro.com>

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>
---
 drivers/base/regmap/regcache-rbtree.c |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/base/regmap/regcache-rbtree.c b/drivers/base/regmap/regcache-rbtree.c
index 56486d9..353f602 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,
 		max = reg + max_dist;
 
 		/* look for an adjacent register to the one we are about to add */
-		for (node = rb_first(&rbtree_ctx->root); node;
-		     node = rb_next(node)) {
+		node = rbtree_ctx->root.rb_node;
+		while (node) {
 			rbnode_tmp = rb_entry(node, struct regcache_rbtree_node,
 					      node);
 
@@ -425,6 +425,11 @@ static int regcache_rbtree_write(struct regmap *map, unsigned int reg,
 				new_base_reg = min(reg, base_reg);
 				new_top_reg = max(reg, top_reg);
 			} else {
+				if (max < base_reg)
+					node = node->rb_left;
+				else
+					node = node->rb_right;
+
 				continue;
 			}
 
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] regmap: rbtree: When adding a reg do a bsearch for target node
  2015-10-21 13:16 [PATCH] regmap: rbtree: When adding a reg do a bsearch for target node Nikesh Oswal
@ 2015-10-22  8:44 ` Charles Keepax
  0 siblings, 0 replies; 2+ messages in thread
From: Charles Keepax @ 2015-10-22  8:44 UTC (permalink / raw)
  To: Nikesh Oswal
  Cc: broonie, gregkh, linux-kernel, patches, Nikesh.Oswal,
	Nikesh Oswal

On Wed, Oct 21, 2015 at 02:16:14PM +0100, Nikesh Oswal wrote:
> From: Nikesh Oswal <Nikesh.Oswal@wolfsonmicro.com>

If you are going to use your non-opensource email, might as well
use the cirrus one here.

> 
> 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>
> ---

Patch looks fine to me though:

Reviewed-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>

Thanks,
Charles

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-10-22  9:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-21 13:16 [PATCH] regmap: rbtree: When adding a reg do a bsearch for target node Nikesh Oswal
2015-10-22  8:44 ` Charles Keepax

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).