1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-12 09:58:36 +00:00

"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_dma = 1;
static int ata_wc = 0; static int ata_wc = 0;
static int ata_tags = 0; static int ata_tags = 0;
TUNABLE_INT("hw.ata.ata_dma", ata_dma); TUNABLE_INT("hw.ata.ata_dma", &ata_dma);
TUNABLE_INT("hw.ata.wc", ata_wc); TUNABLE_INT("hw.ata.wc", &ata_wc);
TUNABLE_INT("hw.ata.tags", ata_tags); TUNABLE_INT("hw.ata.tags", &ata_tags);
/* sysctl vars */ /* sysctl vars */
SYSCTL_DECL(_hw_ata); SYSCTL_DECL(_hw_ata);

View File

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

View File

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

View File

@ -151,3 +151,18 @@ kernenv_next(char *cp)
return(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, ""); SYSCTL_INT(_debug_ktr, OID_AUTO, extend, CTLFLAG_RD, &ktr_extend, 0, "");
int ktr_cpumask = KTR_CPUMASK; 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, ""); SYSCTL_INT(_debug_ktr, OID_AUTO, cpumask, CTLFLAG_RW, &ktr_cpumask, 0, "");
int ktr_mask = KTR_MASK; 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, ""); SYSCTL_INT(_debug_ktr, OID_AUTO, mask, CTLFLAG_RW, &ktr_mask, 0, "");
int ktr_entries = KTR_ENTRIES; int ktr_entries = KTR_ENTRIES;
@ -102,7 +102,7 @@ volatile int ktr_idx = 0;
struct ktr_entry ktr_buf[KTR_ENTRIES]; struct ktr_entry ktr_buf[KTR_ENTRIES];
int ktr_verbose = KTR_VERBOSE_DEFAULT; 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, ""); SYSCTL_INT(_debug_ktr, OID_AUTO, verbose, CTLFLAG_RW, &ktr_verbose, 0, "");
#ifdef KTR #ifdef KTR

View File

@ -463,7 +463,7 @@ kmeminit(dummy)
#endif #endif
/* Allow final override from the kernel environment */ /* 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. * 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"); MALLOC_DEFINE(M_WITNESS, "witness", "witness structure");
static int witness_watch = 1; 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, ""); SYSCTL_INT(_debug, OID_AUTO, witness_watch, CTLFLAG_RD, &witness_watch, 0, "");
#ifdef DDB #ifdef DDB
@ -160,7 +160,7 @@ int witness_ddb = 1;
#else #else
int witness_ddb = 0; int witness_ddb = 0;
#endif #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, ""); SYSCTL_INT(_debug, OID_AUTO, witness_ddb, CTLFLAG_RW, &witness_ddb, 0, "");
#endif /* DDB */ #endif /* DDB */
@ -169,7 +169,7 @@ int witness_skipspin = 1;
#else #else
int witness_skipspin = 0; int witness_skipspin = 0;
#endif #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, 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, SYSCTL_INT(_kern_ipc, OID_AUTO, nmbcnt, CTLFLAG_RD, &nmbcnt, 0,
"Maximum number of ext_buf counters available"); "Maximum number of ext_buf counters available");
TUNABLE_INT("kern.ipc.nmbclusters", nmbclusters); TUNABLE_INT("kern.ipc.nmbclusters", &nmbclusters);
TUNABLE_INT("kern.ipc.nmbufs", nmbufs); TUNABLE_INT("kern.ipc.nmbufs", &nmbufs);
TUNABLE_INT("kern.ipc.nmbcnt", nmbcnt); TUNABLE_INT("kern.ipc.nmbcnt", &nmbcnt);
static void m_reclaim(void); 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) 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)); maxsockets = imax(maxsockets, imax(maxfiles, nmbclusters));
} }
SYSINIT(param, SI_SUB_TUNABLES, SI_ORDER_ANY, init_maxsockets, NULL); 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) 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)); maxsockets = imax(maxsockets, imax(maxfiles, nmbclusters));
} }
SYSINIT(param, SI_SUB_TUNABLES, SI_ORDER_ANY, init_maxsockets, NULL); 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) { switch (type) {
case MOD_LOAD: case MOD_LOAD:
TUNABLE_INT_FETCH("net.nloop", nloop); TUNABLE_INT_FETCH("net.nloop", &nloop);
if (nloop < 1) /* sanity check */ if (nloop < 1) /* sanity check */
nloop = 1; nloop = 1;
for (i = 0; i < nloop; i++) for (i = 0; i < nloop; i++)

View File

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

View File

@ -194,7 +194,7 @@ tcp_init()
LIST_INIT(&tcb); LIST_INIT(&tcb);
tcbinfo.listhead = &tcb; tcbinfo.listhead = &tcb;
TUNABLE_INT_FETCH("net.inet.tcp.tcbhashsize", hashsize); TUNABLE_INT_FETCH("net.inet.tcp.tcbhashsize", &hashsize);
if (!powerof2(hashsize)) { if (!powerof2(hashsize)) {
printf("WARNING: TCB hash size not a power of 2\n"); printf("WARNING: TCB hash size not a power of 2\n");
hashsize = 512; /* safe default */ 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. * in a SYSINIT function at SI_SUB_TUNABLES with SI_ORDER_LAST.
*/ */
#define TUNABLE_INT(path, var) \ extern void tunable_int_init(void *);
static void __Tunable_ ## var (void *ignored) \ struct tunable_int {
{ \ const char *path;
TUNABLE_INT_FETCH((path), (var)); \ int *var;
} \ };
SYSINIT(__Tunable_init_ ## var, SI_SUB_TUNABLES, SI_ORDER_MIDDLE, __Tunable_ ## var , NULL) #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) \ #define TUNABLE_INT_FETCH(path, var) \
do { \ do { \
getenv_int((path), &(var)); \ getenv_int((path), (var)); \
} while (0) } while (0)
#define TUNABLE_STR(path, var, size) \ extern void tunable_str_init(void *);
static void __Tunable_ ## var (void *ignored) \ struct tunable_str {
{ \ const char *path;
TUNABLE_STR_FETCH((path), (var), (size)); \ char *var;
} \ int size;
SYSINIT(__Tunable_init_ ## var, SI_SUB_TUNABLES, SI_ORDER_MIDDLE, __Tunable_ ## var , NULL) };
#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) \ #define TUNABLE_STR_FETCH(path, var, size) \
do { \ do { \