[PATCH] "automated" make -j value

David O'Brien obrien at freebsd.org
Wed Dec 13 20:19:54 PST 2006


With multi-socket systems becoming more prevalent, and the continued
increase in cores per processors, I thought it would be nice for
'make -j' to gain some automation.

Attached is a patch that makes "-j-" be the same as
"-j `sysctl -n kern.smp.cpus`" and "-j=" be twice that.

I've also thought that maybe just supporting "-j-" would be better - with
a definition of
    num_core = `sysctl -n kern.smp.cpus`
    -j => MAX(num_core * 5 / 4, num_core + 1)
the idea being one would want a few more jobs than cores, but not a whole
lot more.

comments?  (redirected back to list)

-- 
-- David  (obrien at FreeBSD.org)

Index: main.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/make/main.c,v
retrieving revision 1.160
diff -u -p -r1.160 main.c
--- main.c	17 Jul 2006 19:16:12 -0000	1.160
+++ main.c	14 Dec 2006 02:26:15 -0000
@@ -456,11 +456,20 @@ rearg:
 			char *endptr;
 
 			forceJobs = TRUE;
+			size_t jLlen = sizeof(jobLimit);
 			jobLimit = strtol(optarg, &endptr, 10);
-			if (jobLimit <= 0 || *endptr != '\0') {
-				warnx("illegal number, -j argument -- %s",
-				    optarg);
-				usage();
+			if ((*optarg == '-' || *optarg == '=') &&
+			    *endptr != '\0') {
+				sysctlbyname("kern.smp.cpus", &jobLimit, &jLlen,
+				    NULL, 0);
+				if (*optarg == '=')
+					jobLimit *= 2;
+			} else {
+				if (jobLimit <= 0 || *endptr != '\0') {
+				      warnx("illegal number, -j argument -- %s",
+					    optarg);
+					usage();
+				}
 			}
 			MFLAGS_append("-j", optarg);
 			break;

Index: make.1
===================================================================
RCS file: /home/ncvs/src/usr.bin/make/make.1,v
retrieving revision 1.99
diff -u -p -r1.99 make.1
--- make.1	29 Sep 2006 21:17:10 -0000	1.99
+++ make.1	14 Dec 2006 04:19:22 -0000
@@ -218,6 +218,14 @@ may have running at any one time.
 Turns compatibility mode off, unless the
 .Fl B
 flag is also specified.
+The special values
+.It Ar -
+and 
+.It Ar =
+causes
+.It Ar max_jobs
+to be set to the value returned from the kern.smp.cpus sysctl and twice
+kern.smp.cpus respectively.
 .It Fl k
 Continue processing after errors are encountered, but only on those targets
 that do not depend on the target whose creation caused the error.


More information about the freebsd-hackers mailing list