Linux device drivers book

Since I’m always forgetting where the free O’Reilly ‘Linux Device Drivers 3rd edition’ book can be found, here’s a link: http://lwn.net/Kernel/LDD3/

Chapter 7 about timing is especially interesting even though the tricks with jiffies seem a bit weird? The book says to get the interval between two jiffies you can do this:

diff = (long)t2 - (long)t1;

Well if t1 is just before the MAX_JIFFY_OFFSET and t2 has wrapped around (which jiffies do due to their 32bit nature) you get a nice BIG negative number. That’s not useful at all…anyway in the meantime i’ve learned that time_after() and msecs_to_jiffies() are your best friends. The time_after/time_before macros actually take the wrapping into account.

So the tip for the day: avoid working with jiffy intervals, just let your code do stuff based on the time_before() and time_after() macros.