Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

210 lines
7.5 KiB

  1. #ifndef __TSCONFIG_H
  2. #define __TSCONFIG_H
  3. #ifndef BASEONLY
  4. #define BASEONLY 0
  5. #endif
  6. //note to builders: the VERBOSE (and PING/P5_DEBUG/TESTHILO/CHICO/NOVELL, etc)
  7. // should be commented out for test & release builds!
  8. //#define VERBOSE //for potentially interesting messages to Doug & Arnold (developers)
  9. //#define TAPI //for using TAPI (won't work without TAPI32.DLL) - not done
  10. //#define NOVELL //for playing around with time from Netware (won't work without two DLLs)
  11. //#define CHICO //for trying to make things work on Windows 95 (if so, compile m ust be on x86)
  12. //#define PING //for testing Internet delay to NIST, uses ICMP
  13. //#define ENUM //enumerates all timesources on the network (don't include)
  14. //#define PERF //for using QueryPerformanceFrequency/Counter
  15. //#define P5_DEBUG //for toying around with Pentium's RDTSC instruction (10ns co unter)
  16. //#define TESTHILO //loops so that GC-100x sub-tenths (et al) can be compared to bc620AT and adjusted
  17. //#define AEC //for AEC-BOX code (doesn't find BREAK reliably, so not normally b uilt)
  18. // #define TRUETIME //for TrueTime format, not tested yet
  19. #define KENR //for CMOS
  20. #ifdef P5_DEBUG
  21. #define rdtsc __asm __emit 0x0F __asm __emit 0x31 //the RDTSC instruction
  22. DWORD hi32, lo32; //where we'll put edx & eax
  23. DWORD hi32temp, lo32temp;
  24. #define P5START __asm {\
  25. __asm push edx\
  26. rdtsc\
  27. __asm mov hi32temp,edx\
  28. __asm pop edx\
  29. __asm mov lo32temp,eax\
  30. }
  31. #define P5END __asm {\
  32. __asm push edx\
  33. rdtsc\
  34. __asm mov hi32,edx\
  35. __asm pop edx\
  36. __asm mov lo32,eax\
  37. }\
  38. printf("66MHz RDTSC diff=%.7fs\n",((float)hi32*65536*65536+lo32-((float)hi32temp*65536*65536+lo32temp))*1/66666666.7);\
  39. printf("166MHz RDTSC diff=%.7fs\n",((float)hi32*65536*65536+lo32-((float)hi32temp*65536*65536+lo32temp))*1/166666666.7);//display
  40. #else //if not P5_DEBUG, we want these to be blank
  41. #define P5START
  42. #define P5END
  43. #endif
  44. #define rollover() if (++nt.wSecond >59) {nt.wSecond=0; if (++nt.wMinute >59) {nt.wMinute=0; if (++nt.wHour>23) fTimeFailed = TRUE;}}
  45. //note unfortunately the above rollover routine will skip any leap second, but i t would be so rare anyway...
  46. #define MAXTYPE 32 // please maintain this
  47. #define NZ 31 // for New Nealand
  48. #define RCC 30//for Radiocode Clocks MSF, etc
  49. #define CMOS 29//for CMOS RTC
  50. #define TTPC16 28//for board level PC-SG2
  51. #define PC03XT 27//for old board from Bancomm
  52. #define TTK 26//for Kinemetrics style
  53. #define TTTL3 25//for TL-3 WWV
  54. #define MOBATIME 24//for IF482 Mobaline/RS232 DCF77 receiver
  55. #define PCLTC 23//for AEC PC-LTC/IOR (what about VITC?)
  56. #define AECBOX 22//AEC-BOX 1/2/10/20 for VITC, etc
  57. #define AMDAT 21//for ADC-60 MSF/DCF77 receiver
  58. #ifdef NOVELL
  59. #define NETWARE 20
  60. #endif
  61. #define HP 19 //for 58503A Time and Frequency Reference Receiver or 59551A - not tested well
  62. #define ATOMIC 18 //for 1PPS only
  63. #define NMEA 17
  64. #define SPECTRACOM 16
  65. #define BC630AT 15
  66. #define NTP 14
  67. #define MOTOROLA 13
  68. #define ROCKWELL 12
  69. #define TRIMBLE 11
  70. #define EUROPE 10
  71. #define COMPUTIME 9
  72. #define NRCBBC 8
  73. #define BC620AT 7
  74. #define GC1001 6
  75. #define GC1000 5
  76. #define USNO 4
  77. #define NISTACTS 3
  78. #define INTERNET 2
  79. //
  80. // N.B. The order of the following two must remain as is and these must be the
  81. // lowest numbered types. So keepa ya hands offa this.
  82. //
  83. #define PRIMARY 1
  84. #define SECONDARY 0
  85. #define DEFAULT_TYPE 0xFFFF
  86. #define SERVICE 1
  87. #define ANALYSIS 2
  88. #if 1
  89. #define LOCAL FALSE
  90. #define MODEM FALSE
  91. #define RECEIVER FALSE
  92. #else
  93. #define LOCAL (type==GC1000)||((type==BC620AT)&&bclocal)||(type==COMPUTIME)||(uselocal)||(type==AMDAT)||(type==MOBATIME)||(type==CMOS)
  94. #define MODEM (type==NISTACTS)||(type==USNO)||(type==NRCBBC)||(type==EUROPE)||(type==COMPUTIME)||(type==NZ)
  95. #define RECEIVER (type==SPECTRACOM)||(type==HP)||(type==MOTOROLA)||(type==GC1000)||(type==GC1001)||(type==ROCKWELL)||(type==TRIMBLE)||(type==AMDAT)||(type==NMEA)||(type==AECBOX)||(type==MOBATIME)||(type==TTTL3)||(type==RCC)||(type==TTK)
  96. #endif
  97. #define NETWORKTYPE(type) \
  98. ((type == NTP) || (type == PRIMARY) || (type == SECONDARY))
  99. #define JITTER_LIMIT 50
  100. #define NextSkewX(x) x++
  101. #define ModSkew(x) (x % SKEWHISTORYSIZE)
  102. #define SECTION TEXT("timeserv")
  103. #define PROFILE TEXT("timeserv.ini")
  104. #define DEFAULT(x) x.element[0].key
  105. #define CLUSTER_PERIOD 0xFFFC
  106. #define BIDAILY_PERIOD 0xFFFF
  107. #define TRIDAILY_PERIOD 0xFFFE
  108. #define WEEKLY_PERIOD 0xFFFD
  109. #define SPECIAL_PERIOD_FLOOR 0xFFFC
  110. #if BASEONLY == 0
  111. #define LegalType(x) (x < MAXTYPE)
  112. #else
  113. #define LegalType(x) ((x == PRIMARY) \
  114. || \
  115. (x == SECONDARY) \
  116. || \
  117. (x == NTP))
  118. #endif
  119. #define MAX_THREADS_IN_SERVER 8
  120. #define TSKEY TEXT("SYSTEM\\CurrentControlSet\\Services\\TimeServ\\Parameters")
  121. #define SECOND_TICKS (1000L)
  122. #define MINUTE_TICKS (60 * SECOND_TICKS)
  123. #define HOUR_TICKS (60 * MINUTE_TICKS)
  124. #define DAY_TICKS (24 * HOUR_TICKS)
  125. #define MAXBACKSLEW (3 * MINUTE_TICKS) // max back correction allowed
  126. #define CLUSTERSHORTINTERVAL (45 * MINUTE_TICKS)
  127. #define CLUSTERLONGHOURS (8)
  128. #define CLUSTERLONGINTERVAL (CLUSTERLONGHOURS * HOUR_TICKS)
  129. //
  130. // ERRORPART is the minimum contribution that the inherent clock frequency
  131. // is allowed to introduce. This is used as a multiplier of the clock
  132. // frequency to be the floor for the clock error to which a skew correction
  133. // can be applied. In other words, if F is the number of ms per clock tick,
  134. // then the minimum clockerror that can be used is:
  135. // F * 2 * ERRORPART
  136. // The 2 is used to compensate for two clocks.
  137. //
  138. // If you change the value, please update the following explanation:
  139. //
  140. // The number 7 was chosen to give the best resolution for the "cluster"
  141. // mode. In this mode, we wish to do a "quick", around 3 hours, slew analysis
  142. // to ensure that the clocks are reasonably close. The value 7 means
  143. // that a three hour sample must produce an error > 140 ms in order for
  144. // skew correction to happen. This is the equivalent of almost 1.2 secs/day
  145. // of error. Then we wish to lapse into a "long" cycle, namely 8 hours,
  146. // before sampling. A 1.2 sec/day error sampled each 8 hours allows for
  147. // 400 ms of observed error, or just within the bounds of 1/2 sec of skew
  148. // among the cluster systems. Using 7 means we are tolerating 1 part in
  149. // 7 of error, or around 15%. It's not great, but it's probably good
  150. // enough.\
  151. //
  152. // Note also that 140 is very close to 1/2 of the minimum clock correction
  153. // applied over 8 hours. The correction of 1 part is about 296 ms over
  154. // 8 hours. 1/2 of that is about 148 ms. So, using 7 not only provides
  155. // a good management of measurement error, it also is very close
  156. // to the minimum skew correction it makes sense to apply. What this
  157. // says is that in a cycle of 8 hours or more, the filter based on
  158. // ERRORPART is probably unnecessary, hence it exists principally
  159. // for catching errors over smaller measurement intervals. And that
  160. // is the intent.
  161. //
  162. #define ERRORPART 7
  163. #define ERRORMINIMUM(x) (x * 2 * ERRORPART)
  164. //
  165. // N.B. Another factor to consider is that one tick of the system clock, or
  166. // 100 ns, adjustment produces a change of 864 ms/day. So, in principle,
  167. // any adjustement for a skew of less than 864 ms a day is unstable and will
  168. // produce precesion. Of course, by changing the adjustment periodically,
  169. // it is possible to get two clocks that disagree by less than 864 ms/day
  170. // to come into better agreement, but it requires a constant adjustment
  171. // of at least one of the clocks.
  172. //
  173. #define MAXSKEWCORRECT 30000 // max ms/day error we will correct.
  174. #define MAXERRORTOALLOW 500 // keep it within this
  175. #endif // TSCONGIF