Other Portability Issues
In addition to data typing, there are a few other software issues to keep in mind when writing a driver if you want it to be portable across Linux platforms:
- Time intervals
When dealing with time intervals, don’t assume that there are 100 jiffies per second. Although this is currently true for Linux-x86, not every Linux platform runs at 100Hz. The assumption can be false even for the x86 if you play with the
HZ
value, and nobody knows what will happen in future kernels. Whenever you calculate time intervals using jiffies, scale your times usingHZ
. For example, to check against a timeout of half a second, compare the elapsed time againstHZ/2
. More generally, the number of jiffies corresponding tomsec
milliseconds is alwaysmsec*HZ/1000
. This detail had to be fixed in many network drivers when porting them to the Alpha; some drivers originally designed for the PC included an explicit jiffy value for the timeout, but the Alpha has a differentHZ
value.- Page size
When playing games with memory, remember that a memory page is
PAGE_SIZE
bytes, not 4KB. Assuming that the page size is 4KB and hard-coding the value is a common error among PC programmers--the Alpha has pages twice as big. The relevant macros arePAGE_SIZE
andPAGE_SHIFT
. The latter contains the number of bits to shift an address to get its page number. The number currently is 12 or 13, for 4KB and 8KB pages. The macros are defined in<asm/page.h>
.Let’s look at a non-trivial situation. ...
Get Linux Device Drivers now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.