]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kern/coalition.h
xnu-6153.11.26.tar.gz
[apple/xnu.git] / osfmk / kern / coalition.h
CommitLineData
fe8ab488
A
1/*
2 * Copyright (c) 2013 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 5 *
fe8ab488
A
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.
0a7de745 14 *
fe8ab488
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
0a7de745 17 *
fe8ab488
A
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.
0a7de745 25 *
fe8ab488
A
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29#ifndef _KERN_COALITION_H_
30#define _KERN_COALITION_H_
31
3e170ce0 32/* only kernel-private interfaces */
fe8ab488 33#ifdef XNU_KERNEL_PRIVATE
3e170ce0 34#include <mach/coalition.h>
5ba3f43e 35#include <kern/thread_group.h>
fe8ab488 36
3e170ce0
A
37#if CONFIG_COALITIONS
38
39void coalitions_init(void);
fe8ab488
A
40
41/* These may return:
42 * KERN_ALREADY_IN_SET task is already in a coalition (maybe this one, maybe a different one)
43 * KERN_TERMINATED coalition is already terminated (so it may not adopt any more tasks)
44 */
3e170ce0
A
45kern_return_t coalitions_adopt_task(coalition_t *coaltions, task_t task);
46kern_return_t coalitions_adopt_init_task(task_t task);
39037602 47kern_return_t coalitions_adopt_corpse_task(task_t task);
fe8ab488
A
48
49/* Currently, no error conditions. If task is not already in a coalition,
50 * KERN_SUCCESS is returned because removing it did not fail.
51 */
3e170ce0
A
52kern_return_t coalitions_remove_task(task_t task);
53void task_release_coalitions(task_t task);
54
55/*
56 *
57 */
58kern_return_t coalitions_set_roles(coalition_t coalitions[COALITION_NUM_TYPES],
0a7de745 59 task_t task, int roles[COALITION_NUM_TYPES]);
fe8ab488
A
60
61uint64_t coalition_id(coalition_t coal);
3e170ce0
A
62void task_coalition_ids(task_t task, uint64_t ids[COALITION_NUM_TYPES]);
63void task_coalition_roles(task_t task, int roles[COALITION_NUM_TYPES]);
64int coalition_type(coalition_t coal);
65
66void task_coalition_update_gpu_stats(task_t task, uint64_t gpu_ns_delta);
5ba3f43e 67boolean_t task_coalition_adjust_focal_count(task_t task, int count, uint32_t *new_count);
3e170ce0 68uint32_t task_coalition_focal_count(task_t task);
5ba3f43e 69boolean_t task_coalition_adjust_nonfocal_count(task_t task, int count, uint32_t *new_count);
3e170ce0 70uint32_t task_coalition_nonfocal_count(task_t task);
d9a64523 71struct thread_group *task_coalition_get_thread_group(task_t task);
0a7de745 72void coalition_set_thread_group(coalition_t coal, struct thread_group *tg);
d9a64523
A
73struct thread_group *kdp_coalition_get_thread_group(coalition_t coal);
74struct thread_group *coalition_get_thread_group(coalition_t coal);
5ba3f43e 75void task_coalition_thread_group_focal_update(task_t task);
3e170ce0
A
76
77void coalition_for_each_task(coalition_t coal, void *ctx,
0a7de745 78 void (*callback)(coalition_t, void *, task_t));
fe8ab488 79
5ba3f43e
A
80void coalition_set_efficient(coalition_t coal);
81
cb323159
A
82/* Coalition ledger */
83struct coalition_ledger_indices {
84 int logical_writes;
85};
86void init_coalition_ledgers(void);
87int coalition_ledger_set_logical_writes_limit(coalition_t coal, int64_t limit);
88void coalition_io_monitor_ctl(struct coalition *coalition, uint32_t flags, int64_t limit);
89ledger_t coalition_ledger_get_from_task(task_t task);
90void coalition_io_rate_exceeded(int warning, const void *param0, __unused const void *param1);
91void coalition_io_ledger_update(task_t task, int32_t flavor, boolean_t is_credit, uint32_t io_size);
92
93/* Max limit for coalition logical_writes ledger in MB. Setting to 16 TB */
94#define COALITION_MAX_LOGICAL_WRITES_LIMIT ((ledger_amount_t)(1ULL << 24))
95/* logical_writes ledger's refill time interval */
96#define COALITION_LEDGER_MONITOR_INTERVAL_SECS (24 * 60 * 60)
97
98
5ba3f43e
A
99typedef void (*coalition_iterate_fn_t)(void*, int, coalition_t);
100kern_return_t coalition_iterate_stackshot(coalition_iterate_fn_t callout, void *arg, uint32_t coalition_type);
101
fe8ab488
A
102/* Returns with a reference, or COALITION_NULL.
103 * There is no coalition with id 0.
104 */
105coalition_t coalition_find_by_id(uint64_t coal_id);
106
107/* Returns with a reference and an activation, or COALITION_NULL.
108 * There is no coalition with id 0.
109 */
110coalition_t coalition_find_and_activate_by_id(uint64_t coal_id);
111
fe8ab488
A
112void coalition_remove_active(coalition_t coal);
113
114void coalition_release(coalition_t coal);
115
116/*
117 * The following functions are to be used by the syscall wrapper
118 * in bsd/kern/kern_proc.c, after it has verified the caller's privilege.
119 */
120
121/* This may return:
122 * KERN_DEFAULT_SET The default coalition, which contains the kernel, may
123 * not be terminated.
124 * KERN_TERMINATED The coalition was already reaped.
125 * KERN_FAILURE The coalition was not empty or has never been terminated.
126 */
127kern_return_t coalition_reap_internal(coalition_t coal);
128
129/* This may return:
130 * KERN_DEFAULT_SET The default coalition, which contains the kernel, may
131 * not be terminated.
132 * KERN_TERMINATED The coalition was already terminated (or even reaped)
133 * KERN_INVALID_NAME The coalition was already reaped.
134 */
135kern_return_t coalition_request_terminate_internal(coalition_t coal);
136
137/* This may return:
138 * KERN_RESOURCE_SHORTAGE Unable to allocate kernel resources for a
139 * new coalition.
140 */
5ba3f43e 141kern_return_t coalition_create_internal(int type, int role, boolean_t privileged, coalition_t *out);
fe8ab488 142
5ba3f43e
A
143boolean_t coalition_term_requested(coalition_t coal);
144boolean_t coalition_is_terminated(coalition_t coal);
145boolean_t coalition_is_reaped(coalition_t coal);
fe8ab488 146boolean_t coalition_is_privileged(coalition_t coal);
3e170ce0 147boolean_t task_is_in_privileged_coalition(task_t task, int type);
fe8ab488
A
148
149kern_return_t coalition_resource_usage_internal(coalition_t coal, struct coalition_resource_usage *cru_out);
150
5ba3f43e
A
151task_t kdp_coalition_get_leader(coalition_t coal);
152
3e170ce0
A
153/*
154 * development/debug interfaces
155 */
5ba3f43e 156#if DEVELOPMENT || DEBUG
3e170ce0
A
157int coalition_should_notify(coalition_t coal);
158void coalition_set_notify(coalition_t coal, int notify);
159#endif
160
161#else /* !CONFIG_COALITIONS */
162
0a7de745
A
163static inline void
164task_coalition_update_gpu_stats(__unused task_t task,
165 __unused uint64_t gpu_ns_delta)
3e170ce0
A
166{
167 return;
168}
169
0a7de745
A
170static inline boolean_t
171task_coalition_adjust_focal_count(__unused task_t task,
172 __unused int count,
173 __unused uint32_t *new_count)
3e170ce0 174{
5ba3f43e 175 return FALSE;
3e170ce0
A
176}
177
0a7de745
A
178static inline boolean_t
179task_coalition_adjust_nonfocal_count(__unused task_t task,
180 __unused int count,
181 __unused uint32_t *new_count)
3e170ce0 182{
5ba3f43e 183 return FALSE;
3e170ce0
A
184}
185
0a7de745
A
186static inline uint32_t
187task_coalition_focal_count(__unused task_t task)
3e170ce0
A
188{
189 return 0;
190}
191
0a7de745
A
192static inline void
193coalition_for_each_task(__unused coalition_t coal,
194 __unused void *ctx,
195 __unused void (*callback)(coalition_t, void *, task_t))
3e170ce0
A
196{
197 return;
198}
199
200#endif /* CONFIG_COALITIONS */
fe8ab488 201#endif /* XNU_KERNEL_PRIVATE */
fe8ab488 202#endif /* _KERN_COALITION_H */