tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: nanosleep() for shorted than schedule slice



On 2017-07-02 23:24, Michael van Elst wrote:
bqt%softjar.se@localhost (Johnny Billquist) writes:

I don't get it. What was the problem with using nanosleep for short
usleep's?

usleep is just a wrapper around nanosleep. There is no difference
except that nanosleep accepts higher precision delays.

So, the comment previously that it was not ok to use nanosleep for short usleeps seems to not hold much water.

The kernel computes the number of ticks to sleep, schedules a callout
that will wake the thread up and calls the scheduler to run other
threads in the meantime. The callout is later dispatched by the
clock interrupt.

So you always have to wait for at least one tick, with HZ=100 that's 10ms.

Right. With the current implementation. And which means that "higher precision delays" are just imaginary. Our implementation does not actually give us any higher precision delays.

A tickless kernel wouldn't run callouts from the regular clock interrupt
but would use a hires timer to issue interrupts at arbitrary times.
The callout API could then be changed to either accept timespec values or
just fake a much higher HZ value.

Right. Not that I believe this have to be tied into tickless, but I suspect it might be easier to do it if we go tickless.

I think it's pretty bad that our timers only have the precision of ticks, even if people call something like nanosleep. By the way, the fact that nanosleep also in the end uses ticks means that the OP suggestion of using nanosleep for short usleeps will not really improve the situation at all.

We really should be able to deal with shorter times, even if we have ticks. But I guess it all depends on the hardware (which it does if we go to tickless as well, though.)

Part of my confusion might also be slightly different uses of the term tickless. The kernels use of ticks for time keeping and some work does not necessarily force us to use them for callouts. It's just convenient. We could (maybe should?) use a different mechanism for the callout subsystem.

	Johnny

--
Johnny Billquist                  || "I'm on a bus
                                  ||  on a psychedelic trip
email: bqt%softjar.se@localhost             ||  Reading murder books
pdp is alive!                     ||  tryin' to stay hip" - B. Idol


Home | Main Index | Thread Index | Old Index