线程调度的部分资料

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值