- Set the right Thread->WaitTime dring waits

- Initialize WaitBlock->Thread during thread creation.
- Make APCs queuable for the thread after it's created
- Enable Timer Block optimization since it works now. This allows us not to always set-up for each wait, since most of its fields can remain static.
- Properly link wait block together with the waitlist of the timer.

svn path=/trunk/; revision=20632
This commit is contained in:
Alex Ionescu 2006-01-06 22:57:21 +00:00
parent 357c1b2aa4
commit 3a24f9a505
4 changed files with 39 additions and 38 deletions

View file

@ -63,13 +63,12 @@ KeWaitForGate(PKGATE Gate,
GateWaitBlock->Thread = CurrentThread;
/* Set the Thread Wait Data */
CurrentThread->WaitReason = WaitReason;
CurrentThread->WaitMode = WaitMode;
CurrentThread->WaitIrql = OldIrql;
CurrentThread->GateObject = Gate;
/* Insert into the Wait List */
InsertTailList(&Gate->Header.WaitListHead, &GateWaitBlock->WaitListEntry);
InsertTailList(&Gate->Header.WaitListHead,
&GateWaitBlock->WaitListEntry);
/* Handle Kernel Queues */
if (CurrentThread->Queue)
@ -81,7 +80,7 @@ KeWaitForGate(PKGATE Gate,
/* Setup the wait information */
CurrentThread->WaitMode = WaitMode;
CurrentThread->WaitReason = WaitReason;
CurrentThread->WaitTime = 0;
CurrentThread->WaitTime = ((PLARGE_INTEGER)&KeTickCount)->LowPart;
CurrentThread->State = Waiting;
/* Find a new thread to run */

View file

@ -19,6 +19,8 @@
#define THREAD_ALERT_INCREMENT 2
extern EX_WORK_QUEUE ExWorkerQueue[MaximumWorkQueue];
#define TIMER_WAIT_BLOCK 0x3L
/*
* PURPOSE: List of threads associated with each priority level
@ -789,6 +791,10 @@ KeInitializeThread(PKPROCESS Process,
PVOID Teb,
PVOID KernelStack)
{
ULONG i;
PKWAIT_BLOCK TimerWaitBlock;
PKTIMER Timer;
/* Initalize the Dispatcher Header */
DPRINT("Initializing Dispatcher Header for New Thread: %x in Process: %x\n", Thread, Process);
KeInitializeDispatcherHeader(&Thread->DispatcherHeader,
@ -803,6 +809,13 @@ KeInitializeThread(PKPROCESS Process,
/* Initialize the Mutant List */
InitializeListHead(&Thread->MutantListHead);
/* Initialize the wait blocks */
for (i = 0; i< (THREAD_WAIT_OBJECTS + 1); i++)
{
/* Put our pointer */
Thread->WaitBlock[i].Thread = Thread;
}
/* Setup the Service Descriptor Table for Native Calls */
Thread->ServiceTable = KeServiceDescriptorTable;
@ -813,6 +826,7 @@ KeInitializeThread(PKPROCESS Process,
Thread->ApcStatePointer[OriginalApcEnvironment] = &Thread->ApcState;
Thread->ApcStatePointer[AttachedApcEnvironment] = &Thread->SavedApcState;
Thread->ApcStateIndex = OriginalApcEnvironment;
Thread->ApcQueueable = TRUE;
KeInitializeSpinLock(&Thread->ApcQueueLock);
/* Initialize the Suspend APC */
@ -829,16 +843,17 @@ KeInitializeThread(PKPROCESS Process,
KeInitializeSemaphore(&Thread->SuspendSemaphore, 0, 128);
/* FIXME OPTIMIZATION OF DOOM. DO NOT ENABLE FIXME */
#if 0
Thread->WaitBlock[3].Object = (PVOID)&Thread->Timer;
Thread->WaitBlock[3].Thread = Thread;
Thread->WaitBlock[3].WaitKey = STATUS_TIMEOUT;
Thread->WaitBlock[3].WaitType = WaitAny;
Thread->WaitBlock[3].NextWaitBlock = NULL;
InsertTailList(&Thread->Timer.Header.WaitListHead,
&Thread->WaitBlock[3].WaitListEntry);
#endif
KeInitializeTimer(&Thread->Timer);
Timer = &Thread->Timer;
KeInitializeTimer(Timer);
TimerWaitBlock = &Thread->WaitBlock[TIMER_WAIT_BLOCK];
TimerWaitBlock->Object = Timer;
TimerWaitBlock->WaitKey = STATUS_TIMEOUT;
TimerWaitBlock->WaitType = WaitAny;
TimerWaitBlock->NextWaitBlock = NULL;
/* Link the two wait lists together */
TimerWaitBlock->WaitListEntry.Flink = &Timer->Header.WaitListHead;
TimerWaitBlock->WaitListEntry.Blink = &Timer->Header.WaitListHead;
/* Set the TEB */
Thread->Teb = Teb;

View file

@ -270,8 +270,8 @@ KeRemoveQueue(IN PKQUEUE Queue,
WaitBlock->WaitType = WaitAny;
/* Link the timer to this Wait Block */
InitializeListHead(&Timer->Header.WaitListHead);
InsertTailList(&Timer->Header.WaitListHead, &WaitBlock->WaitListEntry);
Timer->Header.WaitListHead.Flink = &WaitBlock->WaitListEntry;
Timer->Header.WaitListHead.Blink = &WaitBlock->WaitListEntry;
/* Create Timer */
DPRINT("Creating Timer with timeout %I64d\n", *Timeout);
@ -290,7 +290,7 @@ KeRemoveQueue(IN PKQUEUE Queue,
Thread->WaitMode = WaitMode;
Thread->WaitReason = WrQueue;
Thread->Alertable = FALSE;
Thread->WaitTime = 0;
Thread->WaitTime = ((PLARGE_INTEGER)&KeTickCount)->LowPart;
Thread->State = Waiting;
/* Find a new thread to run */

View file

@ -148,15 +148,11 @@ KeDelayExecutionThread(KPROCESSOR_MODE WaitMode,
/* Setup the Wait Block */
CurrentThread->WaitBlockList = TimerWaitBlock;
TimerWaitBlock->Object = (PVOID)ThreadTimer;
TimerWaitBlock->Thread = CurrentThread;
TimerWaitBlock->WaitKey = (USHORT)STATUS_TIMEOUT;
TimerWaitBlock->WaitType = WaitAny;
TimerWaitBlock->NextWaitBlock = TimerWaitBlock;
/* Link the timer to this Wait Block */
InitializeListHead(&ThreadTimer->Header.WaitListHead);
InsertTailList(&ThreadTimer->Header.WaitListHead, &TimerWaitBlock->WaitListEntry);
ThreadTimer->Header.WaitListHead.Flink = &TimerWaitBlock->WaitListEntry;
ThreadTimer->Header.WaitListHead.Blink = &TimerWaitBlock->WaitListEntry;
/* Insert the Timer into the Timer Lists and enable it */
if (!KiInsertTimer(ThreadTimer, *Interval))
@ -177,7 +173,7 @@ KeDelayExecutionThread(KPROCESSOR_MODE WaitMode,
CurrentThread->Alertable = Alertable;
CurrentThread->WaitMode = WaitMode;
CurrentThread->WaitReason = DelayExecution;
CurrentThread->WaitTime = 0;
CurrentThread->WaitTime = ((PLARGE_INTEGER)&KeTickCount)->LowPart;
CurrentThread->State = Waiting;
/* Find a new thread to run */
@ -336,16 +332,11 @@ KeWaitForSingleObject(PVOID Object,
WaitBlock->NextWaitBlock = TimerWaitBlock;
/* Set up the Timer Wait Block */
TimerWaitBlock->Object = (PVOID)ThreadTimer;
TimerWaitBlock->Thread = CurrentThread;
TimerWaitBlock->WaitKey = STATUS_TIMEOUT;
TimerWaitBlock->WaitType = WaitAny;
TimerWaitBlock->NextWaitBlock = WaitBlock;
/* Link the timer to this Wait Block */
InitializeListHead(&ThreadTimer->Header.WaitListHead);
InsertTailList(&ThreadTimer->Header.WaitListHead,
&TimerWaitBlock->WaitListEntry);
ThreadTimer->Header.WaitListHead.Flink = &TimerWaitBlock->WaitListEntry;
ThreadTimer->Header.WaitListHead.Blink = &TimerWaitBlock->WaitListEntry;
/* Insert the Timer into the Timer Lists and enable it */
if (!KiInsertTimer(ThreadTimer, *Timeout))
@ -371,7 +362,7 @@ KeWaitForSingleObject(PVOID Object,
CurrentThread->Alertable = Alertable;
CurrentThread->WaitMode = WaitMode;
CurrentThread->WaitReason = WaitReason;
CurrentThread->WaitTime = 0;
CurrentThread->WaitTime = ((PLARGE_INTEGER)&KeTickCount)->LowPart;
CurrentThread->State = Waiting;
/* Find a new thread to run */
@ -610,13 +601,9 @@ KeWaitForMultipleObjects(ULONG Count,
WaitBlock->NextWaitBlock = TimerWaitBlock;
/* Set up the Timer Wait Block */
TimerWaitBlock->Object = (PVOID)ThreadTimer;
TimerWaitBlock->Thread = CurrentThread;
TimerWaitBlock->WaitKey = STATUS_TIMEOUT;
TimerWaitBlock->WaitType = WaitAny;
TimerWaitBlock->NextWaitBlock = WaitBlockArray;
/* Link the timer to this Wait Block */
/* Initialize the list head */
InitializeListHead(&ThreadTimer->Header.WaitListHead);
/* Insert the Timer into the Timer Lists and enable it */
@ -655,7 +642,7 @@ KeWaitForMultipleObjects(ULONG Count,
CurrentThread->Alertable = Alertable;
CurrentThread->WaitMode = WaitMode;
CurrentThread->WaitReason = WaitReason;
CurrentThread->WaitTime = 0;
CurrentThread->WaitTime = ((PLARGE_INTEGER)&KeTickCount)->LowPart;
CurrentThread->State = Waiting;
/* Find a new thread to run */