Date: Tue, 5 Jan 2010 07:36:02 +0000 (UTC) From: Kip Macy <kmacy@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r201564 - in user/kmacy/releng_8_rump/lib/libunet: . include/opt include/sys Message-ID: <201001050736.o057a2w6027935@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kmacy Date: Tue Jan 5 07:36:02 2010 New Revision: 201564 URL: http://svn.freebsd.org/changeset/base/201564 Log: shim mutexes, rwlocks, and rmlocks Added: user/kmacy/releng_8_rump/lib/libunet/include/opt/opt_mprof.h (contents, props changed) user/kmacy/releng_8_rump/lib/libunet/include/sys/_rwlock.h (contents, props changed) Modified: user/kmacy/releng_8_rump/lib/libunet/Makefile user/kmacy/releng_8_rump/lib/libunet/unet_glue.c user/kmacy/releng_8_rump/lib/libunet/unet_lock.c Modified: user/kmacy/releng_8_rump/lib/libunet/Makefile ============================================================================== --- user/kmacy/releng_8_rump/lib/libunet/Makefile Tue Jan 5 06:58:54 2010 (r201563) +++ user/kmacy/releng_8_rump/lib/libunet/Makefile Tue Jan 5 07:36:02 2010 (r201564) @@ -17,6 +17,7 @@ UNET_KERN_COMMON_OBJS += \ kern_sysctl.o \ md5c.o \ subr_eventhandler.o \ + subr_lock.o \ subr_param.o \ subr_pcpu.o \ subr_sbuf.o \ @@ -120,6 +121,7 @@ CFLAGS+= -I./include/opt CFLAGS+= -I${PREFIX} CFLAGS+= -D_KERNEL CFLAGS+= -DMUTEX_NOINLINE +CFLAGS+= -DRWLOCK_NOINLINE CFLAGS+= -DUNET CFLAGS+= -DMAXUSERS=32 CFLAGS+= -fno-builtin Added: user/kmacy/releng_8_rump/lib/libunet/include/opt/opt_mprof.h ============================================================================== Added: user/kmacy/releng_8_rump/lib/libunet/include/sys/_rwlock.h ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ user/kmacy/releng_8_rump/lib/libunet/include/sys/_rwlock.h Tue Jan 5 07:36:02 2010 (r201564) @@ -0,0 +1,43 @@ +/*- + * Copyright (c) 2006 John Baldwin <jhb@FreeBSD.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS__RWLOCK_H_ +#define _SYS__RWLOCK_H_ + +/* + * Reader/writer lock. + */ +struct rwlock { + struct lock_object lock_object; + pthread_rwlock_t rw_lock; +}; + +#endif /* !_SYS__RWLOCK_H_ */ Modified: user/kmacy/releng_8_rump/lib/libunet/unet_glue.c ============================================================================== --- user/kmacy/releng_8_rump/lib/libunet/unet_glue.c Tue Jan 5 06:58:54 2010 (r201563) +++ user/kmacy/releng_8_rump/lib/libunet/unet_glue.c Tue Jan 5 07:36:02 2010 (r201564) @@ -67,7 +67,6 @@ struct filterops fs_filtops; struct filterops sig_filtops; int cold; -struct mtx Giant; static void timevalfix(struct timeval *); Modified: user/kmacy/releng_8_rump/lib/libunet/unet_lock.c ============================================================================== --- user/kmacy/releng_8_rump/lib/libunet/unet_lock.c Tue Jan 5 06:58:54 2010 (r201563) +++ user/kmacy/releng_8_rump/lib/libunet/unet_lock.c Tue Jan 5 07:36:02 2010 (r201564) @@ -1,3 +1,5 @@ + + #include <sys/param.h> #include <sys/systm.h> #include <sys/bus.h> @@ -20,89 +22,94 @@ #include <sys/vmmeter.h> #include <sys/lock_profile.h> +#include <pthread.h> +struct mtx Giant; -void -mtx_init(struct mtx *m, const char *name, const char *type, int opts) -{ - - panic(""); -} -void -mtx_destroy(struct mtx *m) +static void +assert_mtx(struct lock_object *lock, int what) { - panic(""); + mtx_assert((struct mtx *)lock, what); } -void -mtx_sysinit(void *arg) -{ - - panic(""); -} +/* + * Lock classes for sleep and spin mutexes. + */ +struct lock_class lock_class_mtx_sleep = { + .lc_name = "sleep mutex", + .lc_flags = LC_SLEEPLOCK | LC_RECURSABLE, + .lc_assert = assert_mtx, +#ifdef DDB + .lc_ddb_show = db_show_mtx, +#endif +#ifdef KDTRACE_HOOKS + .lc_owner = owner_mtx, +#endif +}; void -_mtx_lock_flags(struct mtx *m, int opts, const char *file, int line) +mtx_init(struct mtx *m, const char *name, const char *type, int opts) { + pthread_mutexattr_t attr; - panic(""); + lock_init(&m->lock_object, &lock_class_mtx_sleep, name, type, opts); + pthread_mutexattr_init(&attr); + pthread_mutex_init(&m->lock_object.lo_mutex, &attr); } void -_mtx_unlock_flags(struct mtx *m, int opts, const char *file, int line) +mtx_destroy(struct mtx *m) { - panic(""); -} - - - -void -rm_init_flags(struct rmlock *rm, const char *name, int opts) -{ - - panic(""); + pthread_mutex_destroy(&m->lock_object.lo_mutex); } void -rm_destroy(struct rmlock *rm) +mtx_sysinit(void *arg) { + struct mtx_args *margs = arg; - panic(""); + mtx_init(margs->ma_mtx, margs->ma_desc, NULL, margs->ma_opts); } void -_rm_wlock(struct rmlock *rm) +_mtx_lock_flags(struct mtx *m, int opts, const char *file, int line) { - panic(""); + pthread_mutex_lock(&m->lock_object.lo_mutex); } void -_rm_wunlock(struct rmlock *rm) +_mtx_unlock_flags(struct mtx *m, int opts, const char *file, int line) { - panic(""); + pthread_mutex_unlock(&m->lock_object.lo_mutex); } -void -_rm_rlock(struct rmlock *rm, struct rm_priotracker *tracker) -{ - panic(""); -} + void -_rm_runlock(struct rmlock *rm, struct rm_priotracker *tracker) +assert_rw(struct lock_object *lock, int what) { - panic(""); + rw_assert((struct rwlock *)lock, what); } +struct lock_class lock_class_rw = { + .lc_name = "rw", + .lc_flags = LC_SLEEPLOCK | LC_RECURSABLE | LC_UPGRADABLE, + .lc_assert = assert_rw, +#ifdef DDB + .lc_ddb_show = db_show_rwlock, +#endif - +#ifdef KDTRACE_HOOKS + .lc_owner = owner_rw, +#endif +}; void rw_sysinit(void *arg) { @@ -113,90 +120,160 @@ rw_sysinit(void *arg) void rw_init_flags(struct rwlock *rw, const char *name, int opts) { + pthread_rwlockattr_t attr; + int flags; - panic(""); + MPASS((opts & ~(RW_DUPOK | RW_NOPROFILE | RW_NOWITNESS | RW_QUIET | + RW_RECURSE)) == 0); + ASSERT_ATOMIC_LOAD_PTR(rw->rw_lock, + ("%s: rw_lock not aligned for %s: %p", __func__, name, + &rw->rw_lock)); + + flags = LO_UPGRADABLE; + if (opts & RW_DUPOK) + flags |= LO_DUPOK; + if (opts & RW_NOPROFILE) + flags |= LO_NOPROFILE; + if (!(opts & RW_NOWITNESS)) + flags |= LO_WITNESS; + if (opts & RW_RECURSE) + flags |= LO_RECURSABLE; + if (opts & RW_QUIET) + flags |= LO_QUIET; + + lock_init(&rw->lock_object, &lock_class_rw, name, NULL, flags); + pthread_rwlockattr_init(&attr); + pthread_rwlock_init(&rw->rw_lock, &attr); } + void rw_destroy(struct rwlock *rw) { - panic(""); + pthread_rwlock_destroy(&rw->rw_lock); } void _rw_wlock(struct rwlock *rw, const char *file, int line) { - panic(""); + pthread_rwlock_wrlock(&rw->rw_lock); } int _rw_try_wlock(struct rwlock *rw, const char *file, int line) { - panic(""); - return (0); + return (pthread_rwlock_trywrlock(&rw->rw_lock)); } void _rw_wunlock(struct rwlock *rw, const char *file, int line) { - panic(""); + pthread_rwlock_unlock(&rw->rw_lock); } void _rw_rlock(struct rwlock *rw, const char *file, int line) { - panic(""); + pthread_rwlock_rdlock(&rw->rw_lock); } int _rw_try_rlock(struct rwlock *rw, const char *file, int line) { - panic(""); - return (0); + pthread_rwlock_tryrdlock(&rw->rw_lock); + } void _rw_runlock(struct rwlock *rw, const char *file, int line) { - panic(""); + pthread_rwlock_unlock(&rw->rw_lock); } -void -_rw_wlock_hard(struct rwlock *rw, uintptr_t tid, const char *file, - int line) +int +_rw_try_upgrade(struct rwlock *rw, const char *file, int line) { - panic(""); + return (0); } void -_rw_wunlock_hard(struct rwlock *rw, uintptr_t tid, const char *file, - int line) +_rw_downgrade(struct rwlock *rw, const char *file, int line) { panic(""); } -int -_rw_try_upgrade(struct rwlock *rw, const char *file, int line) + + +static void +assert_rm(struct lock_object *lock, int what) { - - panic(""); - return (0); + + panic("assert_rm called"); } +struct lock_class lock_class_rm = { + .lc_name = "rm", + .lc_flags = LC_SLEEPLOCK | LC_RECURSABLE, + .lc_assert = assert_rm, +#if 0 +#ifdef DDB + .lc_ddb_show = db_show_rwlock, +#endif +#endif +#ifdef KDTRACE_HOOKS + .lc_owner = owner_rm, +#endif +}; + void -_rw_downgrade(struct rwlock *rw, const char *file, int line) +rm_init_flags(struct rmlock *rm, const char *name, int opts) { - - panic(""); + + rw_init_flags((struct rwlock *)rm, name, opts); +} + +void +rm_destroy(struct rmlock *rm) +{ + + rw_destroy((struct rwlock *)rm); +} + +void +_rm_wlock(struct rmlock *rm) +{ + + _rw_wlock((struct rwlock *)rm, __FILE__, __LINE__); +} + +void +_rm_wunlock(struct rmlock *rm) +{ + + _rw_wunlock((struct rwlock *)rm, __FILE__, __LINE__); +} + +void +_rm_rlock(struct rmlock *rm, struct rm_priotracker *tracker) +{ + + _rw_rlock((struct rwlock *)rm, __FILE__, __LINE__); +} + +void +_rm_runlock(struct rmlock *rm, struct rm_priotracker *tracker) +{ + + _rw_runlock((struct rwlock *)rm, __FILE__, __LINE__); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201001050736.o057a2w6027935>