teknoraver / rpms / rpm

Forked from rpms/rpm 4 months ago
Clone

Blame 0002-Cap-number-of-threads-on-32bit-platforms-add-a-tunab.patch

Panu Matilainen d678a6
From bcaa30872087a1002648653358ab9514f829de9a Mon Sep 17 00:00:00 2001
Panu Matilainen d678a6
Message-Id: <bcaa30872087a1002648653358ab9514f829de9a.1566556488.git.pmatilai@redhat.com>
Panu Matilainen d678a6
In-Reply-To: <3ba0136000c986c692baab7b112aba163173d2d3.1566556488.git.pmatilai@redhat.com>
Panu Matilainen d678a6
References: <3ba0136000c986c692baab7b112aba163173d2d3.1566556488.git.pmatilai@redhat.com>
Panu Matilainen d678a6
From: Panu Matilainen <pmatilai@redhat.com>
Panu Matilainen d678a6
Date: Fri, 23 Aug 2019 11:17:21 +0300
Panu Matilainen d678a6
Subject: [PATCH 2/2] Cap number of threads on 32bit platforms, add a tunable
Panu Matilainen d678a6
 (RhBug:1729382)
Panu Matilainen d678a6
Panu Matilainen d678a6
On 32bit plaforms, address space is easily exhausted with multiple
Panu Matilainen d678a6
threads, causing arbitrary builds failure regressions (RhBug:1729382).
Panu Matilainen d678a6
Simply cap the number of threads to maximum of four on any 32bit
Panu Matilainen d678a6
platform to play it safe. It's still three more than we were able to
Panu Matilainen d678a6
use on older releases...
Panu Matilainen d678a6
Panu Matilainen d678a6
In addition, introduce a separate tunable for tweaking the maximum
Panu Matilainen d678a6
number of threads just in case, defaulting to max CPUs available.
Panu Matilainen d678a6
---
Panu Matilainen d678a6
 build/parseSpec.c | 10 +++++++++-
Panu Matilainen d678a6
 platform.in       |  3 +++
Panu Matilainen d678a6
 2 files changed, 12 insertions(+), 1 deletion(-)
Panu Matilainen d678a6
Panu Matilainen d678a6
diff --git a/build/parseSpec.c b/build/parseSpec.c
Panu Matilainen d678a6
index 61858aabd..d987bdc7b 100644
Panu Matilainen d678a6
--- a/build/parseSpec.c
Panu Matilainen d678a6
+++ b/build/parseSpec.c
Panu Matilainen d678a6
@@ -1035,9 +1035,17 @@ static rpmSpec parseSpec(const char *specFile, rpmSpecFlags flags,
Panu Matilainen d678a6
 
Panu Matilainen d678a6
 #ifdef ENABLE_OPENMP
Panu Matilainen d678a6
     /* Set number of OMP threads centrally */
Panu Matilainen d678a6
-    int ncpus = rpmExpandNumeric("%{?_smp_build_ncpus}");
Panu Matilainen d678a6
+    int ncpus = rpmExpandNumeric("%{?_smp_nthreads_max}");
Panu Matilainen d678a6
+#if __WORDSIZE == 32
Panu Matilainen d678a6
+    /* On 32bit platforms, address space shortage is an issue. Play safe. */
Panu Matilainen d678a6
+    if (ncpus <= 0 || ncpus > 4) {
Panu Matilainen d678a6
+	ncpus = 4;
Panu Matilainen d678a6
+	rpmlog(RPMLOG_DEBUG,
Panu Matilainen d678a6
+		"limiting number of threads to %d due to platform\n", ncpus);
Panu Matilainen d678a6
+    }
Panu Matilainen d678a6
     if (ncpus > 0) {
Panu Matilainen d678a6
 	omp_set_num_threads(ncpus);
Panu Matilainen d678a6
+#endif
Panu Matilainen d678a6
 #endif
Panu Matilainen d678a6
 
Panu Matilainen d678a6
     if (spec->clean == NULL) {
Panu Matilainen d678a6
diff --git a/platform.in b/platform.in
Panu Matilainen d678a6
index db6d2382f..c70f44193 100644
Panu Matilainen d678a6
--- a/platform.in
Panu Matilainen d678a6
+++ b/platform.in
Panu Matilainen d678a6
@@ -59,6 +59,9 @@
Panu Matilainen d678a6
 
Panu Matilainen d678a6
 %_smp_mflags -j%{_smp_build_ncpus}
Panu Matilainen d678a6
 
Panu Matilainen d678a6
+# Maximum number of CPU's to use for threads
Panu Matilainen d678a6
+%_smp_nthreads_max %{_smp_build_ncpus}
Panu Matilainen d678a6
+
Panu Matilainen d678a6
 #==============================================================================
Panu Matilainen d678a6
 # ---- Build policy macros.
Panu Matilainen d678a6
 #
Panu Matilainen d678a6
-- 
Panu Matilainen d678a6
2.21.0
Panu Matilainen d678a6