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.

591 lines
15 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. kernldat.c
  5. Abstract:
  6. This module contains the declaration and allocation of kernel data
  7. structures.
  8. Author:
  9. David N. Cutler (davec) 12-Mar-1989
  10. --*/
  11. #include "ki.h"
  12. //
  13. // The following data is read/write data that is grouped together for
  14. // performance. The layout of this data is important and must not be
  15. // changed.
  16. //
  17. // KiDispatcherReadyListHead - This is an array of type list entry. The
  18. // elements of the array are indexed by priority. Each element is a list
  19. // head for a set of threads that are in a ready state for the respective
  20. // priority. This array is used by the find next thread code to speed up
  21. // search for a ready thread when a thread becomes unrunnable. See also
  22. // KiReadySummary.
  23. //
  24. LIST_ENTRY KiDispatcherReadyListHead[MAXIMUM_PRIORITY];
  25. //
  26. // KiTimerTableListHead - This is a array of list heads that anchor the
  27. // individual timer lists.
  28. //
  29. LIST_ENTRY KiTimerTableListHead[TIMER_TABLE_SIZE];
  30. //
  31. // KiTimeUpdateNotifyRoutine - This is the address of a callout routine
  32. // which is called when the runtime for a thread is updated if the
  33. // address is not NULL.
  34. //
  35. PTIME_UPDATE_NOTIFY_ROUTINE KiTimeUpdateNotifyRoutine;
  36. //
  37. // Public kernel data declaration and allocation.
  38. //
  39. // KeActiveProcessors - This is the set of processors that active in the
  40. // system.
  41. //
  42. KAFFINITY KeActiveProcessors = 0;
  43. //
  44. // KeBootTime - This is the absolute time when the system was booted.
  45. //
  46. LARGE_INTEGER KeBootTime;
  47. //
  48. // KeBootTimeBias - The time for which KeBootTime has ever been biased
  49. //
  50. ULONGLONG KeBootTimeBias;
  51. //
  52. // KeInterruptTimeBias - The time for which InterrupTime has ever been biased
  53. //
  54. ULONGLONG KeInterruptTimeBias;
  55. //
  56. // KeBugCheckCallbackListHead - This is the list head for registered
  57. // bug check callback routines.
  58. //
  59. LIST_ENTRY KeBugCheckCallbackListHead;
  60. LIST_ENTRY KeBugCheckReasonCallbackListHead;
  61. //
  62. // KeBugCheckCallbackLock - This is the spin lock that guards the bug
  63. // check callback list.
  64. //
  65. KSPIN_LOCK KeBugCheckCallbackLock;
  66. //
  67. // KeDcacheFlushCount - This is the number of data cache flushes that have
  68. // been performed since the system was booted.
  69. //
  70. ULONG KeDcacheFlushCount = 0;
  71. //
  72. // KeIcacheFlushCount - This is the number of instruction cache flushes that
  73. // have been performed since the system was booted.
  74. //
  75. ULONG KeIcacheFlushCount = 0;
  76. //
  77. // KeGdiFlushUserBatch - This is the address of the GDI user batch flush
  78. // routine which is initialized when the win32k subsystem is loaded.
  79. //
  80. PGDI_BATCHFLUSH_ROUTINE KeGdiFlushUserBatch;
  81. //
  82. // KeLoaderBlock - This is a pointer to the loader parameter block which is
  83. // constructed by the OS Loader.
  84. //
  85. PLOADER_PARAMETER_BLOCK KeLoaderBlock = NULL;
  86. //
  87. // KeMinimumIncrement - This is the minimum time between clock interrupts
  88. // in 100ns units that is supported by the host HAL.
  89. //
  90. ULONG KeMinimumIncrement;
  91. //
  92. // KeNumberProcessors - This is the number of processors in the configuration.
  93. // If is used by the ready thread and spin lock code to determine if a
  94. // faster algorithm can be used for the case of a single processor system.
  95. // The value of this variable is set when processors are initialized.
  96. //
  97. CCHAR KeNumberProcessors = 0;
  98. //
  99. // KeRegisteredProcessors - This is the maximum number of processors which
  100. // can utilized by the system.
  101. //
  102. #if !defined(NT_UP)
  103. #if DBG
  104. ULONG KeRegisteredProcessors = 4;
  105. ULONG KeLicensedProcessors;
  106. #else
  107. ULONG KeRegisteredProcessors = 2;
  108. ULONG KeLicensedProcessors;
  109. #endif
  110. #endif
  111. //
  112. // KeProcessorArchitecture - Architecture of all processors present in system.
  113. // See PROCESSOR_ARCHITECTURE_ defines in ntexapi.h
  114. //
  115. USHORT KeProcessorArchitecture = PROCESSOR_ARCHITECTURE_UNKNOWN;
  116. //
  117. // KeProcessorLevel - Architectural specific processor level of all processors
  118. // present in system.
  119. //
  120. USHORT KeProcessorLevel = 0;
  121. //
  122. // KeProcessorRevision - Architectural specific processor revision number that is
  123. // the least common denominator of all processors present in system.
  124. //
  125. USHORT KeProcessorRevision = 0;
  126. //
  127. // KeFeatureBits - Architectural specific processor features present
  128. // on all processors.
  129. //
  130. ULONG KeFeatureBits = 0;
  131. //
  132. // KeServiceDescriptorTable - This is a table of descriptors for system
  133. // service providers. Each entry in the table describes the base
  134. // address of the dispatch table and the number of services provided.
  135. //
  136. KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTable[NUMBER_SERVICE_TABLES];
  137. KSERVICE_TABLE_DESCRIPTOR KeServiceDescriptorTableShadow[NUMBER_SERVICE_TABLES];
  138. //
  139. // KeThreadSwitchCounters - These counters record the number of times a
  140. // thread can be scheduled on the current processor, any processor,
  141. // or the last processor it ran on.
  142. //
  143. KTHREAD_SWITCH_COUNTERS KeThreadSwitchCounters;
  144. //
  145. // KeTimeIncrement - This is the nominal number of 100ns units that are to
  146. // be added to the system time at each interval timer interupt. This
  147. // value is set by the HAL and is used to compute the dure time for
  148. // timer table entries.
  149. //
  150. ULONG KeTimeIncrement;
  151. //
  152. // KeTimeSynchronization - This variable controls whether time synchronization
  153. // is performed using the realtime clock (TRUE) or whether it is under the
  154. // control of a service (FALSE).
  155. //
  156. BOOLEAN KeTimeSynchronization = TRUE;
  157. //
  158. // KeUserApcDispatcher - This is the address of the user mode APC dispatch
  159. // code. This address is looked up in NTDLL.DLL during initialization
  160. // of the system.
  161. //
  162. PVOID KeUserApcDispatcher;
  163. //
  164. // KeUserCallbackDispatcher - This is the address of the user mode callback
  165. // dispatch code. This address is looked up in NTDLL.DLL during
  166. // initialization of the system.
  167. //
  168. PVOID KeUserCallbackDispatcher;
  169. //
  170. // KeUserExceptionDispatcher - This is the address of the user mode exception
  171. // dispatch code. This address is looked up in NTDLL.DLL during system
  172. // initialization.
  173. //
  174. PVOID KeUserExceptionDispatcher;
  175. //
  176. // KeRaiseUserExceptionDispatcher - This is the address of the raise user
  177. // mode exception dispatch code. This address is looked up in NTDLL.DLL
  178. // during system initialization.
  179. //
  180. PVOID KeRaiseUserExceptionDispatcher;
  181. //
  182. // KeLargestCacheLine - This variable contains the size in bytes of
  183. // the largest cache line discovered during system initialization.
  184. // It is used to provide the recommend alignment (and padding)
  185. // for data that may be used heavily by more than one processor.
  186. // The initial value was chosen as a reasonable value to use on
  187. // systems where the discovery process doesn't find a value.
  188. //
  189. ULONG KeLargestCacheLine = 64;
  190. //
  191. // Private kernel data declaration and allocation.
  192. //
  193. // KiBugCodeMessages - Address of where the BugCode messages can be found.
  194. //
  195. PMESSAGE_RESOURCE_DATA KiBugCodeMessages = NULL;
  196. //
  197. // KiDmaIoCoherency - This determines whether the host platform supports
  198. // coherent DMA I/O.
  199. //
  200. ULONG KiDmaIoCoherency;
  201. //
  202. // KiMaximumSearchCount - this is the maximum number of timers entries that
  203. // have had to be examined to insert in the timer tree.
  204. //
  205. ULONG KiMaximumSearchCount = 0;
  206. //
  207. // KiDebugRoutine - This is the address of the kernel debugger. Initially
  208. // this is filled with the address of a routine that just returns. If
  209. // the system debugger is present in the system, then it sets this
  210. // location to the address of the systemn debugger's routine.
  211. //
  212. PKDEBUG_ROUTINE KiDebugRoutine;
  213. //
  214. // KiDebugSwitchRoutine - This is the address of the kernel debuggers
  215. // processor switch routine. This is used on an MP system to
  216. // switch host processors while debugging.
  217. //
  218. PKDEBUG_SWITCH_ROUTINE KiDebugSwitchRoutine;
  219. //
  220. // KiDispatcherLock - This is the spin lock that guards the dispatcher
  221. // database.
  222. //
  223. extern KSPIN_LOCK KiDispatcherLock;
  224. const CCHAR KiFindFirstSetRight[256] = {
  225. 0, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  226. 4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  227. 5, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0,
  228. 4, 0, 1, 0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, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  249. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  250. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  251. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  252. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  253. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  254. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  255. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  256. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  257. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7};
  258. //
  259. // KiFreezeExecutionLock - This is the spin lock that guards the freezing
  260. // of execution.
  261. //
  262. extern KSPIN_LOCK KiFreezeExecutionLock;
  263. //
  264. // KiFreezeLockBackup - For debug builds only. Allows kernel debugger to
  265. // be entered even FreezeExecutionLock is jammed.
  266. //
  267. extern KSPIN_LOCK KiFreezeLockBackup;
  268. //
  269. // KiFreezeFlag - For debug builds only. Flags to track and signal non-
  270. // normal freezelock conditions.
  271. //
  272. ULONG KiFreezeFlag;
  273. //
  274. // KiSuspenState - Flag to track suspend/resume state of processors.
  275. //
  276. volatile ULONG KiSuspendState;
  277. //
  278. // KiProcessorBlock - This is an array of pointers to processor control blocks.
  279. // The elements of the array are indexed by processor number. Each element
  280. // is a pointer to the processor control block for one of the processors
  281. // in the configuration. This array is used by various sections of code
  282. // that need to effect the execution of another processor.
  283. //
  284. PKPRCB KiProcessorBlock[MAXIMUM_PROCESSORS];
  285. //
  286. // KeNumberNodes - This is the number of ccNUMA nodes in the system. Logically
  287. // an SMP system is the same as a single node ccNUMA system.
  288. //
  289. UCHAR KeNumberNodes = 1;
  290. //
  291. // KeNodeBlock - This is an array of pointers to KNODE structures. A KNODE
  292. // structure describes the resources of a NODE in a ccNUMA system.
  293. //
  294. KNODE KiNode0;
  295. #if defined(KE_MULTINODE)
  296. PKNODE KeNodeBlock[MAXIMUM_CCNUMA_NODES];
  297. UCHAR KeProcessNodeSeed;
  298. #else
  299. PKNODE KeNodeBlock[1] = { &KiNode0 };
  300. #endif
  301. //
  302. // KiSwapEvent - This is the event that is used to wake up the balance set
  303. // thread to inswap processes, outswap processes, and to inswap kernel
  304. // stacks.
  305. //
  306. KEVENT KiSwapEvent;
  307. //
  308. // KiSwappingThread - This is a pointer to the swap thread object.
  309. //
  310. PKTHREAD KiSwappingThread;
  311. //
  312. // KiProcessInSwapListHead - This is the list of processes that are waiting
  313. // to be inswapped.
  314. //
  315. SINGLE_LIST_ENTRY KiProcessInSwapListHead;
  316. //
  317. // KiProcessOutSwapListHead - This is the list of processes that are waiting
  318. // to be outswapped.
  319. //
  320. SINGLE_LIST_ENTRY KiProcessOutSwapListHead;
  321. //
  322. // KiStackInSwapListHead - This is the list of threads that are waiting
  323. // to get their stack inswapped before they can run. Threads are
  324. // inserted in this list in ready thread and removed by the balance
  325. // set thread.
  326. //
  327. SINGLE_LIST_ENTRY KiStackInSwapListHead;
  328. //
  329. // KiProfileSourceListHead - The list of profile sources that are currently
  330. // active.
  331. //
  332. LIST_ENTRY KiProfileSourceListHead;
  333. //
  334. // KiProfileAlignmentFixup - Indicates whether alignment fixup profiling
  335. // is active.
  336. //
  337. BOOLEAN KiProfileAlignmentFixup;
  338. //
  339. // KiProfileAlignmentFixupInterval - Indicates the current alignment fixup
  340. // profiling interval.
  341. //
  342. ULONG KiProfileAlignmentFixupInterval;
  343. //
  344. // KiProfileAlignmentFixupCount - Indicates the current alignment fixup
  345. // count.
  346. //
  347. ULONG KiProfileAlignmentFixupCount;
  348. //
  349. // KiProfileInterval - The profile interval in 100ns units.
  350. //
  351. #if !defined(_IA64_)
  352. ULONG KiProfileInterval = DEFAULT_PROFILE_INTERVAL;
  353. #endif // !_IA64_
  354. //
  355. // KiProfileListHead - This is the list head for the profile list.
  356. //
  357. LIST_ENTRY KiProfileListHead;
  358. //
  359. // KiProfileLock - This is the spin lock that guards the profile list.
  360. //
  361. extern KSPIN_LOCK KiProfileLock;
  362. //
  363. // KiTimerExpireDpc - This is the Deferred Procedure Call (DPC) object that
  364. // is used to process the timer queue when a timer has expired.
  365. //
  366. KDPC KiTimerExpireDpc;
  367. //
  368. // KiTimeIncrementReciprocal - This is the reciprocal fraction of the time
  369. // increment value that is specified by the HAL when the system is
  370. // booted.
  371. //
  372. LARGE_INTEGER KiTimeIncrementReciprocal;
  373. //
  374. // KiTimeIncrementShiftCount - This is the shift count that corresponds to
  375. // the time increment reciprocal value.
  376. //
  377. CCHAR KiTimeIncrementShiftCount;
  378. //
  379. // KiWaitListHead - This is a list of threads that are waiting with a
  380. // resident kernel stack and are elligible to have their stack
  381. // swapped.
  382. //
  383. LIST_ENTRY KiWaitListHead;
  384. //
  385. // KiIpiCounts - This is the instrumentation counters for IPI requests. Each
  386. // processor has its own set. Intstrumentation build only.
  387. //
  388. #if NT_INST
  389. KIPI_COUNTS KiIpiCounts[MAXIMUM_PROCESSORS];
  390. #endif // NT_INST
  391. //
  392. // KxUnexpectedInterrupt - This is the interrupt object that is used to
  393. // populate the interrupt vector table for interrupt that are not
  394. // connected to any interrupt.
  395. //
  396. #if defined(_IA64_)
  397. KINTERRUPT KxUnexpectedInterrupt;
  398. #endif
  399. //
  400. // Performance data declaration and allocation.
  401. //
  402. // KiFlushSingleCallData - This is the call performance data for the kernel
  403. // flush single TB function.
  404. //
  405. #if defined(_COLLECT_FLUSH_SINGLE_CALLDATA_)
  406. CALL_PERFORMANCE_DATA KiFlushSingleCallData;
  407. #endif
  408. //
  409. // KiSetEventCallData - This is the call performance data for the kernel
  410. // set event function.
  411. //
  412. #if defined(_COLLECT_SET_EVENT_CALLDATA_)
  413. CALL_PERFORMANCE_DATA KiSetEventCallData;
  414. #endif
  415. //
  416. // KiWaitSingleCallData - This is the call performance data for the kernel
  417. // wait for single object function.
  418. //
  419. #if defined(_COLLECT_WAIT_SINGLE_CALLDATA_)
  420. CALL_PERFORMANCE_DATA KiWaitSingleCallData;
  421. #endif
  422. //
  423. // KiEnableTimerWatchdog - Flag to enable/disable timer latency watchdog.
  424. //
  425. #if (DBG)
  426. ULONG KiEnableTimerWatchdog = 1;
  427. #else
  428. ULONG KiEnableTimerWatchdog = 0;
  429. #endif