From b75f351b8367eb21aa1051ac2f3d9f06a9afa6c7 Mon Sep 17 00:00:00 2001 From: kib Date: Sat, 5 Jun 2010 14:53:34 +0000 Subject: [PATCH] MFC r208731: Add a facility to dynamically adjust or unconfigure p1003_1b mib. Use it to allow to tune sem_nsem_max at runtime, only when sem.ko module is present in kernel. Approved by: re (bz) git-svn-id: svn://svn.freebsd.org/base/stable/8@208832 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- sys/kern/posix4_mib.c | 40 +++++++++++++++++++++++++++++++++++----- sys/kern/uipc_sem.c | 2 ++ sys/sys/posix4.h | 1 + 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/sys/kern/posix4_mib.c b/sys/kern/posix4_mib.c index 5242b316e..cbe140df6 100644 --- a/sys/kern/posix4_mib.c +++ b/sys/kern/posix4_mib.c @@ -45,6 +45,8 @@ __FBSDID("$FreeBSD$"); static int facility[CTL_P1003_1B_MAXID - 1]; static int facility_initialized[CTL_P1003_1B_MAXID - 1]; +static int p31b_sysctl_proc(SYSCTL_HANDLER_ARGS); + /* OID_AUTO isn't working with sysconf(3). I guess I'd have to * modify it to do a lookup by name from the index. * For now I've left it a top-level sysctl. @@ -55,16 +57,21 @@ static int facility_initialized[CTL_P1003_1B_MAXID - 1]; SYSCTL_DECL(_p1003_1b); #define P1B_SYSCTL(num, name) \ -SYSCTL_INT(_p1003_1b, num, \ - name, CTLFLAG_RD, facility + num - 1, 0, ""); + SYSCTL_INT(_p1003_1b, num, name, CTLFLAG_RD, facility + num - 1, 0, ""); +#define P1B_SYSCTL_RW(num, name) \ + SYSCTL_PROC(_p1003_1b, num, name, CTLTYPE_INT | CTLFLAG_RW, NULL, num, \ + p31b_sysctl_proc, "I", ""); #else SYSCTL_DECL(_kern_p1003_1b); #define P1B_SYSCTL(num, name) \ -SYSCTL_INT(_kern_p1003_1b, OID_AUTO, \ - name, CTLFLAG_RD, facility + num - 1, 0, ""); + SYSCTL_INT(_kern_p1003_1b, OID_AUTO, name, CTLFLAG_RD, \ + facility + num - 1, 0, ""); +#define P1B_SYSCTL_RW(num, name) \ + SYSCTL_PROC(_p1003_1b, OID_AUTO, name, CTLTYPE_INT | CTLFLAG_RW, NULL, \ + num, p31b_sysctl_proc, "I", ""); SYSCTL_NODE(_kern, OID_AUTO, p1003_1b, CTLFLAG_RW, 0, "P1003.1B"); #endif @@ -91,13 +98,28 @@ P1B_SYSCTL(CTL_P1003_1B_DELAYTIMER_MAX, delaytimer_max); P1B_SYSCTL(CTL_P1003_1B_MQ_OPEN_MAX, mq_open_max); P1B_SYSCTL(CTL_P1003_1B_PAGESIZE, pagesize); P1B_SYSCTL(CTL_P1003_1B_RTSIG_MAX, rtsig_max); -P1B_SYSCTL(CTL_P1003_1B_SEM_NSEMS_MAX, sem_nsems_max); +P1B_SYSCTL_RW(CTL_P1003_1B_SEM_NSEMS_MAX, sem_nsems_max); P1B_SYSCTL(CTL_P1003_1B_SEM_VALUE_MAX, sem_value_max); P1B_SYSCTL(CTL_P1003_1B_SIGQUEUE_MAX, sigqueue_max); P1B_SYSCTL(CTL_P1003_1B_TIMER_MAX, timer_max); #define P31B_VALID(num) ((num) >= 1 && (num) < CTL_P1003_1B_MAXID) +static int +p31b_sysctl_proc(SYSCTL_HANDLER_ARGS) +{ + int error, num, val; + + num = arg2; + if (!P31B_VALID(num)) + return (EINVAL); + val = facility_initialized[num] ? facility[num - 1] : 0; + error = sysctl_handle_int(oidp, &val, 0, req); + if (error == 0 && req->newptr != NULL && facility_initialized[num]) + facility[num - 1] = val; + return (error); +} + /* p31b_setcfg: Set the configuration */ void @@ -110,6 +132,14 @@ p31b_setcfg(int num, int value) } } +void +p31b_unsetcfg(int num) +{ + + facility[num - 1] = 0; + facility_initialized[num -1] = 0; +} + int p31b_getcfg(int num) { diff --git a/sys/kern/uipc_sem.c b/sys/kern/uipc_sem.c index 0aee3f741..a1f80c16f 100644 --- a/sys/kern/uipc_sem.c +++ b/sys/kern/uipc_sem.c @@ -977,6 +977,8 @@ ksem_module_destroy(void) sx_destroy(&ksem_dict_lock); mtx_destroy(&ksem_count_lock); mtx_destroy(&sem_lock); + p31b_unsetcfg(CTL_P1003_1B_SEM_VALUE_MAX); + p31b_unsetcfg(CTL_P1003_1B_SEM_NSEMS_MAX); } static int diff --git a/sys/sys/posix4.h b/sys/sys/posix4.h index ea379c0be..34f77f43c 100644 --- a/sys/sys/posix4.h +++ b/sys/sys/posix4.h @@ -64,6 +64,7 @@ int p31b_proc(struct proc *, pid_t, struct proc **); void p31b_setcfg(int, int); int p31b_getcfg(int); int p31b_iscfg(int); +void p31b_unsetcfg(int); #ifdef _KPOSIX_PRIORITY_SCHEDULING -- 2.45.0