Use native atomic function instead of DTrace's own one
So we don't need to implement it for each architecture. This change is from FreeBSD (not as-is though).
This commit is contained in:
parent
74fc44ee86
commit
9d2dfffd73
61
external/cddl/osnet/dev/dtrace/dtrace_debug.c
vendored
61
external/cddl/osnet/dev/dtrace/dtrace_debug.c
vendored
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: dtrace_debug.c,v 1.7 2014/03/04 03:20:49 ozaki-r Exp $ */
|
||||
/* $NetBSD: dtrace_debug.c,v 1.8 2014/03/05 06:06:42 ozaki-r Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (C) 2008 John Birrell <jb@freebsd.org>.
|
||||
@ -36,62 +36,6 @@ static char const hex2ascii_data[] = "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
#if defined(__amd64__)
|
||||
static __inline int
|
||||
dtrace_cmpset_long(volatile u_long *dst, u_long exp, u_long src)
|
||||
{
|
||||
u_char res;
|
||||
|
||||
__asm __volatile(
|
||||
" lock ; "
|
||||
" cmpxchgq %2,%1 ; "
|
||||
" sete %0 ; "
|
||||
"1: "
|
||||
"# dtrace_cmpset_long"
|
||||
: "=a" (res), /* 0 */
|
||||
"=m" (*dst) /* 1 */
|
||||
: "r" (src), /* 2 */
|
||||
"a" (exp), /* 3 */
|
||||
"m" (*dst) /* 4 */
|
||||
: "memory");
|
||||
|
||||
return (res);
|
||||
}
|
||||
#elif defined(__i386__)
|
||||
static __inline int
|
||||
dtrace_cmpset_long(volatile u_long *dst, u_long exp, u_long src)
|
||||
{
|
||||
u_char res;
|
||||
|
||||
__asm __volatile(
|
||||
" lock ; "
|
||||
" cmpxchgl %2,%1 ; "
|
||||
" sete %0 ; "
|
||||
"1: "
|
||||
"# dtrace_cmpset_long"
|
||||
: "=a" (res), /* 0 */
|
||||
"=m" (*dst) /* 1 */
|
||||
: "r" (src), /* 2 */
|
||||
"a" (exp), /* 3 */
|
||||
"m" (*dst) /* 4 */
|
||||
: "memory");
|
||||
|
||||
return (res);
|
||||
}
|
||||
#elif defined(__arm__)
|
||||
static __inline int
|
||||
dtrace_cmpset_long(volatile u_long *dst, u_long exp, u_long src)
|
||||
{
|
||||
u_char res;
|
||||
if (*dst == src) {
|
||||
res = *dst;
|
||||
*dst = src;
|
||||
return res;
|
||||
}
|
||||
return exp;
|
||||
}
|
||||
#endif
|
||||
|
||||
#define DTRACE_DEBUG_BUFR_SIZE (32 * 1024)
|
||||
|
||||
struct dtrace_debug_data {
|
||||
@ -108,7 +52,8 @@ static volatile u_long dtrace_debug_flag[MAXCPUS];
|
||||
static void
|
||||
dtrace_debug_lock(int cpu)
|
||||
{
|
||||
while (dtrace_cmpset_long(&dtrace_debug_flag[cpu], 0, 1) == 0)
|
||||
/* FIXME: use atomic_cmpset_ulong once we have it */
|
||||
while (atomic_cas_ulong(&dtrace_debug_flag[cpu], 0, 1) == 0)
|
||||
/* Loop until the lock is obtained. */
|
||||
;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user