开发者

When to call schedule()?

I'm writing a driver for device that has no DMA.

Driver start device operation and then waits for operation to complete by pulling busy flag from device periodically.

The operation takes 4.5 or 9 microseconds to complete. Under no circumstances device completes operation earlier. No errors will arise from reading state of device later than designated amount of time (9 microseconds).

Busywait

All kernel articles found in Internet tell to busywait for intervals this small. They argue that any sleep operation will waste more resources than busywait. Personally, I don't like wasting cycles on trivial wait.

Schedule/sleep

I've found out th开发者_如何学JAVAat on target hardware with a process using whole CPU schedule() call causing other threads (on empty processor there are no other threads) can be invoked up to 4 times before device operation completes. When I add more dummy processes to load the CPU, I see that schedule call in my driver gives fairer CPU allocation for concurrently running processes.

Should I call schedule() or even usleep_range() while waiting for my device, or should I rely on kernel preemption to deal with busywaits?


According to Documentation/timers/timers-howto.txt, usleep_range is what you want for recent kernels.

[Update: Whoops! I should have read more carefully. For < 10us, it says to use udelay. So I guess it depends on how long you are willing to sleep for.]

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜