bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] src/main.c: Add -J to detect number of job slots based on nproc.


From: Matt Staveley-Taylor
Subject: [PATCH] src/main.c: Add -J to detect number of job slots based on nproc.
Date: Fri, 12 Apr 2024 02:13:36 +0100

Add the -J/--detect-job-slots flag as an shorthand equivalent for
-j$(nproc). The help message is deliberately left ambiguous so that we
could change it to nproc + 1 in future, if desired.

Signed-off-by: Matt Staveley-Taylor <matt.stav.taylor@gmail.com>
---
Browsing the mailing list I can see that the behaviour of -j with no
arguments has been discussed a few times. Given it would affect
backwards compatability to change how -j works, introducing a new
flag seems appropriate.

 bootstrap.conf |  3 ++-
 src/main.c     | 14 +++++++++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/bootstrap.conf b/bootstrap.conf
index 98a709a5..9716025e 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -62,4 +62,5 @@ getloadavg
 host-cpu-c-abi
 largefile
 make-glob
-make-macros"
+make-macros
+nproc"
diff --git a/src/main.c b/src/main.c
index 15104212..49c329b2 100644
--- a/src/main.c
+++ b/src/main.c
@@ -15,6 +15,7 @@ You should have received a copy of the GNU General Public 
License along with
 this program.  If not, see <https://www.gnu.org/licenses/>.  */
 
 #include "makeint.h"
+#include "nproc.h"
 
 #include <assert.h>
 #if MK_OS_W32
@@ -297,6 +298,9 @@ static int warn_undefined_variables_flag;
 static int always_make_set = 0;
 int always_make_flag = 0;
 
+/* If nonzero, detect the number of job slots based on the number of CPUs.  */
+static int detect_job_slots_flag = 0;
+
 /* If nonzero, we're in the "try to rebuild makefiles" phase.  */
 
 int rebuilding_makefiles = 0;
@@ -360,6 +364,8 @@ static const char *const usage[] =
     N_("\
   --jobserver-style=STYLE     Select the style of jobserver to use.\n"),
     N_("\
+  -J, --detect-job-slots      Detect job slots based on number of CPU 
cores.\n"),
+    N_("\
   -k, --keep-going            Keep going when some targets can't be made.\n"),
     N_("\
   -l [N], --load-average[=N], --max-load[=N]\n\
@@ -465,6 +471,7 @@ static struct command_switch switches[] =
     { 'E', strlist, &eval_strings, 1, 0, 0, 0, 0, 0, "eval", 0 },
     { 'h', flag, &print_usage_flag, 0, 0, 0, 0, 0, 0, "help", 0 },
     { 'i', flag, &ignore_errors_flag, 1, 1, 0, 0, 0, 0, "ignore-errors", 0 },
+    { 'J', flag, &detect_job_slots_flag, 1, 1, 0, 0, 0, 0, "detect-job-slots", 
0 },
     { 'k', flag, &keep_going_flag, 1, 1, 0, 0, 0, &default_keep_going_flag,
       "keep-going", &keep_going_origin },
     { 'L', flag, &check_symlink_flag, 1, 1, 0, 0, 0, 0, "check-symlink-times", 
0 },
@@ -1616,7 +1623,12 @@ main (int argc, char **argv, char **envp)
     argv_slots = arg_job_slots;
 
     if (arg_job_slots == INVALID_JOB_SLOTS)
-      arg_job_slots = env_slots;
+      {
+        if (detect_job_slots_flag)
+          arg_job_slots = num_processors(NPROC_CURRENT_OVERRIDABLE);
+        else
+          arg_job_slots = env_slots;
+      }
   }
 
   if (print_usage_flag)
-- 
2.44.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]