X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/c0fea4742e91338fffdcf79f86a7c1d5e2b97eb1..060df5ea7c632b1ac8cc8aac1fb59758165c2084:/osfmk/i386/commpage/spinlocks.s diff --git a/osfmk/i386/commpage/spinlocks.s b/osfmk/i386/commpage/spinlocks.s index f8d6329fa..a0e98bcb3 100644 --- a/osfmk/i386/commpage/spinlocks.s +++ b/osfmk/i386/commpage/spinlocks.s @@ -1,23 +1,29 @@ /* - * Copyright (c) 2003-2006 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2003-2009 Apple, Inc. All rights reserved. * - * @APPLE_LICENSE_HEADER_START@ + * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * - * The contents of this file constitute Original Code as defined in and - * are subject to the Apple Public Source License Version 1.1 (the - * "License"). You may not use this file except in compliance with the - * License. Please obtain a copy of the License at - * http://www.apple.com/publicsource and read it before using this file. + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. * - * This Original Code and all software distributed under the License are - * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this file. + * + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License. + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. * - * @APPLE_LICENSE_HEADER_END@ + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ #include @@ -26,13 +32,7 @@ #include - -#define MP_SPIN_TRIES 1024 - - .text - .align 4, 0x90 - -Lspin_lock_try_up: +COMMPAGE_FUNCTION_START(spin_lock_try_up, 32, 4) movl 4(%esp), %ecx xorl %eax, %eax orl $-1, %edx @@ -40,12 +40,10 @@ Lspin_lock_try_up: setz %dl movzbl %dl, %eax ret - - COMMPAGE_DESCRIPTOR(spin_lock_try_up,_COMM_PAGE_SPINLOCK_TRY,kUP,0) +COMMPAGE_DESCRIPTOR(spin_lock_try_up,_COMM_PAGE_SPINLOCK_TRY,kUP,0) - - .align 4, 0x90 -Lspin_lock_try_mp: + +COMMPAGE_FUNCTION_START(spin_lock_try_mp, 32, 4) movl 4(%esp), %ecx xorl %eax, %eax orl $-1, %edx @@ -54,17 +52,15 @@ Lspin_lock_try_mp: setz %dl movzbl %dl, %eax ret - - COMMPAGE_DESCRIPTOR(spin_lock_try_mp,_COMM_PAGE_SPINLOCK_TRY,0,kUP) +COMMPAGE_DESCRIPTOR(spin_lock_try_mp,_COMM_PAGE_SPINLOCK_TRY,0,kUP) - .align 4, 0x90 -Lspin_lock_up: +COMMPAGE_FUNCTION_START(spin_lock_up, 32, 4) movl 4(%esp), %ecx xorl %eax, %eax orl $-1, %edx cmpxchgl %edx, (%ecx) - jnz,pn 1f /* predict not taken */ + jnz 1f ret 1: /* failed to get lock so relinquish the processor immediately on UP */ @@ -76,19 +72,17 @@ Lspin_lock_up: int $(MACH_INT) addl $16, %esp /* adjust stack*/ jmp Lspin_lock_up +COMMPAGE_DESCRIPTOR(spin_lock_up,_COMM_PAGE_SPINLOCK_LOCK,kUP,0) - COMMPAGE_DESCRIPTOR(spin_lock_up,_COMM_PAGE_SPINLOCK_LOCK,kUP,0) - - .align 4, 0x90 -Lspin_lock_mp: +COMMPAGE_FUNCTION_START(spin_lock_mp, 32, 4) movl 4(%esp), %ecx xorl %eax, %eax 0: orl $-1, %edx lock cmpxchgl %edx, (%ecx) - jnz,pn 1f /* predict not taken */ + jnz 1f ret 1: xorl %eax, %eax @@ -96,9 +90,9 @@ Lspin_lock_mp: 2: pause cmpl %eax, (%ecx) - jz,pt 0b /* favor success and slow down spin loop */ + jz 0b /* favor success and slow down spin loop */ decl %edx - jnz,pn 2b /* slow down spin loop with a mispredict */ + jnz 2b /* failed to get lock after spinning so relinquish */ pushl $1 /* 1 ms */ pushl $1 /* SWITCH_OPTION_DEPRESS */ @@ -108,39 +102,30 @@ Lspin_lock_mp: int $(MACH_INT) addl $16, %esp /* adjust stack*/ jmp Lspin_lock_mp - - COMMPAGE_DESCRIPTOR(spin_lock_mp,_COMM_PAGE_SPINLOCK_LOCK,0,kUP) +COMMPAGE_DESCRIPTOR(spin_lock_mp,_COMM_PAGE_SPINLOCK_LOCK,0,kUP) - .align 4, 0x90 -Lspin_unlock: +COMMPAGE_FUNCTION_START(spin_unlock, 32, 4) movl 4(%esp), %ecx movl $0, (%ecx) ret - - COMMPAGE_DESCRIPTOR(spin_unlock,_COMM_PAGE_SPINLOCK_UNLOCK,0,0) +COMMPAGE_DESCRIPTOR(spin_unlock,_COMM_PAGE_SPINLOCK_UNLOCK,0,0) /* ============================ 64-bit versions follow ===================== */ - .text - .code64 - .align 4, 0x90 - -Lspin_lock_try_up_64: +COMMPAGE_FUNCTION_START(spin_lock_try_up_64, 64, 4) xorl %eax, %eax orl $-1, %edx cmpxchgl %edx, (%rdi) setz %dl movzbl %dl, %eax ret +COMMPAGE_DESCRIPTOR(spin_lock_try_up_64,_COMM_PAGE_SPINLOCK_TRY,kUP,0) - COMMPAGE_DESCRIPTOR(spin_lock_try_up_64,_COMM_PAGE_SPINLOCK_TRY,kUP,0) - - .align 4, 0x90 -Lspin_lock_try_mp_64: +COMMPAGE_FUNCTION_START(spin_lock_try_mp_64, 64, 4) xorl %eax, %eax orl $-1, %edx lock @@ -148,18 +133,16 @@ Lspin_lock_try_mp_64: setz %dl movzbl %dl, %eax ret - - COMMPAGE_DESCRIPTOR(spin_lock_try_mp_64,_COMM_PAGE_SPINLOCK_TRY,0,kUP) +COMMPAGE_DESCRIPTOR(spin_lock_try_mp_64,_COMM_PAGE_SPINLOCK_TRY,0,kUP) - .align 4, 0x90 -Lspin_lock_up_64: +COMMPAGE_FUNCTION_START(spin_lock_up_64, 64, 4) movq %rdi,%r8 0: xorl %eax, %eax orl $-1, %edx cmpxchgl %edx, (%r8) - jnz,pn 1f /* predict not taken */ + jnz 1f ret 1: /* failed to get lock so relinquish the processor immediately on UP */ @@ -169,20 +152,17 @@ Lspin_lock_up_64: movl $(SYSCALL_CONSTRUCT_MACH(61)),%eax /* 61 = thread_switch */ syscall jmp 0b - - COMMPAGE_DESCRIPTOR(spin_lock_up_64,_COMM_PAGE_SPINLOCK_LOCK,kUP,0) +COMMPAGE_DESCRIPTOR(spin_lock_up_64,_COMM_PAGE_SPINLOCK_LOCK,kUP,0) - - .align 4, 0x90 -Lspin_lock_mp_64: +COMMPAGE_FUNCTION_START(spin_lock_mp_64, 64, 4) movq %rdi,%r8 0: xorl %eax, %eax orl $-1, %edx lock cmpxchgl %edx, (%r8) - jnz,pn 1f /* predict not taken */ + jnz 1f ret 1: xorl %eax, %eax @@ -200,13 +180,10 @@ Lspin_lock_mp_64: movl $(SYSCALL_CONSTRUCT_MACH(61)),%eax /* 61 = thread_switch */ syscall jmp 0b - - COMMPAGE_DESCRIPTOR(spin_lock_mp_64,_COMM_PAGE_SPINLOCK_LOCK,0,kUP) +COMMPAGE_DESCRIPTOR(spin_lock_mp_64,_COMM_PAGE_SPINLOCK_LOCK,0,kUP) - .align 4, 0x90 -Lspin_unlock_64: +COMMPAGE_FUNCTION_START(spin_unlock_64, 64, 4) movl $0, (%rdi) ret - - COMMPAGE_DESCRIPTOR(spin_unlock_64,_COMM_PAGE_SPINLOCK_UNLOCK,0,0) +COMMPAGE_DESCRIPTOR(spin_unlock_64,_COMM_PAGE_SPINLOCK_UNLOCK,0,0)