diff options
author | 2007-11-28 09:40:08 +0000 | |
---|---|---|
committer | 2007-11-28 09:40:08 +0000 | |
commit | 639e17138705f14e08e10af8cfc45a32cfb1c88f (patch) | |
tree | 7c8c8d1cd377a3055abba32b13b02bec908bc997 | |
parent | PHONY targets never correspond to real files. (diff) | |
download | wireguard-openbsd-639e17138705f14e08e10af8cfc45a32cfb1c88f.tar.xz wireguard-openbsd-639e17138705f14e08e10af8cfc45a32cfb1c88f.zip |
debug scaffolding: allows the insertion of a random delay before firing up
jobs in parallel mode.
-rw-r--r-- | usr.bin/make/defines.h | 3 | ||||
-rw-r--r-- | usr.bin/make/job.c | 5 | ||||
-rw-r--r-- | usr.bin/make/main.c | 5 | ||||
-rw-r--r-- | usr.bin/make/make.1 | 18 | ||||
-rw-r--r-- | usr.bin/make/make.c | 47 | ||||
-rw-r--r-- | usr.bin/make/make.h | 3 |
6 files changed, 67 insertions, 14 deletions
diff --git a/usr.bin/make/defines.h b/usr.bin/make/defines.h index 1d668fabc1f..90f762742c6 100644 --- a/usr.bin/make/defines.h +++ b/usr.bin/make/defines.h @@ -2,7 +2,7 @@ #define DEFINES_H /* $OpenPackages$ */ -/* $OpenBSD: defines.h,v 1.5 2007/11/03 11:44:30 espie Exp $ */ +/* $OpenBSD: defines.h,v 1.6 2007/11/28 09:40:08 espie Exp $ */ /* * Copyright (c) 2001 Marc Espie. @@ -90,6 +90,7 @@ extern int debug; #define DEBUG_FOR 0x0400 #define DEBUG_LOUD 0x0800 #define DEBUG_JOBBANNER 0x1000 +#define DEBUG_PARALLEL 0x2000 #define CONCAT(a,b) a##b diff --git a/usr.bin/make/job.c b/usr.bin/make/job.c index 6d22e3bbb13..0124a7afbb4 100644 --- a/usr.bin/make/job.c +++ b/usr.bin/make/job.c @@ -1,5 +1,5 @@ /* $OpenPackages$ */ -/* $OpenBSD: job.c,v 1.108 2007/11/10 12:51:40 espie Exp $ */ +/* $OpenBSD: job.c,v 1.109 2007/11/28 09:40:08 espie Exp $ */ /* $NetBSD: job.c,v 1.16 1996/11/06 17:59:08 christos Exp $ */ /* @@ -763,6 +763,9 @@ JobExec(Job *job) # endif #endif /* USE_PGRP */ + if (random_delay) + usleep(random() % random_delay); + /* most cases won't return, but will exit directly */ result = run_gnode(job->node, 1); switch(result) { diff --git a/usr.bin/make/main.c b/usr.bin/make/main.c index 1525fc65107..27baeef4709 100644 --- a/usr.bin/make/main.c +++ b/usr.bin/make/main.c @@ -1,5 +1,5 @@ /* $OpenPackages$ */ -/* $OpenBSD: main.c,v 1.89 2007/11/17 09:49:53 espie Exp $ */ +/* $OpenBSD: main.c,v 1.90 2007/11/28 09:40:08 espie Exp $ */ /* $NetBSD: main.c,v 1.34 1997/03/24 20:56:36 gwr Exp $ */ /* @@ -267,6 +267,9 @@ MainParseArgs(int argc, char **argv) case 'm': debug |= DEBUG_MAKE; break; + case 'p': + debug |= DEBUG_PARALLEL; + break; case 's': debug |= DEBUG_SUFF; break; diff --git a/usr.bin/make/make.1 b/usr.bin/make/make.1 index f28bfda0d36..69d356b90f1 100644 --- a/usr.bin/make/make.1 +++ b/usr.bin/make/make.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: make.1,v 1.74 2007/11/03 15:29:29 jmc Exp $ +.\" $OpenBSD: make.1,v 1.75 2007/11/28 09:40:08 espie Exp $ .\" $OpenPackages$ .\" $NetBSD: make.1,v 1.18 1997/03/10 21:19:53 christos Exp $ .\" @@ -31,7 +31,7 @@ .\" .\" from: @(#)make.1 8.4 (Berkeley) 3/19/94 .\" -.Dd $Mdocdate: November 3 2007 $ +.Dd $Mdocdate: November 28 2007 $ .Dt MAKE 1 .Os .Sh NAME @@ -174,6 +174,20 @@ Also known as loud behavior. .It Ar m Print debugging information about making targets, including modification dates. +.It Ar p +Help finding concurrency issues for parallel make by adding some randomization. +If +.Va RANDOM_ORDER +is defined, +targets will be shuffled before being built. +If +.Va RANDOM_DELAY +is defined, +.Nm +will wait between 0 and ${RANDOM_DELAY} seconds at the start of each job. +A given random seed can be forced by setting +.Va RANDOM_SEED , +but this does not guarantee reproductibility. .It Ar s Print debugging information about suffix-transformation rules. .It Ar t diff --git a/usr.bin/make/make.c b/usr.bin/make/make.c index f06570f7dbf..14ad085d5a8 100644 --- a/usr.bin/make/make.c +++ b/usr.bin/make/make.c @@ -1,5 +1,5 @@ /* $OpenPackages$ */ -/* $OpenBSD: make.c,v 1.53 2007/11/26 22:48:18 espie Exp $ */ +/* $OpenBSD: make.c,v 1.54 2007/11/28 09:40:08 espie Exp $ */ /* $NetBSD: make.c,v 1.10 1996/11/06 17:59:15 christos Exp $ */ /* @@ -61,6 +61,7 @@ #include <stdio.h> #include <signal.h> #include <stddef.h> +#include <stdlib.h> #include <string.h> #include <ohash.h> #include "config.h" @@ -94,6 +95,33 @@ static void add_targets_to_make(Lst); static bool has_unmade_predecessor(GNode *); static void requeue_successors(GNode *); +static void random_setup(void); + +static bool randomize_queue; +long random_delay = 0; + +static void +random_setup() +{ + randomize_queue = Var_Definedi("RANDOM_ORDER", NULL); + + if (Var_Definedi("RANDOM_DELAY", NULL)) + random_delay = strtonum(Var_Value("RANDOM_DELAY"), 0, 1000, + NULL) * 1000000; + + if (randomize_queue || random_delay) { + unsigned int random_seed; + char *t; + + t = Var_Value("RANDOM_SEED"); + if (t != NULL) + random_seed = strtonum(t, 0, UINT_MAX, NULL); + else + random_seed = time(NULL); + fprintf(stderr, "RANDOM_SEED=%u\n", random_seed); + srandom(random_seed); + } +} static bool has_unmade_predecessor(GNode *gn) @@ -193,8 +221,8 @@ Make_Update(GNode *cgn) /* the child node */ for (ln = Lst_First(&cgn->parents); ln != NULL; ln = Lst_Adv(ln)) { pgn = (GNode *)Lst_Datum(ln); - pgn->unmade--; if (pgn->must_make) { + pgn->unmade--; if (DEBUG(MAKE)) printf("%s--=%d ", pgn->name, pgn->unmade); @@ -217,7 +245,7 @@ Make_Update(GNode *cgn) /* the child node */ */ if (DEBUG(MAKE)) printf("QUEUING "); - Lst_EnQueue(&toBeMade, pgn); + Lst_Push(&toBeMade, pgn); } else if (pgn->unmade < 0) { Error("Child %s discovered graph cycles through %s", cgn->name, pgn->name); } @@ -238,7 +266,7 @@ try_to_make_node(GNode *gn) if (DEBUG(MAKE)) printf(" Requeuing (%d)\n", gn->unmade); add_targets_to_make(&gn->children); - Lst_EnQueue(&toBeMade, gn); + Lst_Push(&toBeMade, gn); return false; } if (has_been_built(gn)) { @@ -306,7 +334,7 @@ MakeStartJobs(void) { GNode *gn; - while (!Job_Full() && (gn = (GNode *)Lst_DeQueue(&toBeMade)) != NULL) { + while (!Job_Full() && (gn = (GNode *)Lst_Pop(&toBeMade)) != NULL) { if (try_to_make_node(gn)) return true; } @@ -371,7 +399,7 @@ MakeAddChild(void *to_addp, void *lp) GNode *gn = (GNode *)to_addp; if (!gn->must_make && !(gn->type & OP_USE)) - Lst_EnQueue((Lst)lp, gn); + Lst_Push((Lst)lp, gn); } static void @@ -393,7 +421,7 @@ add_targets_to_make(Lst todo) Lst_Clone(&examine, todo, NOCOPY); - while ((gn = (GNode *)Lst_DeQueue(&examine)) != NULL) { + while ((gn = (GNode *)Lst_Pop(&examine)) != NULL) { if (gn->must_make) /* already known */ continue; gn->must_make = true; @@ -421,7 +449,7 @@ add_targets_to_make(Lst todo) } else { if (DEBUG(MAKE)) printf("%s: queuing\n", gn->name); - Lst_EnQueue(&toBeMade, gn); + Lst_Push(&toBeMade, gn); } } } @@ -456,7 +484,10 @@ Make_Run(Lst targs) /* the initial list of targets */ bool cycle; Static_Lst_Init(&toBeMade); + /* wild guess at initial sizes */ ohash_init(&targets, 10, &gnode_info); + if (DEBUG(PARALLEL)) + random_setup(); add_targets_to_make(targs); if (queryFlag) { diff --git a/usr.bin/make/make.h b/usr.bin/make/make.h index 2b214fe2595..63281c25da3 100644 --- a/usr.bin/make/make.h +++ b/usr.bin/make/make.h @@ -2,7 +2,7 @@ #define _MAKE_H_ /* $OpenPackages$ */ -/* $OpenBSD: make.h,v 1.34 2007/09/17 11:43:12 espie Exp $ */ +/* $OpenBSD: make.h,v 1.35 2007/11/28 09:40:08 espie Exp $ */ /* $NetBSD: make.h,v 1.15 1997/03/10 21:20:00 christos Exp $ */ /* @@ -43,5 +43,6 @@ extern void Make_Update(GNode *); extern bool Make_Run(Lst); +extern long random_delay; #endif /* _MAKE_H_ */ |