-/* $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>
#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;
}
#else
void
-mtx_enter(struct mutex *mtx)
+__mtx_enter(struct mutex *mtx)
{
struct cpu_info *ci = curcpu();
}
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;
-/* $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>
#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
};
/*
#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 { \
#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_ */
-/* $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>
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;
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;
#endif
-ENTRY(mtx_leave)
+ENTRY(__mtx_leave)
movq %rdi, %rax
#ifdef DIAGNOSTIC
movq CPUVAR(SELF), %rcx
-/* $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>
#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
};
/*
#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()) \
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
-/* $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>
* 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;
}
void
-mtx_enter(struct mutex *mtx)
+__mtx_enter(struct mutex *mtx)
{
if (mtx->mtx_wantipl != IPL_NONE)
mtx->mtx_oldipl = _splraise(mtx->mtx_wantipl);
}
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);
}
void
-mtx_leave(struct mutex *mtx)
+__mtx_leave(struct mutex *mtx)
{
MUTEX_ASSERT_LOCKED(mtx);
mtx->mtx_lock = 0;
-/* $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>
#ifndef _ARM_MUTEX_H_
#define _ARM_MUTEX_H_
+#include <sys/_lock.h>
+
/*
* Simple non-mp implementation.
*/
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 { \
#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
-/* $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>
#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
};
/*
#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()) \
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
-/* $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>
#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);
}
#else
void
-mtx_enter(struct mutex *mtx)
+__mtx_enter(struct mutex *mtx)
{
struct cpu_info *ci = curcpu();
}
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);
-/* $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>
#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. */
int mtx_wantipl;
int mtx_oldipl;
void *mtx_owner;
+#ifdef WITNESS
+ struct lock_object mtx_lock_obj;
+#endif
};
/*
#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 { \
#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
-/* $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>
#define SOFF 8
-ENTRY(mtx_enter)
+ENTRY(__mtx_enter)
pushl %ebp
movl %esp, %ebp
1: movl SOFF(%ebp), %ecx
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
5: .asciz "mtx_enter_try: locking against myself"
#endif
-
-ENTRY(mtx_leave)
+
+ENTRY(__mtx_leave)
pushl %ebp
movl %esp, %ebp
movl SOFF(%ebp), %ecx
-/* $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>
#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.
int mtx_wantipl;
int mtx_oldipl;
void *mtx_owner;
+#ifdef WITNESS
+ struct lock_object mtx_lock_obj;
+#endif
};
/*
#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()) \
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
#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.
* 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
};
/*
#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
#endif
+#define MUTEX_LOCK_OBJECT(mtx) (&(mtx)->mtx_lock_obj)
#define MUTEX_OLDIPL(mtx) (mtx)->mtx_oldipl
#endif /* _M88K_MUTEX_H_ */
-/* $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.
/*
* void mtx_enter(struct mutex *mtx)
*/
-ENTRY(mtx_enter)
+ENTRY(__mtx_enter)
subu %r31, %r31, 8
st %r1, %r31, 4 /* save return address */
/*
* 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 */
/*
* void mtx_leave(struct mutex *mtx)
*/
-ENTRY(mtx_leave)
+ENTRY(__mtx_leave)
ld %r3, %r2, MTX_OLDIPL
ld %r4, %r2, MTX_WANTIPL
#ifdef DIAGNOSTIC
-/* $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>
#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
};
/*
#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 { \
#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
-/* $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>
#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);
}
int
-mtx_enter_try(struct mutex *mtx)
+__mtx_enter_try(struct mutex *mtx)
{
struct cpu_info *owner, *ci = curcpu();
int s;
}
#else
void
-mtx_enter(struct mutex *mtx)
+__mtx_enter(struct mutex *mtx)
{
struct cpu_info *ci = curcpu();
}
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;
-/* $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>
#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
};
/*
#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 { \
#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
-/* $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>
#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)
}
int
-mtx_enter_try(struct mutex *mtx)
+__mtx_enter_try(struct mutex *mtx)
{
struct cpu_info *owner, *ci = curcpu();
int s;
}
#else
void
-mtx_enter(struct mutex *mtx)
+__mtx_enter(struct mutex *mtx)
{
struct cpu_info *ci = curcpu();
}
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;
-/* $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>
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 { \
-/* $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>
* 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;
}
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);
}
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);
}
void
-mtx_leave(struct mutex *mtx)
+__mtx_leave(struct mutex *mtx)
{
MUTEX_ASSERT_LOCKED(mtx);
#ifdef DIAGNOSTIC
-/* $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>
#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
};
/*
#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 { \
#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
-/* $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
retl
stw %g0, [%o0 + MTX_OLDIPL]
-ENTRY(mtx_enter)
+ENTRY(__mtx_enter)
rdpr %pil, %g4
GET_CURCPU(%g1)
1:
retl
membar #LoadLoad | #LoadStore
-ENTRY(mtx_enter_try)
+ENTRY(__mtx_enter_try)
rdpr %pil, %g4
GET_CURCPU(%g1)
1:
retl
mov 1, %o0
-ENTRY(mtx_leave)
+ENTRY(__mtx_leave)
#ifdef DIAGNOSTIC
GET_CURCPU(%g1)
ld [%g1 + CI_MUTEX_LEVEL], %g5
-# $OpenBSD: files,v 1.640 2017/04/20 12:59:36 visa Exp $
+# $OpenBSD: files,v 1.641 2017/04/20 13:57:30 visa Exp $
# $NetBSD: files,v 1.87 1996/05/19 17:17:50 jonathan Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
file kern/kern_lock.c
file kern/kern_malloc.c
file kern/kern_malloc_debug.c malloc_debug
+file kern/kern_mutex.c witness
file kern/kern_rwlock.c
file kern/kern_physio.c
file kern/kern_proc.c
--- /dev/null
+/* $OpenBSD: kern_mutex.c,v 1.1 2017/04/20 13:57:30 visa Exp $ */
+
+/*
+ * Copyright (c) 2017 Visa Hankala
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/mutex.h>
+#include <sys/witness.h>
+
+void
+_mtx_init_flags(struct mutex *m, int ipl, const char *name, int flags,
+ struct lock_type *type)
+{
+ struct lock_object *lo = MUTEX_LOCK_OBJECT(m);
+
+ lo->lo_flags = MTX_LO_FLAGS(flags);
+ if (name != NULL)
+ lo->lo_name = name;
+ else
+ lo->lo_name = type->lt_name;
+ WITNESS_INIT(lo, type);
+
+ _mtx_init(m, ipl);
+}
+
+void
+_mtx_enter(struct mutex *m, const char *file, int line)
+{
+ struct lock_object *lo = MUTEX_LOCK_OBJECT(m);
+
+ WITNESS_CHECKORDER(lo, LOP_EXCLUSIVE | LOP_NEWORDER, file, line, NULL);
+ __mtx_enter(m);
+ WITNESS_LOCK(lo, LOP_EXCLUSIVE, file, line);
+}
+
+int
+_mtx_enter_try(struct mutex *m, const char *file, int line)
+{
+ struct lock_object *lo = MUTEX_LOCK_OBJECT(m);
+
+ if (__mtx_enter_try(m)) {
+ WITNESS_LOCK(lo, LOP_EXCLUSIVE, file, line);
+ return 1;
+ }
+ return 0;
+}
+
+void
+_mtx_leave(struct mutex *m, const char *file, int line)
+{
+ struct lock_object *lo = MUTEX_LOCK_OBJECT(m);
+
+ WITNESS_UNLOCK(lo, LOP_EXCLUSIVE, file, line);
+ __mtx_leave(m);
+}
-/* $OpenBSD: kern_synch.c,v 1.139 2017/04/20 13:33:00 visa Exp $ */
+/* $OpenBSD: kern_synch.c,v 1.140 2017/04/20 13:57:30 visa Exp $ */
/* $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */
/*
#ifdef MULTIPROCESSOR
int hold_count;
#endif
+ WITNESS_SAVE_DECL(lock_fl);
KASSERT((priority & ~(PRIMASK | PCATCH | PNORELOCK)) == 0);
KASSERT(mtx != NULL);
sleep_setup_timeout(&sls, timo);
sleep_setup_signal(&sls, priority);
+ WITNESS_SAVE(MUTEX_LOCK_OBJECT(mtx), lock_fl);
+
/* XXX - We need to make sure that the mutex doesn't
* unblock splsched. This can be made a bit more
* correct when the sched_lock is a mutex.
if ((priority & PNORELOCK) == 0) {
mtx_enter(mtx);
MUTEX_OLDIPL(mtx) = spl; /* put the ipl back */
+ WITNESS_RESTORE(MUTEX_LOCK_OBJECT(mtx), lock_fl);
} else
splx(spl);
-/* $OpenBSD: mutex.h,v 1.7 2009/08/13 13:24:55 weingart Exp $ */
+/* $OpenBSD: mutex.h,v 1.8 2017/04/20 13:57:30 visa Exp $ */
/*
* Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
#include <machine/mutex.h>
+#define MTX_LO_FLAGS(flags) \
+ ((!((flags) & MTX_NOWITNESS) ? LO_WITNESS : 0) | \
+ ((flags) & MTX_DUPOK ? LO_DUPOK : 0) | \
+ LO_INITIALIZED | (LO_CLASS_MUTEX << LO_CLASSSHIFT))
+
+#define __MTX_S(x) #x
+#define __MTX_LINE __MTX_S(__LINE__)
+#define __MTX_NAME __FILE__ ":" __MTX_S(__LINE__)
+
+#define MTX_LO_INITIALIZER(name, flags) \
+ { .lo_type = &(struct lock_type){ .lt_name = __MTX_NAME }, \
+ .lo_name = (name) != NULL ? (name) : __MTX_NAME, \
+ .lo_flags = MTX_LO_FLAGS(flags) }
+
+#define MTX_NOWITNESS 0x01
+#define MTX_DUPOK 0x02
+
+#define MUTEX_INITIALIZER(ipl) \
+ MUTEX_INITIALIZER_FLAGS(ipl, NULL, 0)
+
/*
* Some architectures need to do magic for the ipl, so they need a macro.
*/
-#ifndef mtx_init
-void mtx_init(struct mutex *, int);
+#ifndef _mtx_init
+void _mtx_init(struct mutex *, int);
#endif
-void mtx_enter(struct mutex *);
-void mtx_leave(struct mutex *);
-int mtx_enter_try(struct mutex *);
+
+void __mtx_enter(struct mutex *);
+int __mtx_enter_try(struct mutex *);
+void __mtx_leave(struct mutex *);
+
+#ifdef WITNESS
+
+void _mtx_init_flags(struct mutex *, int, const char *, int,
+ struct lock_type *);
+
+void _mtx_enter(struct mutex *, const char *, int);
+int _mtx_enter_try(struct mutex *, const char *, int);
+void _mtx_leave(struct mutex *, const char *, int);
+
+#define mtx_init_flags(m, ipl, name, flags) do { \
+ static struct lock_type __lock_type = { .lt_name = #m }; \
+ _mtx_init_flags(m, ipl, name, flags, &__lock_type); \
+} while (0)
+
+#define mtx_init(m, ipl) mtx_init_flags(m, ipl, NULL, 0)
+#define mtx_enter(m) _mtx_enter(m, __FILE__, __LINE__)
+#define mtx_enter_try(m) _mtx_enter_try(m, __FILE__, __LINE__)
+#define mtx_leave(m) _mtx_leave(m, __FILE__, __LINE__)
+
+#else /* WITNESS */
+
+#define mtx_init(m, ipl) __mtx_init(m, ipl)
+
+#define mtx_init_flags(m, ipl, name, flags) do { \
+ (void)(name); (void)(flags); \
+ __mtx_init(m, ipl); \
+} while (0)
+
+#define mtx_enter __mtx_enter
+#define mtx_leave __mtx_leave
+#define mtx_enter_try __mtx_enter_try
+
+#endif /* WITNESS */
#endif