Author: ion
Date: Wed Sep 23 05:10:58 2015
New Revision: 69324
URL:
http://svn.reactos.org/svn/reactos?rev=69324&view=rev
Log:
[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 ;-)
Modified:
trunk/reactos/include/ndk/pstypes.h
trunk/reactos/ntoskrnl/config/cmdata.c
trunk/reactos/ntoskrnl/include/internal/ps.h
trunk/reactos/ntoskrnl/io/iomgr/driver.c
trunk/reactos/ntoskrnl/ke/thrdschd.c
trunk/reactos/ntoskrnl/ps/process.c
Modified: trunk/reactos/include/ndk/pstypes.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/include/ndk/pstypes.h?rev=…
==============================================================================
--- trunk/reactos/include/ndk/pstypes.h [iso-8859-1] (original)
+++ trunk/reactos/include/ndk/pstypes.h [iso-8859-1] Wed Sep 23 05:10:58 2015
@@ -129,8 +129,11 @@
//
// 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
//
Modified: trunk/reactos/ntoskrnl/config/cmdata.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/config/cmdata.c?r…
==============================================================================
--- trunk/reactos/ntoskrnl/config/cmdata.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/config/cmdata.c [iso-8859-1] Wed Sep 23 05:10:58 2015
@@ -765,7 +765,7 @@
{
L"PriorityControl",
L"Win32PrioritySeparation",
- &DummyData,
+ &PsRawPrioritySeparation,
NULL,
NULL
},
Modified: trunk/reactos/ntoskrnl/include/internal/ps.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/include/internal/…
==============================================================================
--- trunk/reactos/ntoskrnl/include/internal/ps.h [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/include/internal/ps.h [iso-8859-1] Wed Sep 23 05:10:58 2015
@@ -452,6 +452,7 @@
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;
Modified: trunk/reactos/ntoskrnl/io/iomgr/driver.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/io/iomgr/driver.c…
==============================================================================
--- trunk/reactos/ntoskrnl/io/iomgr/driver.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/io/iomgr/driver.c [iso-8859-1] Wed Sep 23 05:10:58 2015
@@ -1495,7 +1495,7 @@
/* 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;
Modified: trunk/reactos/ntoskrnl/ke/thrdschd.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ke/thrdschd.c?rev…
==============================================================================
--- trunk/reactos/ntoskrnl/ke/thrdschd.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ke/thrdschd.c [iso-8859-1] Wed Sep 23 05:10:58 2015
@@ -171,6 +171,14 @@
/* 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)
Modified: trunk/reactos/ntoskrnl/ps/process.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/ps/process.c?rev=…
==============================================================================
--- trunk/reactos/ntoskrnl/ps/process.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/ps/process.c [iso-8859-1] Wed Sep 23 05:10:58 2015
@@ -24,7 +24,7 @@
LARGE_INTEGER ShortPsLockDelay;
-ULONG PsRawPrioritySeparation = 0;
+ULONG PsRawPrioritySeparation;
ULONG PsPrioritySeparation;
CHAR PspForegroundQuantum[3];
@@ -255,17 +255,32 @@
/* 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)
{
/* 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 */
@@ -292,12 +307,10 @@
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 @@
if ((Process->Job) && (PspUseJobSchedulingClasses))
{
/* Use job quantum */
- Quantum = PspJobSchedulingClasses[Process->Job->
- SchedulingClass];
+ Quantum =
PspJobSchedulingClasses[Process->Job->SchedulingClass];
}
else
{