Skip to content

Commit 3022d74

Browse files
committed
[NTOS:EX/KE][HALX86] Add support for NUMPROC, BOOTPROC, MAXPROC, ONECPU boot switches (reactos#6024)
These SMP-specific switches allow to test and control configurations with various number of CPUs on multiprocessor systems. - NUMPROC: maximum number of logical processors that can be started (including dynamically, not currently supported by ReactOS) at run-time. - BOOTPROC: maximum number of logical processors that can be started at boot-time. - MAXPROC: forces the OS to report the maximum possible number of CPUs as existing on the system. - ONECPU (MP HAL-only boot switch): causes the HAL to only use one (the boot) CPU on a multiprocessor system. Attempting to start other processors will fail. For more information, see: https://www.geoffchappell.com/notes/windows/boot/bcd/osloader/numproc.htm https://www.geoffchappell.com/notes/windows/license/processors.htm https://rmscrypt.wordpress.com/2011/02/ https://codeinsecurity.wordpress.com/2022/04/07/cpu-socket-and-core-count-limits-in-windows-10-and-how-to-remove-them/ Generic references about BOOT.INI switches: https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/boot-options-in-a-boot-ini-file https://www.itprotoday.com/cloud-computing/what-switches-can-be-used-bootini http://franck.kiechel.free.fr/dbr_eng/BootIni.htm References about BCD options: https://learn.microsoft.com/en-us/windows-hardware/drivers/devtest/bcdedit--set http://www.mistyprojects.co.uk/documents/BCDEdit/files/commands.6.1.7601.htm#TYPES%20OSLOADER
1 parent 7093412 commit 3022d74

File tree

6 files changed

+90
-6
lines changed

6 files changed

+90
-6
lines changed

hal/halx86/generic/halinit.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
/* GLOBALS *******************************************************************/
1616

17+
//#ifdef CONFIG_SMP // FIXME: Reenable conditional once HAL is consistently compiled for SMP mode
18+
BOOLEAN HalpOnlyBootProcessor;
19+
//#endif
1720
BOOLEAN HalpPciLockSettings;
1821

1922
/* PRIVATE FUNCTIONS *********************************************************/
@@ -30,6 +33,12 @@ HalpGetParameters(
3033
/* Read the command line */
3134
PCSTR CommandLine = LoaderBlock->LoadOptions;
3235

36+
//#ifdef CONFIG_SMP // FIXME: Reenable conditional once HAL is consistently compiled for SMP mode
37+
/* Check whether we should only start one CPU */
38+
if (strstr(CommandLine, "ONECPU"))
39+
HalpOnlyBootProcessor = TRUE;
40+
//#endif
41+
3342
/* Check if PCI is locked */
3443
if (strstr(CommandLine, "PCILOCK"))
3544
HalpPciLockSettings = TRUE;

hal/halx86/smp/i386/spinup.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
/* GLOBALS *******************************************************************/
1818

19+
extern BOOLEAN HalpOnlyBootProcessor;
20+
1921
extern PPROCESSOR_IDENTITY HalpProcessorIdentity;
2022
extern PHYSICAL_ADDRESS HalpLowStubPhysicalAddress;
2123
extern PVOID HalpLowStub;
@@ -88,6 +90,11 @@ HalStartNextProcessor(
8890
_In_ PLOADER_PARAMETER_BLOCK LoaderBlock,
8991
_In_ PKPROCESSOR_STATE ProcessorState)
9092
{
93+
/* Bail out if we only use the boot CPU */
94+
if (HalpOnlyBootProcessor)
95+
return FALSE;
96+
97+
/* Bail out if we have started all available CPUs */
9198
if (HalpStartedProcessorCount == HalpApicInfoTable.ProcessorCount)
9299
return FALSE;
93100

ntoskrnl/ex/init.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,6 +1559,34 @@ Phase1InitializationDiscard(IN PVOID Context)
15591559
}
15601560

15611561
#ifdef CONFIG_SMP
1562+
/*
1563+
* IMPORTANT NOTE:
1564+
* Because ReactOS is a "nice" OS, we do not care _at all_
1565+
* about any number of registered/licensed processors:
1566+
* no usage of KeRegisteredProcessors nor KeLicensedProcessors.
1567+
*/
1568+
if (CommandLine)
1569+
{
1570+
PSTR Option;
1571+
1572+
/* Check for NUMPROC: maximum number of logical processors
1573+
* that can be started (including dynamically) at run-time */
1574+
Option = strstr(CommandLine, "NUMPROC");
1575+
if (Option) Option = strstr(Option, "=");
1576+
if (Option) KeNumprocSpecified = atol(Option + 1);
1577+
1578+
/* Check for BOOTPROC (NT6+ and ReactOS): maximum number
1579+
* of logical processors that can be started at boot-time */
1580+
Option = strstr(CommandLine, "BOOTPROC");
1581+
if (Option) Option = strstr(Option, "=");
1582+
if (Option) KeBootprocSpecified = atol(Option + 1);
1583+
1584+
/* Check for MAXPROC (NT6+ and ReactOS): forces the kernel to report
1585+
* as existing the maximum number of processors that can be handled */
1586+
if (strstr(CommandLine, "MAXPROC"))
1587+
KeMaximumProcessors = MAXIMUM_PROCESSORS;
1588+
}
1589+
15621590
/* Start Application Processors */
15631591
KeStartAllProcessors();
15641592
#endif

ntoskrnl/include/internal/ke.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ typedef PCHAR
9090
IN ULONG Length
9191
);
9292

93-
extern KAFFINITY KeActiveProcessors;
9493
extern PKNMI_HANDLER_CALLBACK KiNmiCallbackListHead;
9594
extern KSPIN_LOCK KiNmiCallbackListLock;
9695
extern PVOID KeUserApcDispatcher;
@@ -104,6 +103,13 @@ extern USHORT KeProcessorArchitecture;
104103
extern USHORT KeProcessorLevel;
105104
extern USHORT KeProcessorRevision;
106105
extern ULONG64 KeFeatureBits;
106+
extern KAFFINITY KeActiveProcessors;
107+
extern PKPRCB KiProcessorBlock[];
108+
#ifdef CONFIG_SMP
109+
extern ULONG KeMaximumProcessors;
110+
extern ULONG KeNumprocSpecified;
111+
extern ULONG KeBootprocSpecified;
112+
#endif
107113
extern KNODE KiNode0;
108114
extern PKNODE KeNodeBlock[1];
109115
extern UCHAR KeNumberNodes;
@@ -136,7 +142,6 @@ extern LIST_ENTRY KiProcessListHead;
136142
extern LIST_ENTRY KiProcessInSwapListHead, KiProcessOutSwapListHead;
137143
extern LIST_ENTRY KiStackInSwapListHead;
138144
extern KEVENT KiSwapEvent;
139-
extern PKPRCB KiProcessorBlock[];
140145
extern KAFFINITY KiIdleSummary;
141146
extern PVOID KeUserApcDispatcher;
142147
extern PVOID KeUserCallbackDispatcher;

ntoskrnl/ke/i386/mproc.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/* INCLUDES *****************************************************************/
1010

1111
#include <ntoskrnl.h>
12+
1213
#define NDEBUG
1314
#include <debug.h>
1415

@@ -38,12 +39,28 @@ NTAPI
3839
KeStartAllProcessors(VOID)
3940
{
4041
PVOID KernelStack, DPCStack;
41-
ULONG ProcessorCount = 0;
4242
PAPINFO APInfo;
43+
ULONG ProcessorCount;
44+
ULONG MaximumProcessors;
45+
46+
/* NOTE: NT6+ HAL exports HalEnumerateProcessors() and
47+
* HalQueryMaximumProcessorCount() that help determining
48+
* the number of detected processors on the system. */
49+
MaximumProcessors = KeMaximumProcessors;
50+
51+
/* Limit the number of processors we can start at run-time */
52+
if (KeNumprocSpecified)
53+
MaximumProcessors = min(MaximumProcessors, KeNumprocSpecified);
54+
55+
/* Limit also the number of processors we can start during boot-time */
56+
if (KeBootprocSpecified)
57+
MaximumProcessors = min(MaximumProcessors, KeBootprocSpecified);
58+
59+
// TODO: Support processor nodes
4360

44-
while (TRUE)
61+
/* Start ProcessorCount at 1 because we already have the boot CPU */
62+
for (ProcessorCount = 1; ProcessorCount < MaximumProcessors; ++ProcessorCount)
4563
{
46-
ProcessorCount++;
4764
KernelStack = NULL;
4865
DPCStack = NULL;
4966

ntoskrnl/ke/processor.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,27 @@
1313

1414
/* GLOBALS *******************************************************************/
1515

16-
CCHAR KeNumberProcessors = 0;
1716
KAFFINITY KeActiveProcessors = 0;
1817

18+
/* Number of processors */
19+
CCHAR KeNumberProcessors = 0;
20+
21+
#ifdef CONFIG_SMP
22+
23+
/* Theoretical maximum number of processors that can be handled.
24+
* Set once at run-time. Returned by KeQueryMaximumProcessorCount(). */
25+
ULONG KeMaximumProcessors = MAXIMUM_PROCESSORS;
26+
27+
/* Maximum number of logical processors that can be started
28+
* (including dynamically) at run-time. If 0: do not perform checks. */
29+
ULONG KeNumprocSpecified = 0;
30+
31+
/* Maximum number of logical processors that can be started
32+
* at boot-time. If 0: do not perform checks. */
33+
ULONG KeBootprocSpecified = 0;
34+
35+
#endif // CONFIG_SMP
36+
1937
/* FUNCTIONS *****************************************************************/
2038

2139
KAFFINITY

0 commit comments

Comments
 (0)