Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/config config(1): Sort objects by weight in modular ...
details: https://anonhg.NetBSD.org/src/rev/5321cc5db027
branches: trunk
changeset: 803870:5321cc5db027
user: uebayasi <uebayasi%NetBSD.org@localhost>
date: Sat Nov 15 08:21:38 2014 +0000
description:
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.)
diffstat:
usr.bin/config/defs.h | 4 ++-
usr.bin/config/mkmakefile.c | 56 ++++++++++++++++++++++++++++++++++++++++----
usr.bin/config/sem.c | 11 +++++---
usr.bin/config/sem.h | 3 +-
4 files changed, 63 insertions(+), 11 deletions(-)
diffs (197 lines):
diff -r 51049a03ee11 -r 5321cc5db027 usr.bin/config/defs.h
--- a/usr.bin/config/defs.h Sat Nov 15 08:20:42 2014 +0000
+++ b/usr.bin/config/defs.h Sat Nov 15 08:21:38 2014 +0000
@@ -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 @@
#endif
int m_expanding;
TAILQ_HEAD(, files) m_files;
+ int m_weight;
};
/*
@@ -183,6 +184,7 @@
#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 */
diff -r 51049a03ee11 -r 5321cc5db027 usr.bin/config/mkmakefile.c
--- a/usr.bin/config/mkmakefile.c Sat Nov 15 08:20:42 2014 +0000
+++ b/usr.bin/config/mkmakefile.c Sat Nov 15 08:21:38 2014 +0000
@@ -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 @@
#include <stdlib.h>
#include <string.h>
#include <err.h>
+#include <util.h>
#include "defs.h"
#include "sem.h"
@@ -361,30 +362,74 @@
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;
+
+ 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);
- ht_enumerate(attrtab, emitallkobjscb, 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)
{
extern struct hashtab *attrtab;
@@ -404,6 +449,7 @@
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);
diff -r 51049a03ee11 -r 5321cc5db027 usr.bin/config/sem.c
--- a/usr.bin/config/sem.c Sat Nov 15 08:20:42 2014 +0000
+++ b/usr.bin/config/sem.c Sat Nov 15 08:21:38 2014 +0000
@@ -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 @@
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 @@
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 @@
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);
}
diff -r 51049a03ee11 -r 5321cc5db027 usr.bin/config/sem.h
--- a/usr.bin/config/sem.h Sat Nov 15 08:20:42 2014 +0000
+++ b/usr.bin/config/sem.h Sat Nov 15 08:21:38 2014 +0000
@@ -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 @@
extern const char *s_qmark;
extern const char *s_none;
extern const char *s_ifnet;
+extern int nattrs;
Home |
Main Index |
Thread Index |
Old Index