From fd18464207a4944a4247f4c0530cb037f5f33a67 Mon Sep 17 00:00:00 2001 From: Saint Wesonga Date: Tue, 30 Jan 2024 11:40:11 -0700 Subject: [PATCH] Add product flag for enabling all processor groups --- src/hotspot/os/windows/globals_windows.hpp | 3 ++ src/hotspot/os/windows/os_windows.cpp | 53 ++++++++++--------- .../hotspot/gtest/runtime/test_os_windows.cpp | 5 +- test/hotspot/jtreg/TEST.groups | 1 + .../jtreg/gtest/WindowsProcessorGroups.java | 33 ++++++++++++ 5 files changed, 70 insertions(+), 25 deletions(-) create mode 100644 test/hotspot/jtreg/gtest/WindowsProcessorGroups.java diff --git a/src/hotspot/os/windows/globals_windows.hpp b/src/hotspot/os/windows/globals_windows.hpp index 7ddf3c9131b8a..f0cf567254d57 100644 --- a/src/hotspot/os/windows/globals_windows.hpp +++ b/src/hotspot/os/windows/globals_windows.hpp @@ -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)") diff --git a/src/hotspot/os/windows/os_windows.cpp b/src/hotspot/os/windows/os_windows.cpp index 0a00e970efbee..1b775ab15c1b7 100644 --- a/src/hotspot/os/windows/os_windows.cpp +++ b/src/hotspot/os/windows/os_windows.cpp @@ -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; + } } } @@ -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; diff --git a/test/hotspot/gtest/runtime/test_os_windows.cpp b/test/hotspot/gtest/runtime/test_os_windows.cpp index 74b9563696f32..3c1860a89016f 100644 --- a/test/hotspot/gtest/runtime/test_os_windows.cpp +++ b/test/hotspot/gtest/runtime/test_os_windows.cpp @@ -704,6 +704,9 @@ 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"; @@ -711,7 +714,7 @@ TEST_VM(os_windows, 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. diff --git a/test/hotspot/jtreg/TEST.groups b/test/hotspot/jtreg/TEST.groups index 7c48edcb10520..fde1c79317359 100644 --- a/test/hotspot/jtreg/TEST.groups +++ b/test/hotspot/jtreg/TEST.groups @@ -145,6 +145,7 @@ tier1_common = \ gtest/MetaspaceGtests.java \ gtest/LargePageGtests.java \ gtest/NMTGtests.java \ + gtest/WindowsProcessorGroups.java tier1_compiler = \ :tier1_compiler_1 \ diff --git a/test/hotspot/jtreg/gtest/WindowsProcessorGroups.java b/test/hotspot/jtreg/gtest/WindowsProcessorGroups.java new file mode 100644 index 0000000000000..787acf7a1f580 --- /dev/null +++ b/test/hotspot/jtreg/gtest/WindowsProcessorGroups.java @@ -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 + */