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