Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/make When a parallel make job completes, always put ...



details:   https://anonhg.NetBSD.org/src/rev/5a1fa7ed9b10
branches:  trunk
changeset: 586890:5a1fa7ed9b10
user:      dsl <dsl%NetBSD.org@localhost>
date:      Wed Jan 04 21:31:55 2006 +0000

description:
When a parallel make job completes, always put the job token back into the
job_pipe and collect another one for the next job.
If we are aborting, remove all the 'normal' job tokens and add an 'error' one.
If we get an 'error' token, remove any other tokens, re-insert the error
token and exit (with error 'cos that is easier).
Add the current pid to some of the DEBUG(JOB) traces.
Combined effect is that parallel makes actually stop some fairly shortly
after an error, rather than running on long enough to fill the scrollback.

diffstat:

 usr.bin/make/job.c  |  69 +++++++++++++++++++++++-----------------------------
 usr.bin/make/job.h  |   3 +-
 usr.bin/make/main.c |   7 ++---
 3 files changed, 35 insertions(+), 44 deletions(-)

diffs (231 lines):

diff -r 15cf2a3980a4 -r 5a1fa7ed9b10 usr.bin/make/job.c
--- a/usr.bin/make/job.c        Wed Jan 04 21:25:03 2006 +0000
+++ b/usr.bin/make/job.c        Wed Jan 04 21:31:55 2006 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: job.c,v 1.100 2006/01/04 21:25:03 dsl Exp $    */
+/*     $NetBSD: job.c,v 1.101 2006/01/04 21:31:55 dsl Exp $    */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -70,14 +70,14 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: job.c,v 1.100 2006/01/04 21:25:03 dsl Exp $";
+static char rcsid[] = "$NetBSD: job.c,v 1.101 2006/01/04 21:31:55 dsl Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char sccsid[] = "@(#)job.c      8.2 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: job.c,v 1.100 2006/01/04 21:25:03 dsl Exp $");
+__RCSID("$NetBSD: job.c,v 1.101 2006/01/04 21:31:55 dsl Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -177,6 +177,7 @@
 #define ABORT_ERROR    1           /* Because of an error */
 #define ABORT_INTERRUPT        2           /* Because it was interrupted */
 #define ABORT_WAIT     3           /* Waiting for jobs to finish */
+#define JOB_TOKENS     "+EI+"      /* Token to requeue for each abort state */
 
 /*
  * XXX: Avoid SunOS bug... FILENO() is fp->_file, and file
@@ -2596,7 +2597,6 @@
 #endif
 
     (void)fflush(stdout);
-    Job_TokenFlush();
 #ifdef RMT_WILL_WATCH
     pnJobs = nJobs;
 
@@ -3244,7 +3244,6 @@
            JobRun(postCommands);
        }
     }
-    Job_TokenFlush();
     return(errors);
 }
 
@@ -3293,7 +3292,6 @@
        Job_CatchChildren(!usePipes);
 #endif /* RMT_WILL_WATCH */
     }
-    Job_TokenFlush();
     aborting = 0;
 }
 
@@ -3524,10 +3522,16 @@
 static void
 JobTokenAdd(void)
 {
+    char tok = JOB_TOKENS[aborting], tok1;
+
+    /* If we are depositing an error token flush everything else */
+    while (tok != '+' && read(job_pipe[0], &tok1, 1) == 1)
+       continue;
 
     if (DEBUG(JOB))
-       printf("deposit token\n");
-    write(job_pipe[1], "+", 1);
+       printf("(%d) aborting %d, deposit token %c\n",
+           getpid(), aborting, JOB_TOKENS[aborting]);
+    write(job_pipe[1], &tok, 1);
 }
 
 /*-
@@ -3577,7 +3581,7 @@
 
     Var_Append(MAKEFLAGS, "-J", VAR_GLOBAL);
     Var_Append(MAKEFLAGS, jobarg, VAR_GLOBAL);                 
-       
+
     /*
      * Preload job_pipe with one token per job, save the one
      * "extra" token for the primary job.
@@ -3594,7 +3598,6 @@
  * this tracks the number of tokens currently "out" to build jobs.
  */
 int jobTokensRunning = 0;
-int jobTokensFree = 0;
 /*-
  *-----------------------------------------------------------------------
  * Job_TokenReturn --
@@ -3610,7 +3613,7 @@
     if (jobTokensRunning < 0)
        Punt("token botch");
     if (jobTokensRunning)
-       jobTokensFree++;
+       JobTokenAdd();
 }
 
 /*-
@@ -3633,10 +3636,13 @@
 Boolean
 Job_TokenWithdraw(void)
 {
-    char tok;
+    char tok, tok1;
     int count;
 
     wantToken = FALSE;
+    if (DEBUG(JOB))
+       printf("Job_TokenWithdraw(%d): aborting %d, running %d\n",
+               getpid(), aborting, jobTokensRunning);
 
     if (aborting)
            return FALSE;
@@ -3647,11 +3653,6 @@
        jobTokensRunning++;
        return TRUE;
     }
-    if (jobTokensFree > 0) {
-       jobTokensFree--;
-       jobTokensRunning++;
-       return TRUE;
-    }
     count = read(job_pipe[0], &tok, 1);
     if (count == 0)
        Fatal("eof on job pipe!");
@@ -3660,35 +3661,27 @@
            Fatal("job pipe read: %s", strerror(errno));
        }
        if (DEBUG(JOB))
-           printf("blocked for token\n");
+           printf("(%d) blocked for token\n", getpid());
        wantToken = TRUE;
        return FALSE;
     }
+    if (tok != '+') {
+       /* Remove any other job tokens */
+       if (DEBUG(JOB))
+           printf("(%d) abort token %c\n", getpid(), tok);
+       while (read(job_pipe[0], &tok1, 1) == 1)
+           continue;
+       /* And put the stopper back */
+       write(job_pipe[1], &tok, 1);
+       aborting = ABORT_ERROR;
+       return FALSE;
+    }
     jobTokensRunning++;
     if (DEBUG(JOB))
-       printf("withdrew token\n");
+       printf("(%d) withdrew token\n", getpid());
     return TRUE;
 }
 
-/*-
- *-----------------------------------------------------------------------
- * Job_TokenFlush --
- *     Return free tokens to the pool.
- *
- *-----------------------------------------------------------------------
- */
-
-void
-Job_TokenFlush(void)
-{
-    if (compatMake) return;
-       
-    while (jobTokensFree > 0) {
-       JobTokenAdd();
-       jobTokensFree--;
-    }
-}
-
 #ifdef USE_SELECT
 int
 emul_poll(struct pollfd *fd, int nfd, int timeout)
diff -r 15cf2a3980a4 -r 5a1fa7ed9b10 usr.bin/make/job.h
--- a/usr.bin/make/job.h        Wed Jan 04 21:25:03 2006 +0000
+++ b/usr.bin/make/job.h        Wed Jan 04 21:31:55 2006 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: job.h,v 1.21 2003/12/20 00:18:22 jmc Exp $     */
+/*     $NetBSD: job.h,v 1.22 2006/01/04 21:31:55 dsl Exp $     */
 
 /*
  * Copyright (c) 1988, 1989, 1990 The Regents of the University of California.
@@ -310,7 +310,6 @@
 void Job_AbortAll(void);
 void JobFlagForMigration(int);
 void Job_TokenReturn(void);
-void Job_TokenFlush(void);
 Boolean Job_TokenWithdraw(void);
 void Job_ServerStart(int);
 
diff -r 15cf2a3980a4 -r 5a1fa7ed9b10 usr.bin/make/main.c
--- a/usr.bin/make/main.c       Wed Jan 04 21:25:03 2006 +0000
+++ b/usr.bin/make/main.c       Wed Jan 04 21:31:55 2006 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: main.c,v 1.116 2005/08/09 21:36:42 christos Exp $      */
+/*     $NetBSD: main.c,v 1.117 2006/01/04 21:31:55 dsl Exp $   */
 
 /*
  * Copyright (c) 1988, 1989, 1990, 1993
@@ -69,7 +69,7 @@
  */
 
 #ifndef MAKE_NATIVE
-static char rcsid[] = "$NetBSD: main.c,v 1.116 2005/08/09 21:36:42 christos Exp $";
+static char rcsid[] = "$NetBSD: main.c,v 1.117 2006/01/04 21:31:55 dsl Exp $";
 #else
 #include <sys/cdefs.h>
 #ifndef lint
@@ -81,7 +81,7 @@
 #if 0
 static char sccsid[] = "@(#)main.c     8.3 (Berkeley) 3/19/94";
 #else
-__RCSID("$NetBSD: main.c,v 1.116 2005/08/09 21:36:42 christos Exp $");
+__RCSID("$NetBSD: main.c,v 1.117 2006/01/04 21:31:55 dsl Exp $");
 #endif
 #endif /* not lint */
 #endif
@@ -1511,7 +1511,6 @@
        va_start(ap, fmt);
        if (jobsRunning)
                Job_Wait();
-       Job_TokenFlush();
 
        (void)vfprintf(stderr, fmt, ap);
        va_end(ap);



Home | Main Index | Thread Index | Old Index