Tuesday, April 30, 2024

Use the right number of CPU in JDK ports

ports@

Here the patch which switched all JDK to use actual number of online CPU on
machine, instead of total count.

Usually JDK application (Java, Scala, you name it) checks number of
available CPU to prepare working threads, and on OpenBSD it runs 2x threads
becaus hw.smt=0 by default.

This trivial changes improves user expirences for Intellij IDEA and for
compiling something large in sbt.

Everything is tested on amd64 -curent.

I also add to a carbon copy ports maintainer.

diff --git devel/jdk/1.8/Makefile devel/jdk/1.8/Makefile
index 5f5d491f6e1..fd904bca568 100644
--- devel/jdk/1.8/Makefile
+++ devel/jdk/1.8/Makefile
@@ -12,6 +12,7 @@ V= ${BASE_VER}.${UPDATE_VER}.${BUILD_VER}.${BSD_PORT_REL}
PKGNAME= jdk-${V}
PKGSTEM= jdk-${BASE_VER}
EPOCH= 0
+REVISION= 0

DIST_SUBDIR= jdk
DISTNAME= jdk8u${UPDATE_VER}-${BUILD_VER}.${BSD_PORT_REL}
diff --git devel/jdk/1.8/patches/patch-hotspot_src_os_bsd_vm_os_bsd_cpp devel/jdk/1.8/patches/patch-hotspot_src_os_bsd_vm_os_bsd_cpp
new file mode 100644
index 00000000000..70a309b0d89
--- /dev/null
+++ devel/jdk/1.8/patches/patch-hotspot_src_os_bsd_vm_os_bsd_cpp
@@ -0,0 +1,12 @@
+Index: hotspot/src/os/bsd/vm/os_bsd.cpp
+--- hotspot/src/os/bsd/vm/os_bsd.cpp.orig
++++ hotspot/src/os/bsd/vm/os_bsd.cpp
+@@ -299,7 +299,7 @@ void os::Bsd::initialize_system_info() {
+
+ /* get processors count via hw.ncpus sysctl */
+ mib[0] = CTL_HW;
+- mib[1] = HW_NCPU;
++ mib[1] = HW_NCPUONLINE;
+ len = sizeof(cpu_val);
+ if (sysctl(mib, 2, &cpu_val, &len, NULL, 0) != -1 && cpu_val >= 1) {
+ assert(len == sizeof(cpu_val), "unexpected data size");
diff --git devel/jdk/11/Makefile devel/jdk/11/Makefile
index 101d3c5c1c6..ddc9407bf3b 100644
--- devel/jdk/11/Makefile
+++ devel/jdk/11/Makefile
@@ -12,6 +12,7 @@ PACKAGE_VER= ${BASE_VER}.${PATCH_VER}.${BSD_PORT_REL}
PKGNAME= jdk-${PACKAGE_VER}
PKGSTEM= jdk-11
EPOCH= 0
+REVISION= 0

DIST_SUBDIR= jdk
DISTNAME= jdk-${VERSION_STR}
diff --git devel/jdk/11/patches/patch-make_common_NativeCompilation_gmk devel/jdk/11/patches/patch-make_common_NativeCompilation_gmk
index 7011c045672..86ec279f34e 100644
--- devel/jdk/11/patches/patch-make_common_NativeCompilation_gmk
+++ devel/jdk/11/patches/patch-make_common_NativeCompilation_gmk
@@ -5,7 +5,7 @@ get the debug package without bloating the size of the jdk package.
Index: make/common/NativeCompilation.gmk
--- make/common/NativeCompilation.gmk.orig
+++ make/common/NativeCompilation.gmk
-@@ -1003,9 +1003,7 @@ define SetupNativeCompilationBody
+@@ -1008,9 +1008,7 @@ define SetupNativeCompilationBody
# Setup the command line creating debuginfo files, to be run after linking.
# It cannot be run separately since it updates the original target file
$1_CREATE_DEBUGINFO_CMDS := \
diff --git devel/jdk/11/patches/patch-src_hotspot_os_bsd_os_bsd_cpp devel/jdk/11/patches/patch-src_hotspot_os_bsd_os_bsd_cpp
new file mode 100644
index 00000000000..5bbbc172c08
--- /dev/null
+++ devel/jdk/11/patches/patch-src_hotspot_os_bsd_os_bsd_cpp
@@ -0,0 +1,12 @@
+Index: src/hotspot/os/bsd/os_bsd.cpp
+--- src/hotspot/os/bsd/os_bsd.cpp.orig
++++ src/hotspot/os/bsd/os_bsd.cpp
+@@ -327,7 +327,7 @@ void os::Bsd::initialize_system_info() {
+
+ // get processors count via hw.ncpus sysctl
+ mib[0] = CTL_HW;
+- mib[1] = HW_NCPU;
++ mib[1] = HW_NCPUONLINE;
+ len = sizeof(cpu_val);
+ if (sysctl(mib, 2, &cpu_val, &len, NULL, 0) != -1 && cpu_val >= 1) {
+ assert(len == sizeof(cpu_val), "unexpected data size");
diff --git devel/jdk/17/Makefile devel/jdk/17/Makefile
index 8487e88f923..d8e9d13e899 100644
--- devel/jdk/17/Makefile
+++ devel/jdk/17/Makefile
@@ -12,6 +12,7 @@ PACKAGE_VER= ${BASE_VER}.${PATCH_VER}.${BSD_PORT_REL}
PKGNAME= jdk-${PACKAGE_VER}
PKGSTEM= jdk-17
EPOCH= 0
+REVISION= 0

DIST_SUBDIR= jdk
DISTNAME= jdk-${VERSION_STR}
diff --git devel/jdk/17/patches/patch-src_hotspot_os_bsd_os_bsd_cpp devel/jdk/17/patches/patch-src_hotspot_os_bsd_os_bsd_cpp
new file mode 100644
index 00000000000..37e95e05526
--- /dev/null
+++ devel/jdk/17/patches/patch-src_hotspot_os_bsd_os_bsd_cpp
@@ -0,0 +1,12 @@
+Index: src/hotspot/os/bsd/os_bsd.cpp
+--- src/hotspot/os/bsd/os_bsd.cpp.orig
++++ src/hotspot/os/bsd/os_bsd.cpp
+@@ -294,7 +294,7 @@ void os::Bsd::initialize_system_info() {
+
+ // get processors count via hw.ncpus sysctl
+ mib[0] = CTL_HW;
+- mib[1] = HW_NCPU;
++ mib[1] = HW_NCPUONLINE;
+ len = sizeof(cpu_val);
+ if (sysctl(mib, 2, &cpu_val, &len, NULL, 0) != -1 && cpu_val >= 1) {
+ assert(len == sizeof(cpu_val), "unexpected data size");
diff --git devel/jdk/21/Makefile devel/jdk/21/Makefile
index 803f7e01057..ba557131418 100644
--- devel/jdk/21/Makefile
+++ devel/jdk/21/Makefile
@@ -12,6 +12,7 @@ PACKAGE_VER= ${BASE_VER}.${PATCH_VER}.${BSD_PORT_REL}
PKGNAME= jdk-${PACKAGE_VER}
PKGSTEM= jdk-21
EPOCH= 0
+REVISION= 0

DIST_SUBDIR= jdk
DISTNAME= jdk-${VERSION_STR}
diff --git devel/jdk/21/patches/patch-src_hotspot_os_bsd_os_bsd_cpp devel/jdk/21/patches/patch-src_hotspot_os_bsd_os_bsd_cpp
new file mode 100644
index 00000000000..682b549cc44
--- /dev/null
+++ devel/jdk/21/patches/patch-src_hotspot_os_bsd_os_bsd_cpp
@@ -0,0 +1,12 @@
+Index: src/hotspot/os/bsd/os_bsd.cpp
+--- src/hotspot/os/bsd/os_bsd.cpp.orig
++++ src/hotspot/os/bsd/os_bsd.cpp
+@@ -280,7 +280,7 @@ void os::Bsd::initialize_system_info() {
+
+ // get processors count via hw.ncpus sysctl
+ mib[0] = CTL_HW;
+- mib[1] = HW_NCPU;
++ mib[1] = HW_NCPUONLINE;
+ len = sizeof(cpu_val);
+ if (sysctl(mib, 2, &cpu_val, &len, nullptr, 0) != -1 && cpu_val >= 1) {
+ assert(len == sizeof(cpu_val), "unexpected data size");


--
wbr, Kirill

No comments:

Post a Comment