mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jonghwan Choi <jhbird.choi@samsung.com>
To: "'open list'" <linux-kernel@vger.kernel.org>
Cc: "'Liam Girdwood'" <lgirdwood@gmail.com>,
	"'Mark Brown'" <broonie@kernel.org>
Subject: [PATCH] regulator: core: Reduce busy-wait looping
Date: Fri, 21 Mar 2014 11:31:25 +0900	[thread overview]
Message-ID: <000001cf44ad$a8e2f1b0$faa8d510$%choi@samsung.com> (raw)

Commit 5df529d440("regulator: core: Reduce busy-wait looping")
can also be used in regulator_do_set_voltage.

Signed-off-by: Jonghwan Choi <jhbird.choi@samsung.com>
---
 drivers/regulator/core.c |   39 +++++++++++++++++++++++++++++++++------
 1 file changed, 33 insertions(+), 6 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index afca1bc..c375bfb 100644
--- a/drivers/regulator/core.c
+++ b/d728099474rivers/regulator/core.c
@@ -2355,12 +2355,39 @@ static int _regulator_do_set_voltage(struct
regulator_dev *rdev,
 			delay = 0;
 		}
 
-		/* Insert any necessary delays */
-		if (delay >= 1000) {
-			mdelay(delay / 1000);
-			udelay(delay % 1000);
-		} else if (delay) {
-			udelay(delay);
+		/*
+		 * Delay for the requested amount of time as per the
guidelines in:
+		 *
+		 *     Documentation/timers/timers-howto.txt
+		 *
+		 * The assumption here is that regulators will never set the
voltage in
+		 * atomic context and therefore sleeping functions can be
used.
+		 */
+		if (delay) {
+			unsigned int ms = delay / 1000;
+			unsigned int us = delay % 1000;
+
+			if (ms > 0) {
+				/*
+				 * For small enough values, handle
super-millisecond
+				 * delays in the usleep_range() call below.
+				 */
+				if (ms < 20)
+					us += ms * 1000;
+				else
+					msleep(ms);
+			}
+
+			/*
+			 * Give the scheduler some room to coalesce with any
other
+			 * wakeup sources. For delays shorter than 10 us,
don't even
+			 * bother setting up high-resolution timers and just
busy-
+			 * loop.
+			 */
+			if (us >= 10)
+				usleep_range(us, us + 100);
+			else
+				udelay(us);
 		}
 	}
 
-- 
1.7.10.4


             reply	other threads:[~2014-03-21  2:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-21  2:31 Jonghwan Choi [this message]
2014-03-21 11:50 ` Mark Brown
  -- strict thread matches above, loose matches on Subject: below --
2013-09-20 11:51 Thierry Reding
2013-09-20 16:42 ` 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='000001cf44ad$a8e2f1b0$faa8d510$%choi@samsung.com' \
    --to=jhbird.choi@samsung.com \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®