"Fix" the previous initial attempt at fixing TUNABLE_INT(). This time

around, use a common function for looking up and extracting the tunables
from the kernel environment.  This saves duplicating the same function
over and over again.  This way typically has an overhead of 8 bytes + the
path string, versus about 26 bytes + the path string.
This commit is contained in:
Peter Wemm 2001-06-08 05:24:21 +00:00
parent 7fa34c1180
commit 0978669829
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=77900
14 changed files with 72 additions and 33 deletions

View File

@ -85,9 +85,9 @@ static MALLOC_DEFINE(M_AD, "AD driver", "ATA disk driver");
static int ata_dma = 1;
static int ata_wc = 0;
static int ata_tags = 0;
TUNABLE_INT("hw.ata.ata_dma", ata_dma);
TUNABLE_INT("hw.ata.wc", ata_wc);
TUNABLE_INT("hw.ata.tags", ata_tags);
TUNABLE_INT("hw.ata.ata_dma", &ata_dma);
TUNABLE_INT("hw.ata.wc", &ata_wc);
TUNABLE_INT("hw.ata.tags", &ata_tags);
/* sysctl vars */
SYSCTL_DECL(_hw_ata);

View File

@ -55,7 +55,7 @@ static char *atapi_skey2str(u_int8_t);
/* internal vars */
static MALLOC_DEFINE(M_ATAPI, "ATAPI generic", "ATAPI driver generic layer");
static int atapi_dma = 0;
TUNABLE_INT("hw.ata.atapi_dma", atapi_dma);
TUNABLE_INT("hw.ata.atapi_dma", &atapi_dma);
/* systcl vars */
SYSCTL_DECL(_hw_ata);

View File

@ -93,7 +93,7 @@ static devclass_t pcm_devclass;
#ifdef USING_DEVFS
static int snd_unit = 0;
TUNABLE_INT("hw.snd.unit", snd_unit);
TUNABLE_INT("hw.snd.unit", &snd_unit);
#endif
SYSCTL_NODE(_hw, OID_AUTO, snd, CTLFLAG_RD, 0, "Sound driver");

View File

@ -151,3 +151,18 @@ kernenv_next(char *cp)
return(cp);
}
void
tunable_int_init(void *data)
{
struct tunable_int *d = (struct tunable_int *)data;
TUNABLE_INT_FETCH(d->path, d->var);
}
void
tunable_str_init(void *data)
{
struct tunable_str *d = (struct tunable_str *)data;
TUNABLE_STR_FETCH(d->path, d->var, d->size);
}

View File

@ -88,11 +88,11 @@ int ktr_extend = KTR_EXTEND_DEFAULT;
SYSCTL_INT(_debug_ktr, OID_AUTO, extend, CTLFLAG_RD, &ktr_extend, 0, "");
int ktr_cpumask = KTR_CPUMASK;
TUNABLE_INT("debug.ktr.cpumask", ktr_cpumask);
TUNABLE_INT("debug.ktr.cpumask", &ktr_cpumask);
SYSCTL_INT(_debug_ktr, OID_AUTO, cpumask, CTLFLAG_RW, &ktr_cpumask, 0, "");
int ktr_mask = KTR_MASK;
TUNABLE_INT("debug.ktr.mask", ktr_mask);
TUNABLE_INT("debug.ktr.mask", &ktr_mask);
SYSCTL_INT(_debug_ktr, OID_AUTO, mask, CTLFLAG_RW, &ktr_mask, 0, "");
int ktr_entries = KTR_ENTRIES;
@ -102,7 +102,7 @@ volatile int ktr_idx = 0;
struct ktr_entry ktr_buf[KTR_ENTRIES];
int ktr_verbose = KTR_VERBOSE_DEFAULT;
TUNABLE_INT("debug.ktr.verbose", ktr_verbose);
TUNABLE_INT("debug.ktr.verbose", &ktr_verbose);
SYSCTL_INT(_debug_ktr, OID_AUTO, verbose, CTLFLAG_RW, &ktr_verbose, 0, "");
#ifdef KTR

View File

@ -463,7 +463,7 @@ kmeminit(dummy)
#endif
/* Allow final override from the kernel environment */
TUNABLE_INT_FETCH("kern.vm.kmem.size", vm_kmem_size);
TUNABLE_INT_FETCH("kern.vm.kmem.size", &vm_kmem_size);
/*
* Limit kmem virtual size to twice the physical memory.

View File

@ -145,7 +145,7 @@ static struct lock_instance *find_instance(struct lock_list_entry *lock_list,
MALLOC_DEFINE(M_WITNESS, "witness", "witness structure");
static int witness_watch = 1;
TUNABLE_INT("debug.witness_watch", witness_watch);
TUNABLE_INT("debug.witness_watch", &witness_watch);
SYSCTL_INT(_debug, OID_AUTO, witness_watch, CTLFLAG_RD, &witness_watch, 0, "");
#ifdef DDB
@ -160,7 +160,7 @@ int witness_ddb = 1;
#else
int witness_ddb = 0;
#endif
TUNABLE_INT("debug.witness_ddb", witness_ddb);
TUNABLE_INT("debug.witness_ddb", &witness_ddb);
SYSCTL_INT(_debug, OID_AUTO, witness_ddb, CTLFLAG_RW, &witness_ddb, 0, "");
#endif /* DDB */
@ -169,7 +169,7 @@ int witness_skipspin = 1;
#else
int witness_skipspin = 0;
#endif
TUNABLE_INT("debug.witness_skipspin", witness_skipspin);
TUNABLE_INT("debug.witness_skipspin", &witness_skipspin);
SYSCTL_INT(_debug, OID_AUTO, witness_skipspin, CTLFLAG_RD, &witness_skipspin, 0,
"");

View File

@ -103,9 +103,9 @@ SYSCTL_INT(_kern_ipc, OID_AUTO, nmbufs, CTLFLAG_RD, &nmbufs, 0,
SYSCTL_INT(_kern_ipc, OID_AUTO, nmbcnt, CTLFLAG_RD, &nmbcnt, 0,
"Maximum number of ext_buf counters available");
TUNABLE_INT("kern.ipc.nmbclusters", nmbclusters);
TUNABLE_INT("kern.ipc.nmbufs", nmbufs);
TUNABLE_INT("kern.ipc.nmbcnt", nmbcnt);
TUNABLE_INT("kern.ipc.nmbclusters", &nmbclusters);
TUNABLE_INT("kern.ipc.nmbufs", &nmbufs);
TUNABLE_INT("kern.ipc.nmbcnt", &nmbcnt);
static void m_reclaim(void);

View File

@ -1012,7 +1012,7 @@ SYSCTL_INT(_kern_ipc, KIPC_SOCKBUF_WASTE, sockbuf_waste_factor, CTLFLAG_RW,
*/
static void init_maxsockets(void *ignored)
{
TUNABLE_INT_FETCH("kern.ipc.maxsockets", maxsockets);
TUNABLE_INT_FETCH("kern.ipc.maxsockets", &maxsockets);
maxsockets = imax(maxsockets, imax(maxfiles, nmbclusters));
}
SYSINIT(param, SI_SUB_TUNABLES, SI_ORDER_ANY, init_maxsockets, NULL);

View File

@ -1012,7 +1012,7 @@ SYSCTL_INT(_kern_ipc, KIPC_SOCKBUF_WASTE, sockbuf_waste_factor, CTLFLAG_RW,
*/
static void init_maxsockets(void *ignored)
{
TUNABLE_INT_FETCH("kern.ipc.maxsockets", maxsockets);
TUNABLE_INT_FETCH("kern.ipc.maxsockets", &maxsockets);
maxsockets = imax(maxsockets, imax(maxfiles, nmbclusters));
}
SYSINIT(param, SI_SUB_TUNABLES, SI_ORDER_ANY, init_maxsockets, NULL);

View File

@ -179,7 +179,7 @@ loop_modevent(module_t mod, int type, void *data)
switch (type) {
case MOD_LOAD:
TUNABLE_INT_FETCH("net.nloop", nloop);
TUNABLE_INT_FETCH("net.nloop", &nloop);
if (nloop < 1) /* sanity check */
nloop = 1;
for (i = 0; i < nloop; i++)

View File

@ -194,7 +194,7 @@ tcp_init()
LIST_INIT(&tcb);
tcbinfo.listhead = &tcb;
TUNABLE_INT_FETCH("net.inet.tcp.tcbhashsize", hashsize);
TUNABLE_INT_FETCH("net.inet.tcp.tcbhashsize", &hashsize);
if (!powerof2(hashsize)) {
printf("WARNING: TCB hash size not a power of 2\n");
hashsize = 512; /* safe default */

View File

@ -194,7 +194,7 @@ tcp_init()
LIST_INIT(&tcb);
tcbinfo.listhead = &tcb;
TUNABLE_INT_FETCH("net.inet.tcp.tcbhashsize", hashsize);
TUNABLE_INT_FETCH("net.inet.tcp.tcbhashsize", &hashsize);
if (!powerof2(hashsize)) {
printf("WARNING: TCB hash size not a power of 2\n");
hashsize = 512; /* safe default */

View File

@ -258,24 +258,48 @@ void sysinit_add __P((struct sysinit **set));
* in a SYSINIT function at SI_SUB_TUNABLES with SI_ORDER_LAST.
*/
#define TUNABLE_INT(path, var) \
static void __Tunable_ ## var (void *ignored) \
{ \
TUNABLE_INT_FETCH((path), (var)); \
} \
SYSINIT(__Tunable_init_ ## var, SI_SUB_TUNABLES, SI_ORDER_MIDDLE, __Tunable_ ## var , NULL)
extern void tunable_int_init(void *);
struct tunable_int {
const char *path;
int *var;
};
#define TUNABLE_INT(path, var) \
_TUNABLE_INT((path), (var), __LINE__)
#define _TUNABLE_INT(path, var, line) \
__TUNABLE_INT((path), (var), line)
#define __TUNABLE_INT(path, var, line) \
static struct tunable_int __tunable_int_ ## line = { \
path, \
var, \
}; \
SYSINIT(__Tunable_init_ ## line, SI_SUB_TUNABLES, SI_ORDER_MIDDLE, \
tunable_int_init, &__tunable_int_ ## line)
#define TUNABLE_INT_FETCH(path, var) \
do { \
getenv_int((path), &(var)); \
getenv_int((path), (var)); \
} while (0)
#define TUNABLE_STR(path, var, size) \
static void __Tunable_ ## var (void *ignored) \
{ \
TUNABLE_STR_FETCH((path), (var), (size)); \
} \
SYSINIT(__Tunable_init_ ## var, SI_SUB_TUNABLES, SI_ORDER_MIDDLE, __Tunable_ ## var , NULL)
extern void tunable_str_init(void *);
struct tunable_str {
const char *path;
char *var;
int size;
};
#define TUNABLE_STR(path, var, size) \
_TUNABLE_STR((path), (var), (size), __LINE__)
#define _TUNABLE_STR(path, var, size, line) \
__TUNABLE_STR((path), (var), (size), line)
#define __TUNABLE_STR(path, var, size, line) \
static struct tunable_str __tunable_str_ ## line = { \
path, \
var, \
size, \
}; \
SYSINIT(__Tunable_init_ ## line, SI_SUB_TUNABLES, SI_ORDER_MIDDLE, \
tunable_str_init, &__tunable_str_ ## line)
#define TUNABLE_STR_FETCH(path, var, size) \
do { \