All device drivers must eventually deal with issues of time and timing. Chapter 6 of Linux Device Drivers provides extensive time management information for Linux drivers. This chapter highlights the architectural differences of SGI Altix systems in the interval timer counter (ITC) and provides brief information about execution delays in drivers.
The ITC register is a free running, 64-bit counter that counts up at a fixed relationship to the processor clock. To retrieve elapsed cycles, Itanium 2 processors provide this register to programs via the ia64_get_itc (void) routine. Drivers should use the cycle_t get_cycles (void); interface in order to be portable. On SGI systems, these registers are not synchronized among the other CPUs on the system. Callers of this routine must be very careful that these calls are made within the same CPU. For more information regarding the ITC register, see the Intel IA-64 Architecture Software Developer's Manual , volume 2, “IA-64 System Architecture.”
For system-wide synchronized timing information, you can use the do_gettimeofday() function.
The Linux kernel also provides the following routines to allow callers to delay for a specified amount of time:
void udelay (unsigned long usecs) void mdelay (unsigned long msecs) void ndelay (unsigned long nsecs) |
The udelay() routine pauses for the specified number of microseconds while the mdelay() routine pauses for the specified number of milliseconds. The ndelay() routine pauses for the specified number of nanoseconds. Because these routines simply spin in the CPU, they should be used only for pausing small amounts of time.
If your driver requires longer delays than the delays that the simple udelay() and mdelay() commands provide, you must use other facilities provided by Linux that will provide execution of your tasks at a later time without depending on interrupts or spinning in a loop. Linux provides the following interfaces for this purpose:
Task queues
Tasklets
Kernel timers
For documentation on these features, see Linux Device Drivers, chapter 6, “Flow of Time.” All of these interfaces are supported on SGI Altix systems.