[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Short sleeps.
Mark Collins wrote:
> Well, that could be a problem with such high-resolution sleeps, and could be
> a wasted effort (although the loopback idea sounds good...).
The infamous paperclip hack *does* work - so it's true that in theory, if you
could find a clean way to cause a kernel-level interrupt in 1ms, you could
block for that long.
> When you give control to another process, that process could block for <x>
> milliseconds, then the schedular passes controll to another process, which
> blocks for <y> milliseconds and so on.
I'm assuming that my sleeping process has higher priority than the other
game threads - and that there are no other *significant* processes running.
> Amd, looking at my FIrst Edition of Linux Device Drivers, on page 137, there
> is mention of the udelay() function, which is pretty high resolution, BUT, it
> blocks. The books says that there are no functions (or fails to mention
> functions) for such high resolution delays.
I don't see a 'udelay' in any modern Linux docs.
> Of course, this is quite an old book, and things might have changed since
Yes. Early Linux was not very standardized. Also, if it was a book on device
drivers, there may well be some functions inside the kernel that drivers can
use that are not available to user-level processes.
> I just tried a very simple program, which uses sleep(), which looked like it
> had no delay. I'm not sure if this blocks, but if you pass 0 as an argument,
> it MAY continue performing tasks in the schedule queue for one cycle. Stick
> that in a loop like the one I mentioned eariler, and you may be in luck...
Yes - come to think of it, people do that a lot on IRIX machines using
an IRIX-specific function called 'sginap'. The problem with sginap (and
probably this suggestion) is that if you have a higher process priority
than the other threads you'd like to run, then it's just like a busy-wait
and if your process priority is lower then you get kicked off the CPU for
----------------------------- Steve Baker -------------------------------
Mail : <firstname.lastname@example.org> WorkMail: <email@example.com>
URLs : http://www.sjbaker.org
http://plib.sf.net http://tuxaqfh.sf.net http://tuxkart.sf.net