summaryrefslogtreecommitdiff
path: root/sys/arch
diff options
context:
space:
mode:
authorVisa Hankala <visa@cvs.openbsd.org>2017-04-20 13:57:31 +0000
committerVisa Hankala <visa@cvs.openbsd.org>2017-04-20 13:57:31 +0000
commitda85a125dd7fd9af53b0919887129daaf4fa53bb (patch)
treea8a5d35dfd86d6f624f47c01ea1bd6c6ac4b32b6 /sys/arch
parent4718dfdd3c76a956f1a6022f2dbb3c240b27f3e2 (diff)
Hook up mutex(9) to witness(4).
Diffstat (limited to 'sys/arch')
-rw-r--r--sys/arch/alpha/alpha/mutex.c16
-rw-r--r--sys/arch/alpha/include/mutex.h18
-rw-r--r--sys/arch/amd64/amd64/mutex.S8
-rw-r--r--sys/arch/amd64/include/mutex.h18
-rw-r--r--sys/arch/arm/armv7/armv7_mutex.c10
-rw-r--r--sys/arch/arm/include/mutex.h18
-rw-r--r--sys/arch/arm64/include/mutex.h18
-rw-r--r--sys/arch/hppa/hppa/mutex.c16
-rw-r--r--sys/arch/hppa/include/mutex.h26
-rw-r--r--sys/arch/i386/i386/mutex.S10
-rw-r--r--sys/arch/i386/include/mutex.h18
-rw-r--r--sys/arch/m88k/include/mutex.h19
-rw-r--r--sys/arch/m88k/m88k/mutex.S8
-rw-r--r--sys/arch/mips64/include/mutex.h18
-rw-r--r--sys/arch/mips64/mips64/mutex.c16
-rw-r--r--sys/arch/powerpc/include/mutex.h18
-rw-r--r--sys/arch/powerpc/powerpc/mutex.c16
-rw-r--r--sys/arch/sh/include/mutex.h7
-rw-r--r--sys/arch/sh/sh/mutex.c10
-rw-r--r--sys/arch/sparc64/include/mutex.h18
-rw-r--r--sys/arch/sparc64/sparc64/mutex.S8
21 files changed, 219 insertions, 95 deletions
diff --git a/sys/arch/alpha/alpha/mutex.c b/sys/arch/alpha/alpha/mutex.c
index f3603e42154..ada28fad1cc 100644
--- a/sys/arch/alpha/alpha/mutex.c
+++ b/sys/arch/alpha/alpha/mutex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.c,v 1.16 2016/06/13 01:26:14 dlg Exp $ */
+/* $OpenBSD: mutex.c,v 1.17 2017/04/20 13:57:29 visa Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -45,14 +45,14 @@ __mtx_init(struct mutex *mtx, int wantipl)
#ifdef MULTIPROCESSOR
void
-mtx_enter(struct mutex *mtx)
+__mtx_enter(struct mutex *mtx)
{
- while (mtx_enter_try(mtx) == 0)
+ while (__mtx_enter_try(mtx) == 0)
SPINLOCK_SPIN_HOOK;
}
int
-mtx_enter_try(struct mutex *mtx)
+__mtx_enter_try(struct mutex *mtx)
{
struct cpu_info *owner, *ci = curcpu();
int s;
@@ -82,7 +82,7 @@ mtx_enter_try(struct mutex *mtx)
}
#else
void
-mtx_enter(struct mutex *mtx)
+__mtx_enter(struct mutex *mtx)
{
struct cpu_info *ci = curcpu();
@@ -101,15 +101,15 @@ mtx_enter(struct mutex *mtx)
}
int
-mtx_enter_try(struct mutex *mtx)
+__mtx_enter_try(struct mutex *mtx)
{
- mtx_enter(mtx);
+ __mtx_enter(mtx);
return (1);
}
#endif
void
-mtx_leave(struct mutex *mtx)
+__mtx_leave(struct mutex *mtx)
{
int s;
diff --git a/sys/arch/alpha/include/mutex.h b/sys/arch/alpha/include/mutex.h
index c5509881c5a..a75afb2e4e8 100644
--- a/sys/arch/alpha/include/mutex.h
+++ b/sys/arch/alpha/include/mutex.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.h,v 1.7 2015/04/17 12:38:54 dlg Exp $ */
+/* $OpenBSD: mutex.h,v 1.8 2017/04/20 13:57:29 visa Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -28,10 +28,15 @@
#ifndef _MACHINE_MUTEX_H_
#define _MACHINE_MUTEX_H_
+#include <sys/_lock.h>
+
struct mutex {
void *mtx_owner;
int mtx_wantipl;
int mtx_oldipl;
+#ifdef WITNESS
+ struct lock_object mtx_lock_obj;
+#endif
};
/*
@@ -48,10 +53,16 @@ struct mutex {
#define __MUTEX_IPL(ipl) (ipl)
#endif
-#define MUTEX_INITIALIZER(ipl) { NULL, __MUTEX_IPL((ipl)), IPL_NONE }
+#ifdef WITNESS
+#define MUTEX_INITIALIZER_FLAGS(ipl, name, flags) \
+ { NULL, __MUTEX_IPL((ipl)), IPL_NONE, MTX_LO_INITIALIZER(name, flags) }
+#else
+#define MUTEX_INITIALIZER_FLAGS(ipl, name, flags) \
+ { NULL, __MUTEX_IPL((ipl)), IPL_NONE }
+#endif
void __mtx_init(struct mutex *, int);
-#define mtx_init(mtx, ipl) __mtx_init((mtx), __MUTEX_IPL((ipl)))
+#define _mtx_init(mtx, ipl) __mtx_init((mtx), __MUTEX_IPL((ipl)))
#ifdef DIAGNOSTIC
#define MUTEX_ASSERT_LOCKED(mtx) do { \
@@ -68,6 +79,7 @@ void __mtx_init(struct mutex *, int);
#define MUTEX_ASSERT_UNLOCKED(mtx) do { } while (0)
#endif
+#define MUTEX_LOCK_OBJECT(mtx) (&(mtx)->mtx_lock_obj)
#define MUTEX_OLDIPL(mtx) (mtx)->mtx_oldipl
#endif /* _MACHINE_MUTEX_H_ */
diff --git a/sys/arch/amd64/amd64/mutex.S b/sys/arch/amd64/amd64/mutex.S
index 5d33dbcf451..e31c2198a36 100644
--- a/sys/arch/amd64/amd64/mutex.S
+++ b/sys/arch/amd64/amd64/mutex.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.S,v 1.11 2017/03/07 14:03:22 visa Exp $ */
+/* $OpenBSD: mutex.S,v 1.12 2017/04/20 13:57:29 visa Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -44,7 +44,7 @@ ENTRY(__mtx_init)
movq $0, MTX_OWNER(%rdi)
ret
-ENTRY(mtx_enter)
+ENTRY(__mtx_enter)
1: movl MTX_WANTIPL(%rdi), %eax
movq CPUVAR(SELF), %rcx
movl CPU_INFO_ILEVEL(%rcx), %edx # oipl = cpl;
@@ -89,7 +89,7 @@ ENTRY(mtx_enter)
5: .asciz "mtx_enter: locking against myself"
#endif
-ENTRY(mtx_enter_try)
+ENTRY(__mtx_enter_try)
1: movl MTX_WANTIPL(%rdi), %eax
movq CPUVAR(SELF), %rcx
movl CPU_INFO_ILEVEL(%rcx), %edx # oipl = cpl;
@@ -133,7 +133,7 @@ ENTRY(mtx_enter_try)
#endif
-ENTRY(mtx_leave)
+ENTRY(__mtx_leave)
movq %rdi, %rax
#ifdef DIAGNOSTIC
movq CPUVAR(SELF), %rcx
diff --git a/sys/arch/amd64/include/mutex.h b/sys/arch/amd64/include/mutex.h
index 092760840fb..69685e53443 100644
--- a/sys/arch/amd64/include/mutex.h
+++ b/sys/arch/amd64/include/mutex.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.h,v 1.7 2014/03/29 18:09:28 guenther Exp $ */
+/* $OpenBSD: mutex.h,v 1.8 2017/04/20 13:57:29 visa Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -27,10 +27,15 @@
#ifndef _MACHINE_MUTEX_H_
#define _MACHINE_MUTEX_H_
+#include <sys/_lock.h>
+
struct mutex {
int mtx_wantipl;
int mtx_oldipl;
volatile void *mtx_owner;
+#ifdef WITNESS
+ struct lock_object mtx_lock_obj;
+#endif
};
/*
@@ -47,10 +52,16 @@ struct mutex {
#define __MUTEX_IPL(ipl) (ipl)
#endif
-#define MUTEX_INITIALIZER(ipl) { __MUTEX_IPL((ipl)), 0, NULL }
+#ifdef WITNESS
+#define MUTEX_INITIALIZER_FLAGS(ipl, name, flags) \
+ { __MUTEX_IPL((ipl)), 0, NULL, MTX_LO_INITIALIZER(name, flags) }
+#else
+#define MUTEX_INITIALIZER_FLAGS(ipl, name, flags) \
+ { __MUTEX_IPL((ipl)), 0, NULL }
+#endif
void __mtx_init(struct mutex *, int);
-#define mtx_init(mtx, ipl) __mtx_init((mtx), __MUTEX_IPL((ipl)))
+#define _mtx_init(mtx, ipl) __mtx_init((mtx), __MUTEX_IPL((ipl)))
#define MUTEX_ASSERT_LOCKED(mtx) do { \
if ((mtx)->mtx_owner != curcpu()) \
@@ -62,6 +73,7 @@ void __mtx_init(struct mutex *, int);
panic("mutex %p held in %s", (mtx), __func__); \
} while (0)
+#define MUTEX_LOCK_OBJECT(mtx) (&(mtx)->mtx_lock_obj)
#define MUTEX_OLDIPL(mtx) (mtx)->mtx_oldipl
#endif
diff --git a/sys/arch/arm/armv7/armv7_mutex.c b/sys/arch/arm/armv7/armv7_mutex.c
index 47120723594..8b138116783 100644
--- a/sys/arch/arm/armv7/armv7_mutex.c
+++ b/sys/arch/arm/armv7/armv7_mutex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: armv7_mutex.c,v 1.2 2013/05/09 14:27:17 patrick Exp $ */
+/* $OpenBSD: armv7_mutex.c,v 1.3 2017/04/20 13:57:29 visa Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -43,7 +43,7 @@
* raising semantics of the mutexes.
*/
void
-mtx_init(struct mutex *mtx, int wantipl)
+__mtx_init(struct mutex *mtx, int wantipl)
{
mtx->mtx_oldipl = 0;
mtx->mtx_wantipl = wantipl;
@@ -51,7 +51,7 @@ mtx_init(struct mutex *mtx, int wantipl)
}
void
-mtx_enter(struct mutex *mtx)
+__mtx_enter(struct mutex *mtx)
{
if (mtx->mtx_wantipl != IPL_NONE)
mtx->mtx_oldipl = _splraise(mtx->mtx_wantipl);
@@ -64,7 +64,7 @@ mtx_enter(struct mutex *mtx)
}
int
-mtx_enter_try(struct mutex *mtx)
+__mtx_enter_try(struct mutex *mtx)
{
if (mtx->mtx_wantipl != IPL_NONE)
mtx->mtx_oldipl = _splraise(mtx->mtx_wantipl);
@@ -82,7 +82,7 @@ mtx_enter_try(struct mutex *mtx)
}
void
-mtx_leave(struct mutex *mtx)
+__mtx_leave(struct mutex *mtx)
{
MUTEX_ASSERT_LOCKED(mtx);
mtx->mtx_lock = 0;
diff --git a/sys/arch/arm/include/mutex.h b/sys/arch/arm/include/mutex.h
index 9dcea763704..a2e26718ef8 100644
--- a/sys/arch/arm/include/mutex.h
+++ b/sys/arch/arm/include/mutex.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.h,v 1.2 2011/03/23 16:54:34 pirofti Exp $ */
+/* $OpenBSD: mutex.h,v 1.3 2017/04/20 13:57:29 visa Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -28,6 +28,8 @@
#ifndef _ARM_MUTEX_H_
#define _ARM_MUTEX_H_
+#include <sys/_lock.h>
+
/*
* Simple non-mp implementation.
*/
@@ -35,11 +37,20 @@ struct mutex {
int mtx_lock;
int mtx_wantipl;
int mtx_oldipl;
+#ifdef WITNESS
+ struct lock_object mtx_lock_obj;
+#endif
};
-void mtx_init(struct mutex *, int);
+void __mtx_init(struct mutex *, int);
-#define MUTEX_INITIALIZER(ipl) { 0, ipl, 0 }
+#ifdef WITNESS
+#define MUTEX_INITIALIZER_FLAGS(ipl, name, flags) \
+ { 0, ipl, 0, MTX_LO_INITIALIZER(name, flags) }
+#else
+#define MUTEX_INITIALIZER_FLAGS(ipl, name, flags) \
+ { 0, ipl, 0 }
+#endif
#ifdef DIAGNOSTIC
#define MUTEX_ASSERT_LOCKED(mtx) do { \
@@ -56,6 +67,7 @@ void mtx_init(struct mutex *, int);
#define MUTEX_ASSERT_UNLOCKED(mtx) do { } while (0)
#endif
+#define MUTEX_LOCK_OBJECT(mtx) (&(mtx)->mtx_lock_obj)
#define MUTEX_OLDIPL(mtx) (mtx)->mtx_oldipl
#endif
diff --git a/sys/arch/arm64/include/mutex.h b/sys/arch/arm64/include/mutex.h
index 1cad62e8b4e..5fec6284c91 100644
--- a/sys/arch/arm64/include/mutex.h
+++ b/sys/arch/arm64/include/mutex.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.h,v 1.1 2016/12/17 23:38:33 patrick Exp $ */
+/* $OpenBSD: mutex.h,v 1.2 2017/04/20 13:57:29 visa Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -27,10 +27,15 @@
#ifndef _MACHINE_MUTEX_H_
#define _MACHINE_MUTEX_H_
+#include <sys/_lock.h>
+
struct mutex {
int mtx_wantipl;
int mtx_oldipl;
volatile void *mtx_owner;
+#ifdef WITNESS
+ struct lock_object mtx_lock_obj;
+#endif
};
/*
@@ -47,10 +52,16 @@ struct mutex {
#define __MUTEX_IPL(ipl) (ipl)
#endif
-#define MUTEX_INITIALIZER(ipl) { __MUTEX_IPL((ipl)), 0, NULL }
+#ifdef WITNESS
+#define MUTEX_INITIALIZER_FLAGS(ipl, name, flags) \
+ { __MUTEX_IPL((ipl)), 0, NULL, MTX_LO_INITIALIZER(name, flags) }
+#else
+#define MUTEX_INITIALIZER_FLAGS(ipl, name, flags) \
+ { __MUTEX_IPL((ipl)), 0, NULL }
+#endif
void __mtx_init(struct mutex *, int);
-#define mtx_init(mtx, ipl) __mtx_init((mtx), __MUTEX_IPL((ipl)))
+#define _mtx_init(mtx, ipl) __mtx_init((mtx), __MUTEX_IPL((ipl)))
#define MUTEX_ASSERT_LOCKED(mtx) do { \
if ((mtx)->mtx_owner != curcpu()) \
@@ -62,6 +73,7 @@ void __mtx_init(struct mutex *, int);
panic("mutex %p held in %s", (mtx), __func__); \
} while (0)
+#define MUTEX_LOCK_OBJECT(mtx) (&(mtx)->mtx_lock_obj)
#define MUTEX_OLDIPL(mtx) (mtx)->mtx_oldipl
#endif
diff --git a/sys/arch/hppa/hppa/mutex.c b/sys/arch/hppa/hppa/mutex.c
index 160337c1aa7..9da3224674d 100644
--- a/sys/arch/hppa/hppa/mutex.c
+++ b/sys/arch/hppa/hppa/mutex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.c,v 1.15 2015/09/20 19:19:03 kettenis Exp $ */
+/* $OpenBSD: mutex.c,v 1.16 2017/04/20 13:57:29 visa Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -57,14 +57,14 @@ __mtx_init(struct mutex *mtx, int wantipl)
#ifdef MULTIPROCESSOR
void
-mtx_enter(struct mutex *mtx)
+__mtx_enter(struct mutex *mtx)
{
- while (mtx_enter_try(mtx) == 0)
+ while (__mtx_enter_try(mtx) == 0)
;
}
int
-mtx_enter_try(struct mutex *mtx)
+__mtx_enter_try(struct mutex *mtx)
{
struct cpu_info *ci = curcpu();
volatile int *lock = __mtx_lock(mtx);
@@ -104,7 +104,7 @@ mtx_enter_try(struct mutex *mtx)
}
#else
void
-mtx_enter(struct mutex *mtx)
+__mtx_enter(struct mutex *mtx)
{
struct cpu_info *ci = curcpu();
@@ -124,15 +124,15 @@ mtx_enter(struct mutex *mtx)
}
int
-mtx_enter_try(struct mutex *mtx)
+__mtx_enter_try(struct mutex *mtx)
{
- mtx_enter(mtx);
+ __mtx_enter(mtx);
return (1);
}
#endif
void
-mtx_leave(struct mutex *mtx)
+__mtx_leave(struct mutex *mtx)
{
#ifdef MULTIPROCESSOR
volatile int *lock = __mtx_lock(mtx);
diff --git a/sys/arch/hppa/include/mutex.h b/sys/arch/hppa/include/mutex.h
index 36be0577813..48eacedd33e 100644
--- a/sys/arch/hppa/include/mutex.h
+++ b/sys/arch/hppa/include/mutex.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.h,v 1.6 2015/05/02 10:59:47 dlg Exp $ */
+/* $OpenBSD: mutex.h,v 1.7 2017/04/20 13:57:29 visa Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -28,6 +28,8 @@
#ifndef _MACHINE_MUTEX_H_
#define _MACHINE_MUTEX_H_
+#include <sys/_lock.h>
+
#define MUTEX_UNLOCKED { 1, 1, 1, 1 }
/* Note: mtx_lock must be 16-byte aligned. */
@@ -38,6 +40,9 @@ struct mutex {
int mtx_wantipl;
int mtx_oldipl;
void *mtx_owner;
+#ifdef WITNESS
+ struct lock_object mtx_lock_obj;
+#endif
};
/*
@@ -50,14 +55,22 @@ struct mutex {
#ifdef MULTIPROCESSOR
#define __MUTEX_IPL(ipl) \
(((ipl) > IPL_NONE && (ipl) < IPL_AUDIO) ? IPL_AUDIO : (ipl))
-#define MUTEX_INITIALIZER(ipl) { MUTEX_UNLOCKED, __MUTEX_IPL((ipl)), 0, NULL }
-#else
+#ifdef WITNESS
+#define MUTEX_INITIALIZER_FLAGS(ipl, name, flags) \
+ { MUTEX_UNLOCKED, __MUTEX_IPL((ipl)), 0, NULL, \
+ MTX_LO_INITIALIZER(name, flags) }
+#else /* WITNESS */
+#define MUTEX_INITIALIZER_FLAGS(ipl, name, flags) \
+ { MUTEX_UNLOCKED, __MUTEX_IPL((ipl)), 0, NULL }
+#endif /* WITNESS */
+#else /* MULTIPROCESSOR */
#define __MUTEX_IPL(ipl) (ipl)
-#define MUTEX_INITIALIZER(ipl) { __MUTEX_IPL((ipl)), 0, NULL }
-#endif
+#define MUTEX_INITIALIZER_FLAGS(ipl, name, flags) \
+ { __MUTEX_IPL((ipl)), 0, NULL }
+#endif /* MULTIPROCESSOR */
void __mtx_init(struct mutex *, int);
-#define mtx_init(mtx, ipl) __mtx_init((mtx), __MUTEX_IPL((ipl)))
+#define _mtx_init(mtx, ipl) __mtx_init((mtx), __MUTEX_IPL((ipl)))
#ifdef DIAGNOSTIC
#define MUTEX_ASSERT_LOCKED(mtx) do { \
@@ -74,6 +87,7 @@ void __mtx_init(struct mutex *, int);
#define MUTEX_ASSERT_UNLOCKED(mtx) do { } while (0)
#endif
+#define MUTEX_LOCK_OBJECT(mtx) (&(mtx)->mtx_lock_obj)
#define MUTEX_OLDIPL(mtx) (mtx)->mtx_oldipl
#endif
diff --git a/sys/arch/i386/i386/mutex.S b/sys/arch/i386/i386/mutex.S
index f3fbd7b802b..afa3446ca71 100644
--- a/sys/arch/i386/i386/mutex.S
+++ b/sys/arch/i386/i386/mutex.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.S,v 1.10 2017/03/07 14:03:22 visa Exp $ */
+/* $OpenBSD: mutex.S,v 1.11 2017/04/20 13:57:29 visa Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -45,7 +45,7 @@ ENTRY(__mtx_init)
#define SOFF 8
-ENTRY(mtx_enter)
+ENTRY(__mtx_enter)
pushl %ebp
movl %esp, %ebp
1: movl SOFF(%ebp), %ecx
@@ -93,7 +93,7 @@ ENTRY(mtx_enter)
6: .asciz "mtx_enter: locking against myself"
#endif
-ENTRY(mtx_enter_try)
+ENTRY(__mtx_enter_try)
pushl %ebp
movl %esp, %ebp
1: movl SOFF(%ebp), %ecx
@@ -140,8 +140,8 @@ ENTRY(mtx_enter_try)
5: .asciz "mtx_enter_try: locking against myself"
#endif
-
-ENTRY(mtx_leave)
+
+ENTRY(__mtx_leave)
pushl %ebp
movl %esp, %ebp
movl SOFF(%ebp), %ecx
diff --git a/sys/arch/i386/include/mutex.h b/sys/arch/i386/include/mutex.h
index 8fce51d2310..72d9bbf1638 100644
--- a/sys/arch/i386/include/mutex.h
+++ b/sys/arch/i386/include/mutex.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.h,v 1.8 2015/07/02 23:01:19 dlg Exp $ */
+/* $OpenBSD: mutex.h,v 1.9 2017/04/20 13:57:29 visa Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -27,6 +27,8 @@
#ifndef _MACHINE_MUTEX_H_
#define _MACHINE_MUTEX_H_
+#include <sys/_lock.h>
+
/*
* XXX - we don't really need the mtx_lock field, we can use mtx_oldipl
* as the lock to save some space.
@@ -36,6 +38,9 @@ struct mutex {
int mtx_wantipl;
int mtx_oldipl;
void *mtx_owner;
+#ifdef WITNESS
+ struct lock_object mtx_lock_obj;
+#endif
};
/*
@@ -52,10 +57,16 @@ struct mutex {
#define __MUTEX_IPL(ipl) (ipl)
#endif
-#define MUTEX_INITIALIZER(ipl) { 0, __MUTEX_IPL((ipl)), 0, NULL }
+#ifdef WITNESS
+#define MUTEX_INITIALIZER_FLAGS(ipl, name, flags) \
+ { 0, __MUTEX_IPL(ipl), 0, NULL, MTX_LO_INITIALIZER(name, flags) }
+#else
+#define MUTEX_INITIALIZER_FLAGS(ipl, name, flags) \
+ { 0, __MUTEX_IPL(ipl), 0, NULL }
+#endif
void __mtx_init(struct mutex *, int);
-#define mtx_init(mtx, ipl) __mtx_init((mtx), __MUTEX_IPL((ipl)))
+#define _mtx_init(mtx, ipl) __mtx_init((mtx), __MUTEX_IPL((ipl)))
#define MUTEX_ASSERT_LOCKED(mtx) do { \
if ((mtx)->mtx_owner != curcpu()) \
@@ -67,6 +78,7 @@ void __mtx_init(struct mutex *, int);
panic("mutex %p held in %s", (mtx), __func__); \
} while (0)
+#define MUTEX_LOCK_OBJECT(mtx) (&(mtx)->mtx_lock_obj)
#define MUTEX_OLDIPL(mtx) (mtx)->mtx_oldipl
#endif
diff --git a/sys/arch/m88k/include/mutex.h b/sys/arch/m88k/include/mutex.h
index 73cd600b766..dba995bf6d6 100644
--- a/sys/arch/m88k/include/mutex.h
+++ b/sys/arch/m88k/include/mutex.h
@@ -1,6 +1,6 @@
#ifndef _M88K_MUTEX_H_
#define _M88K_MUTEX_H_
-/* $OpenBSD: mutex.h,v 1.4 2015/07/03 15:12:49 miod Exp $ */
+/* $OpenBSD: mutex.h,v 1.5 2017/04/20 13:57:29 visa Exp $ */
/*
* Copyright (c) 2005, Miodrag Vallat.
@@ -27,11 +27,16 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include <sys/_lock.h>
+
struct mutex {
volatile int mtx_lock; /* mutex.S relies upon this field being first */
int mtx_wantipl;
int mtx_oldipl;
void *mtx_owner;
+#ifdef WITNESS
+ struct lock_object mtx_lock_obj;
+#endif
};
/*
@@ -48,10 +53,17 @@ struct mutex {
#define __MUTEX_IPL(ipl) (ipl)
#endif
-#define MUTEX_INITIALIZER(ipl) { 0, __MUTEX_IPL((ipl)), IPL_NONE, NULL }
+#ifdef WITNESS
+#define MUTEX_INITIALIZER_FLAGS(ipl, name, flags) \
+ { 0, __MUTEX_IPL((ipl)), IPL_NONE, NULL, \
+ MTX_LO_INITIALIZER(name, flags) }
+#else
+#define MUTEX_INITIALIZER_FLAGS(ipl, name, flags) \
+ { 0, __MUTEX_IPL((ipl)), IPL_NONE, NULL }
+#endif
void __mtx_init(struct mutex *, int);
-#define mtx_init(mtx, ipl) __mtx_init((mtx), __MUTEX_IPL((ipl)))
+#define _mtx_init(mtx, ipl) __mtx_init((mtx), __MUTEX_IPL((ipl)))
#ifdef DIAGNOSTIC
@@ -72,6 +84,7 @@ void __mtx_init(struct mutex *, int);
#endif
+#define MUTEX_LOCK_OBJECT(mtx) (&(mtx)->mtx_lock_obj)
#define MUTEX_OLDIPL(mtx) (mtx)->mtx_oldipl
#endif /* _M88K_MUTEX_H_ */
diff --git a/sys/arch/m88k/m88k/mutex.S b/sys/arch/m88k/m88k/mutex.S
index 5f0fee2edc5..2cc5a3f5a6c 100644
--- a/sys/arch/m88k/m88k/mutex.S
+++ b/sys/arch/m88k/m88k/mutex.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.S,v 1.15 2016/06/13 23:51:59 dlg Exp $ */
+/* $OpenBSD: mutex.S,v 1.16 2017/04/20 13:57:30 visa Exp $ */
/*
* Copyright (c) 2005, Miodrag Vallat.
@@ -45,7 +45,7 @@ ENTRY(__mtx_init)
/*
* void mtx_enter(struct mutex *mtx)
*/
-ENTRY(mtx_enter)
+ENTRY(__mtx_enter)
subu %r31, %r31, 8
st %r1, %r31, 4 /* save return address */
@@ -138,7 +138,7 @@ enter_panic:
/*
* int mtx_enter_try(struct mutex *mtx)
*/
-ENTRY(mtx_enter_try)
+ENTRY(__mtx_enter_try)
subu %r31, %r31, 8
st %r1, %r31, 4 /* save return address */
@@ -232,7 +232,7 @@ enter_try_panic:
/*
* void mtx_leave(struct mutex *mtx)
*/
-ENTRY(mtx_leave)
+ENTRY(__mtx_leave)
ld %r3, %r2, MTX_OLDIPL
ld %r4, %r2, MTX_WANTIPL
#ifdef DIAGNOSTIC
diff --git a/sys/arch/mips64/include/mutex.h b/sys/arch/mips64/include/mutex.h
index 6ba15aca16e..e8cd240b8ee 100644
--- a/sys/arch/mips64/include/mutex.h
+++ b/sys/arch/mips64/include/mutex.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.h,v 1.1 2015/07/08 13:37:31 dlg Exp $ */
+/* $OpenBSD: mutex.h,v 1.2 2017/04/20 13:57:30 visa Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -28,10 +28,15 @@
#ifndef _MACHINE_MUTEX_H_
#define _MACHINE_MUTEX_H_
+#include <sys/_lock.h>
+
struct mutex {
void *mtx_owner;
int mtx_wantipl;
int mtx_oldipl;
+#ifdef WITNESS
+ struct lock_object mtx_lock_obj;
+#endif
};
/*
@@ -48,10 +53,16 @@ struct mutex {
#define __MUTEX_IPL(ipl) (ipl)
#endif
-#define MUTEX_INITIALIZER(ipl) { NULL, __MUTEX_IPL((ipl)), IPL_NONE }
+#ifdef WITNESS
+#define MUTEX_INITIALIZER_FLAGS(ipl, name, flags) \
+ { NULL, __MUTEX_IPL((ipl)), IPL_NONE, MTX_LO_INITIALIZER(name, flags) }
+#else
+#define MUTEX_INITIALIZER_FLAGS(ipl, name, flags) \
+ { NULL, __MUTEX_IPL((ipl)), IPL_NONE }
+#endif
void __mtx_init(struct mutex *, int);
-#define mtx_init(mtx, ipl) __mtx_init((mtx), __MUTEX_IPL((ipl)))
+#define _mtx_init(mtx, ipl) __mtx_init((mtx), __MUTEX_IPL((ipl)))
#ifdef DIAGNOSTIC
#define MUTEX_ASSERT_LOCKED(mtx) do { \
@@ -68,6 +79,7 @@ void __mtx_init(struct mutex *, int);
#define MUTEX_ASSERT_UNLOCKED(mtx) do { } while (0)
#endif
+#define MUTEX_LOCK_OBJECT(mtx) (&(mtx)->mtx_lock_obj)
#define MUTEX_OLDIPL(mtx) (mtx)->mtx_oldipl
#endif
diff --git a/sys/arch/mips64/mips64/mutex.c b/sys/arch/mips64/mips64/mutex.c
index f05db1894ef..b0923d9605f 100644
--- a/sys/arch/mips64/mips64/mutex.c
+++ b/sys/arch/mips64/mips64/mutex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.c,v 1.4 2016/03/19 11:34:22 mpi Exp $ */
+/* $OpenBSD: mutex.c,v 1.5 2017/04/20 13:57:30 visa Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -54,13 +54,13 @@ extern int __mp_lock_spinout;
#endif
void
-mtx_enter(struct mutex *mtx)
+__mtx_enter(struct mutex *mtx)
{
#ifdef MP_LOCKDEBUG
int nticks = __mp_lock_spinout;
#endif
- while (mtx_enter_try(mtx) == 0) {
+ while (__mtx_enter_try(mtx) == 0) {
#ifdef MP_LOCKDEBUG
if (--nticks == 0) {
db_printf("%s(%p): lock spun out", __func__, mtx);
@@ -72,7 +72,7 @@ mtx_enter(struct mutex *mtx)
}
int
-mtx_enter_try(struct mutex *mtx)
+__mtx_enter_try(struct mutex *mtx)
{
struct cpu_info *owner, *ci = curcpu();
int s;
@@ -102,7 +102,7 @@ mtx_enter_try(struct mutex *mtx)
}
#else
void
-mtx_enter(struct mutex *mtx)
+__mtx_enter(struct mutex *mtx)
{
struct cpu_info *ci = curcpu();
@@ -122,15 +122,15 @@ mtx_enter(struct mutex *mtx)
}
int
-mtx_enter_try(struct mutex *mtx)
+__mtx_enter_try(struct mutex *mtx)
{
- mtx_enter(mtx);
+ __mtx_enter(mtx);
return (1);
}
#endif
void
-mtx_leave(struct mutex *mtx)
+__mtx_leave(struct mutex *mtx)
{
int s;
diff --git a/sys/arch/powerpc/include/mutex.h b/sys/arch/powerpc/include/mutex.h
index 8f6f2f1d57b..2826ebd6f08 100644
--- a/sys/arch/powerpc/include/mutex.h
+++ b/sys/arch/powerpc/include/mutex.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.h,v 1.5 2015/08/14 06:14:19 dlg Exp $ */
+/* $OpenBSD: mutex.h,v 1.6 2017/04/20 13:57:30 visa Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -27,10 +27,15 @@
#ifndef _POWERPC_MUTEX_H_
#define _POWERPC_MUTEX_H_
+#include <sys/_lock.h>
+
struct mutex {
volatile void *mtx_owner;
int mtx_wantipl;
int mtx_oldipl;
+#ifdef WITNESS
+ struct lock_object mtx_lock_obj;
+#endif
};
/*
@@ -47,10 +52,16 @@ struct mutex {
#define __MUTEX_IPL(ipl) (ipl)
#endif
-#define MUTEX_INITIALIZER(ipl) { NULL, __MUTEX_IPL(ipl), IPL_NONE }
+#ifdef WITNESS
+#define MUTEX_INITIALIZER_FLAGS(ipl, name, flags) \
+ { NULL, __MUTEX_IPL(ipl), IPL_NONE, MTX_LO_INITIALIZER(name, flags) }
+#else
+#define MUTEX_INITIALIZER_FLAGS(ipl, name, flags) \
+ { NULL, __MUTEX_IPL(ipl), IPL_NONE }
+#endif
void __mtx_init(struct mutex *, int);
-#define mtx_init(mtx, ipl) __mtx_init((mtx), __MUTEX_IPL((ipl)))
+#define _mtx_init(mtx, ipl) __mtx_init((mtx), __MUTEX_IPL((ipl)))
#ifdef DIAGNOSTIC
#define MUTEX_ASSERT_LOCKED(mtx) do { \
@@ -67,6 +78,7 @@ void __mtx_init(struct mutex *, int);
#define MUTEX_ASSERT_UNLOCKED(mtx) do { } while (0)
#endif
+#define MUTEX_LOCK_OBJECT(mtx) (&(mtx)->mtx_lock_obj)
#define MUTEX_OLDIPL(mtx) ((mtx)->mtx_oldipl)
#endif
diff --git a/sys/arch/powerpc/powerpc/mutex.c b/sys/arch/powerpc/powerpc/mutex.c
index 1428dfb595a..699fad5a6ad 100644
--- a/sys/arch/powerpc/powerpc/mutex.c
+++ b/sys/arch/powerpc/powerpc/mutex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.c,v 1.3 2016/03/19 11:34:22 mpi Exp $ */
+/* $OpenBSD: mutex.c,v 1.4 2017/04/20 13:57:30 visa Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -54,13 +54,13 @@ extern int __mp_lock_spinout;
#endif
void
-mtx_enter(struct mutex *mtx)
+__mtx_enter(struct mutex *mtx)
{
#if defined(MP_LOCKDEBUG)
int nticks = __mp_lock_spinout;
#endif
- while (mtx_enter_try(mtx) == 0) {
+ while (__mtx_enter_try(mtx) == 0) {
SPINLOCK_SPIN_HOOK;
#if defined(MP_LOCKDEBUG)
@@ -73,7 +73,7 @@ mtx_enter(struct mutex *mtx)
}
int
-mtx_enter_try(struct mutex *mtx)
+__mtx_enter_try(struct mutex *mtx)
{
struct cpu_info *owner, *ci = curcpu();
int s;
@@ -103,7 +103,7 @@ mtx_enter_try(struct mutex *mtx)
}
#else
void
-mtx_enter(struct mutex *mtx)
+__mtx_enter(struct mutex *mtx)
{
struct cpu_info *ci = curcpu();
@@ -122,15 +122,15 @@ mtx_enter(struct mutex *mtx)
}
int
-mtx_enter_try(struct mutex *mtx)
+__mtx_enter_try(struct mutex *mtx)
{
- mtx_enter(mtx);
+ __mtx_enter(mtx);
return (1);
}
#endif
void
-mtx_leave(struct mutex *mtx)
+__mtx_leave(struct mutex *mtx)
{
int s;
diff --git a/sys/arch/sh/include/mutex.h b/sys/arch/sh/include/mutex.h
index 658b3671dc6..87c82d2b5d4 100644
--- a/sys/arch/sh/include/mutex.h
+++ b/sys/arch/sh/include/mutex.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.h,v 1.2 2007/05/05 12:06:20 miod Exp $ */
+/* $OpenBSD: mutex.h,v 1.3 2017/04/20 13:57:30 visa Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -37,9 +37,10 @@ struct mutex {
int mtx_oldipl;
};
-void mtx_init(struct mutex *, int);
+void __mtx_init(struct mutex *, int);
-#define MUTEX_INITIALIZER(ipl) { 0, (ipl) << 4, 0 }
+#define MUTEX_INITIALIZER_FLAGS(ipl, name, flags) \
+ { 0, (ipl) << 4, 0 }
#ifdef DIAGNOSTIC
#define MUTEX_ASSERT_LOCKED(mtx) do { \
diff --git a/sys/arch/sh/sh/mutex.c b/sys/arch/sh/sh/mutex.c
index 24b1814250c..3f8cf57f4fd 100644
--- a/sys/arch/sh/sh/mutex.c
+++ b/sys/arch/sh/sh/mutex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.c,v 1.7 2011/04/21 04:34:12 miod Exp $ */
+/* $OpenBSD: mutex.c,v 1.8 2017/04/20 13:57:30 visa Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -40,7 +40,7 @@
* raising semantics of the mutexes.
*/
void
-mtx_init(struct mutex *mtx, int wantipl)
+__mtx_init(struct mutex *mtx, int wantipl)
{
mtx->mtx_oldipl = 0;
mtx->mtx_wantipl = wantipl << 4;
@@ -48,7 +48,7 @@ mtx_init(struct mutex *mtx, int wantipl)
}
void
-mtx_enter(struct mutex *mtx)
+__mtx_enter(struct mutex *mtx)
{
if (mtx->mtx_wantipl != IPL_NONE << 4)
mtx->mtx_oldipl = _cpu_intr_raise(mtx->mtx_wantipl);
@@ -61,7 +61,7 @@ mtx_enter(struct mutex *mtx)
}
int
-mtx_enter_try(struct mutex *mtx)
+__mtx_enter_try(struct mutex *mtx)
{
if (mtx->mtx_wantipl != IPL_NONE)
mtx->mtx_oldipl = _cpu_intr_raise(mtx->mtx_wantipl);
@@ -75,7 +75,7 @@ mtx_enter_try(struct mutex *mtx)
}
void
-mtx_leave(struct mutex *mtx)
+__mtx_leave(struct mutex *mtx)
{
MUTEX_ASSERT_LOCKED(mtx);
#ifdef DIAGNOSTIC
diff --git a/sys/arch/sparc64/include/mutex.h b/sys/arch/sparc64/include/mutex.h
index 0ac9deb5b5e..c022930143f 100644
--- a/sys/arch/sparc64/include/mutex.h
+++ b/sys/arch/sparc64/include/mutex.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.h,v 1.4 2014/03/29 18:09:30 guenther Exp $ */
+/* $OpenBSD: mutex.h,v 1.5 2017/04/20 13:57:30 visa Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
@@ -28,10 +28,15 @@
#ifndef _MACHINE_MUTEX_H_
#define _MACHINE_MUTEX_H_
+#include <sys/_lock.h>
+
struct mutex {
volatile void *mtx_owner; /* mutex.S relies upon this being first */
int mtx_wantipl;
int mtx_oldipl;
+#ifdef WITNESS
+ struct lock_object mtx_lock_obj;
+#endif
};
/*
@@ -48,10 +53,16 @@ struct mutex {
#define __MUTEX_IPL(ipl) (ipl)
#endif
-#define MUTEX_INITIALIZER(ipl) { NULL, __MUTEX_IPL((ipl)), 0 }
+#ifdef WITNESS
+#define MUTEX_INITIALIZER_FLAGS(ipl, name, flags) \
+ { NULL, __MUTEX_IPL((ipl)), 0, MTX_LO_INITIALIZER(name, flags) }
+#else
+#define MUTEX_INITIALIZER_FLAGS(ipl, name, flags) \
+ { NULL, __MUTEX_IPL((ipl)), 0 }
+#endif
void __mtx_init(struct mutex *, int);
-#define mtx_init(mtx, ipl) __mtx_init((mtx), __MUTEX_IPL((ipl)))
+#define _mtx_init(mtx, ipl) __mtx_init((mtx), __MUTEX_IPL((ipl)))
#ifdef DIAGNOSTIC
#define MUTEX_ASSERT_LOCKED(mtx) do { \
@@ -68,6 +79,7 @@ void __mtx_init(struct mutex *, int);
#define MUTEX_ASSERT_UNLOCKED(mtx) do { } while (0)
#endif
+#define MUTEX_LOCK_OBJECT(mtx) (&(mtx)->mtx_lock_obj)
#define MUTEX_OLDIPL(mtx) (mtx)->mtx_oldipl
#endif
diff --git a/sys/arch/sparc64/sparc64/mutex.S b/sys/arch/sparc64/sparc64/mutex.S
index bfdfdf4e5c5..72816ee273d 100644
--- a/sys/arch/sparc64/sparc64/mutex.S
+++ b/sys/arch/sparc64/sparc64/mutex.S
@@ -1,4 +1,4 @@
-/* $OpenBSD: mutex.S,v 1.8 2013/07/14 21:22:09 kettenis Exp $ */
+/* $OpenBSD: mutex.S,v 1.9 2017/04/20 13:57:30 visa Exp $ */
/*
* Copyright (c) 2007 Mark Kettenis
@@ -44,7 +44,7 @@ ENTRY(__mtx_init)
retl
stw %g0, [%o0 + MTX_OLDIPL]
-ENTRY(mtx_enter)
+ENTRY(__mtx_enter)
rdpr %pil, %g4
GET_CURCPU(%g1)
1:
@@ -80,7 +80,7 @@ ENTRY(mtx_enter)
retl
membar #LoadLoad | #LoadStore
-ENTRY(mtx_enter_try)
+ENTRY(__mtx_enter_try)
rdpr %pil, %g4
GET_CURCPU(%g1)
1:
@@ -112,7 +112,7 @@ ENTRY(mtx_enter_try)
retl
mov 1, %o0
-ENTRY(mtx_leave)
+ENTRY(__mtx_leave)
#ifdef DIAGNOSTIC
GET_CURCPU(%g1)
ld [%g1 + CI_MUTEX_LEVEL], %g5