]>
Commit | Line | Data |
---|---|---|
0a7de745 A |
1 | /* |
2 | * Copyright (c) 2018 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * This file contains Original Code and/or Modifications of Original Code | |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
14 | * | |
15 | * Please obtain a copy of the License at | |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
25 | * | |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
27 | */ | |
28 | #ifndef _KERN_LOCK_GROUP_H | |
29 | #define _KERN_LOCK_GROUP_H | |
30 | ||
31 | #include <kern/queue.h> | |
32 | #include <mach/mach_types.h> | |
33 | ||
f427ee49 | 34 | __BEGIN_DECLS |
0a7de745 | 35 | |
f427ee49 | 36 | #define LCK_GRP_NULL (lck_grp_t *)NULL |
0a7de745 | 37 | |
f427ee49 A |
38 | typedef enum lck_type { |
39 | LCK_TYPE_SPIN, | |
40 | LCK_TYPE_MTX, | |
41 | LCK_TYPE_RW, | |
42 | LCK_TYPE_TICKET | |
43 | } lck_type_t; | |
0a7de745 A |
44 | |
45 | #if XNU_KERNEL_PRIVATE | |
f427ee49 | 46 | #include <kern/startup.h> |
cb323159 | 47 | #include <os/refcnt.h> |
f427ee49 | 48 | |
0a7de745 A |
49 | /* |
50 | * Arguments wrapped in LCK_GRP_ARG() will be elided | |
51 | * when LOCK_STATS is not set. | |
52 | * | |
53 | * Arguments wrapped with LCK_GRP_PROBEARG() will be | |
54 | * NULL when LOCK_STATS is not set | |
55 | */ | |
56 | #if LOCK_STATS | |
57 | #define LCK_GRP_ARG(expr) ,expr | |
58 | #define LCK_GRP_PROBEARG(grp) grp | |
59 | #else | |
60 | #define LCK_GRP_ARG(expr) | |
61 | #define LCK_GRP_PROBEARG(grp) LCK_GRP_NULL | |
62 | #endif /* LOCK_STATS */ | |
63 | ||
64 | typedef struct _lck_grp_stat_ { | |
65 | uint64_t lgs_count; | |
66 | uint32_t lgs_enablings; | |
67 | #if CONFIG_DTRACE | |
68 | /* | |
69 | * Protected by dtrace_lock | |
70 | */ | |
71 | uint32_t lgs_probeid; | |
72 | uint64_t lgs_limit; | |
73 | #endif /* CONFIG_DTRACE */ | |
74 | } lck_grp_stat_t; | |
75 | ||
76 | typedef struct _lck_grp_stats_ { | |
77 | #if LOCK_STATS | |
f427ee49 A |
78 | lck_grp_stat_t lgss_spin_held; |
79 | lck_grp_stat_t lgss_spin_miss; | |
80 | lck_grp_stat_t lgss_spin_spin; | |
81 | lck_grp_stat_t lgss_ticket_held; | |
82 | lck_grp_stat_t lgss_ticket_miss; | |
83 | lck_grp_stat_t lgss_ticket_spin; | |
0a7de745 A |
84 | #endif /* LOCK_STATS */ |
85 | ||
f427ee49 A |
86 | lck_grp_stat_t lgss_mtx_held; |
87 | lck_grp_stat_t lgss_mtx_direct_wait; | |
88 | lck_grp_stat_t lgss_mtx_miss; | |
89 | lck_grp_stat_t lgss_mtx_wait; | |
0a7de745 A |
90 | } lck_grp_stats_t; |
91 | ||
92 | #define LCK_GRP_MAX_NAME 64 | |
93 | ||
94 | typedef struct _lck_grp_ { | |
95 | queue_chain_t lck_grp_link; | |
cb323159 | 96 | os_refcnt_t lck_grp_refcnt; |
0a7de745 | 97 | uint32_t lck_grp_spincnt; |
f427ee49 | 98 | uint32_t lck_grp_ticketcnt; |
0a7de745 A |
99 | uint32_t lck_grp_mtxcnt; |
100 | uint32_t lck_grp_rwcnt; | |
101 | uint32_t lck_grp_attr; | |
102 | char lck_grp_name[LCK_GRP_MAX_NAME]; | |
103 | lck_grp_stats_t lck_grp_stats; | |
104 | } lck_grp_t; | |
105 | ||
106 | #else | |
107 | typedef struct _lck_grp_ lck_grp_t; | |
108 | #endif /* XNU_KERNEL_PRIVATE */ | |
109 | ||
f427ee49 A |
110 | #define LCK_GRP_ATTR_STAT 0x1 |
111 | #define LCK_GRP_ATTR_TIME_STAT 0x2 | |
cb323159 | 112 | |
f427ee49 | 113 | #ifdef XNU_KERNEL_PRIVATE |
0a7de745 A |
114 | typedef struct _lck_grp_attr_ { |
115 | uint32_t grp_attr_val; | |
116 | } lck_grp_attr_t; | |
117 | ||
f427ee49 A |
118 | struct lck_grp_attr_startup_spec { |
119 | lck_grp_attr_t *grp_attr; | |
120 | uint32_t grp_attr_set_flags; | |
121 | uint32_t grp_attr_clear_flags; | |
122 | }; | |
0a7de745 | 123 | |
f427ee49 A |
124 | struct lck_grp_startup_spec { |
125 | lck_grp_t *grp; | |
126 | const char *grp_name; | |
127 | lck_grp_attr_t *grp_attr; | |
128 | }; | |
129 | ||
130 | extern void lck_grp_attr_startup_init( | |
131 | struct lck_grp_attr_startup_spec *spec); | |
132 | ||
133 | extern void lck_grp_startup_init( | |
134 | struct lck_grp_startup_spec *spec); | |
135 | ||
136 | /* | |
137 | * Auto-initializing lock group declarations | |
138 | * ----------------------------------------- | |
139 | * | |
140 | * Use LCK_GRP_DECLARE to declare an automatically initialized group. | |
141 | * | |
142 | * Unless you need to configure your lock groups in very specific ways, | |
143 | * there is no point creating explicit lock group attributes. If however | |
144 | * you do need to tune the group, then LCK_GRP_DECLARE_ATTR can be used | |
145 | * and takes an extra lock group attr argument previously declared with | |
146 | * LCK_GRP_ATTR_DECLARE. | |
147 | */ | |
148 | #define LCK_GRP_ATTR_DECLARE(var, set_flags, clear_flags) \ | |
149 | SECURITY_READ_ONLY_LATE(lck_grp_attr_t) var; \ | |
150 | static __startup_data struct lck_grp_attr_startup_spec \ | |
151 | __startup_lck_grp_attr_spec_ ## var = { &var, set_flags, clear_flags }; \ | |
152 | STARTUP_ARG(LOCKS_EARLY, STARTUP_RANK_SECOND, lck_grp_attr_startup_init, \ | |
153 | &__startup_lck_grp_attr_spec_ ## var) | |
154 | ||
155 | #define LCK_GRP_DECLARE_ATTR(var, name, attr) \ | |
156 | __PLACE_IN_SECTION("__DATA,__lock_grp") lck_grp_t var; \ | |
157 | static __startup_data struct lck_grp_startup_spec \ | |
158 | __startup_lck_grp_spec_ ## var = { &var, name, attr }; \ | |
159 | STARTUP_ARG(LOCKS_EARLY, STARTUP_RANK_THIRD, lck_grp_startup_init, \ | |
160 | &__startup_lck_grp_spec_ ## var) | |
161 | ||
162 | #define LCK_GRP_DECLARE(var, name) \ | |
163 | LCK_GRP_DECLARE_ATTR(var, name, LCK_GRP_ATTR_NULL); | |
0a7de745 A |
164 | |
165 | #else | |
166 | typedef struct __lck_grp_attr__ lck_grp_attr_t; | |
f427ee49 | 167 | #endif /* XNU_KERNEL_PRIVATE */ |
0a7de745 | 168 | |
cb323159 | 169 | #define LCK_GRP_ATTR_NULL (lck_grp_attr_t *)NULL |
0a7de745 | 170 | |
0a7de745 A |
171 | extern lck_grp_attr_t *lck_grp_attr_alloc_init( |
172 | void); | |
173 | ||
f427ee49 A |
174 | extern void lck_grp_attr_setdefault( |
175 | lck_grp_attr_t *attr); | |
0a7de745 | 176 | |
f427ee49 A |
177 | extern void lck_grp_attr_setstat( |
178 | lck_grp_attr_t *attr); | |
0a7de745 | 179 | |
f427ee49 A |
180 | extern void lck_grp_attr_free( |
181 | lck_grp_attr_t *attr); | |
0a7de745 | 182 | |
f427ee49 | 183 | extern lck_grp_t *lck_grp_alloc_init( |
0a7de745 A |
184 | const char* grp_name, |
185 | lck_grp_attr_t *attr); | |
186 | ||
f427ee49 | 187 | extern void lck_grp_free( |
0a7de745 A |
188 | lck_grp_t *grp); |
189 | ||
0a7de745 | 190 | #ifdef MACH_KERNEL_PRIVATE |
f427ee49 | 191 | extern void lck_grp_init( |
0a7de745 A |
192 | lck_grp_t *grp, |
193 | const char* grp_name, | |
f427ee49 | 194 | lck_grp_attr_t *attr); |
0a7de745 | 195 | |
f427ee49 | 196 | extern void lck_grp_reference( |
0a7de745 A |
197 | lck_grp_t *grp); |
198 | ||
f427ee49 | 199 | extern void lck_grp_deallocate( |
0a7de745 A |
200 | lck_grp_t *grp); |
201 | ||
f427ee49 | 202 | extern void lck_grp_lckcnt_incr( |
0a7de745 A |
203 | lck_grp_t *grp, |
204 | lck_type_t lck_type); | |
205 | ||
f427ee49 | 206 | extern void lck_grp_lckcnt_decr( |
0a7de745 A |
207 | lck_grp_t *grp, |
208 | lck_type_t lck_type); | |
0a7de745 A |
209 | #endif /* MACH_KERNEL_PRIVATE */ |
210 | ||
f427ee49 A |
211 | __END_DECLS |
212 | ||
0a7de745 | 213 | #endif /* _KERN_LOCK_GROUP_H */ |