[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Sleeping for <1 jiffie in kernel module
Hi All,
I'm working on a kernel module to drive a PCI card. The module reads a
clock port (frequency: 1187 Hz) and sends a bit to the data port every
time the clock port rises. This stream of bits has to flow as long as
the PCI card is used – for hours maybe.
The module has to check the clock port to detect a rise. This looks
something like this:
while (...) {
while (port_get() != 0) { } // wait for the clock to fall
while (port_get() == 0) { } // wait for the clock to rise
*** send bit ***
}
This effectively locks up the computer as it eats all the CPU cycles do
do... nothing ;-) Given the clock frequency of 1187Hz, the time between
two clock port rises is about 842ns. So a better code that's supposed
NOT to eat up all CPU cycles should look something like this:
while (...) {
nanosleep(800);
while (port_get() == 0) { nanosleep(20); } // wait for the clock to
rise
*** send bit ***
}
Last but not least: the question!
I can't use nanosleep() in kernel modules and the resolution of
schedule_timeout() is way too large. What else can I use instead of
nanosleep()?
Many thanks for your help,
-sven
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive: http://mail.nl.linux.org/kernelnewbies/
FAQ: http://kernelnewbies.org/faq/