xref: /xnu-12377.81.4/osfmk/kern/work_interval.h (revision 043036a2b3718f7f0be807e2870f8f47d3fa0796)
1 /*
2  * Copyright (c) 2017 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 _KERN_WORK_INTERVAL_H_
30 #define _KERN_WORK_INTERVAL_H_
31 
32 #include <sys/cdefs.h>
33 
34 #include <stdint.h>
35 #include <kern/kern_types.h>
36 
37 #include <kern/thread_group.h>
38 #include <kern/recount.h>
39 
40 __BEGIN_DECLS
41 
42 struct work_interval;
43 
44 struct kern_work_interval_args {
45 	uint64_t work_interval_id;
46 	uint64_t start;
47 	uint64_t finish;
48 	uint64_t deadline;
49 	uint64_t next_start;
50 	uint32_t notify_flags;
51 	uint32_t create_flags;
52 	uint16_t urgency;
53 };
54 
55 struct kern_work_interval_create_args {
56 	uint64_t        wica_id;          /* out param */
57 	mach_port_name_t wica_port;        /* out param */
58 	uint32_t        wica_create_flags;
59 };
60 
61 struct kern_work_interval_workload_id_args {
62 	uint32_t        wlida_flags;            /* in/out param */
63 	uint32_t        wlida_wicreate_flags;   /* in/out param */
64 	char *          wlida_name;             /* in param */
65 	uint64_t        wlida_syscall_mask[2];  /* out param */
66 };
67 
68 /*
69  * Allocate/assign a single work interval ID for a thread,
70  * and support deallocating it.
71  */
72 extern kern_return_t
73 kern_work_interval_create(thread_t thread, struct kern_work_interval_create_args *create_params);
74 
75 extern kern_return_t
76 kern_work_interval_get_flags_from_port(mach_port_name_t port_name, uint32_t*flags);
77 
78 /*
79  * A private interface for kevent subsystem.
80  * Returns a +1 ref to the work_interval associated with a given port.
81  */
82 extern kern_return_t
83 kern_port_name_to_work_interval(mach_port_name_t name,
84     struct work_interval **work_interval);
85 
86 /*
87  * A private interface for kevent subsystem.
88  * Returns following scheduling policies associated with a work interval,
89  * if available.
90  * : Priority
91  * : Scheduling policy/mode
92  */
93 extern kern_return_t
94 kern_work_interval_get_policy(struct work_interval *work_interval,
95     integer_t *policy,
96     integer_t *priority);
97 
98 #if CONFIG_THREAD_GROUPS
99 /*
100  * A private interface for kevent subsystem.
101  * Returns a +1 ref on the backing thread group associated with a work interval,
102  * if available.
103  */
104 extern kern_return_t
105 kern_work_interval_get_thread_group(struct work_interval *work_interval,
106     struct thread_group **tg);
107 #endif /* CONFIG_THREAD_GROUPS */
108 
109 /*
110  * A private interface for kevent subsystem.
111  * Routine to release a ref count on the work interval.
112  * For more information, see work_interval_release.
113  */
114 extern void
115 kern_work_interval_release(struct work_interval *work_interval);
116 
117 /*
118  * A private interface for workqueue subsystem.
119  * Routine to join a work interval specified in @work_interval argument.
120  * It takes +1 ref on the work interval and passes it to the thread as a part of
121  * join the work interval. Expects @thread to be the calling thread.
122  */
123 extern kern_return_t
124 kern_work_interval_explicit_join(thread_t thread, struct work_interval *work_interval);
125 
126 
127 extern kern_return_t
128 kern_work_interval_destroy(thread_t thread, uint64_t work_interval_id);
129 extern kern_return_t
130 kern_work_interval_join(thread_t thread, mach_port_name_t port_name);
131 
132 extern kern_return_t
133 kern_work_interval_notify(thread_t thread, struct kern_work_interval_args* kwi_args);
134 extern kern_return_t
135 kern_work_interval_set_name(mach_port_name_t port_name, char *name, size_t len);
136 extern kern_return_t
137 kern_work_interval_set_workload_id(mach_port_name_t port_name,
138     struct kern_work_interval_workload_id_args *workload_id_args);
139 
140 #ifdef MACH_KERNEL_PRIVATE
141 
142 bool work_interval_port_type_render_server(mach_port_name_t port_name);
143 
144 #if CONFIG_SCHED_AUTO_JOIN
145 bool work_interval_should_propagate(thread_t cthread, thread_t thread);
146 void work_interval_auto_join_propagate(thread_t from, thread_t to);
147 void work_interval_auto_join_unwind(thread_t thread);
148 void work_interval_auto_join_demote(thread_t thread);
149 #endif /* CONFIG_SCHED_AUTO_JOIN */
150 
151 
152 struct recount_track *work_interval_get_recount_tracks(struct work_interval *work_interval);
153 
154 extern kern_return_t work_interval_thread_terminate(thread_t thread);
155 extern int work_interval_get_priority(thread_t thread);
156 
157 #endif /* MACH_KERNEL_PRIVATE */
158 
159 #ifdef KERNEL_PRIVATE
160 
161 __enum_closed_decl(wi_class_t, uint8_t, {
162 	WI_CLASS_NONE              = 0,
163 	WI_CLASS_DISCRETIONARY     = 1,
164 	WI_CLASS_BEST_EFFORT       = 2,
165 	WI_CLASS_APPLICATION       = 3,
166 	WI_CLASS_SYSTEM            = 4,
167 	WI_CLASS_SYSTEM_CRITICAL   = 5,
168 	WI_CLASS_REALTIME          = 6,
169 	WI_CLASS_REALTIME_CRITICAL = 7,
170 	WI_CLASS_APP_SUPPORT       = 8,
171 
172 	WI_CLASS_COUNT
173 });
174 
175 #endif
176 
177 __END_DECLS
178 
179 #endif /* !defined(_KERN_WORK_INTERVAL_H_) */
180