Print this page
9249 System crash dump to NVME not working
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Rick McNeal <rick.mcneal@nexenta.com>
Reviewed by: Ryan Zezeski <rpz@joyent.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/os/semaphore.c
+++ new/usr/src/uts/common/os/semaphore.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 -#pragma ident "%Z%%M% %I% %E% SMI"
27 +/*
28 + * Copyright 2018 Nexenta Systems, Inc. All rights reserved.
29 + */
28 30
29 31 /*
30 32 * This file contains the semaphore operations.
31 33 */
32 34
33 35 #include <sys/param.h>
34 36 #include <sys/types.h>
35 37 #include <sys/systm.h>
36 38 #include <sys/schedctl.h>
37 39 #include <sys/semaphore.h>
38 40 #include <sys/sema_impl.h>
39 41 #include <sys/t_lock.h>
40 42 #include <sys/thread.h>
41 43 #include <sys/proc.h>
42 44 #include <sys/cmn_err.h>
43 45 #include <sys/debug.h>
44 46 #include <sys/disp.h>
45 47 #include <sys/sobject.h>
46 48 #include <sys/cpuvar.h>
47 49 #include <sys/sleepq.h>
48 50 #include <sys/sdt.h>
49 51
50 52 static void sema_unsleep(kthread_t *t);
51 53 static void sema_change_pri(kthread_t *t, pri_t pri, pri_t *t_prip);
52 54 static kthread_t *sema_owner(ksema_t *);
53 55
54 56 /*
55 57 * The sobj_ops vector exports a set of functions needed when a thread
56 58 * is asleep on a synchronization object of this type.
57 59 */
58 60 static sobj_ops_t sema_sobj_ops = {
59 61 SOBJ_SEMA, sema_owner, sema_unsleep, sema_change_pri
60 62 };
61 63
62 64 /*
63 65 * SEMA_BLOCK(sema_impl_t *s, disp_lock_t *lockp)
64 66 */
65 67 #define SEMA_BLOCK(s, lockp) \
66 68 { \
67 69 kthread_t *tp; \
68 70 kthread_t **tpp; \
69 71 pri_t cpri; \
70 72 klwp_t *lwp = ttolwp(curthread); \
71 73 ASSERT(THREAD_LOCK_HELD(curthread)); \
72 74 ASSERT(curthread != CPU->cpu_idle_thread); \
73 75 ASSERT(CPU_ON_INTR(CPU) == 0); \
74 76 ASSERT(curthread->t_wchan0 == NULL); \
75 77 ASSERT(curthread->t_wchan == NULL); \
76 78 ASSERT(curthread->t_state == TS_ONPROC); \
77 79 CL_SLEEP(curthread); \
78 80 THREAD_SLEEP(curthread, lockp); \
79 81 curthread->t_wchan = (caddr_t)s; \
80 82 curthread->t_sobj_ops = &sema_sobj_ops; \
81 83 DTRACE_SCHED(sleep); \
82 84 if (lwp != NULL) { \
83 85 lwp->lwp_ru.nvcsw++; \
84 86 (void) new_mstate(curthread, LMS_SLEEP); \
85 87 } \
86 88 cpri = DISP_PRIO(curthread); \
87 89 tpp = &s->s_slpq; \
88 90 while ((tp = *tpp) != NULL) { \
89 91 if (cpri > DISP_PRIO(tp)) \
90 92 break; \
91 93 tpp = &tp->t_link; \
92 94 } \
93 95 *tpp = curthread; \
94 96 curthread->t_link = tp; \
95 97 ASSERT(s->s_slpq != NULL); \
96 98 }
97 99
98 100 /* ARGSUSED */
99 101 void
100 102 sema_init(ksema_t *sp, unsigned count, char *name, ksema_type_t type, void *arg)
101 103 {
102 104 ((sema_impl_t *)sp)->s_count = count;
103 105 ((sema_impl_t *)sp)->s_slpq = NULL;
104 106 }
105 107
106 108 void
107 109 sema_destroy(ksema_t *sp)
108 110 {
109 111 ASSERT(((sema_impl_t *)sp)->s_slpq == NULL);
110 112 }
111 113
112 114 /*
113 115 * Put a thread on the sleep queue for this semaphore.
114 116 */
115 117 static void
116 118 sema_queue(ksema_t *sp, kthread_t *t)
117 119 {
118 120 kthread_t **tpp;
119 121 kthread_t *tp;
120 122 pri_t cpri;
121 123 sema_impl_t *s;
122 124
123 125 ASSERT(THREAD_LOCK_HELD(t));
124 126 s = (sema_impl_t *)sp;
125 127 tpp = &s->s_slpq;
126 128 cpri = DISP_PRIO(t);
127 129 while ((tp = *tpp) != NULL) {
128 130 if (cpri > DISP_PRIO(tp))
129 131 break;
130 132 tpp = &tp->t_link;
131 133 }
132 134 *tpp = t;
133 135 t->t_link = tp;
134 136 }
135 137
136 138 /*
137 139 * Remove a thread from the sleep queue for this
138 140 * semaphore.
139 141 */
140 142 static void
141 143 sema_dequeue(ksema_t *sp, kthread_t *t)
142 144 {
143 145 kthread_t **tpp;
144 146 kthread_t *tp;
145 147 sema_impl_t *s;
146 148
147 149 ASSERT(THREAD_LOCK_HELD(t));
148 150 s = (sema_impl_t *)sp;
149 151 tpp = &s->s_slpq;
150 152 while ((tp = *tpp) != NULL) {
151 153 if (tp == t) {
152 154 *tpp = t->t_link;
153 155 t->t_link = NULL;
154 156 return;
155 157 }
156 158 tpp = &tp->t_link;
157 159 }
158 160 }
159 161
160 162 /* ARGSUSED */
161 163 static kthread_t *
162 164 sema_owner(ksema_t *sp)
163 165 {
164 166 return ((kthread_t *)NULL);
165 167 }
166 168
167 169 /*
168 170 * Wakeup a thread sleeping on a semaphore, and put it
169 171 * on the dispatch queue.
170 172 * Called via SOBJ_UNSLEEP().
171 173 */
172 174 static void
173 175 sema_unsleep(kthread_t *t)
174 176 {
175 177 kthread_t **tpp;
176 178 kthread_t *tp;
177 179 sema_impl_t *s;
178 180
179 181 ASSERT(THREAD_LOCK_HELD(t));
180 182 s = (sema_impl_t *)t->t_wchan;
181 183 tpp = &s->s_slpq;
182 184 while ((tp = *tpp) != NULL) {
183 185 if (tp == t) {
184 186 *tpp = t->t_link;
185 187 t->t_link = NULL;
186 188 t->t_sobj_ops = NULL;
187 189 t->t_wchan = NULL;
188 190 t->t_wchan0 = NULL;
189 191 /*
190 192 * Change thread to transition state and
191 193 * drop the semaphore sleep queue lock.
192 194 */
193 195 THREAD_TRANSITION(t);
194 196 CL_SETRUN(t);
195 197 return;
196 198 }
197 199 tpp = &tp->t_link;
198 200 }
199 201 }
200 202
201 203 /*
202 204 * operations to perform when changing the priority
203 205 * of a thread asleep on a semaphore.
204 206 * Called via SOBJ_CHANGE_PRI() and SOBJ_CHANGE_EPRI().
205 207 */
206 208 static void
207 209 sema_change_pri(kthread_t *t, pri_t pri, pri_t *t_prip)
208 210 {
209 211 ksema_t *sp;
210 212
211 213 if ((sp = (ksema_t *)t->t_wchan) != NULL) {
212 214 sema_dequeue(sp, t);
213 215 *t_prip = pri;
214 216 sema_queue(sp, t);
215 217 } else
216 218 panic("sema_change_pri: %p not on sleep queue", (void *)t);
217 219 }
218 220
219 221 /*
↓ open down ↓ |
182 lines elided |
↑ open up ↑ |
220 222 * the semaphore is granted when the semaphore's
221 223 * count is greater than zero and blocks when equal
222 224 * to zero.
223 225 */
224 226 void
225 227 sema_p(ksema_t *sp)
226 228 {
227 229 sema_impl_t *s;
228 230 disp_lock_t *sqlp;
229 231
232 + /* no-op during panic */
233 + if (panicstr)
234 + return;
235 +
230 236 s = (sema_impl_t *)sp;
231 237 sqlp = &SQHASH(s)->sq_lock;
232 238 disp_lock_enter(sqlp);
233 239 ASSERT(s->s_count >= 0);
234 240 while (s->s_count == 0) {
235 - if (panicstr) {
236 - disp_lock_exit(sqlp);
237 - return;
238 - }
239 241 thread_lock_high(curthread);
240 242 SEMA_BLOCK(s, sqlp);
241 243 thread_unlock_nopreempt(curthread);
242 244 swtch();
243 245 disp_lock_enter(sqlp);
244 246 }
245 247 s->s_count--;
246 248 disp_lock_exit(sqlp);
247 249 }
248 250
249 251 /*
250 252 * similiar to sema_p except that it blocks at an interruptible
251 253 * priority. if a signal is present then return 1 otherwise 0.
252 254 */
253 255 int
254 256 sema_p_sig(ksema_t *sp)
255 257 {
256 258 kthread_t *t = curthread;
257 259 klwp_t *lwp = ttolwp(t);
258 260 int cancel_pending;
259 261 int cancelled = 0;
260 262 sema_impl_t *s;
261 263 disp_lock_t *sqlp;
262 264
263 265 if (lwp == NULL) {
264 266 sema_p(sp);
265 267 return (0);
266 268 }
267 269
268 270 cancel_pending = schedctl_cancel_pending();
269 271 s = (sema_impl_t *)sp;
270 272 sqlp = &SQHASH(s)->sq_lock;
271 273 disp_lock_enter(sqlp);
272 274 ASSERT(s->s_count >= 0);
273 275 while (s->s_count == 0) {
274 276 proc_t *p = ttoproc(t);
275 277 thread_lock_high(t);
276 278 t->t_flag |= T_WAKEABLE;
277 279 SEMA_BLOCK(s, sqlp);
278 280 lwp->lwp_asleep = 1;
279 281 lwp->lwp_sysabort = 0;
280 282 thread_unlock_nopreempt(t);
281 283 if (ISSIG(t, JUSTLOOKING) || MUSTRETURN(p, t) || cancel_pending)
282 284 setrun(t);
283 285 swtch();
284 286 t->t_flag &= ~T_WAKEABLE;
285 287 if (ISSIG(t, FORREAL) || lwp->lwp_sysabort ||
286 288 MUSTRETURN(p, t) || (cancelled = cancel_pending) != 0) {
287 289 kthread_t *sq, *tp;
288 290 lwp->lwp_asleep = 0;
289 291 lwp->lwp_sysabort = 0;
290 292 disp_lock_enter(sqlp);
291 293 sq = s->s_slpq;
292 294 /*
293 295 * in case sema_v and interrupt happen
294 296 * at the same time, we need to pass the
295 297 * sema_v to the next thread.
296 298 */
297 299 if ((sq != NULL) && (s->s_count > 0)) {
298 300 tp = sq;
299 301 ASSERT(THREAD_LOCK_HELD(tp));
300 302 sq = sq->t_link;
301 303 tp->t_link = NULL;
302 304 DTRACE_SCHED1(wakeup, kthread_t *, tp);
303 305 tp->t_sobj_ops = NULL;
304 306 tp->t_wchan = NULL;
305 307 ASSERT(tp->t_state == TS_SLEEP);
306 308 CL_WAKEUP(tp);
307 309 s->s_slpq = sq;
308 310 disp_lock_exit_high(sqlp);
309 311 thread_unlock(tp);
310 312 } else {
311 313 disp_lock_exit(sqlp);
312 314 }
313 315 if (cancelled)
314 316 schedctl_cancel_eintr();
315 317 return (1);
316 318 }
317 319 lwp->lwp_asleep = 0;
318 320 disp_lock_enter(sqlp);
319 321 }
320 322 s->s_count--;
321 323 disp_lock_exit(sqlp);
322 324 return (0);
323 325 }
324 326
325 327 /*
↓ open down ↓ |
77 lines elided |
↑ open up ↑ |
326 328 * the semaphore's count is incremented by one. a blocked thread
327 329 * is awakened and re-tries to acquire the semaphore.
328 330 */
329 331 void
330 332 sema_v(ksema_t *sp)
331 333 {
332 334 sema_impl_t *s;
333 335 kthread_t *sq, *tp;
334 336 disp_lock_t *sqlp;
335 337
338 + /* no-op during panic */
339 + if (panicstr)
340 + return;
341 +
336 342 s = (sema_impl_t *)sp;
337 343 sqlp = &SQHASH(s)->sq_lock;
338 344 disp_lock_enter(sqlp);
339 - if (panicstr) {
340 - disp_lock_exit(sqlp);
341 - return;
342 - }
343 345 s->s_count++;
344 346 sq = s->s_slpq;
345 347 if (sq != NULL) {
346 348 tp = sq;
347 349 ASSERT(THREAD_LOCK_HELD(tp));
348 350 sq = sq->t_link;
349 351 tp->t_link = NULL;
350 352 DTRACE_SCHED1(wakeup, kthread_t *, tp);
351 353 tp->t_sobj_ops = NULL;
352 354 tp->t_wchan = NULL;
353 355 ASSERT(tp->t_state == TS_SLEEP);
354 356 CL_WAKEUP(tp);
355 357 s->s_slpq = sq;
356 358 disp_lock_exit_high(sqlp);
357 359 thread_unlock(tp);
358 360 } else {
359 361 disp_lock_exit(sqlp);
360 362 }
361 363 }
362 364
363 365 /*
364 366 * try to acquire the semaphore. if the semaphore is greater than
365 367 * zero, then the semaphore is granted and returns 1. otherwise
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
366 368 * return 0.
367 369 */
368 370 int
369 371 sema_tryp(ksema_t *sp)
370 372 {
371 373 sema_impl_t *s;
372 374 sleepq_head_t *sqh;
373 375
374 376 int gotit = 0;
375 377
378 + /* no-op during panic */
379 + if (panicstr)
380 + return (1);
381 +
376 382 s = (sema_impl_t *)sp;
377 383 sqh = SQHASH(s);
378 384 disp_lock_enter(&sqh->sq_lock);
379 385 if (s->s_count > 0) {
380 386 s->s_count--;
381 387 gotit = 1;
382 388 }
383 389 disp_lock_exit(&sqh->sq_lock);
384 390 return (gotit);
385 391 }
386 392
387 393 int
388 394 sema_held(ksema_t *sp)
389 395 {
390 396 sema_impl_t *s;
391 397
392 -
393 - s = (sema_impl_t *)sp;
398 + /* no-op during panic */
394 399 if (panicstr)
395 400 return (1);
396 - else
397 - return (s->s_count <= 0);
401 +
402 + s = (sema_impl_t *)sp;
403 + return (s->s_count <= 0);
398 404 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX