]>
Commit | Line | Data |
---|---|---|
3e170ce0 A |
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 | ||
5ba3f43e | 34 | #define COALITION_CREATE_FLAGS_MASK ((uint32_t)0xFF1) |
3e170ce0 A |
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 | ||
5ba3f43e A |
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) | |
3e170ce0 A |
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 | ||
5ba3f43e | 79 | #define COALITION_TASKROLE_NONE (-1) /* task plays no role in the given coalition */ |
3e170ce0 A |
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 | ||
a39ff7e2 A |
102 | #define COALITION_NUM_THREAD_QOS_TYPES 7 |
103 | ||
5ba3f43e A |
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 | ||
3e170ce0 A |
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; | |
39037602 | 136 | uint64_t energy; |
4bd07ac2 A |
137 | uint64_t logical_immediate_writes; |
138 | uint64_t logical_deferred_writes; | |
139 | uint64_t logical_invalidated_writes; | |
140 | uint64_t logical_metadata_writes; | |
5ba3f43e A |
141 | uint64_t energy_billed_to_me; |
142 | uint64_t energy_billed_to_others; | |
143 | uint64_t cpu_ptime; | |
a39ff7e2 A |
144 | uint64_t cpu_time_eqos_len; /* Stores the number of thread QoS types */ |
145 | uint64_t cpu_time_eqos[COALITION_NUM_THREAD_QOS_TYPES]; | |
3e170ce0 A |
146 | }; |
147 | ||
148 | #ifdef PRIVATE | |
149 | /* definitions shared by only xnu + Libsyscall */ | |
150 | ||
151 | /* Syscall flavors */ | |
152 | #define COALITION_OP_CREATE 1 | |
153 | #define COALITION_OP_TERMINATE 2 | |
154 | #define COALITION_OP_REAP 3 | |
155 | ||
156 | /* coalition_info flavors */ | |
157 | #define COALITION_INFO_RESOURCE_USAGE 1 | |
5ba3f43e A |
158 | #define COALITION_INFO_SET_NAME 2 |
159 | #define COALITION_INFO_SET_EFFICIENCY 3 | |
160 | ||
161 | #define COALITION_EFFICIENCY_VALID_FLAGS (COALITION_FLAGS_EFFICIENT) | |
3e170ce0 A |
162 | |
163 | /* structure returned from libproc coalition listing interface */ | |
164 | struct procinfo_coalinfo { | |
165 | uint64_t coalition_id; | |
166 | uint32_t coalition_type; | |
167 | uint32_t coalition_tasks; | |
168 | }; | |
169 | ||
170 | #endif /* PRIVATE */ | |
171 | ||
172 | #ifdef XNU_KERNEL_PRIVATE | |
173 | #if COALITION_DEBUG | |
174 | #define coal_dbg(fmt, ...) \ | |
175 | printf("%s: " fmt "\n", __func__, ## __VA_ARGS__) | |
176 | #else | |
177 | #define coal_dbg(fmt, ...) | |
178 | #endif | |
179 | ||
180 | #endif | |
181 | ||
182 | #endif /* _MACH_COALITION_H_ */ |