All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] regulator: core: Sleep (not delay) in set_voltage()
@ 2022-04-18 21:12 Brian Norris
  2022-04-18 21:12 ` [PATCH 2/2] regulator: core: Replace _regulator_enable_delay() with fsleep() Brian Norris
  2022-04-18 22:50 ` [PATCH 1/2] regulator: core: Sleep (not delay) in set_voltage() Matthias Kaehlcke
  0 siblings, 2 replies; 7+ messages in thread
From: Brian Norris @ 2022-04-18 21:12 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown; +Cc: Matthias Kaehlcke, linux-kernel, Brian Norris

These delays can be relatively large (e.g., hundreds of microseconds on
RK3399 Gru systems). Per Documentation/timers/timers-howto.rst, that
should usually use a sleeping delay. Let's use fsleep() to handle both
large and small delays appropriately. This avoids burning a bunch of CPU
time and hurting scheduling latencies when hitting regulators a lot
(e.g., during cpufreq).

The sleep vs. delay issue choice has been made differently over time --
early versions of RK3399 Gru PWM-regulator support used usleep_range()
in pwm-regulator.c. More of this got moved into the regulator core,
in commits like:

73e705bf81ce regulator: core: Add set_voltage_time op

At the same time, the sleep turned into a delay.

It's OK to sleep here, as we aren't in an atomic contexts. (All our
callers grab various mutexes already.)

Signed-off-by: Brian Norris <briannorris@chromium.org>
---

 drivers/regulator/core.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index d2553970a67b..223c6d71a2b2 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -3548,12 +3548,7 @@ static int _regulator_do_set_voltage(struct regulator_dev *rdev,
 	}
 
 	/* Insert any necessary delays */
-	if (delay >= 1000) {
-		mdelay(delay / 1000);
-		udelay(delay % 1000);
-	} else if (delay) {
-		udelay(delay);
-	}
+	fsleep(delay);
 
 	if (best_val >= 0) {
 		unsigned long data = best_val;
-- 
2.36.0.rc0.470.gd361397f0d-goog


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

end of thread, other threads:[~2022-04-20 21:12 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-18 21:12 [PATCH 1/2] regulator: core: Sleep (not delay) in set_voltage() Brian Norris
2022-04-18 21:12 ` [PATCH 2/2] regulator: core: Replace _regulator_enable_delay() with fsleep() Brian Norris
2022-04-18 22:53   ` Matthias Kaehlcke
2022-04-20 16:28   ` Mark Brown
2022-04-20 18:24     ` Brian Norris
2022-04-20 21:11       ` Mark Brown
2022-04-18 22:50 ` [PATCH 1/2] regulator: core: Sleep (not delay) in set_voltage() Matthias Kaehlcke

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.