From owner-p4-projects@FreeBSD.ORG Thu Jul 29 20:50:12 2004 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 90E2D16A4D0; Thu, 29 Jul 2004 20:50:12 +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 3774A16A4CF for ; Thu, 29 Jul 2004 20:50:12 +0000 (GMT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id 2996A43D39 for ; Thu, 29 Jul 2004 20:50:12 +0000 (GMT) (envelope-from jhb@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.12.11/8.12.11) with ESMTP id i6TKoCmZ055265 for ; Thu, 29 Jul 2004 20:50:12 GMT (envelope-from jhb@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.12.11/8.12.11/Submit) id i6TKoBfT055261 for perforce@freebsd.org; Thu, 29 Jul 2004 20:50:11 GMT (envelope-from jhb@freebsd.org) Date: Thu, 29 Jul 2004 20:50:11 GMT Message-Id: <200407292050.i6TKoBfT055261@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 58488 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: Thu, 29 Jul 2004 20:50:13 -0000 http://perforce.freebsd.org/chv.cgi?CH=58488 Change 58488 by jhb@jhb_slimer on 2004/07/29 20:49:29 Try to pass curthread around to avoid looking it up via PCPU as often when locking mutexes. Suggested by: rwatson Affected files ... .. //depot/projects/smpng/sys/kern/kern_mutex.c#82 edit .. //depot/projects/smpng/sys/sys/mutex.h#43 edit Differences ... ==== //depot/projects/smpng/sys/kern/kern_mutex.c#82 (text+ko) ==== @@ -417,10 +417,10 @@ * sleep waiting for it), or if we need to recurse on it. */ void -_mtx_lock_sleep(struct mtx *m, int opts, const char *file, int line) +_mtx_lock_sleep(struct mtx *m, struct thread *td, int opts, const char *file, + int line) { struct turnstile *ts; - struct thread *td = curthread; #if defined(SMP) && !defined(NO_ADAPTIVE_MUTEXES) struct thread *owner; #endif @@ -568,7 +568,8 @@ * is handled inline. */ void -_mtx_lock_spin(struct mtx *m, int opts, const char *file, int line) +_mtx_lock_spin(struct mtx *m, struct thread *td, int opts, const char *file, + int line) { int i = 0; @@ -576,7 +577,7 @@ CTR1(KTR_LOCK, "_mtx_lock_spin: %p spinning", m); for (;;) { - if (_obtain_lock(m, curthread)) + if (_obtain_lock(m, td)) break; /* Give interrupts a chance while we spin. */ ==== //depot/projects/smpng/sys/sys/mutex.h#43 (text+ko) ==== @@ -100,17 +100,19 @@ void mtx_destroy(struct mtx *m); void mtx_sysinit(void *arg); void mutex_init(void); -void _mtx_lock_sleep(struct mtx *m, int opts, const char *file, int line); +void _mtx_lock_sleep(struct mtx *m, struct thread *td, int opts, + const char *file, int line); void _mtx_unlock_sleep(struct mtx *m, int opts, const char *file, int line); -void _mtx_lock_spin(struct mtx *m, int opts, const char *file, int line); +void _mtx_lock_spin(struct mtx *m, struct thread *td, int opts, + const char *file, int line); void _mtx_unlock_spin(struct mtx *m, int opts, const char *file, int line); int _mtx_trylock(struct mtx *m, int opts, const char *file, int line); void _mtx_lock_flags(struct mtx *m, int opts, const char *file, int line); void _mtx_unlock_flags(struct mtx *m, int opts, const char *file, int line); void _mtx_lock_spin_flags(struct mtx *m, int opts, const char *file, - int line); + int line); void _mtx_unlock_spin_flags(struct mtx *m, int opts, const char *file, - int line); + int line); #ifdef INVARIANT_SUPPORT void _mtx_assert(struct mtx *m, int what, const char *file, int line); #endif @@ -144,8 +146,10 @@ */ #ifndef _get_sleep_lock #define _get_sleep_lock(mp, tid, opts, file, line) do { \ - if (!_obtain_lock((mp), (tid))) \ - _mtx_lock_sleep((mp), (opts), (file), (line)); \ + struct thread *_tid = (tid); \ + \ + if (!_obtain_lock((mp), _tid)) \ + _mtx_lock_sleep((mp), _tid, (opts), (file), (line)); \ } while (0) #endif @@ -158,12 +162,14 @@ */ #ifndef _get_spin_lock #define _get_spin_lock(mp, tid, opts, file, line) do { \ + struct thread *_tid = (tid); \ + \ critical_enter(); \ - if (!_obtain_lock((mp), (tid))) { \ - if ((mp)->mtx_lock == (uintptr_t)(tid)) \ + if (!_obtain_lock((mp), _tid)) { \ + if ((mp)->mtx_lock == (uintptr_t)_tid) \ (mp)->mtx_recurse++; \ else \ - _mtx_lock_spin((mp), (opts), (file), (line)); \ + _mtx_lock_spin((mp), _tid, (opts), (file), (line)); \ } \ } while (0) #endif @@ -195,7 +201,7 @@ (mp)->mtx_recurse--; \ else \ _release_lock_quick((mp)); \ - critical_exit(); \ + critical_exit(); \ } while (0) #endif