All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
To: Mark Brown <broonie@opensource.wolfsonmicro.com>,
	Liam Girdwood <lrg@ti.com>
Cc: alsa-devel@alsa-project.org, patches@opensource.wolfsonmicro.com,
	Liam Girdwood <lrg@slimlogic.co.uk>
Subject: [PATCH 2/2 v2] ASoC: soc-cache: cache a pointer to the last accessed rbtree block
Date: Mon,  2 May 2011 13:28:29 +0100	[thread overview]
Message-ID: <1304339309-28820-2-git-send-email-dp@opensource.wolfsonmicro.com> (raw)
In-Reply-To: <1304339309-28820-1-git-send-email-dp@opensource.wolfsonmicro.com>

Whenever we are doing a read or a write through the rbtree code, we'll
cache a pointer to the register block.  To avoid looking up the register
everytime we do a read or a write, we first check if it can be found in
the cached register block, otherwise we go through the slow path and in the
end we cache the pointer to the register block.

Signed-off-by: Dimitris Papastamos <dp@opensource.wolfsonmicro.com>
---
 sound/soc/soc-cache.c |   34 ++++++++++++++++++++++++++++++++--
 1 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/sound/soc/soc-cache.c b/sound/soc/soc-cache.c
index c518b6e..09048ea 100644
--- a/sound/soc/soc-cache.c
+++ b/sound/soc/soc-cache.c
@@ -608,6 +608,7 @@ struct snd_soc_rbtree_node {
 
 struct snd_soc_rbtree_ctx {
 	struct rb_root root;
+	struct snd_soc_rbtree_node *cached_rbnode;
 };
 
 static inline int snd_soc_rbtree_block_count(void)
@@ -727,11 +728,25 @@ static int snd_soc_rbtree_cache_write(struct snd_soc_codec *codec,
 	struct snd_soc_rbtree_ctx *rbtree_ctx;
 	struct snd_soc_rbtree_node *rbnode;
 	struct snd_soc_rbtree_reg_blk *regblk;
-	struct snd_soc_rbtree_reg_blk *baseblk;
+	struct snd_soc_rbtree_reg_blk *baseblk, *topblk;
 	unsigned int base_reg;
 	int blkcount, i;
 
 	rbtree_ctx = codec->reg_cache;
+	/* handle cached write */
+	rbnode = rbtree_ctx->cached_rbnode;
+	if (rbnode) {
+		baseblk = snd_soc_rbtree_base_block(rbnode);
+		topblk = snd_soc_rbtree_top_block(rbnode);
+		if (reg >= baseblk->reg && reg <= topblk->reg) {
+			regblk = &rbnode->block[reg - baseblk->reg];
+			if (regblk->value == value)
+				return 0;
+			regblk->value = value;
+			return 0;
+		}
+	}
+	/* if not cached, look it up in the rbtree and cache it */
 	rbnode = snd_soc_rbtree_lookup(&rbtree_ctx->root, reg);
 	if (rbnode) {
 		baseblk = snd_soc_rbtree_base_block(rbnode);
@@ -739,6 +754,7 @@ static int snd_soc_rbtree_cache_write(struct snd_soc_codec *codec,
 		if (regblk->value == value)
 			return 0;
 		regblk->value = value;
+		rbtree_ctx->cached_rbnode = rbnode;
 	} else {
 		/* bail out early, no need to create the rbnode yet */
 		if (!value)
@@ -761,6 +777,7 @@ static int snd_soc_rbtree_cache_write(struct snd_soc_codec *codec,
 				regblk->value = value;
 		}
 		snd_soc_rbtree_insert(&rbtree_ctx->root, rbnode);
+		rbtree_ctx->cached_rbnode = rbnode;
 	}
 
 	return 0;
@@ -771,13 +788,25 @@ static int snd_soc_rbtree_cache_read(struct snd_soc_codec *codec,
 {
 	struct snd_soc_rbtree_ctx *rbtree_ctx;
 	struct snd_soc_rbtree_node *rbnode;
-	struct snd_soc_rbtree_reg_blk *baseblk;
+	struct snd_soc_rbtree_reg_blk *baseblk, *topblk;
 
 	rbtree_ctx = codec->reg_cache;
+	/* handle cached read */
+	rbnode = rbtree_ctx->cached_rbnode;
+	if (rbnode) {
+		baseblk = snd_soc_rbtree_base_block(rbnode);
+		topblk = snd_soc_rbtree_top_block(rbnode);
+		if (reg >= baseblk->reg && reg <= topblk->reg) {
+			*value = rbnode->block[reg - baseblk->reg].value;
+			return 0;
+		}
+	}
+	/* if not cached, look it up in the rbtree and cache it */
 	rbnode = snd_soc_rbtree_lookup(&rbtree_ctx->root, reg);
 	if (rbnode) {
 		baseblk = snd_soc_rbtree_base_block(rbnode);
 		*value = rbnode->block[reg - baseblk->reg].value;
+		rbtree_ctx->cached_rbnode = rbnode;
 	} else {
 		/* uninitialized registers default to 0 */
 		*value = 0;
@@ -831,6 +860,7 @@ static int snd_soc_rbtree_cache_init(struct snd_soc_codec *codec)
 
 	rbtree_ctx = codec->reg_cache;
 	rbtree_ctx->root = RB_ROOT;
+	rbtree_ctx->cached_rbnode = NULL;
 
 	if (!codec->reg_def_copy)
 		return 0;
-- 
1.7.5

  reply	other threads:[~2011-05-02 12:28 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-02 12:28 [PATCH 1/2 v2] ASoC: soc-cache: block based rbtree compression Dimitris Papastamos
2011-05-02 12:28 ` Dimitris Papastamos [this message]
2011-05-02 14:29 ` Takashi Iwai
2011-05-02 14:40   ` Dimitris Papastamos
2011-05-02 14:46     ` Takashi Iwai
2011-05-02 14:51       ` Dimitris Papastamos
2011-05-02 14:42   ` Dimitris Papastamos
2011-05-02 14:47     ` Takashi Iwai
2011-05-02 14:58       ` Dimitris Papastamos
2011-05-03  9:43         ` Mark Brown
2011-05-03 10:38           ` Takashi Iwai
2011-05-03 10:47             ` Mark Brown
2011-05-03 10:50               ` Takashi Iwai
2011-05-03 11:02                 ` Mark Brown
2011-05-03 12:25                   ` Takashi Iwai
2011-05-03 13:02                     ` Mark Brown
2011-05-03 13:18                       ` Takashi Iwai
2011-05-03 13:24                         ` Mark Brown
2011-05-03 13:32                           ` Takashi Iwai
2011-05-03 13:51                             ` Mark Brown
2011-05-03 14:07                               ` Takashi Iwai
2011-05-03 14:27                                 ` Mark Brown
2011-05-03 15:22                                   ` Takashi Iwai
2011-05-03 15:24                                     ` Mark Brown
2011-05-03 15:30                                       ` Takashi Iwai
2011-05-03 15:40                                         ` Mark Brown
2011-05-03 15:47                                           ` Takashi Iwai
2011-05-03 15:48                                             ` Mark Brown
2011-05-03 15:54                                               ` Takashi Iwai
2011-05-03 15:55                                                 ` Mark Brown
2011-05-03 16:06                                                   ` Takashi Iwai
2011-05-03 11:21 ` Mark Brown
2011-05-03 11:24   ` Dimitris Papastamos
2011-05-03 11:26     ` Mark Brown
2011-05-03 11:46       ` Dimitris Papastamos
2011-05-03 13:44         ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1304339309-28820-2-git-send-email-dp@opensource.wolfsonmicro.com \
    --to=dp@opensource.wolfsonmicro.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=lrg@slimlogic.co.uk \
    --cc=lrg@ti.com \
    --cc=patches@opensource.wolfsonmicro.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.