tech-toolchain archive

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

Re: make: remove wantToken and skip polling tokenWaitJob



Christos Zoulas <christos%zoulas.com@localhost> wrote:
> | The patch I've been using allows enable/disable of polling
> | (disable by forcing wantToken=0)
> | but results to date, would support simply ripping it out.
> | 
> | I checked back through the history of wantToken
> | and it has been there from the initial commit that added the token pipe,
> | rather than introduced later to address any issue.
> | 
> | If anyone is interested in doing their own testing
> | the patch is on morden in
> | ~sjg/tmp/d-make-poll-jobq-bool
> 
> I would just set wantToken = 0 and see what breaks...

Yes, that's what many folk have been doing.
It's what the patch above does too (when disabled).

There is a possibility though of busy waiting when there are no tokens
available and no jobs running.

Actually since Job_TokenWithdraw is only setting wantToken when jobs
*are* running, this issue already exists.

Below would leave wantToken=0 and address the possiblity of busy
waiting.

diff -r 663b16a373e5 bmake/job.c
--- a/bmake/job.c	Sun Apr 15 11:34:25 2018 -0700
+++ b/bmake/job.c	Fri May 11 17:03:17 2018 -0700
@@ -2963,14 +2958,16 @@
     count = read(tokenWaitJob.inPipe, &tok, 1);
     if (count == 0)
 	Fatal("eof on job pipe!");
-    if (count < 0 && jobTokensRunning != 0) {
+    if (count < 0) {
 	if (errno != EAGAIN) {
 	    Fatal("job pipe read: %s", strerror(errno));
 	}
 	if (DEBUG(JOB))
 	    fprintf(debug_file, "(%d) blocked for token\n", getpid());
-	wantToken = 1;
-	return FALSE;
+	if (!jobTokensRunning)
+	    sleep(1);			/* avoid busy wait */
+	else
+	    return FALSE;
     }
 
     if (count == 1 && tok != '+') {


Home | Main Index | Thread Index | Old Index