Skip to content

Commit

Permalink
Add product flag for enabling all processor groups
Browse files Browse the repository at this point in the history
  • Loading branch information
swesonga committed Feb 7, 2024
1 parent 39e9900 commit fd18464
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 25 deletions.
3 changes: 3 additions & 0 deletions src/hotspot/os/windows/globals_windows.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
range, \
constraint) \
\
product(bool, UseAllWindowsProcessorGroups, false, \
"Use all processor groups on supported Windows versions") \
\
product(bool, UseOSErrorReporting, false, \
"Let VM fatal error propagate to the OS (ie. WER on Windows)")

Expand Down
53 changes: 29 additions & 24 deletions src/hotspot/os/windows/os_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -868,19 +868,22 @@ int os::active_processor_count() {
return ActiveProcessorCount;
}

// Starting with Windows 11 and Windows Server 2022, the OS has changed to
// make processes and their threads span all processors in the system,
// across all processor groups, by default. Therefore, we will allow all
// processors to be active processors on these operating systems. However,
// job objects can be used to restrict processor affinity across the
// processor groups. In this case, the number of active processors must be
// obtained from the processor affinity in the job object.
bool schedules_all_processor_groups = win32::is_windows_11_or_greater() || win32::is_windows_server_2022_or_greater();
if (schedules_all_processor_groups) {
DWORD processors_in_job_object = win32::active_processors_in_job_object();

if (processors_in_job_object > 0) {
return processors_in_job_object;
bool schedules_all_processor_groups = false;
if (UseAllWindowsProcessorGroups) {
// Starting with Windows 11 and Windows Server 2022, the OS has changed to
// make processes and their threads span all processors in the system,
// across all processor groups, by default. Therefore, we will allow all
// processors to be active processors on these operating systems. However,
// job objects can be used to restrict processor affinity across the
// processor groups. In this case, the number of active processors must be
// obtained from the processor affinity in the job object.
schedules_all_processor_groups = win32::is_windows_11_or_greater() || win32::is_windows_server_2022_or_greater();
if (schedules_all_processor_groups) {
DWORD processors_in_job_object = win32::active_processors_in_job_object();

if (processors_in_job_object > 0) {
return processors_in_job_object;
}
}
}

Expand All @@ -902,17 +905,19 @@ int os::active_processor_count() {
warning("GetProcessAffinityMask() failed: GetLastError->%ld.", GetLastError());
}

// There are no processor affinity restrictions at this point so we can return
// the overall processor count if the OS automatically schedules threads across
// all processors on the system. Note that older operating systems can
// correctly report processor count but will not schedule threads across
// processor groups unless the application explicitly uses group affinity APIs
// to assign threads to processor groups. On these older operating systems, we
// will continue to use the dwNumberOfProcessors field. For details on the
// latest Windows scheduling behavior, see
// https://learn.microsoft.com/en-us/windows/win32/procthread/processor-groups#behavior-starting-with-windows-11-and-windows-server-2022
if (schedules_all_processor_groups) {
logical_processors = processor_count();
if (UseAllWindowsProcessorGroups) {
// There are no processor affinity restrictions at this point so we can return
// the overall processor count if the OS automatically schedules threads across
// all processors on the system. Note that older operating systems can
// correctly report processor count but will not schedule threads across
// processor groups unless the application explicitly uses group affinity APIs
// to assign threads to processor groups. On these older operating systems, we
// will continue to use the dwNumberOfProcessors field. For details on the
// latest Windows scheduling behavior, see
// https://learn.microsoft.com/en-us/windows/win32/procthread/processor-groups#behavior-starting-with-windows-11-and-windows-server-2022
if (schedules_all_processor_groups) {
logical_processors = processor_count();
}
}

return logical_processors == 0 ? si.dwNumberOfProcessors : logical_processors;
Expand Down
5 changes: 4 additions & 1 deletion test/hotspot/gtest/runtime/test_os_windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -704,14 +704,17 @@ TEST_VM(os_windows, reserve_memory_special) {
}

TEST_VM(os_windows, processor_count) {
JVMFlag* flag = JVMFlag::find_flag("UseAllWindowsProcessorGroups");
EXPECT_NE(flag, nullptr) << "Expected UseAllWindowsProcessorGroups product flag to be available";

int processors = os::processor_count();
EXPECT_GT(processors, 0) << "Expected at least 1 processor";

int active_processors = os::active_processor_count();
EXPECT_GT(active_processors, 0) << "Expected at least 1 active processor";

bool schedules_all_processor_groups = os::win32::is_windows_11_or_greater() || os::win32::is_windows_server_2022_or_greater();
if (schedules_all_processor_groups) {
if (schedules_all_processor_groups && UseAllWindowsProcessorGroups) {
EXPECT_EQ(active_processors, processors) << "Expected all processors to be active";
} else {
// active_processors should be at most the number of processors in 1 Windows processor group.
Expand Down
1 change: 1 addition & 0 deletions test/hotspot/jtreg/TEST.groups
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ tier1_common = \
gtest/MetaspaceGtests.java \
gtest/LargePageGtests.java \
gtest/NMTGtests.java \
gtest/WindowsProcessorGroups.java

tier1_compiler = \
:tier1_compiler_1 \
Expand Down
33 changes: 33 additions & 0 deletions test/hotspot/jtreg/gtest/WindowsProcessorGroups.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/

/*
* This runs the os related gtests on Windows with all processor groups enabled.
*/

/* @test id=use-all-windows-processor-groups
* @summary Run gtests with all Windows processor groups enabled
* @requires os.family == "windows"
* @run main/native GTestWrapper --gtest_filter=os* -XX:+UseAllWindowsProcessorGroups
*/

0 comments on commit fd18464

Please sign in to comment.