Skip to contentSkip to conversation

better msleep for drivers

DISCUSSION Andi Kleen 5 participants 5 messages May 11, 2008 – May 21, 2008

lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

Thomas,

Someone asked if there is a msleep using hrtimers that is more accurate than jiffies/msecs for external drivers. There is hrtimer nanosleep, but it is currently not exported. It can be reimplemented using hrtimer_start etc. which are exported, but that seems rather clumpsy.

Is there any reason such an obvious function is not exported?

Ok I guess right now nobody in tree is using it. But that seems wrong. Perhaps we should have a (exported) usleep_blocking() wrapper or somesuch for that case?

I suspect that a lot of drivers could make use of it. Just from grepping we have a lot of msleep(1)s in drivers and I suspect a lot of those would actually like to delay shorter than one jiffie.

One argument against it would be that it makes them more difficult to test because behavior will differ between hrtimer enabled and disabled systems. Still longer term I suppose there's really no way around having accurate sleep functions and it's probably better to start testing earlier than later.

Thoughts?

-Andi

#1 lore raw

Andi,

Quoted 6 lines · Andi Kleen

Someone asked if there is a msleep using hrtimers that is more accurate than jiffies/msecs for external drivers. There is hrtimer nanosleep, but it is currently not exported. It can be reimplemented using hrtimer_start etc. which are exported, but that seems rather clumpsy.

Is there any reason such an obvious function is not exported?

Well, there was not yet a request / requirement for it.

Quoted 7 lines

Ok I guess right now nobody in tree is using it. But that seems wrong. Perhaps we should have a (exported) usleep_blocking() wrapper or somesuch for that case?

I suspect that a lot of drivers could make use of it. Just from grepping we have a lot of msleep(1)s in drivers and I suspect a lot of those would actually like to delay shorter than one jiffie.

Depends, lots of them are just the kind of "lets delay it a bit" with no real requirement to be accurate. I agree that there are use cases which could benefit from a more precise sleep facility than msleep actually is, but we need to have a careful eye on the possible abuse of such an interface.

Quoted 2 lines

One argument against it would be that it makes them more difficult to test because behavior will differ between hrtimer enabled and disabled systems.

That's what other in tree hrtimer users already face today. scheduler, networking and the user space interfaces. So that should be not a too big problem as the hrtimer infrastructure guarantees that the timer does not expire early whether highres is enabled or not. It's just less finegrained with highres=off and that's just the same as we have right now with msleep().

Quoted 2 lines

Still longer term I suppose there's really no way around having accurate sleep functions and it's probably better to start testing earlier than later.

No objections, but we should not do that with a stupid msleep replacement interface; instead we should expose a flexible in kernel variant of hrtimer_nanosleep() which lets the user utilize ABS/REL_TIME and the different clocks. A msleep helper can be built on top of this very easily.

Thanks,
tglx

#2 lore raw

Hi!

Quoted 8 lines
Quoted 2 lines

Still longer term I suppose there's really no way around having accurate sleep functions and it's probably better to start testing earlier than later.

No objections, but we should not do that with a stupid msleep replacement interface; instead we should expose a flexible in kernel variant of hrtimer_nanosleep() which lets the user utilize ABS/REL_TIME and the different clocks. A msleep helper can be built on top of this very easily.

While you are at it... it would be cool to have

'mdelay(2500 msec), but it is okay to wait 100msec more' -- type interface, so we could use that for nohz benefit.

Currently, mdelay is 'it is okay to wait 10msec more' interface, and it would be nice to have that explicit.

Signature · 6 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#3 lore raw
Quoted 10 lines · Pavel Machek

Hi!

Quoted 7 lines
Quoted 2 lines

Still longer term I suppose there's really no way around having accurate sleep functions and it's probably better to start testing earlier than later.

No objections, but we should not do that with a stupid msleep replacement interface; instead we should expose a flexible in kernel variant of hrtimer_nanosleep() which lets the user utilize ABS/REL_TIME and the different clocks. A msleep helper can be built on top of this very easily.

Quoted 7 lines

While you are at it... it would be cool to have

'mdelay(2500 msec), but it is okay to wait 100msec more' -- type interface, so we could use that for nohz benefit.

Currently, mdelay is 'it is okay to wait 10msec more' interface, and it would be nice to have that explicit.

eh, I think you transposed mdelay with msleep?

msleep() is the "it is okay to wait longer than I said" interface, not mdelay(). mdelay() has always been non-sleeping and exact (as much as the delay loop allows)

Jeff

#4 lore raw

Hi!

Quoted 13 lines
Quoted 13 lines
Quoted 7 lines
Quoted 2 lines

Still longer term I suppose there's really no way around having accurate sleep functions and it's probably better to start testing earlier than later.

No objections, but we should not do that with a stupid msleep replacement interface; instead we should expose a flexible in kernel variant of hrtimer_nanosleep() which lets the user utilize ABS/REL_TIME and the different clocks. A msleep helper can be built on top of this very easily.

While you are at it... it would be cool to have

'mdelay(2500 msec), but it is okay to wait 100msec more' -- type interface, so we could use that for nohz benefit.

Quoted 8 lines
Quoted 2 lines

Currently, mdelay is 'it is okay to wait 10msec more' interface, and it would be nice to have that explicit.

eh, I think you transposed mdelay with msleep?

msleep() is the "it is okay to wait longer than I said" interface, not mdelay(). mdelay() has always been non-sleeping and exact (as much as the delay loop allows)

Okay, I was a bit confused.

Actually, both can delay for longer... msleep() in case of scheduling load, mdelay() in case of interrupt load...

But the above was about hrtimer_nano*sleep*(), so that "how much latency we can tolarate" parameter would still be good.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html