summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorMarc Espie <espie@cvs.openbsd.org>2020-01-13 14:51:51 +0000
committerMarc Espie <espie@cvs.openbsd.org>2020-01-13 14:51:51 +0000
commitebaa80c356f8a3740590c1e7a899bc1cc86c0c97 (patch)
tree3ae037318b3368f955a8f75cf62827ea5acc5ebb /usr.bin
parent74a85bc9460cf9507b68b11206a574670c16c0b9 (diff)
simplify the way we account for different jobs:
- have a simple variable "sequential" that counts whether we are running more than one job (for the expensive heuristics) - don't expose various things globally, just have a set_noparallel() for the parser - preallocate exactly enough job structures and record them in availableJobs - keep one job on the side for .INTERRUPT
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/make/engine.c20
-rw-r--r--usr.bin/make/extern.h3
-rw-r--r--usr.bin/make/job.c54
-rw-r--r--usr.bin/make/job.h6
-rw-r--r--usr.bin/make/main.c29
-rw-r--r--usr.bin/make/main.h5
-rw-r--r--usr.bin/make/parse.c9
7 files changed, 76 insertions, 50 deletions
diff --git a/usr.bin/make/engine.c b/usr.bin/make/engine.c
index 9a87799b9b5..45cd390d33f 100644
--- a/usr.bin/make/engine.c
+++ b/usr.bin/make/engine.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: engine.c,v 1.62 2020/01/13 14:15:21 espie Exp $ */
+/* $OpenBSD: engine.c,v 1.63 2020/01/13 14:51:50 espie Exp $ */
/*
* Copyright (c) 2012 Marc Espie.
*
@@ -603,8 +603,6 @@ run_command(const char *cmd, bool errCheck)
_exit(1);
}
-static Job myjob;
-
void
job_attach_node(Job *job, GNode *node)
{
@@ -680,7 +678,7 @@ job_handle_status(Job *job, int status)
* JOB_IS_EXPENSIVE, perform the computation for
* sequential make to figure out whether to display the
* command or not. */
- if ((job->flags & JOB_SILENT) && job == &myjob)
+ if ((job->flags & JOB_SILENT) && sequential)
determine_expensive_job(job);
if ((job->flags & (JOB_SILENT | JOB_IS_EXPENSIVE))
== JOB_SILENT)
@@ -702,17 +700,23 @@ job_handle_status(Job *job, int status)
int
run_gnode(GNode *gn)
{
+ Job *j;
if (!gn || (gn->type & OP_DUMMY))
return NOSUCHNODE;
- job_attach_node(&myjob, gn);
- while (myjob.exit_type == JOB_EXIT_OKAY) {
- bool finished = job_run_next(&myjob);
+ assert(availableJobs != NULL);
+ j = availableJobs;
+ availableJobs = availableJobs->next;
+ job_attach_node(j, gn);
+ while (j->exit_type == JOB_EXIT_OKAY) {
+ bool finished = job_run_next(j);
if (finished)
break;
- handle_one_job(&myjob);
+ handle_one_job(j);
}
+ j->next = availableJobs;
+ availableJobs = j;
return gn->built_status;
}
diff --git a/usr.bin/make/extern.h b/usr.bin/make/extern.h
index 89797d685b9..2fcafa1fbf6 100644
--- a/usr.bin/make/extern.h
+++ b/usr.bin/make/extern.h
@@ -1,7 +1,7 @@
#ifndef EXTERN_H
#define EXTERN_H
-/* $OpenBSD: extern.h,v 1.43 2010/07/19 19:46:44 espie Exp $ */
+/* $OpenBSD: extern.h,v 1.44 2020/01/13 14:51:50 espie Exp $ */
/* $NetBSD: nonints.h,v 1.12 1996/11/06 17:59:19 christos Exp $ */
/*-
@@ -40,7 +40,6 @@
* from: @(#)nonints.h 8.3 (Berkeley) 3/19/94
*/
-extern bool compatMake; /* True if we are make compatible */
extern bool ignoreErrors; /* True if should ignore all errors */
extern bool beSilent; /* True if should print no commands */
extern bool noExecute; /* True if should execute nothing */
diff --git a/usr.bin/make/job.c b/usr.bin/make/job.c
index cf2828aeff8..ece5b323c5d 100644
--- a/usr.bin/make/job.c
+++ b/usr.bin/make/job.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: job.c,v 1.147 2020/01/13 14:14:24 espie Exp $ */
+/* $OpenBSD: job.c,v 1.148 2020/01/13 14:51:50 espie Exp $ */
/* $NetBSD: job.c,v 1.16 1996/11/06 17:59:08 christos Exp $ */
/*
@@ -121,15 +121,16 @@ static int aborting = 0; /* why is the make aborting? */
#define ABORT_INTERRUPT 2 /* Because it was interrupted */
#define ABORT_WAIT 3 /* Waiting for jobs to finish */
-static int maxJobs; /* The most children we can run at once */
-static int nJobs; /* Number of jobs already allocated */
static bool no_new_jobs; /* Mark recursive shit so we shouldn't start
* something else at the same time
*/
+bool sequential;
Job *runningJobs; /* Jobs currently running a process */
Job *errorJobs; /* Jobs in error at end */
+Job *availableJobs; /* Pool of available jobs */
static Job *heldJobs; /* Jobs not running yet because of expensive */
static pid_t mypid; /* Used for printing debugging messages */
+static Job *extra_job; /* Needed for .INTERRUPT */
static volatile sig_atomic_t got_fatal;
@@ -538,14 +539,19 @@ postprocess_job(Job *job)
if (job->exit_type == JOB_EXIT_OKAY &&
aborting != ABORT_ERROR &&
aborting != ABORT_INTERRUPT) {
+ job->next = availableJobs;
+ availableJobs = job;
/* As long as we aren't aborting and the job didn't return a
* non-zero status that we shouldn't ignore, we call
* Make_Update to update the parents. */
job->node->built_status = REBUILT;
Make_Update(job->node);
- free(job);
- } else if (job->exit_type != JOB_EXIT_OKAY && keepgoing)
- free(job);
+ job->next = availableJobs;
+ availableJobs = job;
+ } else if (job->exit_type != JOB_EXIT_OKAY && keepgoing) {
+ job->next = availableJobs;
+ availableJobs = job;
+ }
if (errorJobs != NULL && aborting != ABORT_INTERRUPT)
aborting = ABORT_ERROR;
@@ -662,12 +668,10 @@ prepare_job(GNode *gn)
Job_Touch(gn);
return NULL;
} else {
- Job *job;
-
- job = emalloc(sizeof(Job));
- if (job == NULL)
- Punt("can't create job: out of memory");
+ Job *job = availableJobs;
+ assert(job != NULL);
+ availableJobs = availableJobs->next;
job_attach_node(job, gn);
return job;
}
@@ -696,7 +700,7 @@ continue_job(Job *job)
bool finished = job_run_next(job);
if (finished)
remove_job(job);
- else
+ else if (!sequential)
determine_expensive_job(job);
}
@@ -719,7 +723,6 @@ Job_Make(GNode *gn)
job = prepare_job(gn);
if (!job)
return;
- nJobs++;
may_continue_job(job);
}
@@ -745,7 +748,6 @@ determine_job_next_step(Job *job)
static void
remove_job(Job *job)
{
- nJobs--;
postprocess_job(job);
}
@@ -876,16 +878,27 @@ loop_handle_running_jobs()
}
void
-Job_Init(int maxproc)
+Job_Init(int maxJobs)
{
+ Job *j;
+ int i;
+
runningJobs = NULL;
heldJobs = NULL;
errorJobs = NULL;
- maxJobs = maxproc;
+ availableJobs = NULL;
+ sequential = maxJobs == 1;
+
+ /* we allocate n+1 jobs, since we may need an extra job for
+ * running .INTERRUPT. */
+ j = ereallocarray(NULL, sizeof(Job), maxJobs+1);
+ for (i = 0; i != maxJobs; i++) {
+ j[i].next = availableJobs;
+ availableJobs = &j[i];
+ }
+ extra_job = &j[maxJobs];
mypid = getpid();
- nJobs = 0;
-
aborting = 0;
setup_all_signals();
}
@@ -893,7 +906,7 @@ Job_Init(int maxproc)
bool
can_start_job(void)
{
- if (aborting || nJobs >= maxJobs)
+ if (aborting || availableJobs == NULL)
return false;
else
return true;
@@ -933,7 +946,8 @@ handle_fatal_signal(int signo)
if (signo == SIGINT && !touchFlag) {
if ((interrupt_node->type & OP_DUMMY) == 0) {
ignoreErrors = false;
-
+ extra_job->next = availableJobs;
+ availableJobs = extra_job;
Job_Make(interrupt_node);
}
}
diff --git a/usr.bin/make/job.h b/usr.bin/make/job.h
index e8152d18fd0..8c0d9aa1fe9 100644
--- a/usr.bin/make/job.h
+++ b/usr.bin/make/job.h
@@ -1,7 +1,7 @@
#ifndef _JOB_H_
#define _JOB_H_
-/* $OpenBSD: job.h,v 1.31 2012/12/14 11:10:03 espie Exp $ */
+/* $OpenBSD: job.h,v 1.32 2020/01/13 14:51:50 espie Exp $ */
/* $NetBSD: job.h,v 1.5 1996/11/06 17:59:10 christos Exp $ */
/*
@@ -93,11 +93,13 @@ extern void handle_running_jobs(void);
extern void handle_all_signals(void);
extern void determine_expensive_job(Job *);
-extern Job *runningJobs, *errorJobs;
+extern Job *runningJobs, *errorJobs, *availableJobs;
extern void debug_job_printf(const char *, ...);
extern void handle_one_job(Job *);
extern int check_dying_signal(void);
extern const char *basedirectory;
+extern bool sequential; /* True if we are running one single-job */
+
#endif /* _JOB_H_ */
diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c
index 4d8a038ef43..8757e51f304 100644
--- a/usr.bin/make/main.c
+++ b/usr.bin/make/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.124 2020/01/08 14:09:29 espie Exp $ */
+/* $OpenBSD: main.c,v 1.125 2020/01/13 14:51:50 espie Exp $ */
/* $NetBSD: main.c,v 1.34 1997/03/24 20:56:36 gwr Exp $ */
/*
@@ -73,12 +73,12 @@ static LIST to_create; /* Targets to be made */
Lst create = &to_create;
bool allPrecious; /* .PRECIOUS given on line by itself */
-static bool noBuiltins; /* -r flag */
-static LIST makefiles; /* ordered list of makefiles to read */
-static LIST varstoprint; /* list of variables to print */
-int maxJobs; /* -j argument */
-bool compatMake; /* -B argument */
-static bool forceJobs = false;
+static bool noBuiltins; /* -r flag */
+static LIST makefiles; /* ordered list of makefiles to read */
+static LIST varstoprint; /* list of variables to print */
+static int optj; /* -j argument */
+static bool compatMake; /* -B argument */
+static bool forceJobs = false;
int debug; /* -d flag */
bool noExecute; /* -n flag */
bool keepgoing; /* -k flag */
@@ -126,6 +126,12 @@ record_option(int c, const char *arg)
Var_Append(MAKEFLAGS, arg);
}
+void
+set_notparallel()
+{
+ compatMake = true;
+}
+
static void
posixParseOptLetter(int c)
{
@@ -313,7 +319,7 @@ MainParseArgs(int argc, char **argv)
const char *errstr;
forceJobs = true;
- maxJobs = strtonum(optarg, 1, INT_MAX, &errstr);
+ optj = strtonum(optarg, 1, INT_MAX, &errstr);
if (errstr != NULL) {
fprintf(stderr,
"make: illegal argument to -j option"
@@ -676,7 +682,7 @@ main(int argc, char **argv)
touchFlag = false; /* Actually update targets */
debug = 0; /* No debug verbosity, please. */
- maxJobs = DEFMAXJOBS;
+ optj = DEFMAXJOBS;
compatMake = false; /* No compat mode */
@@ -757,6 +763,9 @@ main(int argc, char **argv)
read_all_make_rules(noBuiltins, read_depend, &makefiles, &d);
+ if (compatMake)
+ optj = 1;
+
Var_Append("MFLAGS", Var_Value(MAKEFLAGS));
/* Install all the flags into the MAKEFLAGS env variable. */
@@ -796,7 +805,7 @@ main(int argc, char **argv)
else
Targ_FindList(&targs, create);
- Job_Init(maxJobs);
+ Job_Init(optj);
/* If the user has defined a .BEGIN target, execute the commands
* attached to it. */
if (!queryFlag)
diff --git a/usr.bin/make/main.h b/usr.bin/make/main.h
index 469487ee058..035de86e602 100644
--- a/usr.bin/make/main.h
+++ b/usr.bin/make/main.h
@@ -1,6 +1,6 @@
#ifndef MAIN_H
#define MAIN_H
-/* $OpenBSD: main.h,v 1.5 2010/07/19 19:46:44 espie Exp $ */
+/* $OpenBSD: main.h,v 1.6 2020/01/13 14:51:50 espie Exp $ */
/*
* Copyright (c) 2001 Marc Espie.
@@ -38,4 +38,7 @@ extern void Main_ParseArgLine(const char *);
* .if make(...) statements. */
extern Lst create;
+/* set_notparallel(): used to influence running mode from parse.c */
+extern void set_notparallel(void);
+
#endif
diff --git a/usr.bin/make/parse.c b/usr.bin/make/parse.c
index 2dfae983d67..4c8a8fa7de2 100644
--- a/usr.bin/make/parse.c
+++ b/usr.bin/make/parse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.c,v 1.129 2020/01/13 14:07:35 espie Exp $ */
+/* $OpenBSD: parse.c,v 1.130 2020/01/13 14:51:50 espie Exp $ */
/* $NetBSD: parse.c,v 1.29 1997/03/10 21:20:04 christos Exp $ */
/*
@@ -739,13 +739,8 @@ handle_special_targets(Lst paths)
}
break;
case SPECIAL_NOTPARALLEL:
- {
- extern int maxJobs;
-
- maxJobs = 1;
- compatMake = 1;
+ set_notparallel();
break;
- }
case SPECIAL_ORDER:
predecessor = NULL;
break;