| @@ -1,105 +1,104 @@ | | | @@ -1,105 +1,104 @@ |
1 | /* $NetBSD: sleepq.h,v 1.33 2020/11/01 20:55:15 christos Exp $ */ | | 1 | /* $NetBSD: sleepq.h,v 1.34 2020/11/01 20:56:13 christos Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2002, 2006, 2007, 2008, 2009, 2019, 2020 | | 4 | * Copyright (c) 2002, 2006, 2007, 2008, 2009, 2019, 2020 |
5 | * The NetBSD Foundation, Inc. | | 5 | * The NetBSD Foundation, Inc. |
6 | * All rights reserved. | | 6 | * All rights reserved. |
7 | * | | 7 | * |
8 | * This code is derived from software contributed to The NetBSD Foundation | | 8 | * This code is derived from software contributed to The NetBSD Foundation |
9 | * by Jason R. Thorpe and Andrew Doran. | | 9 | * by Jason R. Thorpe and Andrew Doran. |
10 | * | | 10 | * |
11 | * Redistribution and use in source and binary forms, with or without | | 11 | * Redistribution and use in source and binary forms, with or without |
12 | * modification, are permitted provided that the following conditions | | 12 | * modification, are permitted provided that the following conditions |
13 | * are met: | | 13 | * are met: |
14 | * 1. Redistributions of source code must retain the above copyright | | 14 | * 1. Redistributions of source code must retain the above copyright |
15 | * notice, this list of conditions and the following disclaimer. | | 15 | * notice, this list of conditions and the following disclaimer. |
16 | * 2. Redistributions in binary form must reproduce the above copyright | | 16 | * 2. Redistributions in binary form must reproduce the above copyright |
17 | * notice, this list of conditions and the following disclaimer in the | | 17 | * notice, this list of conditions and the following disclaimer in the |
18 | * documentation and/or other materials provided with the distribution. | | 18 | * documentation and/or other materials provided with the distribution. |
19 | * | | 19 | * |
20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | | 20 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 22 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 23 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 24 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 25 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 26 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 27 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 28 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
30 | * POSSIBILITY OF SUCH DAMAGE. | | 30 | * POSSIBILITY OF SUCH DAMAGE. |
31 | */ | | 31 | */ |
32 | | | 32 | |
33 | #ifndef _SYS_SLEEPQ_H_ | | 33 | #ifndef _SYS_SLEEPQ_H_ |
34 | #define _SYS_SLEEPQ_H_ | | 34 | #define _SYS_SLEEPQ_H_ |
35 | | | 35 | |
36 | #include <sys/lwp.h> | | 36 | #include <sys/lwp.h> |
37 | #include <sys/mutex.h> | | 37 | #include <sys/mutex.h> |
38 | #include <sys/pool.h> | | 38 | #include <sys/pool.h> |
39 | #include <sys/queue.h> | | 39 | #include <sys/queue.h> |
40 | #include <sys/sched.h> | | 40 | #include <sys/sched.h> |
41 | #include <sys/syncobj.h> | | 41 | #include <sys/syncobj.h> |
42 | #include <sys/param.h> | | 42 | #include <sys/param.h> |
43 | | | 43 | |
44 | /* | | 44 | /* |
45 | * Generic sleep queues. | | 45 | * Generic sleep queues. |
46 | */ | | 46 | */ |
47 | | | 47 | |
48 | typedef struct sleepq sleepq_t; | | 48 | typedef struct sleepq sleepq_t; |
49 | | | 49 | |
50 | void sleepq_init(sleepq_t *); | | 50 | void sleepq_init(sleepq_t *); |
51 | void sleepq_destroy(sleepq_t *); | | | |
52 | void sleepq_remove(sleepq_t *, lwp_t *); | | 51 | void sleepq_remove(sleepq_t *, lwp_t *); |
53 | void sleepq_enqueue(sleepq_t *, wchan_t, const char *, struct syncobj *, | | 52 | void sleepq_enqueue(sleepq_t *, wchan_t, const char *, struct syncobj *, |
54 | bool); | | 53 | bool); |
55 | void sleepq_transfer(lwp_t *, sleepq_t *, sleepq_t *, wchan_t, const char *, | | 54 | void sleepq_transfer(lwp_t *, sleepq_t *, sleepq_t *, wchan_t, const char *, |
56 | struct syncobj *, kmutex_t *, bool); | | 55 | struct syncobj *, kmutex_t *, bool); |
57 | void sleepq_uncatch(lwp_t *); | | 56 | void sleepq_uncatch(lwp_t *); |
58 | void sleepq_unsleep(lwp_t *, bool); | | 57 | void sleepq_unsleep(lwp_t *, bool); |
59 | void sleepq_timeout(void *); | | 58 | void sleepq_timeout(void *); |
60 | void sleepq_wake(sleepq_t *, wchan_t, u_int, kmutex_t *); | | 59 | void sleepq_wake(sleepq_t *, wchan_t, u_int, kmutex_t *); |
61 | int sleepq_abort(kmutex_t *, int); | | 60 | int sleepq_abort(kmutex_t *, int); |
62 | void sleepq_changepri(lwp_t *, pri_t); | | 61 | void sleepq_changepri(lwp_t *, pri_t); |
63 | void sleepq_lendpri(lwp_t *, pri_t); | | 62 | void sleepq_lendpri(lwp_t *, pri_t); |
64 | int sleepq_block(int, bool); | | 63 | int sleepq_block(int, bool); |
65 | | | 64 | |
66 | #ifdef _KERNEL | | 65 | #ifdef _KERNEL |
67 | typedef union { | | 66 | typedef union { |
68 | kmutex_t lock; | | 67 | kmutex_t lock; |
69 | uint8_t pad[COHERENCY_UNIT]; | | 68 | uint8_t pad[COHERENCY_UNIT]; |
70 | } sleepqlock_t; | | 69 | } sleepqlock_t; |
71 | | | 70 | |
72 | /* | | 71 | /* |
73 | * Return non-zero if it is unsafe to sleep. | | 72 | * Return non-zero if it is unsafe to sleep. |
74 | * | | 73 | * |
75 | * XXX This only exists because panic() is broken. | | 74 | * XXX This only exists because panic() is broken. |
76 | */ | | 75 | */ |
77 | static __inline bool | | 76 | static __inline bool |
78 | sleepq_dontsleep(lwp_t *l) | | 77 | sleepq_dontsleep(lwp_t *l) |
79 | { | | 78 | { |
80 | extern int cold; | | 79 | extern int cold; |
81 | | | 80 | |
82 | return cold || (doing_shutdown && (panicstr || CURCPU_IDLE_P())); | | 81 | return cold || (doing_shutdown && (panicstr || CURCPU_IDLE_P())); |
83 | } | | 82 | } |
84 | | | 83 | |
85 | /* | | 84 | /* |
86 | * Prepare to block on a sleep queue, after which any interlock can be | | 85 | * Prepare to block on a sleep queue, after which any interlock can be |
87 | * safely released. | | 86 | * safely released. |
88 | */ | | 87 | */ |
89 | static __inline void | | 88 | static __inline void |
90 | sleepq_enter(sleepq_t *sq, lwp_t *l, kmutex_t *mp) | | 89 | sleepq_enter(sleepq_t *sq, lwp_t *l, kmutex_t *mp) |
91 | { | | 90 | { |
92 | | | 91 | |
93 | /* | | 92 | /* |
94 | * Acquire the per-LWP mutex and lend it ours sleep queue lock. | | 93 | * Acquire the per-LWP mutex and lend it ours sleep queue lock. |
95 | * Once interlocked, we can release the kernel lock. | | 94 | * Once interlocked, we can release the kernel lock. |
96 | */ | | 95 | */ |
97 | lwp_lock(l); | | 96 | lwp_lock(l); |
98 | lwp_unlock_to(l, mp); | | 97 | lwp_unlock_to(l, mp); |
99 | KERNEL_UNLOCK_ALL(NULL, &l->l_biglocks); | | 98 | KERNEL_UNLOCK_ALL(NULL, &l->l_biglocks); |
100 | } | | 99 | } |
101 | #endif | | 100 | #endif |
102 | | | 101 | |
103 | #include <sys/sleeptab.h> | | 102 | #include <sys/sleeptab.h> |
104 | | | 103 | |
105 | #endif /* _SYS_SLEEPQ_H_ */ | | 104 | #endif /* _SYS_SLEEPQ_H_ */ |