]>
Commit | Line | Data |
---|---|---|
f1a1da6c A |
1 | /* |
2 | * Copyright (c) 2013-2014 Apple Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_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. Please obtain a copy of the License at | |
10 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
11 | * file. | |
12 | * | |
13 | * The Original Code and all software distributed under the License are | |
14 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
15 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
16 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
17 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
18 | * Please see the License for the specific language governing rights and | |
19 | * limitations under the License. | |
20 | * | |
21 | * @APPLE_LICENSE_HEADER_END@ | |
22 | */ | |
23 | ||
24 | #ifndef _QOS_PRIVATE_H | |
25 | #define _QOS_PRIVATE_H | |
26 | ||
27 | #include <pthread/qos.h> | |
214d78a2 | 28 | #include <pthread/priority_private.h> |
a0619f9c | 29 | #include <sys/qos.h> /* qos_class_t */ |
f1a1da6c A |
30 | #include <sys/qos_private.h> |
31 | ||
32 | #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL | |
33 | // allow __DARWIN_C_LEVEL to turn off the use of mach_port_t | |
34 | #include <mach/port.h> | |
35 | #endif | |
36 | ||
f1a1da6c A |
37 | // redeffed here to avoid leaving __QOS_ENUM defined in the public header |
38 | #define __QOS_ENUM(name, type, ...) enum { __VA_ARGS__ }; typedef type name##_t | |
2546420a A |
39 | #define __QOS_AVAILABLE_10_10 |
40 | #define __QOS_AVAILABLE_10_11 | |
41 | #define __QOS_AVAILABLE_10_12 | |
f1a1da6c A |
42 | |
43 | #if defined(__has_feature) && defined(__has_extension) | |
44 | #if __has_feature(objc_fixed_enum) || __has_extension(cxx_strong_enums) | |
45 | #undef __QOS_ENUM | |
46 | #define __QOS_ENUM(name, type, ...) typedef enum : type { __VA_ARGS__ } name##_t | |
47 | #endif | |
48 | #if __has_feature(enumerator_attributes) | |
2546420a | 49 | #undef __QOS_AVAILABLE_10_10 |
a0619f9c | 50 | #define __QOS_AVAILABLE_10_10 __API_AVAILABLE(macos(10.10), ios(8.0)) |
2546420a | 51 | #undef __QOS_AVAILABLE_10_11 |
a0619f9c | 52 | #define __QOS_AVAILABLE_10_11 __API_AVAILABLE(macos(10.11), ios(9.0), tvos(9.0), watchos(2.0)) |
2546420a | 53 | #undef __QOS_AVAILABLE_10_12 |
a0619f9c | 54 | #define __QOS_AVAILABLE_10_12 __API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0)) |
11a10453 A |
55 | #undef __QOS_AVAILABLE_10_15_1 |
56 | #define __QOS_AVAILABLE_10_15_1 __API_AVAILABLE(macos(10.15.1), ios(13.2), tvos(13.2), watchos(6.2)) | |
f1a1da6c A |
57 | #endif |
58 | #endif | |
59 | ||
11a10453 A |
60 | // This enum matches workq_set_self_flags in |
61 | // xnu's workqueue_internal.h. | |
f1a1da6c | 62 | __QOS_ENUM(_pthread_set_flags, unsigned int, |
2546420a A |
63 | _PTHREAD_SET_SELF_QOS_FLAG __QOS_AVAILABLE_10_10 = 0x1, |
64 | _PTHREAD_SET_SELF_VOUCHER_FLAG __QOS_AVAILABLE_10_10 = 0x2, | |
65 | _PTHREAD_SET_SELF_FIXEDPRIORITY_FLAG __QOS_AVAILABLE_10_11 = 0x4, | |
66 | _PTHREAD_SET_SELF_TIMESHARE_FLAG __QOS_AVAILABLE_10_11 = 0x8, | |
67 | _PTHREAD_SET_SELF_WQ_KEVENT_UNBIND __QOS_AVAILABLE_10_12 = 0x10, | |
11a10453 | 68 | _PTHREAD_SET_SELF_ALTERNATE_AMX __QOS_AVAILABLE_10_15_1 = 0x20, |
f1a1da6c A |
69 | ); |
70 | ||
71 | #undef __QOS_ENUM | |
2546420a A |
72 | #undef __QOS_AVAILABLE_10_10 |
73 | #undef __QOS_AVAILABLE_10_11 | |
74 | #undef __QOS_AVAILABLE_10_12 | |
f1a1da6c A |
75 | |
76 | #ifndef KERNEL | |
77 | ||
78 | __BEGIN_DECLS | |
79 | ||
80 | /*! | |
81 | * @function pthread_set_qos_class_np | |
82 | * | |
83 | * @abstract | |
84 | * Sets the requested QOS class and relative priority of the current thread. | |
85 | * | |
86 | * @discussion | |
87 | * The QOS class and relative priority represent an overall combination of | |
88 | * system quality of service attributes on a thread. | |
89 | * | |
90 | * Subsequent calls to interfaces such as pthread_setschedparam() that are | |
91 | * incompatible or in conflict with the QOS class system will unset the QOS | |
92 | * class requested with this interface and pthread_get_qos_class_np() will | |
93 | * return QOS_CLASS_UNSPECIFIED thereafter. A thread so modified is permanently | |
94 | * opted-out of the QOS class system and calls to this function to request a QOS | |
95 | * class for such a thread will fail and return EPERM. | |
96 | * | |
97 | * @param __pthread | |
98 | * The current thread as returned by pthread_self(). | |
99 | * EINVAL will be returned if any other thread is provided. | |
100 | * | |
101 | * @param __qos_class | |
102 | * A QOS class value: | |
103 | * - QOS_CLASS_USER_INTERACTIVE | |
104 | * - QOS_CLASS_USER_INITIATED | |
105 | * - QOS_CLASS_DEFAULT | |
106 | * - QOS_CLASS_UTILITY | |
107 | * - QOS_CLASS_BACKGROUND | |
108 | * - QOS_CLASS_MAINTENANCE | |
109 | * EINVAL will be returned if any other value is provided. | |
110 | * | |
111 | * @param __relative_priority | |
112 | * A relative priority within the QOS class. This value is a negative offset | |
113 | * from the maximum supported scheduler priority for the given class. | |
114 | * EINVAL will be returned if the value is greater than zero or less than | |
115 | * QOS_MIN_RELATIVE_PRIORITY. | |
116 | * | |
117 | * @return | |
118 | * Zero if successful, othwerise an errno value. | |
119 | */ | |
a0619f9c | 120 | __API_DEPRECATED_WITH_REPLACEMENT("pthread_set_qos_class_self_np", macos(10.10, 10.10), ios(8.0, 8.0)) |
f1a1da6c A |
121 | int |
122 | pthread_set_qos_class_np(pthread_t __pthread, | |
123 | qos_class_t __qos_class, | |
124 | int __relative_priority); | |
125 | ||
126 | /* Private interfaces for libdispatch to encode/decode specific values of pthread_priority_t. */ | |
127 | ||
128 | // Encode a class+priority pair into a pthread_priority_t, | |
a0619f9c | 129 | __API_AVAILABLE(macos(10.10), ios(8.0)) |
f1a1da6c A |
130 | pthread_priority_t |
131 | _pthread_qos_class_encode(qos_class_t qos_class, int relative_priority, unsigned long flags); | |
132 | ||
133 | // Decode a pthread_priority_t into a class+priority pair. | |
a0619f9c | 134 | __API_AVAILABLE(macos(10.10), ios(8.0)) |
f1a1da6c A |
135 | qos_class_t |
136 | _pthread_qos_class_decode(pthread_priority_t priority, int *relative_priority, unsigned long *flags); | |
137 | ||
a0619f9c A |
138 | // Encode a legacy workqueue API priority into a pthread_priority_t. This API |
139 | // is deprecated and can be removed when the simulator no longer uses it. | |
140 | __API_DEPRECATED("no longer used", macos(10.10, 10.13), ios(8.0, 11.0)) | |
f1a1da6c A |
141 | pthread_priority_t |
142 | _pthread_qos_class_encode_workqueue(int queue_priority, unsigned long flags); | |
143 | ||
144 | #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL | |
a0619f9c | 145 | |
f1a1da6c | 146 | // Set QoS or voucher, or both, on pthread_self() |
a0619f9c | 147 | __API_AVAILABLE(macos(10.10), ios(8.0)) |
f1a1da6c A |
148 | int |
149 | _pthread_set_properties_self(_pthread_set_flags_t flags, pthread_priority_t priority, mach_port_t voucher); | |
150 | ||
151 | // Set self to fixed priority without disturbing QoS or priority | |
a0619f9c | 152 | __API_AVAILABLE(macos(10.10), ios(8.0)) |
f1a1da6c A |
153 | int |
154 | pthread_set_fixedpriority_self(void); | |
155 | ||
964d3577 | 156 | // Inverse of pthread_set_fixedpriority_self() |
a0619f9c | 157 | __API_AVAILABLE(macos(10.10), ios(8.0)) |
964d3577 A |
158 | int |
159 | pthread_set_timeshare_self(void); | |
160 | ||
11a10453 A |
161 | // Set self to avoid running on the same AMX as |
162 | // other work in this group. | |
163 | // Only allowed on non-workqueue pthreads | |
164 | __API_AVAILABLE(macos(10.15.1), ios(13.2), tvos(13.2), watchos(6.2)) | |
165 | int | |
166 | pthread_prefer_alternate_amx_self(void); | |
167 | ||
a0619f9c A |
168 | /*! |
169 | * @const PTHREAD_MAX_PARALLELISM_PHYSICAL | |
170 | * Flag that can be used with pthread_qos_max_parallelism() and | |
171 | * pthread_time_constraint_max_parallelism() to ask for a count of physical | |
172 | * compute units available for parallelism (default is logical). | |
173 | */ | |
174 | #define PTHREAD_MAX_PARALLELISM_PHYSICAL 0x1 | |
175 | ||
176 | /*! | |
177 | * @function pthread_qos_max_parallelism | |
178 | * | |
179 | * @abstract | |
180 | * Returns the number of compute units available for parallel computation at | |
181 | * a specified QoS class. | |
182 | * | |
183 | * @param qos | |
184 | * The specified QoS class. | |
185 | * | |
186 | * @param flags | |
187 | * 0 or PTHREAD_MAX_PARALLELISM_PHYSICAL. | |
188 | * | |
189 | * @return | |
190 | * The number of compute units available for parallel computation for the | |
191 | * specified QoS, or -1 on failure (with errno set accordingly). | |
192 | */ | |
193 | __API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0)) | |
194 | int | |
195 | pthread_qos_max_parallelism(qos_class_t qos, unsigned long flags); | |
196 | ||
197 | /*! | |
198 | * @function pthread_time_constraint_max_parallelism() | |
199 | * | |
200 | * @abstract | |
201 | * Returns the number of compute units available for parallel computation on | |
202 | * realtime threads. | |
203 | * | |
204 | * @param flags | |
205 | * 0 or PTHREAD_MAX_PARALLELISM_PHYSICAL. | |
206 | * | |
207 | * @return | |
208 | * The number of compute units available for parallel computation on realtime | |
209 | * threads, or -1 on failure (with errno set accordingly). | |
210 | */ | |
211 | __API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0)) | |
212 | int | |
213 | pthread_time_constraint_max_parallelism(unsigned long flags); | |
214 | ||
215 | #endif // __DARWIN_C_LEVEL >= __DARWIN_C_FULL | |
f1a1da6c A |
216 | |
217 | __END_DECLS | |
218 | ||
219 | #endif // KERNEL | |
220 | ||
221 | #endif //_QOS_PRIVATE_H |