Module Name: src
Committed By: uebayasi
Date: Sat Nov 15 08:21:38 UTC 2014
Modified Files:
src/usr.bin/config: defs.h mkmakefile.c sem.c sem.h
Log Message:
config(1): Sort objects by weight in modular build
Sort per-module kernel objects (*.ko) by dependency weight. Important modules
are placed in lower addresses. The ``machdep'' module will be always placed
in the lowest.
(At this moment, the order is not exact because dependency information is
incomplete in config files (files.*). Thus ``sysmon_power.ko'' comes lower
than ``machdep.ko'' and/or ``uvm.ko''; but still much better than alphabetical
sort.)
To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/usr.bin/config/defs.h
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/config/mkmakefile.c
cvs rdiff -u -r1.69 -r1.70 src/usr.bin/config/sem.c
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/config/sem.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/usr.bin/config/defs.h
diff -u src/usr.bin/config/defs.h:1.62 src/usr.bin/config/defs.h:1.63
--- src/usr.bin/config/defs.h:1.62 Thu Nov 6 11:40:32 2014
+++ src/usr.bin/config/defs.h Sat Nov 15 08:21:38 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: defs.h,v 1.62 2014/11/06 11:40:32 uebayasi Exp $ */
+/* $NetBSD: defs.h,v 1.63 2014/11/15 08:21:38 uebayasi Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -159,6 +159,7 @@ struct module {
#endif
int m_expanding;
TAILQ_HEAD(, files) m_files;
+ int m_weight;
};
/*
@@ -183,6 +184,7 @@ struct attr {
#define a_deps a_m.m_deps
#define a_expanding a_m.m_expanding
#define a_files a_m.m_files
+#define a_weight a_m.m_weight
/* "interface attribute" */
int a_iattr; /* true => allows children */
Index: src/usr.bin/config/mkmakefile.c
diff -u src/usr.bin/config/mkmakefile.c:1.26 src/usr.bin/config/mkmakefile.c:1.27
--- src/usr.bin/config/mkmakefile.c:1.26 Thu Nov 6 11:40:32 2014
+++ src/usr.bin/config/mkmakefile.c Sat Nov 15 08:21:38 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: mkmakefile.c,v 1.26 2014/11/06 11:40:32 uebayasi Exp $ */
+/* $NetBSD: mkmakefile.c,v 1.27 2014/11/15 08:21:38 uebayasi Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -45,7 +45,7 @@
#endif
#include <sys/cdefs.h>
-__RCSID("$NetBSD: mkmakefile.c,v 1.26 2014/11/06 11:40:32 uebayasi Exp $");
+__RCSID("$NetBSD: mkmakefile.c,v 1.27 2014/11/15 08:21:38 uebayasi Exp $");
#include <sys/param.h>
#include <ctype.h>
@@ -54,6 +54,7 @@ __RCSID("$NetBSD: mkmakefile.c,v 1.26 20
#include <stdlib.h>
#include <string.h>
#include <err.h>
+#include <util.h>
#include "defs.h"
#include "sem.h"
@@ -361,29 +362,73 @@ emitkobjs(FILE *fp)
emitattrkobjs(fp);
}
+static int emitallkobjsweighcb(const char *name, void *v, void *arg);
+static void weighattr(struct attr *a);
+static int attrcmp(const void *l, const void *r);
+
+struct attr **attrbuf;
+int attridx;
+
static void
emitallkobjs(FILE *fp)
{
+ int i;
- fputs("OBJS=", fp);
+ attrbuf = ecalloc((size_t)nattrs, sizeof(attrbuf));
+
+ ht_enumerate(attrtab, emitallkobjsweighcb, NULL);
ht_enumerate(attrtab, emitallkobjscb, fp);
+ qsort(attrbuf, (size_t)attridx, sizeof(struct attr *), attrcmp);
+
+ fputs("OBJS=", fp);
+ for (i = 0; i < attridx; i++)
+ fprintf(fp, " %s.ko", attrbuf[i]->a_name);
putc('\n', fp);
+
+ free(attrbuf);
}
static int
emitallkobjscb(const char *name, void *v, void *arg)
{
struct attr *a = v;
- FILE *fp = arg;
if (ht_lookup(selecttab, name) == NULL)
return 0;
if (TAILQ_EMPTY(&a->a_files))
return 0;
- fprintf(fp, " %s.ko", name);
+ attrbuf[attridx++] = a;
return 0;
}
+static int
+emitallkobjsweighcb(const char *name, void *v, void *arg)
+{
+ struct attr *a = v;
+
+ weighattr(a);
+ return 0;
+}
+
+static void
+weighattr(struct attr *a)
+{
+ struct attrlist *al;
+
+ for (al = a->a_deps; al != NULL; al = al->al_next) {
+ weighattr(al->al_this);
+ }
+ a->a_weight++;
+}
+
+static int
+attrcmp(const void *l, const void *r)
+{
+ const struct attr * const *a = l, * const *b = r;
+ const int wa = (*a)->a_weight, wb = (*b)->a_weight;
+ return (wa > wb) ? -1 : (wa < wb) ? 1 : 0;
+}
+
static void
emitattrkobjs(FILE *fp)
{
@@ -404,6 +449,7 @@ emitattrkobjscb(const char *name, void *
if (TAILQ_EMPTY(&a->a_files))
return 0;
fputc('\n', fp);
+ fprintf(fp, "# %s (%d)\n", name, a->a_weight);
fprintf(fp, "OBJS.%s=", name);
TAILQ_FOREACH(fi, &a->a_files, fi_anext) {
fprintf(fp, " %s.o", fi->fi_base);
Index: src/usr.bin/config/sem.c
diff -u src/usr.bin/config/sem.c:1.69 src/usr.bin/config/sem.c:1.70
--- src/usr.bin/config/sem.c:1.69 Tue Nov 4 23:02:14 2014
+++ src/usr.bin/config/sem.c Sat Nov 15 08:21:38 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: sem.c,v 1.69 2014/11/04 23:02:14 joerg Exp $ */
+/* $NetBSD: sem.c,v 1.70 2014/11/15 08:21:38 uebayasi Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -45,7 +45,7 @@
#endif
#include <sys/cdefs.h>
-__RCSID("$NetBSD: sem.c,v 1.69 2014/11/04 23:02:14 joerg Exp $");
+__RCSID("$NetBSD: sem.c,v 1.70 2014/11/15 08:21:38 uebayasi Exp $");
#include <sys/param.h>
#include <ctype.h>
@@ -69,6 +69,7 @@ const char *s_none;
static struct hashtab *cfhashtab; /* for config lookup */
struct hashtab *devitab; /* etc */
struct attr allattr;
+int nattrs;
static struct attr errattr;
static struct devbase errdev;
@@ -1981,7 +1982,8 @@ selectattr(struct attr *a)
dep = al->al_this;
selectattr(dep);
}
- (void)ht_insert(selecttab, a->a_name, __UNCONST(a->a_name));
+ if (ht_insert(selecttab, a->a_name, __UNCONST(a->a_name)) == 0)
+ nattrs++;
CFGDBG(3, "attr selected `%s'", a->a_name);
}
@@ -2001,7 +2003,8 @@ deselectattr(struct attr *a)
CFGDBG(5, "deselecting attr `%s'", a->a_name);
ht_enumerate2(attrdeptab, deselectattrcb2, __UNCONST(a->a_name));
- (void)ht_remove(selecttab, a->a_name);
+ if (ht_remove(selecttab, a->a_name) == 0)
+ nattrs--;
CFGDBG(3, "attr deselected `%s'", a->a_name);
}
Index: src/usr.bin/config/sem.h
diff -u src/usr.bin/config/sem.h:1.17 src/usr.bin/config/sem.h:1.18
--- src/usr.bin/config/sem.h:1.17 Fri Oct 31 07:38:36 2014
+++ src/usr.bin/config/sem.h Sat Nov 15 08:21:38 2014
@@ -1,4 +1,4 @@
-/* $NetBSD: sem.h,v 1.17 2014/10/31 07:38:36 uebayasi Exp $ */
+/* $NetBSD: sem.h,v 1.18 2014/11/15 08:21:38 uebayasi Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -88,3 +88,4 @@ int has_attr(struct attrlist *, const c
extern const char *s_qmark;
extern const char *s_none;
extern const char *s_ifnet;
+extern int nattrs;