diff options
-rw-r--r-- | sys/kern/kern_sysctl.c | 7 | ||||
-rw-r--r-- | sys/kern/subr_pool.c | 79 | ||||
-rw-r--r-- | sys/sys/pool.h | 13 | ||||
-rw-r--r-- | sys/sys/sysctl.h | 7 |
4 files changed, 91 insertions, 15 deletions
diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index 8f024c25692..3c026c2b7bc 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sysctl.c,v 1.50 2001/06/22 21:32:58 mickey Exp $ */ +/* $OpenBSD: kern_sysctl.c,v 1.51 2001/06/24 16:00:47 art Exp $ */ /* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */ /*- @@ -259,7 +259,8 @@ kern_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p) /* all sysctl names at this level are terminal */ if (namelen != 1 && !(name[0] == KERN_PROC || name[0] == KERN_PROF || - name[0] == KERN_MALLOCSTATS || name[0] == KERN_TTY)) + name[0] == KERN_MALLOCSTATS || name[0] == KERN_TTY || + name[0] == KERN_POOL)) return (ENOTDIR); /* overloaded */ switch (name[0]) { @@ -412,6 +413,8 @@ kern_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p) return (sysctl_rdint(oldp, oldlenp, newp, ccpu)); case KERN_NPROCS: return (sysctl_rdint(oldp, oldlenp, newp, nprocs)); + case KERN_POOL: + return (sysctl_dopool(name + 1, namelen - 1, oldp, oldlenp)); default: return (EOPNOTSUPP); } diff --git a/sys/kern/subr_pool.c b/sys/kern/subr_pool.c index 114c0e49cd5..66a9aea22f0 100644 --- a/sys/kern/subr_pool.c +++ b/sys/kern/subr_pool.c @@ -1,4 +1,4 @@ -/* $OpenBSD: subr_pool.c,v 1.7 2001/06/23 17:15:46 art Exp $ */ +/* $OpenBSD: subr_pool.c,v 1.8 2001/06/24 16:00:47 art Exp $ */ /* $NetBSD: subr_pool.c,v 1.59 2001/06/05 18:51:04 thorpej Exp $ */ /*- @@ -123,6 +123,12 @@ struct pool_item { ((pp)->pr_nitems < (pp)->pr_minitems) /* + * Every pool get a unique serial number assigned to it. If this counter + * wraps, we're screwed, but we shouldn't create so many pools anyway. + */ +unsigned int pool_serial; + +/* * Pool cache management. * * Pool caches provide a way for constructed objects to be cached by the @@ -444,6 +450,9 @@ pool_init(struct pool *pp, size_t size, u_int align, u_int ioff, int flags, pp->pr_hardlimit_ratecap.tv_usec = 0; pp->pr_hardlimit_warning_last.tv_sec = 0; pp->pr_hardlimit_warning_last.tv_usec = 0; + pp->pr_serial = ++pool_serial; + if (pool_serial == 0) + panic("pool_init: too much uptime"); /* * Decide whether to put the page header off page to avoid @@ -1836,20 +1845,70 @@ pool_cache_reclaim(struct pool_cache *pc) simple_unlock(&pc->pc_slock); } -#ifdef notyet +/* + * We have three different sysctls. + * kern.pool.npools - the number of pools. + * kern.pool.pool.<pool#> - the pool struct for the pool#. + * kern.pool.name.<pool#> - the name for pool#.[6~ + */ int sysctl_dopool(int *name, u_int namelen, char *where, size_t *sizep) { - struct pool *pp; + struct pool *pp, *foundpool = NULL; size_t buflen = where != NULL ? *sizep : 0; - int s; - - if (namelen != 0) - return (ENOTDIR); + int npools = 0, s; + unsigned int lookfor; + size_t len; + + switch (*name) { + case KERN_POOL_NPOOLS: + if (namelen != 1 || buflen != sizeof(int)) + return (EINVAL); + lookfor = 0; + break; + case KERN_POOL_NAME: + if (namelen != 2 || buflen < 1) + return (EINVAL); + lookfor = name[1]; + break; + case KERN_POOL_POOL: + if (namelen != 2 || buflen != sizeof(struct pool)) + return (EINVAL); + lookfor = name[1]; + break; + default: + return (EINVAL); + } - s = splimp(); + s = splvm(); simple_lock(&pool_head_slock); - for (pp = pool_head; pp != NULL; pp = TAILQ_NEXT(pp, pr_poollist)) + TAILQ_FOREACH(pp, &pool_head, pr_poollist) { + npools++; + if (lookfor == pp->pr_serial) { + foundpool = pp; + break; + } + } + + simple_unlock(&pool_head_slock); + splx(s); + + if (lookfor != 0 && foundpool == NULL) + return (ENOENT); + + switch (*name) { + case KERN_POOL_NPOOLS: + return copyout(&npools, where, buflen); + case KERN_POOL_NAME: + len = strlen(foundpool->pr_wchan) + 1; + if (*sizep < len) + return (ENOMEM); + *sizep = len; + return copyout(foundpool->pr_wchan, where, len); + case KERN_POOL_POOL: + return copyout(foundpool, where, buflen); + } + /* NOTREACHED */ + return (0); /* XXX - Stupid gcc */ } -#endif
\ No newline at end of file diff --git a/sys/sys/pool.h b/sys/sys/pool.h index 61432ece692..dcd618f6224 100644 --- a/sys/sys/pool.h +++ b/sys/sys/pool.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pool.h,v 1.3 2001/06/23 16:13:01 art Exp $ */ +/* $OpenBSD: pool.h,v 1.4 2001/06/24 16:00:46 art Exp $ */ /* $NetBSD: pool.h,v 1.27 2001/06/06 22:00:17 rafal Exp $ */ /*- @@ -41,6 +41,16 @@ #ifndef _SYS_POOL_H_ #define _SYS_POOL_H_ +/* + * sysctls. + * kern.pool.npools + * kern.pool.name.<number> + * kern.pool.pool.<number> + */ +#define KERN_POOL_NPOOLS 1 +#define KERN_POOL_NAME 2 +#define KERN_POOL_POOL 3 + #ifdef _KERNEL #define __POOL_EXPOSE #endif @@ -107,6 +117,7 @@ struct pool { unsigned int pr_nout; /* # items currently allocated */ unsigned int pr_hardlimit; /* hard limit to number of allocated items */ + unsigned int pr_serial; /* unique serial number of the pool */ void *(*pr_alloc)(unsigned long, int, int); void (*pr_free)(void *, unsigned long, int); int pr_mtype; /* memory allocator tag */ diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h index 258081efb99..6b29ad1bc98 100644 --- a/sys/sys/sysctl.h +++ b/sys/sys/sysctl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sysctl.h,v 1.40 2001/06/22 21:32:59 mickey Exp $ */ +/* $OpenBSD: sysctl.h,v 1.41 2001/06/24 16:00:45 art Exp $ */ /* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */ /* @@ -162,7 +162,8 @@ struct ctlname { #define KERN_FSCALE 46 /* int: fscale */ #define KERN_NPROCS 47 /* int: number of processes */ #define KERN_MSGBUF 48 /* message buffer, KERN_MSGBUFSIZE */ -#define KERN_MAXID 49 /* number of valid kern ids */ +#define KERN_POOL 49 /* struct: pool information */ +#define KERN_MAXID 50 /* number of valid kern ids */ #define CTL_KERN_NAMES { \ { 0, 0 }, \ @@ -214,6 +215,7 @@ struct ctlname { { "fscale", CTLTYPE_INT }, \ { "nprocs", CTLTYPE_INT }, \ { "msgbuf", CTLTYPE_STRUCT }, \ + { "pool", CTLTYPE_NODE }, \ } /* @@ -432,6 +434,7 @@ int sysctl_ntptime __P((char *, size_t *)); #ifdef GPROF int sysctl_doprof __P((int *, u_int, void *, size_t *, void *, size_t)); #endif +int sysctl_dopool __P((int *, u_int, char *, size_t *)); void fill_eproc __P((struct proc *, struct eproc *)); |