Shrink VAX kmutex from 12 bytes to 8. Fix various LOCKDEBUG/DIAGNOSTIC
problems.
This commit is contained in:
parent
0b7ea235a3
commit
b3cd0abcf6
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: intr.h,v 1.23 2007/02/16 02:53:51 ad Exp $ */
|
||||
/* $NetBSD: intr.h,v 1.24 2007/03/12 02:22:43 matt Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998 Matt Thomas.
|
||||
|
@ -79,42 +79,47 @@
|
|||
#ifdef _KERNEL
|
||||
typedef int ipl_t;
|
||||
|
||||
static inline ipl_t
|
||||
splx(ipl_t new_ipl)
|
||||
{
|
||||
ipl_t old_ipl = mfpr(PR_IPL);
|
||||
mtpr(new_ipl, PR_IPL);
|
||||
return old_ipl;
|
||||
}
|
||||
|
||||
static inline void
|
||||
_splset(ipl_t ipl)
|
||||
{
|
||||
mtpr(ipl, PR_IPL);
|
||||
}
|
||||
|
||||
static inline ipl_t
|
||||
_splget(void)
|
||||
{
|
||||
return mfpr(PR_IPL);
|
||||
}
|
||||
|
||||
static inline ipl_t
|
||||
splx(ipl_t new_ipl)
|
||||
{
|
||||
ipl_t old_ipl = _splget();
|
||||
_splset(new_ipl);
|
||||
return old_ipl;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
ipl_t _ipl;
|
||||
uint8_t _ipl;
|
||||
} ipl_cookie_t;
|
||||
|
||||
static inline ipl_cookie_t
|
||||
makeiplcookie(ipl_t ipl)
|
||||
{
|
||||
|
||||
return (ipl_cookie_t){._ipl = ipl};
|
||||
return (ipl_cookie_t){._ipl = (uint8_t)ipl};
|
||||
}
|
||||
|
||||
static inline int
|
||||
splraiseipl(ipl_cookie_t icookie)
|
||||
{
|
||||
register ipl_t __val;
|
||||
ipl_t newipl = icookie._ipl;
|
||||
ipl_t oldipl;
|
||||
|
||||
__asm volatile ("mfpr %1,%0" : "=&g" (__val) : "g" (PR_IPL));
|
||||
if (newipl > __val) {
|
||||
oldipl = _splget();
|
||||
if (newipl > oldipl) {
|
||||
_splset(newipl);
|
||||
}
|
||||
return __val;
|
||||
return oldipl;
|
||||
}
|
||||
|
||||
#define _setsirr(reg) mtpr((reg), PR_SIRR)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: mutex.h,v 1.6 2007/03/09 21:35:33 thorpej Exp $ */
|
||||
/* $NetBSD: mutex.h,v 1.7 2007/03/12 02:22:43 matt Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2002, 2007 The NetBSD Foundation, Inc.
|
||||
|
@ -86,7 +86,7 @@
|
|||
|
||||
struct kmutex {
|
||||
uintptr_t mtx_pad1;
|
||||
uint32_t mtx_pad2[2];
|
||||
uint32_t mtx_pad2;
|
||||
};
|
||||
|
||||
#else /* __MUTEX_PRIVATE */
|
||||
|
@ -94,19 +94,26 @@ struct kmutex {
|
|||
struct kmutex {
|
||||
/* Adaptive mutex */
|
||||
union {
|
||||
volatile uintptr_t mtxu_owner; /* 0-3 */
|
||||
__cpu_simple_lock_t mtxu_lock; /* 0 */
|
||||
volatile uintptr_t u_owner; /* 0-3 */
|
||||
struct {
|
||||
uint8_t s_dummylo; /* 0 */
|
||||
__cpu_simple_lock_t s_lock; /* 1 */
|
||||
ipl_cookie_t s_ipl; /* 2 */
|
||||
uint8_t s_dummyhi; /* 3 */
|
||||
} u_s;
|
||||
} mtx_u;
|
||||
ipl_cookie_t mtx_ipl; /* 4-7 */
|
||||
uint32_t mtx_id; /* 8-11 */
|
||||
uint32_t mtx_id; /* 4-7 */
|
||||
};
|
||||
#define mtx_owner mtx_u.mtxu_owner
|
||||
#define mtx_lock mtx_u.mtxu_lock
|
||||
#define mtx_owner mtx_u.u_owner
|
||||
#define mtx_lock mtx_u.u_s.s_lock
|
||||
#define mtx_ipl mtx_u.u_s.s_ipl
|
||||
|
||||
#define __HAVE_MUTEX_STUBS 1
|
||||
#define __HAVE_SPIN_MUTEX_STUBS 1
|
||||
|
||||
#define MUTEX_NO_SPIN_ACTIVE_P(ci) ((ci)->ci_mtx_count == 1)
|
||||
#ifndef LOCKDEBUG
|
||||
#define MUTEX_COUNT_BIAS 1
|
||||
#endif
|
||||
|
||||
static inline uintptr_t
|
||||
MUTEX_OWNER(uintptr_t owner)
|
||||
|
@ -143,6 +150,7 @@ static inline void
|
|||
MUTEX_INITIALIZE_SPIN(kmutex_t *mtx, u_int id, int ipl)
|
||||
{
|
||||
mtx->mtx_id = (id << 1) | 1;
|
||||
mtx->mtx_owner = 0x80000000;
|
||||
mtx->mtx_ipl = makeiplcookie(ipl);
|
||||
mtx->mtx_lock = 0;
|
||||
}
|
||||
|
@ -165,7 +173,7 @@ MUTEX_DESTROY(kmutex_t *mtx)
|
|||
static inline u_int
|
||||
MUTEX_GETID(volatile kmutex_t *mtx)
|
||||
{
|
||||
return (mtx)->mtx_id >> 1;
|
||||
return mtx->mtx_id >> 1;
|
||||
}
|
||||
|
||||
static inline bool
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: clock.c,v 1.46 2006/09/16 00:50:52 gdamore Exp $ */
|
||||
/* $NetBSD: clock.c,v 1.47 2007/03/12 02:22:43 matt Exp $ */
|
||||
/*
|
||||
* Copyright (c) 1995 Ludd, University of Lule}, Sweden.
|
||||
* All rights reserved.
|
||||
|
@ -30,7 +30,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.46 2006/09/16 00:50:52 gdamore Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.47 2007/03/12 02:22:43 matt Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/kernel.h>
|
||||
|
@ -135,6 +135,7 @@ cpu_initclocks(void)
|
|||
mtpr(0x800000d1, PR_ICCS); /* Start clock and enable interrupt */
|
||||
|
||||
todr_attach(&todr_handle);
|
||||
printf("cpu_initclocks: %#x\n", mfpr(PR_ICCS));
|
||||
}
|
||||
|
||||
int
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
# $NetBSD: genassym.cf,v 1.31 2007/02/17 05:34:07 matt Exp $
|
||||
# $NetBSD: genassym.cf,v 1.32 2007/03/12 02:22:43 matt Exp $
|
||||
#
|
||||
# Copyright (c) 1997 Ludd, University of Lule}, Sweden.
|
||||
# All rights reserved.
|
||||
|
@ -157,6 +157,9 @@ define PSL_IS PSL_IS
|
|||
define MTX_OWNER offsetof(struct kmutex, mtx_owner)
|
||||
define MTX_IPL offsetof(struct kmutex, mtx_ipl)
|
||||
define MTX_ID offsetof(struct kmutex, mtx_id)
|
||||
ifdef MUTEX_COUNT_BIAS
|
||||
define MTX_COUNT_BIAS MUTEX_COUNT_BIAS
|
||||
endif
|
||||
|
||||
define RW_OWNER offsetof(struct krwlock, rw_owner)
|
||||
define RW_LOCK offsetof(struct krwlock, rw_lock)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: lock_stubs.S,v 1.2 2007/02/17 05:34:07 matt Exp $ */
|
||||
/* $NetBSD: lock_stubs.S,v 1.3 2007/03/12 02:22:43 matt Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2002, 2006, 2007 The NetBSD Foundation, Inc.
|
||||
|
@ -36,10 +36,12 @@
|
|||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "opt_lockdebug.h"
|
||||
#include "opt_multiprocessor.h"
|
||||
#include <machine/asm.h>
|
||||
#include "assym.h"
|
||||
|
||||
#ifndef LOCKDEBUG
|
||||
/*
|
||||
* void mutex_enter(kmutex_t *);
|
||||
*
|
||||
|
@ -64,12 +66,13 @@ NENTRY(mutex_enter, 0)
|
|||
*/
|
||||
NENTRY(mutex_exit, 0)
|
||||
movl 4(%ap), %r0 /* get mutex */
|
||||
blbs MTX_ID(%r0), 1f /* go slow if this is SPIN */
|
||||
mfpr $PR_SSP, %r1 /* get curcpu */
|
||||
cmpl (%r0),CI_CURLWP(%r1) /* is the owner still us and */
|
||||
/* no waiters? */
|
||||
bneq 2f /* no, slow path */
|
||||
bneq 1f /* no, slow path */
|
||||
clrl (%r0) /* clear owner */
|
||||
2: ret
|
||||
ret
|
||||
|
||||
1: callg (%ap), _C_LABEL(mutex_vector_exit)
|
||||
ret
|
||||
|
@ -83,14 +86,13 @@ NENTRY(mutex_spin_enter, 0)
|
|||
blbc MTX_ID(%r0), 3f
|
||||
#endif
|
||||
mfpr $PR_IPL, %r2 /* get current IPL */
|
||||
cmpl MTX_IPL(%r0), %r2 /* does mutex have > IPL? */
|
||||
movzbl MTX_IPL(%r0), %r3
|
||||
cmpl %r3, %r2 /* does mutex have > IPL? */
|
||||
bleq 1f /* no, leave IPL alone */
|
||||
mtpr MTX_IPL(%r0), $PR_IPL /* yes, raise IPL */
|
||||
mtpr %r3, $PR_IPL /* yes, raise IPL */
|
||||
1: mfpr $PR_SSP, %r1 /* get curcpu */
|
||||
decl CI_MTX_COUNT(%r1) /* decr mutex count */
|
||||
bneq 2f /* was mutex count < 1 */
|
||||
sobgeq CI_MTX_COUNT(%r1), 2f /* decr mutex count */
|
||||
movl %r2, CI_MTX_OLDSPL(%r1) /* save was-current IPL */
|
||||
2:
|
||||
#if defined(DIAGNOSTIC) || defined(MULTIPROCESSOR)
|
||||
bbssi $0, (%r0), 3f /* take out mutex */
|
||||
ret
|
||||
|
@ -111,8 +113,7 @@ NENTRY(mutex_spin_exit, 0)
|
|||
#endif
|
||||
mfpr $PR_SSP, %r1 /* get curcpu */
|
||||
movl CI_MTX_OLDSPL(%r1), %r2 /* fetch oldspl */
|
||||
incl CI_MTX_COUNT(%r1) /* incr mtx count */
|
||||
bleq 1f /* was it positive? */
|
||||
aoblss $MTX_COUNT_BIAS, CI_MTX_COUNT(%r1), 1f /* incr mtx count */
|
||||
mtpr %r2, $PR_IPL /* yes, restore saved ipl */
|
||||
1: ret
|
||||
|
||||
|
@ -121,27 +122,33 @@ NENTRY(mutex_spin_exit, 0)
|
|||
ret
|
||||
#endif
|
||||
|
||||
#endif /* LOCKDEBUG */
|
||||
|
||||
/*
|
||||
* bool _rw_cas(krwlock_t *rw, uintptr_t old, uintptr_t new);
|
||||
* {
|
||||
* bool rv = false;
|
||||
* while (rw->rw_owner == old) {
|
||||
* if (__cpu_simple_try_lock(&rw->rw_lock)) {
|
||||
* if (old == rw->rw_owner) {
|
||||
* rw->rw_owner = new;
|
||||
* rv = true;
|
||||
* }
|
||||
* __cpu_simple_unlock(&rw->rw_lock);
|
||||
* break;
|
||||
* }
|
||||
* }
|
||||
* return rv;
|
||||
* }
|
||||
* bool _rw_cas(krwlock_t *rw, uintptr_t old, uintptr_t new);
|
||||
* {
|
||||
* bool rv = false;
|
||||
* int cnt = 4;
|
||||
* while (rw->rw_owner == old && --cnt != 0) {
|
||||
* if (__cpu_simple_try_lock(&rw->rw_lock)) {
|
||||
* if (old == rw->rw_owner) {
|
||||
* rw->rw_owner = new;
|
||||
* rv = true;
|
||||
* }
|
||||
* __cpu_simple_unlock(&rw->rw_lock);
|
||||
* break;
|
||||
* }
|
||||
* }
|
||||
* return rv;
|
||||
* }
|
||||
*/
|
||||
NENTRY(_rw_cas, 0)
|
||||
clrl %r0 /* rv = false */
|
||||
movl $4, %r3 /* cnt = 4 */
|
||||
movq 4(%ap), %r1 /* cache rw, old */
|
||||
1: cmpl (%r1), %r2 /* rw->rw_owner == old? */
|
||||
1: decl %r3 /* --cnt */
|
||||
beql 2f /* if cnt == 0, return */
|
||||
cmpl (%r1), %r2 /* rw->rw_owner == old? */
|
||||
bneq 2f /* nope, return */
|
||||
bbssi $0, RW_LOCK(%r1), 1b /* get lock, loop if failure */
|
||||
cmpl (%r1), %r2 /* rw->rw_owner still == old? */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: multicpu.c,v 1.19 2007/02/17 05:34:07 matt Exp $ */
|
||||
/* $NetBSD: multicpu.c,v 1.20 2007/03/12 02:22:43 matt Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2000 Ludd, University of Lule}, Sweden. All rights reserved.
|
||||
|
@ -35,7 +35,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: multicpu.c,v 1.19 2007/02/17 05:34:07 matt Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: multicpu.c,v 1.20 2007/03/12 02:22:43 matt Exp $");
|
||||
|
||||
#include "opt_multiprocessor.h"
|
||||
|
||||
|
@ -125,7 +125,9 @@ cpu_slavesetup(struct device *dev)
|
|||
ci = &sc->sc_ci;
|
||||
ci->ci_dev = dev;
|
||||
ci->ci_exit = scratch;
|
||||
ci->ci_mtx_count = 1;
|
||||
#ifdef MUTEX_COUNT_BIAS
|
||||
ci->ci_mtx_count = MUTEX_COUNT_BIAS;
|
||||
#endif
|
||||
ci->ci_pcb = (void *)((intptr_t)pcb & ~KERNBASE);
|
||||
ci->ci_istack = istackbase + PAGE_SIZE;
|
||||
SIMPLEQ_INSERT_TAIL(&cpus, ci, ci_next);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: pmap.c,v 1.147 2007/03/09 14:11:22 ad Exp $ */
|
||||
/* $NetBSD: pmap.c,v 1.148 2007/03/12 02:22:43 matt Exp $ */
|
||||
/*
|
||||
* Copyright (c) 1994, 1998, 1999, 2003 Ludd, University of Lule}, Sweden.
|
||||
* All rights reserved.
|
||||
|
@ -30,7 +30,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.147 2007/03/09 14:11:22 ad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.148 2007/03/12 02:22:43 matt Exp $");
|
||||
|
||||
#include "opt_ddb.h"
|
||||
#include "opt_cputype.h"
|
||||
|
@ -401,7 +401,9 @@ pmap_bootstrap()
|
|||
bzero((void *)pcb->SSP,
|
||||
sizeof(struct cpu_info) + sizeof(struct device));
|
||||
curcpu()->ci_exit = scratch;
|
||||
curcpu()->ci_mtx_count = 1;
|
||||
#ifdef MUTEX_COUNT_BIAS
|
||||
curcpu()->ci_mtx_count = MUTEX_COUNT_BIAS;
|
||||
#endif
|
||||
curcpu()->ci_dev = (void *)(pcb->SSP + sizeof(struct cpu_info));
|
||||
#if defined(MULTIPROCESSOR)
|
||||
curcpu()->ci_flags = CI_MASTERCPU|CI_RUNNING;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: subr.S,v 1.15 2007/03/04 07:28:12 ragge Exp $ */
|
||||
/* $NetBSD: subr.S,v 1.16 2007/03/12 02:22:43 matt Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994 Ludd, University of Lule}, Sweden.
|
||||
|
@ -206,7 +206,8 @@ _C_LABEL(ultrix_esigcode):
|
|||
|
||||
.align 2
|
||||
.globl _C_LABEL(idsptch), _C_LABEL(eidsptch)
|
||||
_C_LABEL(idsptch): pushr $0x3f
|
||||
_C_LABEL(idsptch):
|
||||
pushr $0x3f
|
||||
.word 0x9f16 # jsb to absolute address
|
||||
.long _C_LABEL(cmn_idsptch) # the absolute address
|
||||
.long 0 # the callback interrupt routine
|
||||
|
@ -215,16 +216,32 @@ _C_LABEL(idsptch): pushr $0x3f
|
|||
_C_LABEL(eidsptch):
|
||||
|
||||
_C_LABEL(cmn_idsptch):
|
||||
#if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)
|
||||
calls $0,_C_LABEL(krnlock)
|
||||
#endif
|
||||
movl (%sp)+,%r0 # get pointer to idspvec
|
||||
movl 8(%r0),%r1 # get evcnt pointer
|
||||
beql 1f # no ptr, skip increment
|
||||
incl EV_COUNT(%r1) # increment low longword
|
||||
adwc $0,EV_COUNT+4(%r1) # add any carry to hi longword
|
||||
1: incl _C_LABEL(uvmexp)+UVME_INTRS # increment uvmexp.intrs
|
||||
#if 0
|
||||
pushl %r0
|
||||
movq (%r0),-(%sp)
|
||||
pushab 2f
|
||||
calls $3,_C_LABEL(printf)
|
||||
movl (%sp)+,%r0
|
||||
#endif
|
||||
pushl 4(%r0) # push argument
|
||||
calls $1,*(%r0) # call interrupt routine
|
||||
#if defined(MULTIPROCESSOR) || defined(LOCKDEBUG)
|
||||
calls $0,_C_LABEL(krnunlock)
|
||||
#endif
|
||||
popr $0x3f # pop registers
|
||||
rei # return from interrut
|
||||
#if 0
|
||||
2: .asciz "intr %p(%p)\n"
|
||||
#endif
|
||||
|
||||
ENTRY(badaddr,0) # Called with addr,b/w/l
|
||||
mfpr $PR_IPL,%r0 # splhigh()
|
||||
|
@ -581,7 +598,7 @@ ENTRY(fuswintr,0)
|
|||
movl %r1,%r0
|
||||
ret
|
||||
|
||||
#if defined(MULTIPROCESSOR) || defined(DEBUG) || defined(DIAGNOSTIC)
|
||||
#if defined(MULTIPROCESSOR) || defined(DEBUG) || defined(DIAGNOSTIC) || defined(LOCKDEBUG)
|
||||
|
||||
JSBENTRY(Slock)
|
||||
1: bbssi $0,(%r1),1b
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: syscall.c,v 1.4 2007/02/16 02:17:42 ad Exp $ */
|
||||
/* $NetBSD: syscall.c,v 1.5 2007/03/12 02:22:43 matt Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1994 Ludd, University of Lule}, Sweden.
|
||||
|
@ -33,7 +33,7 @@
|
|||
/* All bugs are subject to removal without further notice */
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.4 2007/02/16 02:17:42 ad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.5 2007/03/12 02:22:43 matt Exp $");
|
||||
|
||||
#include "opt_multiprocessor.h"
|
||||
|
||||
|
@ -123,9 +123,9 @@ syscall_plain(struct trapframe *frame)
|
|||
goto bad;
|
||||
}
|
||||
|
||||
if ((callp->sy_flags & SYCALL_MPSAFE) != 0)
|
||||
if ((callp->sy_flags & SYCALL_MPSAFE) != 0) {
|
||||
err = (*callp->sy_call)(curlwp, args, rval);
|
||||
else {
|
||||
} else {
|
||||
KERNEL_LOCK(1, l);
|
||||
err = (*callp->sy_call)(curlwp, args, rval);
|
||||
KERNEL_UNLOCK_LAST(l);
|
||||
|
|
Loading…
Reference in New Issue