All of lore.kernel.org
 help / color / mirror / Atom feed
From: Coly Li <colyli@suse.de>
To: linux-bcache@vger.kernel.org
Cc: linux-block@vger.kernel.org, Coly Li <colyli@suse.de>
Subject: [PATCH 06/15] bcache: remove unnecessary prefetch() in bset_search_tree()
Date: Tue,  4 Jun 2019 23:16:15 +0800	[thread overview]
Message-ID: <20190604151624.105150-7-colyli@suse.de> (raw)
In-Reply-To: <20190604151624.105150-1-colyli@suse.de>

In function bset_search_tree(), when p >= t->size, t->tree[0] will be
prefetched by the following code piece,
 974                 unsigned int p = n << 4;
 975
 976                 p &= ((int) (p - t->size)) >> 31;
 977
 978                 prefetch(&t->tree[p]);

The purpose of the above code is to avoid a branch instruction, but
when p >= t->size, prefetch(&t->tree[0]) has no positive performance
contribution at all. This patch avoids the unncessary prefetch by only
calling prefetch() when p < t->size.

Signed-off-by: Coly Li <colyli@suse.de>
---
 drivers/md/bcache/bset.c | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/drivers/md/bcache/bset.c b/drivers/md/bcache/bset.c
index 8f07fa6e1739..aa2e4ab0fab9 100644
--- a/drivers/md/bcache/bset.c
+++ b/drivers/md/bcache/bset.c
@@ -960,22 +960,10 @@ static struct bset_search_iter bset_search_tree(struct bset_tree *t,
 	unsigned int inorder, j, n = 1;
 
 	do {
-		/*
-		 * A bit trick here.
-		 * If p < t->size, (int)(p - t->size) is a minus value and
-		 * the most significant bit is set, right shifting 31 bits
-		 * gets 1. If p >= t->size, the most significant bit is
-		 * not set, right shifting 31 bits gets 0.
-		 * So the following 2 lines equals to
-		 *	if (p >= t->size)
-		 *		p = 0;
-		 * but a branch instruction is avoided.
-		 */
 		unsigned int p = n << 4;
 
-		p &= ((int) (p - t->size)) >> 31;
-
-		prefetch(&t->tree[p]);
+		if (p < t->size)
+			prefetch(&t->tree[p]);
 
 		j = n;
 		f = &t->tree[j];
-- 
2.16.4


  parent reply	other threads:[~2019-06-04 15:16 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-04 15:16 [PATCH 00/15] bcache fixes before Linux v5.3 Coly Li
2019-06-04 15:16 ` [PATCH 01/15] Revert "bcache: set CACHE_SET_IO_DISABLE in bch_cached_dev_error()" Coly Li
2019-06-04 15:16 ` [PATCH 02/15] bcache: avoid flushing btree node in cache_set_flush() if io disabled Coly Li
2019-06-04 15:16 ` [PATCH 03/15] bcache: ignore read-ahead request failure on backing device Coly Li
2019-06-04 15:16 ` [PATCH 04/15] bcache: add io error counting in write_bdev_super_endio() Coly Li
2019-06-04 15:16 ` [PATCH 05/15] bcache: remove "XXX:" comment line from run_cache_set() Coly Li
2019-06-04 15:16 ` Coly Li [this message]
2019-06-04 15:16 ` [PATCH 07/15] bcache: use sysfs_match_string() instead of __sysfs_match_string() Coly Li
2019-06-04 15:16 ` [PATCH 08/15] bcache: add return value check to bch_cached_dev_run() Coly Li
2019-06-04 15:16 ` [PATCH 09/15] bcache: remove unncessary code in bch_btree_keys_init() Coly Li
2019-06-04 15:16 ` [PATCH 10/15] bcache: check CACHE_SET_IO_DISABLE in allocator code Coly Li
2019-06-04 15:16 ` [PATCH 11/15] bcache: check CACHE_SET_IO_DISABLE bit in bch_journal() Coly Li
2019-06-04 15:16 ` [PATCH 12/15] bcache: more detailed error message to bcache_device_link() Coly Li
2019-06-04 15:16 ` [PATCH 13/15] bcache: add more error message in bch_cached_dev_attach() Coly Li
2019-06-04 15:16 ` [PATCH 14/15] bcache: shrink btree node cache after bch_btree_check() Coly Li
2019-06-04 15:16 ` [PATCH 15/15] bcache: improve error message in bch_cached_dev_run() Coly Li
2019-06-04 15:53 ` [PATCH 16/18] bcache: only set BCACHE_DEV_WB_RUNNING when cached device attached Coly Li
2019-06-04 15:53   ` [PATCH 17/18] bcache: make bset_search_tree() be more understandable Coly Li
2019-06-05  5:43     ` Christoph Hellwig
2019-06-05  5:45       ` Coly Li
2019-06-04 15:53   ` [PATCH 18/18] bcache: add code comments for journal_read_bucket() Coly Li

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=20190604151624.105150-7-colyli@suse.de \
    --to=colyli@suse.de \
    --cc=linux-bcache@vger.kernel.org \
    --cc=linux-block@vger.kernel.org \
    /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.