Sleeping for <1 jiffie in kernel module (cont'd)

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

 



Ooops, messed up the units. I'm not in the nanosecond but in the microsecond range. Here's the mail again with the correct numbers.

--- --- ---

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 842 microseconds. So a better code that's supposed NOT to eat up all CPU cycles should look something like this:

while (...) {
usleep(800);
while (port_get() == 0) { usleep(20); } // wait for the clock to rise
*** send bit ***
}


Last but not least: the question!

I can't use usleep() in kernel modules and the resolution of schedule_timeout() is way too large. What else can I use instead of usleep()?

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/



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux