added initial priorities to threads and processes

svn path=/trunk/; revision=847
This commit is contained in:
Phillip Susi 1999-12-10 22:07:23 +00:00
parent a1c7df6990
commit 424d757107
4 changed files with 52 additions and 19 deletions

View file

@ -396,4 +396,23 @@ typedef struct _EPROCESS
#define PROCESS_STATE_TERMINATED (1) #define PROCESS_STATE_TERMINATED (1)
#define PROCESS_STATE_ACTIVE (2) #define PROCESS_STATE_ACTIVE (2)
// Added by PJS
// Thread priority adjustments, relative to process base priority
#define THREAD_PRIORITY_IDLE -15 // Idle thread priority, within priority class
#define THREAD_PRIORITY_LOWEST -2 // Extra low thread priority
#define THREAD_PRIORITY_BELOW_NORMAL -1 // Slightly lower priority
#define THREAD_PRIORITY_NORMAL 0 // No priority change
#define THREAD_PRIORITY_ABOVE_NORMAL 1 // Boost some
#define THREAD_PRIORITY_HIGHEST 2 // Boost more
#define THREAD_PRIORITY_TIME_CRITICAL 15 // Maximum boost, within priority class
// Process base priority classes, compatable with windows, dont ask where they got these values.
#define REALTIME_PRIORITY_CLASS 0x00000020 // Real Time priority class
#define HIGH_PRIORITY_CLASS 0x00000040 // High priority class
#define NORMAL_PRIORITY_CLASS 0x00000080 // Default process priority class
#define IDLE_PRIORITY_CLASS 0x00000100 // Idle Priority class
#endif /* __INCLUDE_DDK_PSTYPES_H */ #endif /* __INCLUDE_DDK_PSTYPES_H */

View file

@ -32,6 +32,15 @@ NTSTATUS STDCALL PiTerminateProcess(PEPROCESS Process, NTSTATUS ExitStatus);
#define THREAD_STATE_TERMINATED_1 (4) #define THREAD_STATE_TERMINATED_1 (4)
#define THREAD_STATE_TERMINATED_2 (5) #define THREAD_STATE_TERMINATED_2 (5)
#define THREAD_STATE_MAX (6) #define THREAD_STATE_MAX (6)
// Internal thread priorities, added by Phillip Susi
// TODO: rebalence these to make use of all priorities... the ones above 16 can not all be used right now
#define PROCESS_PRIO_IDLE 3
#define PROCESS_PRIO_NORMAL 8
#define PROCESS_PRIO_HIGH 13
#define PROCESS_PRIO_RT 18
/* /*
* Functions the HAL must provide * Functions the HAL must provide

View file

@ -87,6 +87,7 @@ VOID PsInitProcessManagment(VOID)
PsProcessType->Security = NULL; PsProcessType->Security = NULL;
PsProcessType->QueryName = NULL; PsProcessType->QueryName = NULL;
PsProcessType->OkayToClose = NULL; PsProcessType->OkayToClose = NULL;
PsProcessType->Create = NULL;
RtlInitAnsiString(&AnsiString,"Process"); RtlInitAnsiString(&AnsiString,"Process");
RtlAnsiStringToUnicodeString(&PsProcessType->TypeName,&AnsiString,TRUE); RtlAnsiStringToUnicodeString(&PsProcessType->TypeName,&AnsiString,TRUE);
@ -101,6 +102,7 @@ VOID PsInitProcessManagment(VOID)
PROCESS_ALL_ACCESS, PROCESS_ALL_ACCESS,
NULL, NULL,
PsProcessType); PsProcessType);
SystemProcess->Pcb.BasePriority = NORMAL_PRIORITY_CLASS;
KeInitializeDispatcherHeader(&SystemProcess->Pcb.DispatcherHeader, KeInitializeDispatcherHeader(&SystemProcess->Pcb.DispatcherHeader,
InternalProcessType, InternalProcessType,
sizeof(EPROCESS), sizeof(EPROCESS),
@ -265,6 +267,7 @@ NtCreateProcess (
FALSE); FALSE);
KProcess = &(Process->Pcb); KProcess = &(Process->Pcb);
KProcess->BasePriority = NORMAL_PRIORITY_CLASS;
InitializeListHead(&(KProcess->MemoryAreaList)); InitializeListHead(&(KProcess->MemoryAreaList));
Process->UniqueProcessId = InterlockedIncrement(&PiNextProcessUniqueId); Process->UniqueProcessId = InterlockedIncrement(&PiNextProcessUniqueId);
Process->InheritedFromUniqueProcessId = ParentProcess->UniqueProcessId; Process->InheritedFromUniqueProcessId = ParentProcess->UniqueProcessId;
@ -514,3 +517,4 @@ NtSetInformationProcess (
ObDereferenceObject(Process); ObDereferenceObject(Process);
return(Status); return(Status);
} }

View file

@ -1,4 +1,4 @@
/* $Id: thread.c,v 1.34 1999/12/10 17:04:36 dwelch Exp $ /* $Id: thread.c,v 1.35 1999/12/10 22:07:23 phreak Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -37,7 +37,7 @@
POBJECT_TYPE PsThreadType = NULL; POBJECT_TYPE PsThreadType = NULL;
#define NR_THREAD_PRIORITY_LEVELS (31) #define NR_THREAD_PRIORITY_LEVELS (32)
#define THREAD_PRIORITY_MAX (15) #define THREAD_PRIORITY_MAX (15)
KSPIN_LOCK PiThreadListLock; KSPIN_LOCK PiThreadListLock;
@ -205,7 +205,7 @@ static VOID PsDispatchThreadNoLock (ULONG NewThreadStatus)
CurrentThread->Tcb.State = NewThreadStatus; CurrentThread->Tcb.State = NewThreadStatus;
if (CurrentThread->Tcb.State == THREAD_STATE_RUNNABLE) if (CurrentThread->Tcb.State == THREAD_STATE_RUNNABLE)
{ {
PsInsertIntoThreadList(CurrentThread->Tcb.BasePriority, PsInsertIntoThreadList(CurrentThread->Tcb.Priority,
CurrentThread); CurrentThread);
} }
@ -274,7 +274,6 @@ NTSTATUS PsInitializeThread(HANDLE ProcessHandle,
PsThreadType); PsThreadType);
DPRINT("Thread = %x\n",Thread); DPRINT("Thread = %x\n",Thread);
Thread->Tcb.State = THREAD_STATE_SUSPENDED; Thread->Tcb.State = THREAD_STATE_SUSPENDED;
Thread->Tcb.BasePriority = THREAD_PRIORITY_NORMAL;
Thread->Tcb.SuspendCount = 1; Thread->Tcb.SuspendCount = 1;
InitializeListHead(&Thread->Tcb.ApcState.ApcListHead[0]); InitializeListHead(&Thread->Tcb.ApcState.ApcListHead[0]);
InitializeListHead(&Thread->Tcb.ApcState.ApcListHead[1]); InitializeListHead(&Thread->Tcb.ApcState.ApcListHead[1]);
@ -296,6 +295,8 @@ NTSTATUS PsInitializeThread(HANDLE ProcessHandle,
if (Status != STATUS_SUCCESS) if (Status != STATUS_SUCCESS)
{ {
DPRINT("Failed at %s:%d\n",__FILE__,__LINE__); DPRINT("Failed at %s:%d\n",__FILE__,__LINE__);
ObDereferenceObject( Thread );
PiNrThreads--;
return(Status); return(Status);
} }
} }
@ -307,26 +308,19 @@ NTSTATUS PsInitializeThread(HANDLE ProcessHandle,
PsProcessType, PsProcessType,
UserMode); UserMode);
} }
ObReferenceObjectByPointer(Thread->ThreadsProcess,
PROCESS_CREATE_THREAD,
PsProcessType,
UserMode);
InitializeListHead(&Thread->IrpList); InitializeListHead(&Thread->IrpList);
Thread->Cid.UniqueThread = (HANDLE)InterlockedIncrement( Thread->Cid.UniqueThread = (HANDLE)InterlockedIncrement(
&PiNextThreadUniqueId); &PiNextThreadUniqueId);
Thread->Cid.UniqueProcess = (HANDLE)Thread->ThreadsProcess->UniqueProcessId; Thread->Cid.UniqueProcess = (HANDLE)Thread->ThreadsProcess->UniqueProcessId;
DPRINT("Thread->Cid.UniqueThread %d\n",Thread->Cid.UniqueThread); DPRINT("Thread->Cid.UniqueThread %d\n",Thread->Cid.UniqueThread);
ObReferenceObjectByPointer(Thread,
THREAD_ALL_ACCESS,
PsThreadType,
UserMode);
*ThreadPtr = Thread; *ThreadPtr = Thread;
InsertTailList(&PiThreadListHead, &Thread->Tcb.ThreadListEntry); InsertTailList(&PiThreadListHead, &Thread->Tcb.ThreadListEntry);
Thread->Tcb.BasePriority = Thread->ThreadsProcess->Pcb.BasePriority;
Thread->Tcb.Priority = Thread->Tcb.BasePriority;
ObDereferenceObject(Thread->ThreadsProcess);
ObDereferenceObject(Thread);
return(STATUS_SUCCESS); return(STATUS_SUCCESS);
} }
@ -351,7 +345,7 @@ ULONG PsResumeThread(PETHREAD Thread,
{ {
Thread->Tcb.WaitStatus = *WaitStatus; Thread->Tcb.WaitStatus = *WaitStatus;
} }
PsInsertIntoThreadList(Thread->Tcb.BasePriority, Thread); PsInsertIntoThreadList(Thread->Tcb.Priority, Thread);
PiNrRunnableThreads++; PiNrRunnableThreads++;
} }
DPRINT("About release ThreadListLock = %x\n", &PiThreadListLock); DPRINT("About release ThreadListLock = %x\n", &PiThreadListLock);
@ -706,9 +700,16 @@ NTSTATUS PsCreateSystemThread(PHANDLE ThreadHandle,
} }
// Sets thread's base priority relative to the process' base priority
// Should only be passed in THREAD_PRIORITY_ constants in pstypes.h
LONG KeSetBasePriorityThread(PKTHREAD Thread, LONG Increment) LONG KeSetBasePriorityThread(PKTHREAD Thread, LONG Increment)
{ {
UNIMPLEMENTED; Thread->BasePriority = ((PETHREAD)Thread)->ThreadsProcess->Pcb.BasePriority + Increment;
if( Thread->BasePriority < 0 )
Thread->BasePriority = 0;
else if( Thread->BasePriority >= NR_THREAD_PRIORITY_LEVELS )
Thread->BasePriority = NR_THREAD_PRIORITY_LEVELS - 1;
Thread->Priority = Thread->BasePriority;
} }
@ -717,8 +718,8 @@ KPRIORITY KeSetPriorityThread(PKTHREAD Thread, KPRIORITY Priority)
KPRIORITY OldPriority; KPRIORITY OldPriority;
KIRQL oldIrql; KIRQL oldIrql;
OldPriority = Thread->BasePriority; OldPriority = Thread->Priority;
Thread->BasePriority = Priority; Thread->Priority = Priority;
KeAcquireSpinLock(&PiThreadListLock, &oldIrql); KeAcquireSpinLock(&PiThreadListLock, &oldIrql);
RemoveEntryList(&Thread->QueueListEntry); RemoveEntryList(&Thread->QueueListEntry);