]> git.saurik.com Git - apple/xnu.git/blame - osfmk/mach/coalition.h
xnu-4570.41.2.tar.gz
[apple/xnu.git] / osfmk / mach / coalition.h
CommitLineData
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
5ba3f43e
A
102/* Coalition Efficiency Interface Support */
103
104/* Flags for coalition efficiency */
105#define COALITION_FLAGS_EFFICIENT (0x1)
106
107/*
108 * Mapping of launchd plist values to coalition efficiency flags.
109 * Launchd uses this mapping to pass the correct flags to
110 * coalition_info_set_efficiency(cid, flags);
111 *
112 * Current supported values mapping:
113 * { "Efficient" : COALITION_FLAGS_EFFICIENT, }
114 */
115static const char *coalition_efficiency_names[] = {
116 "Efficient",
117};
118static const uint64_t coalition_efficiency_flags[] = {
119 COALITION_FLAGS_EFFICIENT,
120};
121
3e170ce0
A
122struct coalition_resource_usage {
123 uint64_t tasks_started;
124 uint64_t tasks_exited;
125 uint64_t time_nonempty;
126 uint64_t cpu_time;
127 uint64_t interrupt_wakeups;
128 uint64_t platform_idle_wakeups;
129 uint64_t bytesread;
130 uint64_t byteswritten;
131 uint64_t gpu_time;
132 uint64_t cpu_time_billed_to_me;
133 uint64_t cpu_time_billed_to_others;
39037602 134 uint64_t energy;
4bd07ac2
A
135 uint64_t logical_immediate_writes;
136 uint64_t logical_deferred_writes;
137 uint64_t logical_invalidated_writes;
138 uint64_t logical_metadata_writes;
5ba3f43e
A
139 uint64_t energy_billed_to_me;
140 uint64_t energy_billed_to_others;
141 uint64_t cpu_ptime;
3e170ce0
A
142};
143
144#ifdef PRIVATE
145/* definitions shared by only xnu + Libsyscall */
146
147/* Syscall flavors */
148#define COALITION_OP_CREATE 1
149#define COALITION_OP_TERMINATE 2
150#define COALITION_OP_REAP 3
151
152/* coalition_info flavors */
153#define COALITION_INFO_RESOURCE_USAGE 1
5ba3f43e
A
154#define COALITION_INFO_SET_NAME 2
155#define COALITION_INFO_SET_EFFICIENCY 3
156
157#define COALITION_EFFICIENCY_VALID_FLAGS (COALITION_FLAGS_EFFICIENT)
3e170ce0
A
158
159/* structure returned from libproc coalition listing interface */
160struct procinfo_coalinfo {
161 uint64_t coalition_id;
162 uint32_t coalition_type;
163 uint32_t coalition_tasks;
164};
165
166#endif /* PRIVATE */
167
168#ifdef XNU_KERNEL_PRIVATE
169#if COALITION_DEBUG
170#define coal_dbg(fmt, ...) \
171 printf("%s: " fmt "\n", __func__, ## __VA_ARGS__)
172#else
173#define coal_dbg(fmt, ...)
174#endif
175
176#endif
177
178#endif /* _MACH_COALITION_H_ */