| @@ -1,17 +1,17 @@ | | | @@ -1,17 +1,17 @@ |
1 | /* $NetBSD: lock_stubs.S,v 1.30 2019/02/11 14:59:32 cherry Exp $ */ | | 1 | /* $NetBSD: lock_stubs.S,v 1.31 2019/11/23 16:36:38 ad Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2006, 2007, 2008, 2009 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2006, 2007, 2008, 2009, 2019 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Andrew Doran. | | 8 | * by Andrew Doran. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
15 | * 2. Redistributions in binary form must reproduce the above copyright | | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
16 | * notice, this list of conditions and the following disclaimer in the | | 16 | * notice, this list of conditions and the following disclaimer in the |
17 | * documentation and/or other materials provided with the distribution. | | 17 | * documentation and/or other materials provided with the distribution. |
| @@ -25,27 +25,27 @@ | | | @@ -25,27 +25,27 @@ |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | /* | | 32 | /* |
33 | * Where possible we make each routine fit into an assumed 64-byte cache | | 33 | * Where possible we make each routine fit into an assumed 64-byte cache |
34 | * line. Please check alignment with 'objdump -d' after making changes. | | 34 | * line. Please check alignment with 'objdump -d' after making changes. |
35 | */ | | 35 | */ |
36 | | | 36 | |
37 | #include <machine/asm.h> | | 37 | #include <machine/asm.h> |
38 | __KERNEL_RCSID(0, "$NetBSD: lock_stubs.S,v 1.30 2019/02/11 14:59:32 cherry Exp $"); | | 38 | __KERNEL_RCSID(0, "$NetBSD: lock_stubs.S,v 1.31 2019/11/23 16:36:38 ad Exp $"); |
39 | | | 39 | |
40 | #include "opt_lockdebug.h" | | 40 | #include "opt_lockdebug.h" |
41 | | | 41 | |
42 | #include <machine/cputypes.h> | | 42 | #include <machine/cputypes.h> |
43 | #include <machine/frameasm.h> | | 43 | #include <machine/frameasm.h> |
44 | | | 44 | |
45 | #include "assym.h" | | 45 | #include "assym.h" |
46 | | | 46 | |
47 | #define ALIGN64 .align 64 | | 47 | #define ALIGN64 .align 64 |
48 | #define ALIGN32 .align 32 | | 48 | #define ALIGN32 .align 32 |
49 | #define LOCK(num) \ | | 49 | #define LOCK(num) \ |
50 | HOTPATCH(HP_NAME_NOLOCK, 1) ; \ | | 50 | HOTPATCH(HP_NAME_NOLOCK, 1) ; \ |
51 | lock | | 51 | lock |
| @@ -94,48 +94,50 @@ ENTRY(mutex_exit) | | | @@ -94,48 +94,50 @@ ENTRY(mutex_exit) |
94 | jnz 1f | | 94 | jnz 1f |
95 | ret | | 95 | ret |
96 | 1: | | 96 | 1: |
97 | jmp _C_LABEL(mutex_vector_exit) | | 97 | jmp _C_LABEL(mutex_vector_exit) |
98 | END(mutex_exit) | | 98 | END(mutex_exit) |
99 | | | 99 | |
100 | /* | | 100 | /* |
101 | * void rw_enter(krwlock_t *rwl, krw_t op); | | 101 | * void rw_enter(krwlock_t *rwl, krw_t op); |
102 | * | | 102 | * |
103 | * Acquire one hold on a RW lock. | | 103 | * Acquire one hold on a RW lock. |
104 | */ | | 104 | */ |
105 | ENTRY(rw_enter) | | 105 | ENTRY(rw_enter) |
106 | movl 4(%esp), %edx | | 106 | movl 4(%esp), %edx |
| | | 107 | xorl %eax, %eax |
107 | cmpl $RW_READER, 8(%esp) | | 108 | cmpl $RW_READER, 8(%esp) |
108 | jne 2f | | 109 | jne 2f |
109 | | | 110 | |
110 | /* | | 111 | /* |
111 | * Reader | | 112 | * Reader, and no existing readers on the lock: this is a most |
| | | 113 | * common case. Instead of reading from the lock word, use cmpxchg |
| | | 114 | * and get the cache line into the EXCLUSIVE state to begin with. |
112 | */ | | 115 | */ |
113 | movl (%edx), %eax | | | |
114 | 0: | | 116 | 0: |
115 | testb $(RW_WRITE_LOCKED|RW_WRITE_WANTED), %al | | 117 | testb $(RW_WRITE_LOCKED|RW_WRITE_WANTED), %al |
116 | jnz 3f | | 118 | jnz 3f |
117 | leal RW_READ_INCR(%eax), %ecx | | 119 | leal RW_READ_INCR(%eax), %ecx |
118 | LOCK(2) | | 120 | LOCK(2) |
119 | cmpxchgl %ecx, (%edx) | | 121 | cmpxchgl %ecx, (%edx) |
120 | jnz 1f | | 122 | jnz 1f |
121 | RET(2) | | 123 | RET(2) |
122 | 1: | | 124 | 1: |
123 | jmp 0b | | 125 | jmp 0b |
124 | | | 126 | |
125 | /* | | 127 | /* |
126 | * Writer | | 128 | * Writer |
127 | */ | | 129 | */ |
128 | 2: xorl %eax, %eax | | 130 | 2: |
129 | movl %fs:CPU_INFO_CURLWP(%eax), %ecx | | 131 | movl %fs:CPU_INFO_CURLWP(%eax), %ecx |
130 | orl $RW_WRITE_LOCKED, %ecx | | 132 | orl $RW_WRITE_LOCKED, %ecx |
131 | LOCK(3) | | 133 | LOCK(3) |
132 | cmpxchgl %ecx, (%edx) | | 134 | cmpxchgl %ecx, (%edx) |
133 | jnz 3f | | 135 | jnz 3f |
134 | RET(3) | | 136 | RET(3) |
135 | 3: | | 137 | 3: |
136 | jmp _C_LABEL(rw_vector_enter) | | 138 | jmp _C_LABEL(rw_vector_enter) |
137 | END(rw_enter) | | 139 | END(rw_enter) |
138 | | | 140 | |
139 | /* | | 141 | /* |
140 | * void rw_exit(krwlock_t *rwl); | | 142 | * void rw_exit(krwlock_t *rwl); |
141 | * | | 143 | * |
| @@ -176,50 +178,51 @@ ENTRY(rw_exit) | | | @@ -176,50 +178,51 @@ ENTRY(rw_exit) |
176 | /* | | 178 | /* |
177 | * Slow path. | | 179 | * Slow path. |
178 | */ | | 180 | */ |
179 | 3: jmp _C_LABEL(rw_vector_exit) | | 181 | 3: jmp _C_LABEL(rw_vector_exit) |
180 | END(rw_exit) | | 182 | END(rw_exit) |
181 | | | 183 | |
182 | /* | | 184 | /* |
183 | * int rw_tryenter(krwlock_t *rwl, krw_t op); | | 185 | * int rw_tryenter(krwlock_t *rwl, krw_t op); |
184 | * | | 186 | * |
185 | * Try to acquire one hold on a RW lock. | | 187 | * Try to acquire one hold on a RW lock. |
186 | */ | | 188 | */ |
187 | ENTRY(rw_tryenter) | | 189 | ENTRY(rw_tryenter) |
188 | movl 4(%esp), %edx | | 190 | movl 4(%esp), %edx |
| | | 191 | xorl %eax, %eax |
189 | cmpl $RW_READER, 8(%esp) | | 192 | cmpl $RW_READER, 8(%esp) |
190 | jne 2f | | 193 | jne 2f |
191 | | | 194 | |
192 | /* | | 195 | /* |
193 | * Reader | | 196 | * Reader, and no existing readers on the lock: this is a most |
| | | 197 | * common case. Instead of reading from the lock word, use cmpxchg |
| | | 198 | * and get the cache line into the EXCLUSIVE state to begin with. |
194 | */ | | 199 | */ |
195 | movl (%edx), %eax | | | |
196 | 0: | | 200 | 0: |
197 | testb $(RW_WRITE_LOCKED|RW_WRITE_WANTED), %al | | 201 | testb $(RW_WRITE_LOCKED|RW_WRITE_WANTED), %al |
198 | jnz 4f | | 202 | jnz 4f |
199 | leal RW_READ_INCR(%eax), %ecx | | 203 | leal RW_READ_INCR(%eax), %ecx |
200 | LOCK(12) | | 204 | LOCK(12) |
201 | cmpxchgl %ecx, (%edx) | | 205 | cmpxchgl %ecx, (%edx) |
202 | jnz 1f | | 206 | jnz 1f |
203 | movl %edx, %eax /* nonzero */ | | 207 | movl %edx, %eax /* nonzero */ |
204 | RET(4) | | 208 | RET(4) |
205 | 1: | | 209 | 1: |
206 | jmp 0b | | 210 | jmp 0b |
207 | | | 211 | |
208 | /* | | 212 | /* |
209 | * Writer | | 213 | * Writer |
210 | */ | | 214 | */ |
211 | 2: | | 215 | 2: |
212 | xorl %eax, %eax | | | |
213 | movl %fs:CPU_INFO_CURLWP(%eax), %ecx | | 216 | movl %fs:CPU_INFO_CURLWP(%eax), %ecx |
214 | orl $RW_WRITE_LOCKED, %ecx | | 217 | orl $RW_WRITE_LOCKED, %ecx |
215 | LOCK(13) | | 218 | LOCK(13) |
216 | cmpxchgl %ecx, (%edx) | | 219 | cmpxchgl %ecx, (%edx) |
217 | movl $0, %eax | | 220 | movl $0, %eax |
218 | setz %al | | 221 | setz %al |
219 | 3: | | 222 | 3: |
220 | RET(5) | | 223 | RET(5) |
221 | 4: | | 224 | 4: |
222 | xorl %eax, %eax | | 225 | xorl %eax, %eax |
223 | jmp 3b | | 226 | jmp 3b |
224 | END(rw_tryenter) | | 227 | END(rw_tryenter) |
225 | | | 228 | |