time.README 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. README for MIPS time services
  2. Jun Sun
  3. jsun@mvista.com or jsun@junsun.net
  4. ABOUT
  5. -----
  6. This file describes the new arch/mips/kernel/time.c, related files and the
  7. services they provide.
  8. If you are short in patience and just want to know how to use time.c for a
  9. new board or convert an existing board, go to the last section.
  10. FILES, COMPATABILITY AND CONFIGS
  11. ---------------------------------
  12. The old arch/mips/kernel/time.c is renamed to old-time.c.
  13. A new time.c is put there, together with include/asm-mips/time.h.
  14. Two configs variables are introduced, CONFIG_OLD_TIME_C and CONFIG_NEW_TIME_C.
  15. So we allow boards using
  16. 1) old time.c (CONFIG_OLD_TIME_C)
  17. 2) new time.c (CONFIG_NEW_TIME_C)
  18. 3) neither (their own private time.c)
  19. However, it is expected every board will move to the new time.c in the near
  20. future.
  21. WHAT THE NEW CODE PROVIDES?
  22. ---------------------------
  23. The new time code provide the following services:
  24. a) Implements functions required by Linux common code:
  25. time_init
  26. do_gettimeofday
  27. do_settimeofday
  28. b) provides an abstraction of RTC and null RTC implementation as default.
  29. extern unsigned long (*rtc_get_time)(void);
  30. extern int (*rtc_set_time)(unsigned long);
  31. c) a set of gettimeoffset functions for different CPUs and different
  32. needs.
  33. d) high-level and low-level timer interrupt routines where the timer
  34. interrupt source may or may not be the CPU timer. The high-level
  35. routine is dispatched through do_IRQ() while the low-level is
  36. dispatched in assemably code (usually int-handler.S)
  37. WHAT THE NEW CODE REQUIRES?
  38. ---------------------------
  39. For the new code to work properly, each board implementation needs to supply
  40. the following functions or values:
  41. a) board_time_init - a function pointer. Invoked at the beginnig of
  42. time_init(). It is optional.
  43. 1. (optional) set up RTC routines
  44. 2. (optional) calibrate and set the mips_counter_frequency
  45. b) board_timer_setup - a function pointer. Invoked at the end of time_init()
  46. 1. (optional) over-ride any decisions made in time_init()
  47. 2. set up the irqaction for timer interrupt.
  48. 3. enable the timer interrupt
  49. c) (optional) board-specific RTC routines.
  50. d) (optional) mips_counter_frequency - It must be definied if the board
  51. is using CPU counter for timer interrupt or it is using fixed rate
  52. gettimeoffset().
  53. PORTING GUIDE
  54. -------------
  55. Step 1: decide how you like to implement the time services.
  56. a) does this board have a RTC? If yes, implement the two RTC funcs.
  57. b) does the CPU have counter/compare registers?
  58. If the answer is no, you need a timer to provide the timer interrupt
  59. at 100 HZ speed.
  60. You cannot use the fast gettimeoffset functions, i.e.,
  61. unsigned long fixed_rate_gettimeoffset(void);
  62. unsigned long calibrate_div32_gettimeoffset(void);
  63. unsigned long calibrate_div64_gettimeoffset(void);
  64. You can use null_gettimeoffset() will gives the same time resolution as
  65. jiffy. Or you can implement your own gettimeoffset (probably based on
  66. some ad hoc hardware on your machine.)
  67. c) The following sub steps assume your CPU has counter register.
  68. Do you plan to use the CPU counter register as the timer interrupt
  69. or use an exnternal timer?
  70. In order to use CPU counter register as the timer interrupt source, you
  71. must know the counter speed (mips_counter_frequency). It is usually the
  72. same as the CPU speed or an integral divisor of it.
  73. d) decide on whether you want to use high-level or low-level timer
  74. interrupt routines. The low-level one is presumably faster, but should
  75. not make too mcuh difference.
  76. Step 2: the machine setup() function
  77. If you supply board_time_init(), set the function poointer.
  78. Set the function pointer board_timer_setup() (mandatory)
  79. Step 3: implement rtc routines, board_time_init() and board_timer_setup()
  80. if needed.
  81. board_time_init() -
  82. a) (optional) set up RTC routines,
  83. b) (optional) calibrate and set the mips_counter_frequency
  84. (only needed if you intended to use fixed_rate_gettimeoffset
  85. or use cpu counter as timer interrupt source)
  86. board_timer_setup() -
  87. a) (optional) over-write any choices made above by time_init().
  88. b) machine specific code should setup the timer irqaction.
  89. c) enable the timer interrupt
  90. If the RTC chip is a common chip, I suggest the routines are put under
  91. arch/mips/libs. For example, for DS1386 chip, one would create
  92. rtc-ds1386.c under arch/mips/lib directory. Add the following line to
  93. the arch/mips/lib/Makefile:
  94. obj-$(CONFIG_DDB5476) += rtc-ds1386.o
  95. Step 4: if you are using low-level timer interrupt, change your interrupt
  96. dispathcing code to check for timer interrupt and jump to
  97. ll_timer_interrupt() directly if one is detected.
  98. Step 5: Modify arch/mips/config.in and add CONFIG_NEW_TIME_C to your machine.
  99. Modify the appropriate defconfig if applicable.
  100. Final notes:
  101. For some tricky cases, you may need to add your own wrapper functions
  102. for some of the functions in time.c.
  103. For example, you may define your own timer interrupt routine, which does
  104. some of its own processing and then calls timer_interrupt().
  105. You can also over-ride any of the built-in functions (gettimeoffset,
  106. RTC routines and/or timer interrupt routine).
  107. PORTING NOTES FOR SMP
  108. ----------------------
  109. If you have a SMP box, things are slightly more complicated.
  110. The time service running every jiffy is logically divided into two parts:
  111. 1) the one for the whole system (defined in timer_interrupt())
  112. 2) the one that should run for each CPU (defined in local_timer_interrupt())
  113. You need to decide on your timer interrupt sources.
  114. case 1) - whole system has only one timer interrupt delivered to one CPU
  115. In this case, you set up timer interrupt as in UP systems. In addtion,
  116. you need to set emulate_local_timer_interrupt to 1 so that other
  117. CPUs get to call local_timer_interrupt().
  118. THIS IS CURRENTLY NOT IMPLEMNETED. However, it is rather easy to write
  119. one should such a need arise. You simply make a IPI call.
  120. case 2) - each CPU has a separate timer interrupt
  121. In this case, you need to set up IRQ such that each of them will
  122. call local_timer_interrupt(). In addition, you need to arrange
  123. one and only one of them to call timer_interrupt().
  124. You can also do the low-level version of those interrupt routines,
  125. following similar dispatching routes described above.
  126. Note about do_gettimeoffset():
  127. It is very likely the CPU counter registers are not sync'ed up in a SMP box.
  128. Therefore you cannot really use the many of the existing routines that
  129. are based on CPU counter. You should wirte your own gettimeoffset rouinte
  130. if you want intra-jiffy resolution.