From owner-p4-projects@FreeBSD.ORG Wed Mar 30 20:35:12 2005 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id B8DCE16A4D0; Wed, 30 Mar 2005 20:35:11 +0000 (GMT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9397716A4CE for ; Wed, 30 Mar 2005 20:35:11 +0000 (GMT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5ED3343D45 for ; Wed, 30 Mar 2005 20:35:11 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id j2UKZB8G060574 for ; Wed, 30 Mar 2005 20:35:11 GMT (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id j2UKZACx060570 for perforce@freebsd.org; Wed, 30 Mar 2005 20:35:10 GMT (envelope-from jhb@freebsd.org) Date: Wed, 30 Mar 2005 20:35:10 GMT Message-Id: <200503302035.j2UKZACx060570@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to jhb@freebsd.org using -f From: John Baldwin To: Perforce Change Reviews Subject: PERFORCE change 74122 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Mar 2005 20:35:12 -0000 http://perforce.freebsd.org/chv.cgi?CH=74122 Change 74122 by jhb@jhb_slimer on 2005/03/30 20:34:35 Fix UP mutex code to work with uintptr_t for atomic_ptr(). Affected files ... .. //depot/projects/smpng/sys/kern/kern_mutex.c#94 edit .. //depot/projects/smpng/sys/sys/mutex.h#51 edit Differences ... ==== //depot/projects/smpng/sys/kern/kern_mutex.c#94 (text+ko) ==== @@ -417,7 +417,7 @@ atomic_set_ptr(&m->mtx_lock, MTX_RECURSED); rval = 1; } else - rval = _obtain_lock(m, curthread); + rval = _obtain_lock(m, (uintptr_t)curthread); LOCK_LOG_TRY("LOCK", &m->mtx_object, opts, rval, file, line); if (rval) @@ -434,7 +434,7 @@ * sleep waiting for it), or if we need to recurse on it. */ void -_mtx_lock_sleep(struct mtx *m, struct thread *td, int opts, const char *file, +_mtx_lock_sleep(struct mtx *m, uintptr_t tid, int opts, const char *file, int line) { #if defined(SMP) && !defined(NO_ADAPTIVE_MUTEXES) @@ -467,7 +467,7 @@ #ifdef MUTEX_PROFILING contested = 0; #endif - while (!_obtain_lock(m, td)) { + while (!_obtain_lock(m, tid)) { #ifdef MUTEX_PROFILING contested = 1; atomic_add_int(&m->mtx_contest_holding, 1); @@ -495,7 +495,7 @@ * necessary. */ if (v == MTX_CONTESTED) { - m->mtx_lock = (uintptr_t)td | MTX_CONTESTED; + m->mtx_lock = tid | MTX_CONTESTED; turnstile_claim(&m->mtx_object); break; } @@ -507,8 +507,7 @@ * or the state of the MTX_RECURSED bit changed. */ if ((v & MTX_CONTESTED) == 0 && - !atomic_cmpset_ptr(&m->mtx_lock, (void *)v, - (void *)(v | MTX_CONTESTED))) { + !atomic_cmpset_ptr(&m->mtx_lock, v, v | MTX_CONTESTED)) { turnstile_release(&m->mtx_object); cpu_spinwait(); continue; @@ -542,7 +541,7 @@ if (!cont_logged) { CTR6(KTR_CONTENTION, "contention: %p at %s:%d wants %s, taken by %s:%d", - td, file, line, m->mtx_object.lo_name, + (void *)tid, file, line, m->mtx_object.lo_name, WITNESS_FILE(&m->mtx_object), WITNESS_LINE(&m->mtx_object)); cont_logged = 1; @@ -559,7 +558,7 @@ if (cont_logged) { CTR4(KTR_CONTENTION, "contention end: %s acquired by %p at %s:%d", - m->mtx_object.lo_name, td, file, line); + m->mtx_object.lo_name, (void *)tid, file, line); } #endif #ifdef MUTEX_PROFILING @@ -578,7 +577,7 @@ * is handled inline. */ void -_mtx_lock_spin(struct mtx *m, struct thread *td, int opts, const char *file, +_mtx_lock_spin(struct mtx *m, uintptr_t tid, int opts, const char *file, int line) { int i = 0; @@ -590,7 +589,7 @@ CTR1(KTR_LOCK, "_mtx_lock_spin: %p spinning", m); for (;;) { - if (_obtain_lock(m, td)) + if (_obtain_lock(m, tid)) break; /* Give interrupts a chance while we spin. */ ==== //depot/projects/smpng/sys/sys/mutex.h#51 (text+ko) ==== @@ -100,11 +100,11 @@ void mtx_destroy(struct mtx *m); void mtx_sysinit(void *arg); void mutex_init(void); -void _mtx_lock_sleep(struct mtx *m, struct thread *td, int opts, +void _mtx_lock_sleep(struct mtx *m, uintptr_t tid, int opts, const char *file, int line); void _mtx_unlock_sleep(struct mtx *m, int opts, const char *file, int line); #ifdef SMP -void _mtx_lock_spin(struct mtx *m, struct thread *td, int opts, +void _mtx_lock_spin(struct mtx *m, uintptr_t tid, int opts, const char *file, int line); #endif void _mtx_unlock_spin(struct mtx *m, int opts, const char *file, int line); @@ -127,19 +127,19 @@ /* Try to obtain mtx_lock once. */ #ifndef _obtain_lock #define _obtain_lock(mp, tid) \ - atomic_cmpset_acq_ptr(&(mp)->mtx_lock, (void *)MTX_UNOWNED, (tid)) + atomic_cmpset_acq_ptr(&(mp)->mtx_lock, MTX_UNOWNED, (tid)) #endif /* Try to release mtx_lock if it is unrecursed and uncontested. */ #ifndef _release_lock #define _release_lock(mp, tid) \ - atomic_cmpset_rel_ptr(&(mp)->mtx_lock, (tid), (void *)MTX_UNOWNED) + atomic_cmpset_rel_ptr(&(mp)->mtx_lock, (tid), MTX_UNOWNED) #endif /* Release mtx_lock quickly, assuming we own it. */ #ifndef _release_lock_quick #define _release_lock_quick(mp) \ - atomic_store_rel_ptr(&(mp)->mtx_lock, (void *)MTX_UNOWNED) + atomic_store_rel_ptr(&(mp)->mtx_lock, MTX_UNOWNED) #endif /* @@ -148,7 +148,7 @@ */ #ifndef _get_sleep_lock #define _get_sleep_lock(mp, tid, opts, file, line) do { \ - struct thread *_tid = (tid); \ + uintptr_t _tid = (uintptr_t)(tid); \ \ if (!_obtain_lock((mp), _tid)) \ _mtx_lock_sleep((mp), _tid, (opts), (file), (line)); \ @@ -165,11 +165,11 @@ #ifndef _get_spin_lock #ifdef SMP #define _get_spin_lock(mp, tid, opts, file, line) do { \ - struct thread *_tid = (tid); \ + uintptr_t _tid = (uintptr_t)(tid); \ \ critical_enter(); \ if (!_obtain_lock((mp), _tid)) { \ - if ((mp)->mtx_lock == (uintptr_t)_tid) \ + if ((mp)->mtx_lock == _tid) \ (mp)->mtx_recurse++; \ else \ _mtx_lock_spin((mp), _tid, (opts), (file), (line)); \ @@ -177,14 +177,14 @@ } while (0) #else /* SMP */ #define _get_spin_lock(mp, tid, opts, file, line) do { \ - struct thread *_tid = (tid); \ + uintptr_t _tid = (uintptr_t)(tid); \ \ critical_enter(); \ - if ((mp)->mtx_lock == (uintptr_t)_tid) \ + if ((mp)->mtx_lock == _tid) \ (mp)->mtx_recurse++; \ else { \ KASSERT((mp)->mtx_lock == MTX_UNOWNED, ("corrupt spinlock")); \ - (mp)->mtx_lock = (uintptr_t)_tid; \ + (mp)->mtx_lock = _tid; \ } \ } while (0) #endif /* SMP */ @@ -196,7 +196,9 @@ */ #ifndef _rel_sleep_lock #define _rel_sleep_lock(mp, tid, opts, file, line) do { \ - if (!_release_lock((mp), (tid))) \ + uintptr_t _tid = (uintptr_t)(tid); \ + \ + if (!_release_lock((mp), _tid)) \ _mtx_unlock_sleep((mp), (opts), (file), (line)); \ } while (0) #endif