dm-devel.redhat.com archive mirror
 help / color / mirror / Atom feed
From: Mike Snitzer <snitzer@redhat.com>
To: dm-devel@redhat.com
Subject: [PATCH] dm: use cpu_relax when busy waiting for condition
Date: Thu, 9 Sep 2010 18:07:16 -0400	[thread overview]
Message-ID: <20100909220716.GA27774@redhat.com> (raw)

Switch busy loops from using msleep(1) to cpu_relax().

Any improvement is negligible given the rare nature of these busy wait
conditions -- but cpu_relax() is considered the more polite method to
use for busy loops.

Signed-off-by: Mike Snitzer <snitzer@redhat.com>
---
 drivers/md/dm-snap.c  |    6 +++---
 drivers/md/dm-table.c |    2 +-
 drivers/md/dm.c       |    2 +-
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/md/dm-snap.c b/drivers/md/dm-snap.c
index eed2101..d1f44c1 100644
--- a/drivers/md/dm-snap.c
+++ b/drivers/md/dm-snap.c
@@ -264,12 +264,12 @@ static int __chunk_is_tracked(struct dm_snapshot *s, chunk_t chunk)
 
 /*
  * This conflicting I/O is extremely improbable in the caller,
- * so msleep(1) is sufficient and there is no need for a wait queue.
+ * so cpu_relax() is sufficient and there is no need for a wait queue.
  */
 static void __check_for_conflicting_io(struct dm_snapshot *s, chunk_t chunk)
 {
 	while (__chunk_is_tracked(s, chunk))
-		msleep(1);
+		cpu_relax();
 }
 
 /*
@@ -1302,7 +1302,7 @@ static void snapshot_dtr(struct dm_target *ti)
 	unregister_snapshot(s);
 
 	while (atomic_read(&s->pending_exceptions_count))
-		msleep(1);
+		cpu_relax();
 	/*
 	 * Ensure instructions in mempool_destroy aren't reordered
 	 * before atomic_read.
diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
index f9fc07d..2955d46 100644
--- a/drivers/md/dm-table.c
+++ b/drivers/md/dm-table.c
@@ -245,7 +245,7 @@ void dm_table_destroy(struct dm_table *t)
 		return;
 
 	while (atomic_read(&t->holders))
-		msleep(1);
+		cpu_relax();
 	smp_mb();
 
 	/* free the indexes */
diff --git a/drivers/md/dm.c b/drivers/md/dm.c
index f934e98..4e699e4 100644
--- a/drivers/md/dm.c
+++ b/drivers/md/dm.c
@@ -2228,7 +2228,7 @@ static void __dm_destroy(struct mapped_device *md, bool wait)
 	 */
 	if (wait)
 		while (atomic_read(&md->holders))
-			msleep(1);
+			cpu_relax();
 	else if (atomic_read(&md->holders))
 		DMWARN("%s: Forcibly removing mapped_device still in use! (%d users)",
 		       dm_device_name(md), atomic_read(&md->holders));

             reply	other threads:[~2010-09-09 22:07 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-09 22:07 Mike Snitzer [this message]
2011-06-27 10:22 ` [PATCH] dm: use cpu_relax when busy waiting for condition Alasdair G Kergon

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=20100909220716.GA27774@redhat.com \
    --to=snitzer@redhat.com \
    --cc=dm-devel@redhat.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 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).