diff options
author | Tobias Weingartner <weingart@cvs.openbsd.org> | 2009-04-25 20:14:44 +0000 |
---|---|---|
committer | Tobias Weingartner <weingart@cvs.openbsd.org> | 2009-04-25 20:14:44 +0000 |
commit | 63236ac1c42847c6bcc02c8acb7093ae39774ff5 (patch) | |
tree | 8cb2a2f6f6bd68a9532e6eb57af0df12c6ede76d /sys/arch/amd64 | |
parent | 7cd46f20cc6a6ba8a5bf692f17ccd7d9571b6bbb (diff) |
Enter mtx_enter_try. In part for completeness, things may start
using this soon(ish). Ok oga@, sorta yes kettenis@.
Diffstat (limited to 'sys/arch/amd64')
-rw-r--r-- | sys/arch/amd64/amd64/mutex.S | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/sys/arch/amd64/amd64/mutex.S b/sys/arch/amd64/amd64/mutex.S index 17905d3bc5e..d74669e9a4b 100644 --- a/sys/arch/amd64/amd64/mutex.S +++ b/sys/arch/amd64/amd64/mutex.S @@ -1,4 +1,4 @@ -/* $OpenBSD: mutex.S,v 1.4 2005/07/26 08:11:11 art Exp $ */ +/* $OpenBSD: mutex.S,v 1.5 2009/04/25 20:14:42 weingart Exp $ */ /* * Copyright (c) 2004 Artur Grabowski <art@openbsd.org> @@ -84,7 +84,48 @@ ENTRY(mtx_enter) call _C_LABEL(panic) 5: .asciz "mtx_enter: locking against myself" #endif - + +ENTRY(mtx_enter_try) +1: movl MTX_WANTIPL(%rdi), %eax + movq CPUVAR(SELF), %rcx + movl CPU_INFO_ILEVEL(%rcx), %edx # oipl = cpl; + cmpl %eax, %edx # if (cpl < mtx->mtx_wantipl) + cmovge %edx, %eax + movl %eax, CPU_INFO_ILEVEL(%rcx) # cpl = mtx->mtx_wantipl; + /* + * %edx - the old ipl + * %rcx - curcpu() + */ + xorq %rax, %rax +#ifdef MULTIPROCESSOR + lock +#endif + cmpxchgq %rcx, MTX_OWNER(%rdi) # test_and_set(mtx->mtx_owner) + jne 2f + movl %edx, MTX_OLDIPL(%rdi) + movq $1, %rax + ret + + /* We failed to obtain the lock. splx and return 0. */ +2: pushq %rdi + movl %edx, %edi + call _C_LABEL(spllower) + popq %rdi +#ifdef DIAGNOSTIC + movq CPUVAR(SELF), %rcx + cmpq MTX_OWNER(%rdi), %rcx + je 3f +#endif + xorq %rax, %rax + ret + +#ifdef DIAGNOSTIC +3: movq $4f, %rdi + call _C_LABEL(panic) +4: .asciz "mtx_enter: locking against myself" +#endif + + ENTRY(mtx_leave) movq %rdi, %rax xorq %rcx, %rcx |