From owner-svn-src-projects@FreeBSD.ORG Tue Sep 28 12:51:19 2010 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 724891065672; Tue, 28 Sep 2010 12:51:19 +0000 (UTC) (envelope-from attilio@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 5E8CE8FC22; Tue, 28 Sep 2010 12:51:19 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o8SCpIiI074877; Tue, 28 Sep 2010 12:51:18 GMT (envelope-from attilio@svn.freebsd.org) Received: (from attilio@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o8SCpHvC074866; Tue, 28 Sep 2010 12:51:17 GMT (envelope-from attilio@svn.freebsd.org) Message-Id: <201009281251.o8SCpHvC074866@svn.freebsd.org> From: Attilio Rao Date: Tue, 28 Sep 2010 12:51:17 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r213247 - in projects/sv: contrib/top include lib/libstand lib/libthr/thread sbin/geom/class/part share/mk sys/compat/linprocfs sys/conf sys/dev/e1000 sys/dev/gpio sys/kern sys/mips/ath... X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Sep 2010 12:51:19 -0000 Author: attilio Date: Tue Sep 28 12:51:17 2010 New Revision: 213247 URL: http://svn.freebsd.org/changeset/base/213247 Log: MFC @ 213246 Added: projects/sv/sys/dev/gpio/ - copied from r213246, head/sys/dev/gpio/ projects/sv/sys/mips/atheros/ar71xx_gpio.c - copied unchanged from r213246, head/sys/mips/atheros/ar71xx_gpio.c projects/sv/sys/mips/atheros/ar71xx_gpiovar.h - copied unchanged from r213246, head/sys/mips/atheros/ar71xx_gpiovar.h projects/sv/sys/sys/gpio.h - copied unchanged from r213246, head/sys/sys/gpio.h projects/sv/usr.sbin/gpioctl/ - copied from r213246, head/usr.sbin/gpioctl/ Modified: projects/sv/include/pthread.h projects/sv/lib/libstand/net.h projects/sv/lib/libthr/thread/thr_cond.c projects/sv/lib/libthr/thread/thr_init.c projects/sv/lib/libthr/thread/thr_mutex.c projects/sv/lib/libthr/thread/thr_private.h projects/sv/lib/libthr/thread/thr_rwlock.c projects/sv/sbin/geom/class/part/gpart.8 projects/sv/sys/compat/linprocfs/linprocfs.c projects/sv/sys/conf/files projects/sv/sys/dev/e1000/e1000_82571.c projects/sv/sys/dev/e1000/e1000_82571.h projects/sv/sys/dev/e1000/e1000_82575.c projects/sv/sys/dev/e1000/e1000_82575.h projects/sv/sys/dev/e1000/e1000_api.c projects/sv/sys/dev/e1000/e1000_api.h projects/sv/sys/dev/e1000/e1000_defines.h projects/sv/sys/dev/e1000/e1000_hw.h projects/sv/sys/dev/e1000/e1000_ich8lan.c projects/sv/sys/dev/e1000/e1000_ich8lan.h projects/sv/sys/dev/e1000/e1000_mac.c projects/sv/sys/dev/e1000/e1000_nvm.c projects/sv/sys/dev/e1000/e1000_nvm.h projects/sv/sys/dev/e1000/e1000_phy.c projects/sv/sys/dev/e1000/e1000_phy.h projects/sv/sys/dev/e1000/e1000_regs.h projects/sv/sys/dev/e1000/if_em.c projects/sv/sys/dev/e1000/if_em.h projects/sv/sys/dev/e1000/if_igb.c projects/sv/sys/dev/e1000/if_igb.h projects/sv/sys/dev/e1000/if_lem.c projects/sv/sys/kern/subr_trap.c projects/sv/sys/mips/atheros/ar71xxreg.h projects/sv/sys/mips/atheros/files.ar71xx projects/sv/sys/mips/conf/AR71XX projects/sv/sys/mips/conf/AR71XX.hints projects/sv/usr.sbin/Makefile Directory Properties: projects/sv/ (props changed) projects/sv/cddl/contrib/opensolaris/ (props changed) projects/sv/contrib/bind9/ (props changed) projects/sv/contrib/ee/ (props changed) projects/sv/contrib/expat/ (props changed) projects/sv/contrib/file/ (props changed) projects/sv/contrib/gdb/ (props changed) projects/sv/contrib/gdtoa/ (props changed) projects/sv/contrib/gnu-sort/ (props changed) projects/sv/contrib/groff/ (props changed) projects/sv/contrib/less/ (props changed) projects/sv/contrib/libpcap/ (props changed) projects/sv/contrib/llvm/ (props changed) projects/sv/contrib/llvm/tools/clang/ (props changed) projects/sv/contrib/ncurses/ (props changed) projects/sv/contrib/netcat/ (props changed) projects/sv/contrib/ntp/ (props changed) projects/sv/contrib/one-true-awk/ (props changed) projects/sv/contrib/openbsm/ (props changed) projects/sv/contrib/openpam/ (props changed) projects/sv/contrib/pf/ (props changed) projects/sv/contrib/sendmail/ (props changed) projects/sv/contrib/tcpdump/ (props changed) projects/sv/contrib/tcsh/ (props changed) projects/sv/contrib/top/ (props changed) projects/sv/contrib/top/install-sh (props changed) projects/sv/contrib/tzcode/stdtime/ (props changed) projects/sv/contrib/tzcode/zic/ (props changed) projects/sv/contrib/tzdata/ (props changed) projects/sv/contrib/wpa/ (props changed) projects/sv/crypto/openssh/ (props changed) projects/sv/crypto/openssl/ (props changed) projects/sv/lib/libc/ (props changed) projects/sv/lib/libc/stdtime/ (props changed) projects/sv/lib/libutil/ (props changed) projects/sv/lib/libz/ (props changed) projects/sv/sbin/ (props changed) projects/sv/sbin/ipfw/ (props changed) projects/sv/share/mk/bsd.arch.inc.mk (props changed) projects/sv/share/zoneinfo/ (props changed) projects/sv/sys/ (props changed) projects/sv/sys/amd64/include/xen/ (props changed) projects/sv/sys/cddl/contrib/opensolaris/ (props changed) projects/sv/sys/contrib/dev/acpica/ (props changed) projects/sv/sys/contrib/pf/ (props changed) projects/sv/sys/contrib/x86emu/ (props changed) projects/sv/sys/dev/xen/xenpci/ (props changed) projects/sv/usr.bin/calendar/ (props changed) projects/sv/usr.bin/csup/ (props changed) projects/sv/usr.bin/procstat/ (props changed) projects/sv/usr.sbin/zic/ (props changed) Modified: projects/sv/include/pthread.h ============================================================================== --- projects/sv/include/pthread.h Tue Sep 28 11:32:17 2010 (r213246) +++ projects/sv/include/pthread.h Tue Sep 28 12:51:17 2010 (r213247) @@ -98,7 +98,7 @@ * Static initialization values. */ #define PTHREAD_MUTEX_INITIALIZER NULL -#define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP NULL +#define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP ((pthread_mutex_t)1) #define PTHREAD_COND_INITIALIZER NULL #define PTHREAD_RWLOCK_INITIALIZER NULL Modified: projects/sv/lib/libstand/net.h ============================================================================== --- projects/sv/lib/libstand/net.h Tue Sep 28 11:32:17 2010 (r213246) +++ projects/sv/lib/libstand/net.h Tue Sep 28 12:51:17 2010 (r213247) @@ -50,7 +50,7 @@ #define MACPY(s, d) bcopy((char *)s, (char *)d, 6) -#define MAXTMO 20 /* seconds */ +#define MAXTMO 120 /* seconds */ #define MINTMO 2 /* seconds */ #define FNAME_SIZE 128 Modified: projects/sv/lib/libthr/thread/thr_cond.c ============================================================================== --- projects/sv/lib/libthr/thread/thr_cond.c Tue Sep 28 11:32:17 2010 (r213246) +++ projects/sv/lib/libthr/thread/thr_cond.c Tue Sep 28 12:51:17 2010 (r213247) @@ -104,6 +104,19 @@ init_static(struct pthread *thread, pthr return (ret); } +#define CHECK_AND_INIT_COND \ + if (__predict_false((cv = (*cond)) <= THR_COND_DESTROYED)) { \ + if (cv == THR_COND_INITIALIZER) { \ + int ret; \ + ret = init_static(_get_curthread(), cond); \ + if (ret) \ + return (ret); \ + } else if (cv == THR_COND_DESTROYED) { \ + return (EINVAL); \ + } \ + cv = *cond; \ + } + int _pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *cond_attr) { @@ -119,16 +132,14 @@ _pthread_cond_destroy(pthread_cond_t *co struct pthread_cond *cv; int rval = 0; - if (*cond == NULL) + if ((cv = *cond) == THR_COND_INITIALIZER) + rval = 0; + else if (cv == THR_COND_DESTROYED) rval = EINVAL; else { cv = *cond; THR_UMUTEX_LOCK(curthread, &cv->c_lock); - /* - * NULL the caller's pointer now that the condition - * variable has been destroyed: - */ - *cond = NULL; + *cond = THR_COND_DESTROYED; THR_UMUTEX_UNLOCK(curthread, &cv->c_lock); /* @@ -137,7 +148,6 @@ _pthread_cond_destroy(pthread_cond_t *co */ free(cv); } - /* Return the completion status: */ return (rval); } @@ -178,22 +188,18 @@ cond_wait_common(pthread_cond_t *cond, p struct timespec ts, ts2, *tsp; struct cond_cancel_info info; pthread_cond_t cv; - int ret = 0; + int ret; /* * If the condition variable is statically initialized, * perform the dynamic initialization: */ - if (__predict_false(*cond == NULL && - (ret = init_static(curthread, cond)) != 0)) - return (ret); - - _thr_testcancel(curthread); + CHECK_AND_INIT_COND cv = *cond; THR_UMUTEX_LOCK(curthread, &cv->c_lock); ret = _mutex_cv_unlock(mutex, &info.count); - if (ret) { + if (__predict_false(ret != 0)) { THR_UMUTEX_UNLOCK(curthread, &cv->c_lock); return (ret); } @@ -273,11 +279,8 @@ cond_signal_common(pthread_cond_t *cond, * If the condition variable is statically initialized, perform dynamic * initialization. */ - if (__predict_false(*cond == NULL && - (ret = init_static(curthread, cond)) != 0)) - return (ret); + CHECK_AND_INIT_COND - cv = *cond; THR_UMUTEX_LOCK(curthread, &cv->c_lock); if (!broadcast) ret = _thr_ucond_signal(&cv->c_kerncv); Modified: projects/sv/lib/libthr/thread/thr_init.c ============================================================================== --- projects/sv/lib/libthr/thread/thr_init.c Tue Sep 28 11:32:17 2010 (r213246) +++ projects/sv/lib/libthr/thread/thr_init.c Tue Sep 28 12:51:17 2010 (r213247) @@ -92,6 +92,12 @@ struct pthread_mutex_attr _pthread_mutex .m_ceiling = 0 }; +struct pthread_mutex_attr _pthread_mutexattr_adaptive_default = { + .m_type = PTHREAD_MUTEX_ADAPTIVE_NP, + .m_protocol = PTHREAD_PRIO_NONE, + .m_ceiling = 0 +}; + /* Default condition variable attributes: */ struct pthread_cond_attr _pthread_condattr_default = { .c_pshared = PTHREAD_PROCESS_PRIVATE, Modified: projects/sv/lib/libthr/thread/thr_mutex.c ============================================================================== --- projects/sv/lib/libthr/thread/thr_mutex.c Tue Sep 28 11:32:17 2010 (r213246) +++ projects/sv/lib/libthr/thread/thr_mutex.c Tue Sep 28 12:51:17 2010 (r213247) @@ -124,7 +124,7 @@ __weak_reference(_pthread_mutex_isowned_ static int mutex_init(pthread_mutex_t *mutex, - const pthread_mutexattr_t *mutex_attr, + const struct pthread_mutex_attr *mutex_attr, void *(calloc_cb)(size_t, size_t)) { const struct pthread_mutex_attr *attr; @@ -133,7 +133,7 @@ mutex_init(pthread_mutex_t *mutex, if (mutex_attr == NULL) { attr = &_pthread_mutexattr_default; } else { - attr = *mutex_attr; + attr = mutex_attr; if (attr->m_type < PTHREAD_MUTEX_ERRORCHECK || attr->m_type >= PTHREAD_MUTEX_TYPE_MAX) return (EINVAL); @@ -153,6 +153,10 @@ mutex_init(pthread_mutex_t *mutex, pmutex->m_yieldloops = 0; MUTEX_INIT_LINK(pmutex); switch(attr->m_protocol) { + case PTHREAD_PRIO_NONE: + pmutex->m_lock.m_owner = UMUTEX_UNOWNED; + pmutex->m_lock.m_flags = 0; + break; case PTHREAD_PRIO_INHERIT: pmutex->m_lock.m_owner = UMUTEX_UNOWNED; pmutex->m_lock.m_flags = UMUTEX_PRIO_INHERIT; @@ -162,9 +166,6 @@ mutex_init(pthread_mutex_t *mutex, pmutex->m_lock.m_flags = UMUTEX_PRIO_PROTECT; pmutex->m_lock.m_ceilings[0] = attr->m_ceiling; break; - case PTHREAD_PRIO_NONE: - pmutex->m_lock.m_owner = UMUTEX_UNOWNED; - pmutex->m_lock.m_flags = 0; } if (pmutex->m_type == PTHREAD_MUTEX_ADAPTIVE_NP) { @@ -184,11 +185,12 @@ init_static(struct pthread *thread, pthr THR_LOCK_ACQUIRE(thread, &_mutex_static_lock); - if (*mutex == NULL) - ret = mutex_init(mutex, NULL, calloc); + if (*mutex == THR_MUTEX_INITIALIZER) + ret = mutex_init(mutex, &_pthread_mutexattr_default, calloc); + else if (*mutex == THR_ADAPTIVE_MUTEX_INITIALIZER) + ret = mutex_init(mutex, &_pthread_mutexattr_adaptive_default, calloc); else ret = 0; - THR_LOCK_RELEASE(thread, &_mutex_static_lock); return (ret); @@ -210,7 +212,7 @@ int __pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *mutex_attr) { - return mutex_init(mutex, mutex_attr, calloc); + return mutex_init(mutex, mutex_attr ? *mutex_attr : NULL, calloc); } /* This function is used internally by malloc. */ @@ -223,10 +225,9 @@ _pthread_mutex_init_calloc_cb(pthread_mu .m_protocol = PTHREAD_PRIO_NONE, .m_ceiling = 0 }; - static const struct pthread_mutex_attr *pattr = &attr; int ret; - ret = mutex_init(mutex, (pthread_mutexattr_t *)&pattr, calloc_cb); + ret = mutex_init(mutex, &attr, calloc_cb); if (ret == 0) (*mutex)->m_private = 1; return (ret); @@ -261,19 +262,21 @@ _pthread_mutex_destroy(pthread_mutex_t * uint32_t id; int ret = 0; - if (__predict_false(*mutex == NULL)) + m = *mutex; + if (m < THR_MUTEX_DESTROYED) { + ret = 0; + } else if (m == THR_MUTEX_DESTROYED) { ret = EINVAL; - else { + } else { id = TID(curthread); /* * Try to lock the mutex structure, we only need to * try once, if failed, the mutex is in used. */ - ret = _thr_umutex_trylock(&(*mutex)->m_lock, id); + ret = _thr_umutex_trylock(&m->m_lock, id); if (ret) return (ret); - m = *mutex; /* * Check mutex other fields to see if this mutex is * in use. Mostly for prority mutex types, or there @@ -285,11 +288,7 @@ _pthread_mutex_destroy(pthread_mutex_t * _thr_umutex_unlock(&m->m_lock, id); ret = EBUSY; } else { - /* - * Save a pointer to the mutex so it can be free'd - * and set the caller's pointer to NULL. - */ - *mutex = NULL; + *mutex = THR_MUTEX_DESTROYED; if (m->m_lock.m_flags & UMUTEX_PRIO_PROTECT) set_inherited_priority(curthread, m); @@ -314,19 +313,30 @@ _pthread_mutex_destroy(pthread_mutex_t * TAILQ_INSERT_TAIL(&curthread->pp_mutexq, (m), m_qe);\ } while (0) +#define CHECK_AND_INIT_MUTEX \ + if (__predict_false((m = *mutex) <= THR_MUTEX_DESTROYED)) { \ + if (m == THR_MUTEX_DESTROYED) \ + return (EINVAL); \ + int ret; \ + ret = init_static(_get_curthread(), mutex); \ + if (ret) \ + return (ret); \ + m = *mutex; \ + } + static int -mutex_trylock_common(struct pthread *curthread, pthread_mutex_t *mutex) +mutex_trylock_common(pthread_mutex_t *mutex) { - struct pthread_mutex *m; + struct pthread *curthread = _get_curthread(); + struct pthread_mutex *m = *mutex; uint32_t id; int ret; id = TID(curthread); - m = *mutex; if (m->m_private) THR_CRITICAL_ENTER(curthread); ret = _thr_umutex_trylock(&m->m_lock, id); - if (ret == 0) { + if (__predict_true(ret == 0)) { ENQUEUE_MUTEX(curthread, m); } else if (m->m_owner == curthread) { ret = mutex_self_trylock(m); @@ -339,19 +349,11 @@ mutex_trylock_common(struct pthread *cur int __pthread_mutex_trylock(pthread_mutex_t *mutex) { - struct pthread *curthread = _get_curthread(); - int ret; + struct pthread_mutex *m; - /* - * If the mutex is statically initialized, perform the dynamic - * initialization: - */ - if (__predict_false(*mutex == NULL)) { - ret = init_static(curthread, mutex); - if (__predict_false(ret)) - return (ret); - } - return (mutex_trylock_common(curthread, mutex)); + CHECK_AND_INIT_MUTEX + + return (mutex_trylock_common(mutex)); } static int @@ -372,8 +374,10 @@ mutex_lock_sleep(struct pthread *curthre * the lock is likely to be released quickly and it is * faster than entering the kernel */ - if (m->m_lock.m_flags & (UMUTEX_PRIO_PROTECT | UMUTEX_PRIO_INHERIT)) - goto sleep_in_kernel; + if (__predict_false( + (m->m_lock.m_flags & + (UMUTEX_PRIO_PROTECT | UMUTEX_PRIO_INHERIT)) != 0)) + goto sleep_in_kernel; if (!_thr_is_smp) goto yield_loop; @@ -421,9 +425,10 @@ done: } static inline int -mutex_lock_common(struct pthread *curthread, struct pthread_mutex *m, +mutex_lock_common(struct pthread_mutex *m, const struct timespec *abstime) { + struct pthread *curthread = _get_curthread(); int ret; if (m->m_private) @@ -442,50 +447,25 @@ mutex_lock_common(struct pthread *curthr int __pthread_mutex_lock(pthread_mutex_t *mutex) { - struct pthread *curthread; - struct pthread_mutex *m; - int ret; + struct pthread_mutex *m; _thr_check_init(); - curthread = _get_curthread(); + CHECK_AND_INIT_MUTEX - /* - * If the mutex is statically initialized, perform the dynamic - * initialization: - */ - if (__predict_false((m = *mutex) == NULL)) { - ret = init_static(curthread, mutex); - if (__predict_false(ret)) - return (ret); - m = *mutex; - } - - return (mutex_lock_common(curthread, m, NULL)); + return (mutex_lock_common(m, NULL)); } int __pthread_mutex_timedlock(pthread_mutex_t *mutex, const struct timespec *abstime) { - struct pthread *curthread; - struct pthread_mutex *m; - int ret; + struct pthread_mutex *m; _thr_check_init(); - curthread = _get_curthread(); + CHECK_AND_INIT_MUTEX - /* - * If the mutex is statically initialized, perform the dynamic - * initialization: - */ - if (__predict_false((m = *mutex) == NULL)) { - ret = init_static(curthread, mutex); - if (__predict_false(ret)) - return (ret); - m = *mutex; - } - return (mutex_lock_common(curthread, m, abstime)); + return (mutex_lock_common(m, abstime)); } int @@ -495,20 +475,22 @@ _pthread_mutex_unlock(pthread_mutex_t *m } int -_mutex_cv_lock(pthread_mutex_t *m, int count) +_mutex_cv_lock(pthread_mutex_t *mutex, int count) { + struct pthread_mutex *m; int ret; - ret = mutex_lock_common(_get_curthread(), *m, NULL); + m = *mutex; + ret = mutex_lock_common(m, NULL); if (ret == 0) { - (*m)->m_refcount--; - (*m)->m_count += count; + m->m_refcount--; + m->m_count += count; } return (ret); } static int -mutex_self_trylock(pthread_mutex_t m) +mutex_self_trylock(struct pthread_mutex *m) { int ret; @@ -536,7 +518,7 @@ mutex_self_trylock(pthread_mutex_t m) } static int -mutex_self_lock(pthread_mutex_t m, const struct timespec *abstime) +mutex_self_lock(struct pthread_mutex *m, const struct timespec *abstime) { struct timespec ts1, ts2; int ret; @@ -611,8 +593,12 @@ mutex_unlock_common(pthread_mutex_t *mut struct pthread_mutex *m; uint32_t id; - if (__predict_false((m = *mutex) == NULL)) - return (EINVAL); + m = *mutex; + if (__predict_false(m <= THR_MUTEX_DESTROYED)) { + if (m == THR_MUTEX_DESTROYED) + return (EINVAL); + return (EPERM); + } /* * Check if the running thread is not the owner of the mutex. @@ -629,7 +615,7 @@ mutex_unlock_common(pthread_mutex_t *mut m->m_owner = NULL; /* Remove the mutex from the threads queue. */ MUTEX_ASSERT_IS_OWNED(m); - if ((m->m_lock.m_flags & UMUTEX_PRIO_PROTECT) == 0) + if (__predict_true((m->m_lock.m_flags & UMUTEX_PRIO_PROTECT) == 0)) TAILQ_REMOVE(&curthread->mutexq, m, m_qe); else { TAILQ_REMOVE(&curthread->pp_mutexq, m, m_qe); @@ -649,9 +635,7 @@ _mutex_cv_unlock(pthread_mutex_t *mutex, struct pthread *curthread = _get_curthread(); struct pthread_mutex *m; - if (__predict_false((m = *mutex) == NULL)) - return (EINVAL); - + m = *mutex; /* * Check if the running thread is not the owner of the mutex. */ @@ -667,7 +651,7 @@ _mutex_cv_unlock(pthread_mutex_t *mutex, m->m_owner = NULL; /* Remove the mutex from the threads queue. */ MUTEX_ASSERT_IS_OWNED(m); - if ((m->m_lock.m_flags & UMUTEX_PRIO_PROTECT) == 0) + if (__predict_true((m->m_lock.m_flags & UMUTEX_PRIO_PROTECT) == 0)) TAILQ_REMOVE(&curthread->mutexq, m, m_qe); else { TAILQ_REMOVE(&curthread->pp_mutexq, m, m_qe); @@ -685,18 +669,19 @@ int _pthread_mutex_getprioceiling(pthread_mutex_t *mutex, int *prioceiling) { + struct pthread_mutex *m; int ret; - if (*mutex == NULL) - ret = EINVAL; - else if (((*mutex)->m_lock.m_flags & UMUTEX_PRIO_PROTECT) == 0) + m = *mutex; + if ((m <= THR_MUTEX_DESTROYED) || + (m->m_lock.m_flags & UMUTEX_PRIO_PROTECT) == 0) ret = EINVAL; else { - *prioceiling = (*mutex)->m_lock.m_ceilings[0]; + *prioceiling = m->m_lock.m_ceilings[0]; ret = 0; } - return(ret); + return (ret); } int @@ -708,7 +693,8 @@ _pthread_mutex_setprioceiling(pthread_mu int ret; m = *mutex; - if (m == NULL || (m->m_lock.m_flags & UMUTEX_PRIO_PROTECT) == 0) + if ((m <= THR_MUTEX_DESTROYED) || + (m->m_lock.m_flags & UMUTEX_PRIO_PROTECT) == 0) return (EINVAL); ret = __thr_umutex_set_ceiling(&m->m_lock, ceiling, old_ceiling); @@ -737,61 +723,54 @@ _pthread_mutex_setprioceiling(pthread_mu int _pthread_mutex_getspinloops_np(pthread_mutex_t *mutex, int *count) { - if (*mutex == NULL) - return (EINVAL); - *count = (*mutex)->m_spinloops; + struct pthread_mutex *m; + + CHECK_AND_INIT_MUTEX + + *count = m->m_spinloops; return (0); } int __pthread_mutex_setspinloops_np(pthread_mutex_t *mutex, int count) { - struct pthread *curthread = _get_curthread(); - int ret; + struct pthread_mutex *m; - if (__predict_false(*mutex == NULL)) { - ret = init_static(curthread, mutex); - if (__predict_false(ret)) - return (ret); - } - (*mutex)->m_spinloops = count; + CHECK_AND_INIT_MUTEX + + m->m_spinloops = count; return (0); } int _pthread_mutex_getyieldloops_np(pthread_mutex_t *mutex, int *count) { - if (*mutex == NULL) - return (EINVAL); - *count = (*mutex)->m_yieldloops; + struct pthread_mutex *m; + + CHECK_AND_INIT_MUTEX + + *count = m->m_yieldloops; return (0); } int __pthread_mutex_setyieldloops_np(pthread_mutex_t *mutex, int count) { - struct pthread *curthread = _get_curthread(); - int ret; + struct pthread_mutex *m; - if (__predict_false(*mutex == NULL)) { - ret = init_static(curthread, mutex); - if (__predict_false(ret)) - return (ret); - } - (*mutex)->m_yieldloops = count; + CHECK_AND_INIT_MUTEX + + m->m_yieldloops = count; return (0); } int _pthread_mutex_isowned_np(pthread_mutex_t *mutex) { - struct pthread *curthread = _get_curthread(); - int ret; + struct pthread_mutex *m; - if (__predict_false(*mutex == NULL)) { - ret = init_static(curthread, mutex); - if (__predict_false(ret)) - return (ret); - } - return ((*mutex)->m_owner == curthread); + m = *mutex; + if (m <= THR_MUTEX_DESTROYED) + return (0); + return (m->m_owner == _get_curthread()); } Modified: projects/sv/lib/libthr/thread/thr_private.h ============================================================================== --- projects/sv/lib/libthr/thread/thr_private.h Tue Sep 28 11:32:17 2010 (r213246) +++ projects/sv/lib/libthr/thread/thr_private.h Tue Sep 28 12:51:17 2010 (r213247) @@ -125,6 +125,15 @@ TAILQ_HEAD(mutex_queue, pthread_mutex); } \ } while (0) +/* XXX These values should be same as those defined in pthread.h */ +#define THR_MUTEX_INITIALIZER ((struct pthread_mutex *)NULL) +#define THR_ADAPTIVE_MUTEX_INITIALIZER ((struct pthread_mutex *)1) +#define THR_MUTEX_DESTROYED ((struct pthread_mutex *)2) +#define THR_COND_INITIALIZER ((struct pthread_cond *)NULL) +#define THR_COND_DESTROYED ((struct pthread_cond *)1) +#define THR_RWLOCK_INITIALIZER ((struct pthread_rwlock *)NULL) +#define THR_RWLOCK_DESTROYED ((struct pthread_rwlock *)1) + struct pthread_mutex { /* * Lock for accesses to this structure. @@ -627,6 +636,7 @@ extern struct pthread_attr _pthread_attr /* Default mutex attributes: */ extern struct pthread_mutex_attr _pthread_mutexattr_default __hidden; +extern struct pthread_mutex_attr _pthread_mutexattr_adaptive_default __hidden; /* Default condition variable attributes: */ extern struct pthread_cond_attr _pthread_condattr_default __hidden; Modified: projects/sv/lib/libthr/thread/thr_rwlock.c ============================================================================== --- projects/sv/lib/libthr/thread/thr_rwlock.c Tue Sep 28 11:32:17 2010 (r213246) +++ projects/sv/lib/libthr/thread/thr_rwlock.c Tue Sep 28 12:51:17 2010 (r213247) @@ -45,6 +45,19 @@ __weak_reference(_pthread_rwlock_unlock, __weak_reference(_pthread_rwlock_wrlock, pthread_rwlock_wrlock); __weak_reference(_pthread_rwlock_timedwrlock, pthread_rwlock_timedwrlock); +#define CHECK_AND_INIT_RWLOCK \ + if (__predict_false((prwlock = (*rwlock)) <= THR_RWLOCK_DESTROYED)) { \ + if (prwlock == THR_RWLOCK_INITIALIZER) { \ + int ret; \ + ret = init_static(_get_curthread(), rwlock); \ + if (ret) \ + return (ret); \ + } else if (prwlock == THR_RWLOCK_DESTROYED) { \ + return (EINVAL); \ + } \ + prwlock = *rwlock; \ + } + /* * Prototypes */ @@ -64,15 +77,16 @@ rwlock_init(pthread_rwlock_t *rwlock, co int _pthread_rwlock_destroy (pthread_rwlock_t *rwlock) { + pthread_rwlock_t prwlock; int ret; - if (rwlock == NULL) + prwlock = *rwlock; + if (prwlock == THR_RWLOCK_INITIALIZER) + ret = 0; + else if (prwlock == THR_RWLOCK_DESTROYED) ret = EINVAL; else { - pthread_rwlock_t prwlock; - - prwlock = *rwlock; - *rwlock = NULL; + *rwlock = THR_RWLOCK_DESTROYED; free(prwlock); ret = 0; @@ -87,7 +101,7 @@ init_static(struct pthread *thread, pthr THR_LOCK_ACQUIRE(thread, &_rwlock_static_lock); - if (*rwlock == NULL) + if (*rwlock == THR_RWLOCK_INITIALIZER) ret = rwlock_init(rwlock, NULL); else ret = 0; @@ -113,18 +127,7 @@ rwlock_rdlock_common(pthread_rwlock_t *r int flags; int ret; - if (__predict_false(rwlock == NULL)) - return (EINVAL); - - prwlock = *rwlock; - - /* check for static initialization */ - if (__predict_false(prwlock == NULL)) { - if ((ret = init_static(curthread, rwlock)) != 0) - return (ret); - - prwlock = *rwlock; - } + CHECK_AND_INIT_RWLOCK if (curthread->rdlock_count) { /* @@ -206,18 +209,7 @@ _pthread_rwlock_tryrdlock (pthread_rwloc int flags; int ret; - if (__predict_false(rwlock == NULL)) - return (EINVAL); - - prwlock = *rwlock; - - /* check for static initialization */ - if (__predict_false(prwlock == NULL)) { - if ((ret = init_static(curthread, rwlock)) != 0) - return (ret); - - prwlock = *rwlock; - } + CHECK_AND_INIT_RWLOCK if (curthread->rdlock_count) { /* @@ -250,18 +242,7 @@ _pthread_rwlock_trywrlock (pthread_rwloc pthread_rwlock_t prwlock; int ret; - if (__predict_false(rwlock == NULL)) - return (EINVAL); - - prwlock = *rwlock; - - /* check for static initialization */ - if (__predict_false(prwlock == NULL)) { - if ((ret = init_static(curthread, rwlock)) != 0) - return (ret); - - prwlock = *rwlock; - } + CHECK_AND_INIT_RWLOCK ret = _thr_rwlock_trywrlock(&prwlock->lock); if (ret == 0) @@ -277,18 +258,7 @@ rwlock_wrlock_common (pthread_rwlock_t * struct timespec ts, ts2, *tsp; int ret; - if (__predict_false(rwlock == NULL)) - return (EINVAL); - - prwlock = *rwlock; - - /* check for static initialization */ - if (__predict_false(prwlock == NULL)) { - if ((ret = init_static(curthread, rwlock)) != 0) - return (ret); - - prwlock = *rwlock; - } + CHECK_AND_INIT_RWLOCK /* * POSIX said the validity of the abstimeout parameter need @@ -356,12 +326,9 @@ _pthread_rwlock_unlock (pthread_rwlock_t int ret; int32_t state; - if (__predict_false(rwlock == NULL)) - return (EINVAL); - prwlock = *rwlock; - if (__predict_false(prwlock == NULL)) + if (__predict_false(prwlock <= THR_RWLOCK_DESTROYED)) return (EINVAL); state = prwlock->lock.rw_state; Modified: projects/sv/sbin/geom/class/part/gpart.8 ============================================================================== --- projects/sv/sbin/geom/class/part/gpart.8 Tue Sep 28 11:32:17 2010 (r213246) +++ projects/sv/sbin/geom/class/part/gpart.8 Tue Sep 28 12:51:17 2010 (r213247) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd Sep 24, 2010 +.Dd September 28, 2010 .Dt GPART 8 .Os .Sh NAME @@ -382,6 +382,9 @@ about its use. .\" ==== SET ==== .It Cm set Set the named attribute on the partition entry. +See the section entitled +.Sx "ATTRIBUTES" +below for a list of available attributes. .Pp Additional options include: .Bl -tag -width 10n @@ -406,6 +409,9 @@ action and can be used to undo any chang .\" ==== UNSET ==== .It Cm unset Clear the named attribute on the partition entry. +See the section entitled +.Sx "ATTRIBUTES" +below for a list of available attributes. .Pp Additional options include: .Bl -tag -width 10n @@ -502,6 +508,103 @@ This type is known as .Qq Li "!024dee41-33e7-11d3-9d69-0008c781f39f" by GPT. .El +.Sh ATTRIBUTES +The scheme-specific attributes for EBR: +.Bl -tag -width ".Ar active" +.It Ar active +.El +.Pp +The scheme-specific attributes for GPT: +.Bl -tag -width ".Ar bootfailed" +.It Ar bootme +When set, the +.Nm gptboot +stage 1 boot loader will try to boot the system from this partition. +Multiple partitions might be marked with the +.Ar bootme +attribute. +In such scenario the +.Nm gptboot +will try all +.Ar bootme +partitions one by one, until the next boot stage is successfully entered. +.It Ar bootonce +Setting this attribute automatically sets the +.Ar bootme +attribute. +When set, the +.Nm gptboot +stage 1 boot loader will try to boot the system from this partition only once. +Partitions with both +.Ar bootonce +and +.Ar bootme +attributes are tried before partitions with only the +.Ar bootme +attribute. +Before +.Ar bootonce +partition is tried, the +.Nm gptboot +removes the +.Ar bootme +attribute and tries to execute the next boot stage. +If it fails, the +.Ar bootonce +attribute that is now alone is replaced with the +.Ar bootfailed +attribute. +If the execution of the next boot stage succeeds, but the system is not fully +booted, the +.Nm gptboot +will look for +.Ar bootonce +attributes alone (without the +.Ar bootme +attribute) on the next system boot and will replace those with the +.Ar bootfailed +attribute. +If the system is fully booted, the +.Pa /etc/rc.d/gptboot +start-up script will look for partition with the +.Ar bootonce +attribute alone, will remove the attribute and log that the system was +successfully booted from this partition. +There should be at most one +.Ar bootonce +partition when system is successfully booted. +Multiple partitions might be marked with the +.Ar bootonce +and +.Ar bootme +attribute pairs. +.It Ar bootfailed +This attribute should not be manually managed. +It is managed by the +.Nm gptboot +stage 1 boot loader and the +.Pa /etc/rc.d/gptboot +start-up script. +This attribute is used to mark partitions that had the +.Ar bootonce +attribute set, but we failed to boot from them. +Once we successfully boot, the +.Pa /etc/rc.d/gptboot +script will log all the partitions we failed to boot from and will remove the +.Ar bootfailed +attributes. +.El +.Pp +The scheme-specific attributes for MBR: +.Bl -tag -width ".Ar active" +.It Ar active +.El +.Pp +The scheme-specific attributes for PC98: +.Bl -tag -width ".Ar bootable" +.It Ar active +.It Ar bootable +.El .Sh OPERATIONAL FLAGS Actions other than the .Cm commit Modified: projects/sv/sys/compat/linprocfs/linprocfs.c ============================================================================== --- projects/sv/sys/compat/linprocfs/linprocfs.c Tue Sep 28 11:32:17 2010 (r213246) +++ projects/sv/sys/compat/linprocfs/linprocfs.c Tue Sep 28 12:51:17 2010 (r213247) @@ -61,6 +61,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -96,6 +97,10 @@ __FBSDID("$FreeBSD$"); #include #endif /* __i386__ || __amd64__ */ +#ifdef COMPAT_FREEBSD32 +#include +#endif + #ifdef COMPAT_LINUX32 /* XXX */ #include #else @@ -886,78 +891,24 @@ linprocfs_doprocroot(PFS_FILL_ARGS) return (0); } -/* - * Filler function for proc/pid/cmdline - */ -static int -linprocfs_doproccmdline(PFS_FILL_ARGS) -{ - struct ps_strings pstr; - char **ps_argvstr; - int error, i; - - /* - * If we are using the ps/cmdline caching, use that. Otherwise - * revert back to the old way which only implements full cmdline - * for the currept process and just p->p_comm for all other - * processes. - * Note that if the argv is no longer available, we deliberately - * don't fall back on p->p_comm or return an error: the authentic - * Linux behaviour is to return zero-length in this case. - */ - - PROC_LOCK(p); - if (p->p_args && p_cansee(td, p) == 0) { - sbuf_bcpy(sb, p->p_args->ar_args, p->p_args->ar_length); - PROC_UNLOCK(p); - } else if (p != td->td_proc) { - PROC_UNLOCK(p); - sbuf_printf(sb, "%.*s", MAXCOMLEN, p->p_comm); - } else { - PROC_UNLOCK(p); - error = copyin((void *)p->p_sysent->sv_psstrings, &pstr, - sizeof(pstr)); - if (error) - return (error); - if (pstr.ps_nargvstr > ARG_MAX) - return (E2BIG); - ps_argvstr = malloc(pstr.ps_nargvstr * sizeof(char *), - M_TEMP, M_WAITOK); - error = copyin((void *)pstr.ps_argvstr, ps_argvstr, - pstr.ps_nargvstr * sizeof(char *)); - if (error) { - free(ps_argvstr, M_TEMP); - return (error); - } - for (i = 0; i < pstr.ps_nargvstr; i++) { - sbuf_copyin(sb, ps_argvstr[i], 0); - sbuf_printf(sb, "%c", '\0'); - } - free(ps_argvstr, M_TEMP); - } - - return (0); -} - -extern int proc_rwmem(struct proc *p, struct uio *uio); - #define MAX_ARGV_STR 512 /* Max number of argv-like strings */ #define UIO_CHUNK_SZ 256 /* Max chunk size (bytes) for uiomove */ static int linprocfs_doargv(struct thread *td, struct proc *p, struct sbuf *sb, - void (*resolver)(const struct ps_strings, u_long *, int *)) + void (*resolver)(const struct ps_strings, u_long *, int *)) { struct iovec iov; struct uio tmp_uio; struct ps_strings pss; - int ret, i, n_elements, found_end; - u_long addr; - char* env_vector[MAX_ARGV_STR]; + int ret, i, n_elements, elm_len; + u_long addr, pbegin; + char **env_vector, *envp; char env_string[UIO_CHUNK_SZ]; - char *pbegin; - - +#ifdef COMPAT_FREEBSD32 + struct freebsd32_ps_strings pss32; + uint32_t *env_vector32; +#endif *** DIFF OUTPUT TRUNCATED AT 1000 LINES ***