This chapter explores using Linux as an event timer with 1ms resolution. Linux offers several mechanisms for timing, and the do_gettimeofday function with microsecond resolution works best for the three Project Trailblazer target board processors. Whereas determining maximum interrupt latency is difficult, measuring average interrupt latency is relatively easy. Using the interrupt latency device drivers and an oscilloscope, the engineers found the average interrupt latency for the MZ104, the MediaEngine, and the RPX-CLLF to be 50ms, 10ms, and 35ms, respectively. These impressive numbers alleviated the need for the engineers to explore real-time Linux solutions.
The racetimer_x86 device driver implements a split interrupt driver and a 1-second kernel timer. The interrupt top-half routine executes quickly, with interrupts disabled, and schedules the bottom-half tasklet for future execution. The bottom-half tasklet then performs lengthy writes to the system log and starts a 1-second reoccurring kernel timer. By using a kernel timer, the driver avoids using wait loops or sleep functions that dramatically affect system performance.