[NTOSKRNL]: Properly respect the registry's Win32PrioritySeparation value instead of ignoring it.

[NTOSKRNL]: Actually apply the foreground priority boost to threads in a foreground process.
[NTOSKRNL]: Correctly handle the case where the quantum length and fixed/variable flag are set to "default", instead of falling back into the server case.
Thanks to WINSRV doing the right thing, ReactOS console apps now receive the priority separation boost. However, my tests show that it doesn't last as long as it should on Windows (quantums too short? bug in priority decrement?). Also, since Win32k.sys doesn't tell the kernel about foreground GUI apps, they don't get the boost. Someone needs to add a NtSetInformationProcess call in whatever win32k function determines active focus.
Dedicated to ThFabba who needs to write some tests ;-)

svn path=/trunk/; revision=69324
This commit is contained in:
Alex Ionescu 2015-09-23 05:10:58 +00:00
parent 81b8c2bb92
commit 0e86ca73d0
6 changed files with 38 additions and 14 deletions

View file

@ -129,8 +129,11 @@ extern POBJECT_TYPE NTSYSAPI PsJobType;
//
// Process Priority Separation Values (OR)
//
#define PSP_VARIABLE_QUANTUMS 4
#define PSP_LONG_QUANTUMS 16
#define PSP_DEFAULT_QUANTUMS 0x00
#define PSP_VARIABLE_QUANTUMS 0x04
#define PSP_FIXED_QUANTUMS 0x08
#define PSP_LONG_QUANTUMS 0x10
#define PSP_SHORT_QUANTUMS 0x20
#ifndef NTOS_MODE_USER
//

View file

@ -765,7 +765,7 @@ INIT_FUNCTION CM_SYSTEM_CONTROL_VECTOR CmControlVector[] =
{
L"PriorityControl",
L"Win32PrioritySeparation",
&DummyData,
&PsRawPrioritySeparation,
NULL,
NULL
},

View file

@ -452,6 +452,7 @@ extern PVOID PspSystemDllBase;
extern BOOLEAN PspUseJobSchedulingClasses;
extern CHAR PspJobSchedulingClasses[PSP_JOB_SCHEDULING_CLASSES];
extern ULONG PsRawPrioritySeparation;
extern ULONG PsPrioritySeparation;
extern POBJECT_TYPE _PsThreadType, _PsProcessType;
extern PTOKEN PspBootAccessToken;
extern GENERIC_MAPPING PspJobMapping;

View file

@ -1495,7 +1495,7 @@ try_again:
/* Create a random name and set up the string*/
NameLength = (USHORT)swprintf(NameBuffer,
DRIVER_ROOT_NAME L"%08u",
KeTickCount);
KeTickCount.LowPart);
LocalDriverName.Length = NameLength * sizeof(WCHAR);
LocalDriverName.MaximumLength = LocalDriverName.Length + sizeof(UNICODE_NULL);
LocalDriverName.Buffer = NameBuffer;

View file

@ -172,6 +172,14 @@ KiDeferredReadyThread(IN PKTHREAD Thread)
/* Calculate the new priority after the increment */
OldPriority = Thread->BasePriority + Thread->AdjustIncrement;
/* Check if this is a foreground process */
if (CONTAINING_RECORD(Thread->ApcState.Process, EPROCESS, Pcb)->
Vm.Flags.MemoryPriority == MEMORY_PRIORITY_FOREGROUND)
{
/* Apply the foreground boost */
OldPriority += PsPrioritySeparation;
}
/* Check if this new priority is higher */
if (OldPriority > Thread->Priority)
{

View file

@ -24,7 +24,7 @@ KGUARDED_MUTEX PspActiveProcessMutex;
LARGE_INTEGER ShortPsLockDelay;
ULONG PsRawPrioritySeparation = 0;
ULONG PsRawPrioritySeparation;
ULONG PsPrioritySeparation;
CHAR PspForegroundQuantum[3];
@ -255,11 +255,16 @@ PsChangeQuantumTable(IN BOOLEAN Immediate,
/* Use a variable table */
QuantumTable = PspVariableQuantums;
}
else
else if (PspQuantumTypeFromMask(PrioritySeparation) == PSP_FIXED_QUANTUMS)
{
/* Use fixed table */
QuantumTable = PspFixedQuantums;
}
else
{
/* Use default for the type of system we're on */
QuantumTable = MmIsThisAnNtAsSystem() ? PspFixedQuantums : PspVariableQuantums;
}
/* Now check if we should use long or short */
if (PspQuantumLengthFromMask(PrioritySeparation) == PSP_LONG_QUANTUMS)
@ -267,6 +272,16 @@ PsChangeQuantumTable(IN BOOLEAN Immediate,
/* Use long quantums */
QuantumTable += 3;
}
else if (PspQuantumLengthFromMask(PrioritySeparation) == PSP_SHORT_QUANTUMS)
{
/* Keep existing table */
NOTHING;
}
else
{
/* Use default for the type of system we're on */
QuantumTable += MmIsThisAnNtAsSystem() ? 3 : 0;
}
/* Check if we're using long fixed quantums */
if (QuantumTable == &PspFixedQuantums[3])
@ -292,12 +307,10 @@ PsChangeQuantumTable(IN BOOLEAN Immediate,
Process = PsGetNextProcess(Process);
while (Process)
{
/*
* Use the priority separation, unless the process has
* low memory priority
*/
i = (Process->Vm.Flags.MemoryPriority == 1) ?
0: PsPrioritySeparation;
/* Use the priority separation if this is a foreground process */
i = (Process->Vm.Flags.MemoryPriority ==
MEMORY_PRIORITY_BACKGROUND) ?
0: PsPrioritySeparation;
/* Make sure that the process isn't idle */
if (Process->PriorityClass != PROCESS_PRIORITY_CLASS_IDLE)
@ -306,8 +319,7 @@ PsChangeQuantumTable(IN BOOLEAN Immediate,
if ((Process->Job) && (PspUseJobSchedulingClasses))
{
/* Use job quantum */
Quantum = PspJobSchedulingClasses[Process->Job->
SchedulingClass];
Quantum = PspJobSchedulingClasses[Process->Job->SchedulingClass];
}
else
{