System Time and Timer
Board support - system time and timer
Linux relies on an RTC (real-time clock) device to obtain the real calendar data and time when it boots up. It relies on a system timer to advance the tick count, jiffies. If you don't provide proper time and timer code, Linux won't run. In fact it will stick in 'calibrate_delay()' during the startup process because jiffies is never incremented. (See Appendix B for more details about Linux/MIPS startup sequence).
There is an excellent document (I becomes a little shameless. :-0) under 'Documentations/mips/time.README' that should be read to further understand timekeeping for Linux/MIPS. It is a must read.
Here are some comments on implementing time and timer services:
- If your system has a CPU counter and another hardware timer, use the hardware timer over the CPU counter, even though CPU counter might be easier to setup and use. This is because CPU counter relies on the CPU frequency which is more likely to change in the future. In addition, performance-critical code may need to access the CPU counter for its own measurements. Some CPUs may have a variable CPU frequency which makes CPU counter not usable as a timer source. [DEBATE: 03/12/04, I changed my preference on this issue. Linux in the future will have richer and higher resolution time support. If all MIPS boards use CPU counter as the system timer, we can maximize the code sharing.]
- Unless you have to use interrupts to calibrate the CPU frequency, you can generally avoid implementing the 'board_time_init()' function. Most of its work can be done in the board setup routine.
- When you implement 'rtc_set_time()', more than likely you need to call the 'to_tm()' function which converts a single jiffy value to a full 'struct rtc_time'. This function is provided in 'arch/mips/kernel/time.c' and declared in 'include/asm-mips/time.h'.
Next page: PCI Subsystem