]> git.saurik.com Git - apple/xnu.git/blob - osfmk/mach/coalition.h
xnu-7195.60.75.tar.gz
[apple/xnu.git] / osfmk / mach / coalition.h
1 /*
2 * Copyright (c) 2014 Apple 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
29 #ifndef _MACH_COALITION_H_
30 #define _MACH_COALITION_H_
31
32 /* code shared by userspace and xnu */
33
34 #define COALITION_SPAWN_ENTITLEMENT "com.apple.private.coalition-spawn"
35
36 #define COALITION_CREATE_FLAGS_MASK ((uint32_t)0xFF1)
37 #define COALITION_CREATE_FLAGS_PRIVILEGED ((uint32_t)0x01)
38
39 #define COALITION_CREATE_FLAGS_TYPE_MASK ((uint32_t)0xF0)
40 #define COALITION_CREATE_FLAGS_TYPE_SHIFT (4)
41
42 #define COALITION_CREATE_FLAGS_GET_TYPE(flags) \
43 (((flags) & COALITION_CREATE_FLAGS_TYPE_MASK) >> COALITION_CREATE_FLAGS_TYPE_SHIFT)
44
45 #define COALITION_CREATE_FLAGS_SET_TYPE(flags, type) \
46 do { \
47 flags &= ~COALITION_CREATE_FLAGS_TYPE_MASK; \
48 flags |= (((type) << COALITION_CREATE_FLAGS_TYPE_SHIFT) \
49 & COALITION_CREATE_FLAGS_TYPE_MASK); \
50 } while (0)
51
52 #define COALITION_CREATE_FLAGS_ROLE_MASK ((uint32_t)0xF00)
53 #define COALITION_CREATE_FLAGS_ROLE_SHIFT (8)
54
55 #define COALITION_CREATE_FLAGS_GET_ROLE(flags) \
56 (((flags) & COALITION_CREATE_FLAGS_ROLE_MASK) >> COALITION_CREATE_FLAGS_ROLE_SHIFT)
57
58 #define COALITION_CREATE_FLAGS_SET_ROLE(flags, role) \
59 do { \
60 flags &= ~COALITION_CREATE_FLAGS_ROLE_MASK; \
61 flags |= (((role) << COALITION_CREATE_FLAGS_ROLE_SHIFT) \
62 & COALITION_CREATE_FLAGS_ROLE_MASK); \
63 } while (0)
64
65 /*
66 * Default scheduling policy of the lead/parent task in a coalition
67 */
68 #define COALITION_ROLE_UNDEF (0)
69 #define COALITION_ROLE_SYSTEM (1)
70 #define COALITION_ROLE_BACKGROUND (2)
71 #define COALITION_ROLE_ADAPTIVE (3)
72 #define COALITION_ROLE_INTERACTIVE (4)
73 #define COALITION_NUM_ROLES (5)
74
75 #define COALITION_TYPE_RESOURCE (0)
76 #define COALITION_TYPE_JETSAM (1)
77 #define COALITION_TYPE_MAX (1)
78
79 #define COALITION_NUM_TYPES (COALITION_TYPE_MAX + 1)
80
81 #define COALITION_TASKROLE_NONE (-1) /* task plays no role in the given coalition */
82 #define COALITION_TASKROLE_UNDEF (0)
83 #define COALITION_TASKROLE_LEADER (1)
84 #define COALITION_TASKROLE_XPC (2)
85 #define COALITION_TASKROLE_EXT (3)
86
87 #define COALITION_NUM_TASKROLES (4)
88
89 #define COALITION_ROLEMASK_ALLROLES ((1 << COALITION_NUM_TASKROLES) - 1)
90 #define COALITION_ROLEMASK_UNDEF (1 << COALITION_TASKROLE_UNDEF)
91 #define COALITION_ROLEMASK_LEADER (1 << COALITION_TASKROLE_LEADER)
92 #define COALITION_ROLEMASK_XPC (1 << COALITION_TASKROLE_XPC)
93 #define COALITION_ROLEMASK_EXT (1 << COALITION_TASKROLE_EXT)
94
95 #define COALITION_SORT_NOSORT (0)
96 #define COALITION_SORT_DEFAULT (1)
97 #define COALITION_SORT_MEM_ASC (2)
98 #define COALITION_SORT_MEM_DEC (3)
99 #define COALITION_SORT_USER_ASC (4)
100 #define COALITION_SORT_USER_DEC (5)
101
102 #define COALITION_NUM_SORT (6)
103
104 #define COALITION_NUM_THREAD_QOS_TYPES 7
105
106 /* Coalition Efficiency Interface Support */
107
108 /* Flags for coalition efficiency */
109 #define COALITION_FLAGS_EFFICIENT (0x1)
110
111 /*
112 * Mapping of launchd plist values to coalition efficiency flags.
113 * Launchd uses this mapping to pass the correct flags to
114 * coalition_info_set_efficiency(cid, flags);
115 *
116 * Current supported values mapping:
117 * { "Efficient" : COALITION_FLAGS_EFFICIENT, }
118 */
119 static const char *coalition_efficiency_names[] = {
120 "Efficient",
121 };
122 static const uint64_t coalition_efficiency_flags[] = {
123 COALITION_FLAGS_EFFICIENT,
124 };
125
126 struct coalition_resource_usage {
127 uint64_t tasks_started;
128 uint64_t tasks_exited;
129 uint64_t time_nonempty;
130 uint64_t cpu_time;
131 uint64_t interrupt_wakeups;
132 uint64_t platform_idle_wakeups;
133 uint64_t bytesread;
134 uint64_t byteswritten;
135 uint64_t gpu_time;
136 uint64_t cpu_time_billed_to_me;
137 uint64_t cpu_time_billed_to_others;
138 uint64_t energy;
139 uint64_t logical_immediate_writes;
140 uint64_t logical_deferred_writes;
141 uint64_t logical_invalidated_writes;
142 uint64_t logical_metadata_writes;
143 uint64_t logical_immediate_writes_to_external;
144 uint64_t logical_deferred_writes_to_external;
145 uint64_t logical_invalidated_writes_to_external;
146 uint64_t logical_metadata_writes_to_external;
147 uint64_t energy_billed_to_me;
148 uint64_t energy_billed_to_others;
149 uint64_t cpu_ptime;
150 uint64_t cpu_time_eqos_len; /* Stores the number of thread QoS types */
151 uint64_t cpu_time_eqos[COALITION_NUM_THREAD_QOS_TYPES];
152 uint64_t cpu_instructions;
153 uint64_t cpu_cycles;
154 uint64_t fs_metadata_writes;
155 uint64_t pm_writes;
156 };
157
158 #ifdef PRIVATE
159 /* definitions shared by only xnu + Libsyscall */
160
161 /* coalition id for kernel task */
162 #define COALITION_ID_KERNEL 1
163
164 /* Syscall flavors */
165 #define COALITION_OP_CREATE 1
166 #define COALITION_OP_TERMINATE 2
167 #define COALITION_OP_REAP 3
168
169 /* coalition_info flavors */
170 #define COALITION_INFO_RESOURCE_USAGE 1
171 #define COALITION_INFO_SET_NAME 2
172 #define COALITION_INFO_SET_EFFICIENCY 3
173
174 /* coalition_ledger_set operations */
175 #define COALITION_LEDGER_SET_LOGICAL_WRITES_LIMIT 1
176
177 #define COALITION_EFFICIENCY_VALID_FLAGS (COALITION_FLAGS_EFFICIENT)
178
179 /* structure returned from libproc coalition listing interface */
180 struct procinfo_coalinfo {
181 uint64_t coalition_id;
182 uint32_t coalition_type;
183 uint32_t coalition_tasks;
184 };
185
186 #endif /* PRIVATE */
187
188 #ifdef XNU_KERNEL_PRIVATE
189 #if COALITION_DEBUG
190 #define coal_dbg(fmt, ...) \
191 printf("%s: " fmt "\n", __func__, ## __VA_ARGS__)
192 #else
193 #define coal_dbg(fmt, ...)
194 #endif
195
196 #endif
197
198 #endif /* _MACH_COALITION_H_ */