PART 1: Kernel Object//每一位表示对应这个特权级的队列中是否有线程(主要在KiSwapThread用,详细代码见PART3) ULONG KiReadySummary = 0
- Referenced by KeSetAffinityThread(),KiFindReadyThread(),KiReadyThread(), KiScanReadyQueues(), KiSetPriorityThread(), and NtYieldExecution().
// LIST_ENTRY KeBugCheckCallbackListHead
// LIST_ENTRY KiDispatcherReadyListHead[MAXIMUM_PRIORITY]
- Referenced by KeSetAffinityThread(), KiFindReadyThread(), KiInitSystem(), KiReadyThread(), KiScanReadyQueues(), KiSetPriorityThread(), and NtYieldExecution().
// LIST_ENTRY KiProfileListHead
- Referenced by KeStartProfile(), and KiInitSystem().
LIST_ENTRY KiProfileSourceListHead
- Referenced by KeStartProfile(), KeStopProfile(), and KiInitSystem().
// LIST_ENTRY KiProcessOutSwapListHead
- Referenced by KeDetachProcess(), KeSwapProcessOrStack(), KeTerminateThread(), KeUnstackDetachProcess(), KiInitSystem(), KiOutSwapKernelStacks(), and KiOutSwapProcesses().
LIST_ENTRY KiProcessInSwapListHead
- Referenced by KeSwapProcessOrStack(), KiAttachProcess(), KiInitSystem(), KiInSwapProcesses(), KiOutSwapProcesses(), and KiReadyThread().
LIST_ENTRY KiStackInSwapListHead
- Referenced by KeSwapProcessOrStack(), KiInitSystem(), KiInSwapKernelStacks(), and KiReadyThread().
// LIST_ENTRY KiTimerTableListHead[TIMER_TABLE_SIZE]
- Referenced by KeCheckForTimer(), KeSetSystemTime(), KiInitSystem(), KiInsertTimerTable(), KiTimerExpiration(), and VerifierKeInitializeTimerEx().
// LIST_ENTRY KiWaitInListHead
- Referenced by KiInitSystem(), and KiOutSwapKernelStacks().
LIST_ENTRY KiWaitOutListHead
- Referenced by KiInitSystem(), and KiOutSwapKernelStacks().
PART 2: Kernel Object of KPROCESS
LIST_ENTRY _KPROCESS::ThreadListHead - Referenced by ExpGetProcessInformation(), KeDetachProcess(), KeFreezeAllThreads(), KeTerminateThread(), KeThawAllThreads(), and KeUnstackDetachProcess().
LIST_ENTRY _KPROCESS::SwapListEntry
- Referenced by KeDetachProcess(), KeTerminateThread(), KeUnstackDetachProcess(), KiOutSwapKernelStacks(), KiOutSwapProcesses(), and KiReadyThread().
LIST_ENTRY _KPROCESS::ReadyListHead
- Referenced by KiInSwapProcesses(), KiOutSwapProcesses(), and KiReadyThread().
PART 3:
/*------------------------- MmInitSystem -------------------------
- MmInitSystem启动两个线程: KeBalanceSetManager 和 KeSwapProcessOrStack;
- 平衡集管理器(balance set manager)
- 交换管理器(KeSwapProcessOrStack)
- 其实它还启动了MiModifiedPageWriter(将某些页面置入pagefile中)
-----------------------------------------------------------------*/ 01337 // 01338 // Start the modified page writer. 01339 // 01340 01341 InitializeObjectAttributes( &ObjectAttributes, NULL, 0, NULL, NULL ); 01342 01343 if (!NT_SUCCESS(PsCreateSystemThread( 01344 &ThreadHandle, 01345 THREAD_ALL_ACCESS, 01346 &ObjectAttributes, 01347 0L, 01348 NULL, 01349 MiModifiedPageWriter, 01350 NULL 01351 ))) { 01352 return FALSE; 01353 } 01354 ZwClose (ThreadHandle); 01355 01356 // 01357 // Start the balance set manager. 01358 // 01359 // The balance set manager performs stack swapping and working 01360 // set management and requires two threads. 01361 // 01362 01363 KeInitializeEvent (&MmWorkingSetManagerEvent, 01364 SynchronizationEvent, 01365 FALSE); 01366 01367 InitializeObjectAttributes( &ObjectAttributes, NULL, 0, NULL, NULL ); 01368 01369 if (!NT_SUCCESS(PsCreateSystemThread( 01370 &ThreadHandle, 01371 THREAD_ALL_ACCESS, 01372 &ObjectAttributes, 01373 0L, 01374 NULL, 01375 KeBalanceSetManager, 01376 NULL 01377 ))) { 01378 01379 return FALSE; 01380 } 01381 ZwClose (ThreadHandle); 01382 01383 if (!NT_SUCCESS(PsCreateSystemThread( 01384 &ThreadHandle, 01385 THREAD_ALL_ACCESS, 01386 &ObjectAttributes, 01387 0L, 01388 NULL, 01389 KeSwapProcessOrStack, 01390 NULL 01391 ))) { 01392 01393 return FALSE; 01394 }
/*---------------------- KeBalanceSetManager ---------------------
- KeBalanceSetManager也一直循环着并等待着一个MmWorkingSetManagerEvent事件 (当内存低时调整工作集的大小)和另一个定时器.
- 定时器事件处理程序周期性地将KiStackOutSwapRequest设置为TRUE, 并且触发KiSwapEvent信号通知KeSwapProcessOrStack线程, KeSwapProcessOrStack线程 不得不将长时间等待某个东西的线程的内核堆栈交换出去.
- KeBalanceSetManager也调用KiScanReadyQueues 来提高在就绪队列中线程(KiDispatcherReadyListHead数组)的优先级.
- 对于每一个提高了优先级的线程, KiReadyThread将会被调用, 所以马上将PRCB.NextThread设置为提高了优先级的线程也是很有可能的 (KiReadyThread 会抢占原先的NextThread).
-----------------------------------------------------------------*/
00141 VOID 00142 KeBalanceSetManager ( 00143 IN PVOID Context 00144 ) 00145 00146 /*++ 00147 00148 Routine Description: 00149 00150 This function is the startup code for the balance set manager. The 00151 balance set manager thread is created during system initialization 00152 and begins execution in this function. 00153 00154 Arguments: 00155 00156 Context - Supplies a pointer to an arbit
线程调度的部分资料
最新推荐文章于 2023-05-10 10:35:06 发布
本文深入探讨Windows内核的线程调度,包括KiReadySummary、KiDispatcherReadyListHead等数据结构,以及KeBalanceSetManager和KeSwapProcessOrStack线程的角色。平衡集管理器负责栈交换和工作集管理,而KeSwapProcessOrStack处理内核堆栈交换。通过KeSetPriorityThread、KiFindReadyThread等函数,系统动态调整线程优先级和上下文切换。
摘要由CSDN通过智能技术生成