2 * Copyright (c) 2013-2014 Apple Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
24 #ifndef _QOS_PRIVATE_H
25 #define _QOS_PRIVATE_H
27 #include <pthread/qos.h>
28 #include <pthread/priority_private.h>
29 #include <sys/qos.h> /* qos_class_t */
30 #include <sys/qos_private.h>
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>
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
39 #define __QOS_AVAILABLE_10_10
40 #define __QOS_AVAILABLE_10_11
41 #define __QOS_AVAILABLE_10_12
43 #if defined(__has_feature) && defined(__has_extension)
44 #if __has_feature(objc_fixed_enum) || __has_extension(cxx_strong_enums)
46 #define __QOS_ENUM(name, type, ...) typedef enum : type { __VA_ARGS__ } name##_t
48 #if __has_feature(enumerator_attributes)
49 #undef __QOS_AVAILABLE_10_10
50 #define __QOS_AVAILABLE_10_10 __API_AVAILABLE(macos(10.10), ios(8.0))
51 #undef __QOS_AVAILABLE_10_11
52 #define __QOS_AVAILABLE_10_11 __API_AVAILABLE(macos(10.11), ios(9.0), tvos(9.0), watchos(2.0))
53 #undef __QOS_AVAILABLE_10_12
54 #define __QOS_AVAILABLE_10_12 __API_AVAILABLE(macos(10.12), ios(10.0), tvos(10.0), watchos(3.0))
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))
60 // This enum matches workq_set_self_flags in
61 // xnu's workqueue_internal.h.
62 __QOS_ENUM(_pthread_set_flags
, unsigned int,
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,
68 _PTHREAD_SET_SELF_ALTERNATE_AMX __QOS_AVAILABLE_10_15_1
= 0x20,
72 #undef __QOS_AVAILABLE_10_10
73 #undef __QOS_AVAILABLE_10_11
74 #undef __QOS_AVAILABLE_10_12
81 * @function pthread_set_qos_class_np
84 * Sets the requested QOS class and relative priority of the current thread.
87 * The QOS class and relative priority represent an overall combination of
88 * system quality of service attributes on a thread.
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.
98 * The current thread as returned by pthread_self().
99 * EINVAL will be returned if any other thread is provided.
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.
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.
118 * Zero if successful, othwerise an errno value.
120 __API_DEPRECATED_WITH_REPLACEMENT("pthread_set_qos_class_self_np", macos(10.10, 10.10), ios(8.0, 8.0))
122 pthread_set_qos_class_np(pthread_t __pthread
,
123 qos_class_t __qos_class
,
124 int __relative_priority
);
126 /* Private interfaces for libdispatch to encode/decode specific values of pthread_priority_t. */
128 // Encode a class+priority pair into a pthread_priority_t,
129 __API_AVAILABLE(macos(10.10), ios(8.0))
131 _pthread_qos_class_encode(qos_class_t qos_class
, int relative_priority
, unsigned long flags
);
133 // Decode a pthread_priority_t into a class+priority pair.
134 __API_AVAILABLE(macos(10.10), ios(8.0))
136 _pthread_qos_class_decode(pthread_priority_t priority
, int *relative_priority
, unsigned long *flags
);
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))
142 _pthread_qos_class_encode_workqueue(int queue_priority
, unsigned long flags
);
144 #if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
146 // Set QoS or voucher, or both, on pthread_self()
147 __API_AVAILABLE(macos(10.10), ios(8.0))
149 _pthread_set_properties_self(_pthread_set_flags_t flags
, pthread_priority_t priority
, mach_port_t voucher
);
151 // Set self to fixed priority without disturbing QoS or priority
152 __API_AVAILABLE(macos(10.10), ios(8.0))
154 pthread_set_fixedpriority_self(void);
156 // Inverse of pthread_set_fixedpriority_self()
157 __API_AVAILABLE(macos(10.10), ios(8.0))
159 pthread_set_timeshare_self(void);
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))
166 pthread_prefer_alternate_amx_self(void);
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).
174 #define PTHREAD_MAX_PARALLELISM_PHYSICAL 0x1
177 * @function pthread_qos_max_parallelism
180 * Returns the number of compute units available for parallel computation at
181 * a specified QoS class.
184 * The specified QoS class.
187 * 0 or PTHREAD_MAX_PARALLELISM_PHYSICAL.
190 * The number of compute units available for parallel computation for the
191 * specified QoS, or -1 on failure (with errno set accordingly).
193 __API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0))
195 pthread_qos_max_parallelism(qos_class_t qos
, unsigned long flags
);
198 * @function pthread_time_constraint_max_parallelism()
201 * Returns the number of compute units available for parallel computation on
205 * 0 or PTHREAD_MAX_PARALLELISM_PHYSICAL.
208 * The number of compute units available for parallel computation on realtime
209 * threads, or -1 on failure (with errno set accordingly).
211 __API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0))
213 pthread_time_constraint_max_parallelism(unsigned long flags
);
215 #endif // __DARWIN_C_LEVEL >= __DARWIN_C_FULL
221 #endif //_QOS_PRIVATE_H