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