Re: [PATCH] hrtimers: teach usleep_range() to return how many usecswas slept

From: Andrew Morton
Date: Thu Jan 26 2012 - 03:59:33 EST


On Mon, 16 Jan 2012 16:53:23 +0400 Dmitry Antipov <dmitry.antipov@xxxxxxxxxx> wrote:

> Teach usleep_range() to return how many usecs was actually spent
> in sleep. The rationale beyond this is to convert jiffies-based
> wait-for-hardware loops like:
>
> unsigned long timeout = jiffies + msecs_to_jiffies(1000);
> while (hw_is_not_ready()) {
> if (time_after(jiffies, timeout))
> return -ETIMEDOUT;
> msleep(1);
> }
>
> to:
>
> unsigned long timeout = 0;
> while (hw_is_not_ready()) {
> if (timeout > USEC_PER_SEC)
> return -ETIMEDOUT;
> timeout += usleep_range(1000, 2000);
> }
>

Is that useful enough to justify making the change?

>
> int __sched schedule_hrtimeout_range(ktime_t *expires, unsigned long delta,
> - const enum hrtimer_mode mode)
> + const enum hrtimer_mode mode, unsigned long *elapsed)

Rather than adding another argument, I suggest you change the return
type to long and use return value semantics similar to schedule_timeout().

schedule_timeout() never returns -ve numbers and it returns jiffies,
but it will be close(r).

Returning usecs is odd. One would expect it to return a ktime_t. That
might inflict some code-size cost in callers.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/