]> git.saurik.com Git - apple/libpthread.git/blame - sys/qos.h
libpthread-330.220.2.tar.gz
[apple/libpthread.git] / sys / qos.h
CommitLineData
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 _SYS_QOS_H
25#define _SYS_QOS_H
26
27#include <sys/cdefs.h>
28#include <Availability.h>
29
30/*!
31 * @typedef qos_class_t
32 *
33 * @abstract
34 * An abstract thread quality of service (QOS) classification.
35 *
36 * @discussion
37 * Thread quality of service (QOS) classes are ordered abstract representations
38 * of the nature of work that is expected to be performed by a pthread, dispatch
39 * queue, or NSOperation. Each class specifies a maximum thread scheduling
40 * priority for that band (which may be used in combination with a relative
41 * priority offset within the band), as well as quality of service
42 * characteristics for timer latency, CPU throughput, I/O throughput, network
43 * socket traffic management behavior and more.
44 *
45 * A best effort is made to allocate available system resources to every QOS
46 * class. Quality of service degredation only occurs during system resource
47 * contention, proportionally to the QOS class. That said, QOS classes
48 * representing user-initiated work attempt to achieve peak throughput while
49 * QOS classes for other work attempt to achieve peak energy and thermal
50 * efficiency, even in the absence of contention. Finally, the use of QOS
51 * classes does not allow threads to supersede any limits that may be applied
52 * to the overall process.
53 */
54
55/*!
56 * @constant QOS_CLASS_USER_INTERACTIVE
57 * @abstract A QOS class which indicates work performed by this thread
58 * is interactive with the user.
59 * @discussion Such work is requested to run at high priority relative to other
60 * work on the system. Specifying this QOS class is a request to run with
61 * nearly all available system CPU and I/O bandwidth even under contention.
62 * This is not an energy-efficient QOS class to use for large tasks. The use of
63 * this QOS class should be limited to critical interaction with the user such
64 * as handling events on the main event loop, view drawing, animation, etc.
65 *
66 * @constant QOS_CLASS_USER_INITIATED
67 * @abstract A QOS class which indicates work performed by this thread
68 * was initiated by the user and that the user is likely waiting for the
69 * results.
70 * @discussion Such work is requested to run at a priority below critical user-
71 * interactive work, but relatively higher than other work on the system. This
2546420a
A
72 * is not an energy-efficient QOS class to use for large tasks. Its use
73 * should be limited to operations of short enough duration that the user is
74 * unlikely to switch tasks while waiting for the results. Typical
75 * user-initiated work will have progress indicated by the display of
76 * placeholder content or modal user interface.
f1a1da6c
A
77 *
78 * @constant QOS_CLASS_DEFAULT
79 * @abstract A default QOS class used by the system in cases where more specific
80 * QOS class information is not available.
81 * @discussion Such work is requested to run at a priority below critical user-
82 * interactive and user-initiated work, but relatively higher than utility and
83 * background tasks. Threads created by pthread_create() without an attribute
84 * specifying a QOS class will default to QOS_CLASS_DEFAULT. This QOS class
85 * value is not intended to be used as a work classification, it should only be
86 * set when propagating or restoring QOS class values provided by the system.
87 *
88 * @constant QOS_CLASS_UTILITY
89 * @abstract A QOS class which indicates work performed by this thread
90 * may or may not be initiated by the user and that the user is unlikely to be
91 * immediately waiting for the results.
92 * @discussion Such work is requested to run at a priority below critical user-
93 * interactive and user-initiated work, but relatively higher than low-level
2546420a
A
94 * system maintenance tasks. The use of this QOS class indicates the work
95 * should be run in an energy and thermally-efficient manner. The progress of
96 * utility work may or may not be indicated to the user, but the effect of such
97 * work is user-visible.
f1a1da6c
A
98 *
99 * @constant QOS_CLASS_BACKGROUND
100 * @abstract A QOS class which indicates work performed by this thread was not
101 * initiated by the user and that the user may be unaware of the results.
102 * @discussion Such work is requested to run at a priority below other work.
103 * The use of this QOS class indicates the work should be run in the most energy
104 * and thermally-efficient manner.
105 *
106 * @constant QOS_CLASS_UNSPECIFIED
107 * @abstract A QOS class value which indicates the absence or removal of QOS
108 * class information.
109 * @discussion As an API return value, may indicate that threads or pthread
110 * attributes were configured with legacy API incompatible or in conflict with
111 * the QOS class system.
112 */
113
114#define __QOS_ENUM(name, type, ...) enum { __VA_ARGS__ }; typedef type name##_t
a0619f9c 115#define __QOS_CLASS_AVAILABLE(...)
f1a1da6c
A
116
117#if defined(__has_feature) && defined(__has_extension)
118#if __has_feature(objc_fixed_enum) || __has_extension(cxx_strong_enums)
119#undef __QOS_ENUM
120#define __QOS_ENUM(name, type, ...) typedef enum : type { __VA_ARGS__ } name##_t
121#endif
122#if __has_feature(enumerator_attributes)
a0619f9c
A
123#undef __QOS_CLASS_AVAILABLE
124#define __QOS_CLASS_AVAILABLE __API_AVAILABLE
f1a1da6c
A
125#endif
126#endif
127
128__QOS_ENUM(qos_class, unsigned int,
129 QOS_CLASS_USER_INTERACTIVE
a0619f9c 130 __QOS_CLASS_AVAILABLE(macos(10.10), ios(8.0)) = 0x21,
f1a1da6c 131 QOS_CLASS_USER_INITIATED
a0619f9c 132 __QOS_CLASS_AVAILABLE(macos(10.10), ios(8.0)) = 0x19,
f1a1da6c 133 QOS_CLASS_DEFAULT
a0619f9c 134 __QOS_CLASS_AVAILABLE(macos(10.10), ios(8.0)) = 0x15,
f1a1da6c 135 QOS_CLASS_UTILITY
a0619f9c 136 __QOS_CLASS_AVAILABLE(macos(10.10), ios(8.0)) = 0x11,
f1a1da6c 137 QOS_CLASS_BACKGROUND
a0619f9c 138 __QOS_CLASS_AVAILABLE(macos(10.10), ios(8.0)) = 0x09,
f1a1da6c 139 QOS_CLASS_UNSPECIFIED
a0619f9c 140 __QOS_CLASS_AVAILABLE(macos(10.10), ios(8.0)) = 0x00,
f1a1da6c
A
141);
142
143#undef __QOS_ENUM
144
145/*!
146 * @constant QOS_MIN_RELATIVE_PRIORITY
147 * @abstract The minimum relative priority that may be specified within a
148 * QOS class. These priorities are relative only within a given QOS class
149 * and meaningful only for the current process.
150 */
151#define QOS_MIN_RELATIVE_PRIORITY (-15)
152
153/* Userspace (only) definitions */
154
155#ifndef KERNEL
156
157__BEGIN_DECLS
158
159/*!
160 * @function qos_class_self
161 *
162 * @abstract
163 * Returns the requested QOS class of the current thread.
164 *
165 * @return
166 * One of the QOS class values in qos_class_t.
167 */
a0619f9c 168__API_AVAILABLE(macos(10.10), ios(8.0))
f1a1da6c
A
169qos_class_t
170qos_class_self(void);
171
172/*!
173 * @function qos_class_main
174 *
175 * @abstract
176 * Returns the initial requested QOS class of the main thread.
177 *
178 * @discussion
179 * The QOS class that the main thread of a process is created with depends on
180 * the type of process (e.g. application or daemon) and on how it has been
181 * launched.
182 *
183 * This function returns that initial requested QOS class value chosen by the
184 * system to enable propagation of that classification to matching work not
185 * executing on the main thread.
186 *
187 * @return
188 * One of the QOS class values in qos_class_t.
189 */
a0619f9c 190__API_AVAILABLE(macos(10.10), ios(8.0))
f1a1da6c
A
191qos_class_t
192qos_class_main(void);
193
194__END_DECLS
195
196#endif // KERNEL
197
198#endif // _SYS_QOS_H