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
HZvalue, 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 tomsecmilliseconds 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 differentHZvalue.- Page size
When playing games with memory, remember that a memory page is
PAGE_SIZEbytes, 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_SIZEandPAGE_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. ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access