[PATCH 11/15] regulator: core: Use fsleep() to get best sleep mechanism

Anna-Maria Behnsen posted 15 patches 1 year, 3 months ago
There is a newer version of this series
[PATCH 11/15] regulator: core: Use fsleep() to get best sleep mechanism
Posted by Anna-Maria Behnsen 1 year, 3 months ago
_regulator_delay_helper() implements the recommondation of the outdated
documentation which sleep mechanism should be used. There is already a
function in place which does everything and also maps to reality called
fsleep().

Use fsleep() to choose the best mechanism.

Cc: Liam Girdwood <lgirdwood@gmail.com>
Cc: Mark Brown <broonie@kernel.org>
Signed-off-by: Anna-Maria Behnsen <anna-maria@linutronix.de>
---
 drivers/regulator/core.c | 33 ++++-----------------------------
 1 file changed, 4 insertions(+), 29 deletions(-)

diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 7674b7f2df14..155c3e3ab3f1 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -2671,39 +2671,14 @@ static int regulator_ena_gpio_ctrl(struct regulator_dev *rdev, bool enable)
  * _regulator_delay_helper - a delay helper function
  * @delay: time to delay in microseconds
  *
- * Delay for the requested amount of time as per the guidelines in:
+ * For details please refere to fsleep() function description.
  *
- *     Documentation/timers/timers-howto.rst
- *
- * The assumption here is that these regulator operations will never used in
+ * The assumption here is that these regulator operations are never used in
  * atomic context and therefore sleeping functions can be used.
  */
-static void _regulator_delay_helper(unsigned int delay)
+static inline void _regulator_delay_helper(unsigned int 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);
+	fsleep(delay);
 }
 
 /**

-- 
2.39.2
Re: [PATCH 11/15] regulator: core: Use fsleep() to get best sleep mechanism
Posted by Mark Brown 1 year, 3 months ago
On Wed, Sep 04, 2024 at 03:05:01PM +0200, Anna-Maria Behnsen wrote:
> _regulator_delay_helper() implements the recommondation of the outdated
> documentation which sleep mechanism should be used. There is already a
> function in place which does everything and also maps to reality called
> fsleep().

> - * Delay for the requested amount of time as per the guidelines in:
> + * For details please refere to fsleep() function description.

> -static void _regulator_delay_helper(unsigned int delay)
> +static inline void _regulator_delay_helper(unsigned int delay)

Gien that this just becomes a trivial wrapper for fsleep() why not just
replace all the calls with fsleep() and remove the function entirely?
Re: [PATCH 11/15] regulator: core: Use fsleep() to get best sleep mechanism
Posted by Anna-Maria Behnsen 1 year, 3 months ago
Mark Brown <broonie@kernel.org> writes:

> On Wed, Sep 04, 2024 at 03:05:01PM +0200, Anna-Maria Behnsen wrote:
>> _regulator_delay_helper() implements the recommondation of the outdated
>> documentation which sleep mechanism should be used. There is already a
>> function in place which does everything and also maps to reality called
>> fsleep().
>
>> - * Delay for the requested amount of time as per the guidelines in:
>> + * For details please refere to fsleep() function description.
>
>> -static void _regulator_delay_helper(unsigned int delay)
>> +static inline void _regulator_delay_helper(unsigned int delay)
>
> Gien that this just becomes a trivial wrapper for fsleep() why not just
> replace all the calls with fsleep() and remove the function entirely?

Nothing to say against it! I will change it.

Thanks,

	Anna-Maria