1*d8b80295SApple OSS Distributions /* 2*d8b80295SApple OSS Distributions * Copyright (c) 2017 Apple Inc. All rights reserved. 3*d8b80295SApple OSS Distributions * 4*d8b80295SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*d8b80295SApple OSS Distributions * 6*d8b80295SApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7*d8b80295SApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8*d8b80295SApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9*d8b80295SApple OSS Distributions * compliance with the License. The rights granted to you under the License 10*d8b80295SApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11*d8b80295SApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12*d8b80295SApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13*d8b80295SApple OSS Distributions * terms of an Apple operating system software license agreement. 14*d8b80295SApple OSS Distributions * 15*d8b80295SApple OSS Distributions * Please obtain a copy of the License at 16*d8b80295SApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17*d8b80295SApple OSS Distributions * 18*d8b80295SApple OSS Distributions * The Original Code and all software distributed under the License are 19*d8b80295SApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*d8b80295SApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*d8b80295SApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*d8b80295SApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*d8b80295SApple OSS Distributions * Please see the License for the specific language governing rights and 24*d8b80295SApple OSS Distributions * limitations under the License. 25*d8b80295SApple OSS Distributions * 26*d8b80295SApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*d8b80295SApple OSS Distributions */ 28*d8b80295SApple OSS Distributions 29*d8b80295SApple OSS Distributions #ifndef _KERN_WORK_INTERVAL_H_ 30*d8b80295SApple OSS Distributions #define _KERN_WORK_INTERVAL_H_ 31*d8b80295SApple OSS Distributions 32*d8b80295SApple OSS Distributions #include <sys/cdefs.h> 33*d8b80295SApple OSS Distributions 34*d8b80295SApple OSS Distributions #include <stdint.h> 35*d8b80295SApple OSS Distributions #include <kern/kern_types.h> 36*d8b80295SApple OSS Distributions 37*d8b80295SApple OSS Distributions #include <kern/thread_group.h> 38*d8b80295SApple OSS Distributions #include <kern/recount.h> 39*d8b80295SApple OSS Distributions 40*d8b80295SApple OSS Distributions __BEGIN_DECLS 41*d8b80295SApple OSS Distributions 42*d8b80295SApple OSS Distributions struct work_interval; 43*d8b80295SApple OSS Distributions 44*d8b80295SApple OSS Distributions struct kern_work_interval_args { 45*d8b80295SApple OSS Distributions uint64_t work_interval_id; 46*d8b80295SApple OSS Distributions uint64_t start; 47*d8b80295SApple OSS Distributions uint64_t finish; 48*d8b80295SApple OSS Distributions uint64_t deadline; 49*d8b80295SApple OSS Distributions uint64_t next_start; 50*d8b80295SApple OSS Distributions uint32_t notify_flags; 51*d8b80295SApple OSS Distributions uint32_t create_flags; 52*d8b80295SApple OSS Distributions uint16_t urgency; 53*d8b80295SApple OSS Distributions }; 54*d8b80295SApple OSS Distributions 55*d8b80295SApple OSS Distributions struct kern_work_interval_create_args { 56*d8b80295SApple OSS Distributions uint64_t wica_id; /* out param */ 57*d8b80295SApple OSS Distributions mach_port_name_t wica_port; /* out param */ 58*d8b80295SApple OSS Distributions uint32_t wica_create_flags; 59*d8b80295SApple OSS Distributions }; 60*d8b80295SApple OSS Distributions 61*d8b80295SApple OSS Distributions struct kern_work_interval_workload_id_args { 62*d8b80295SApple OSS Distributions uint32_t wlida_flags; /* in/out param */ 63*d8b80295SApple OSS Distributions uint32_t wlida_wicreate_flags; /* in/out param */ 64*d8b80295SApple OSS Distributions char * wlida_name; /* in param */ 65*d8b80295SApple OSS Distributions uint64_t wlida_syscall_mask[2]; /* out param */ 66*d8b80295SApple OSS Distributions }; 67*d8b80295SApple OSS Distributions 68*d8b80295SApple OSS Distributions /* 69*d8b80295SApple OSS Distributions * Allocate/assign a single work interval ID for a thread, 70*d8b80295SApple OSS Distributions * and support deallocating it. 71*d8b80295SApple OSS Distributions */ 72*d8b80295SApple OSS Distributions extern kern_return_t 73*d8b80295SApple OSS Distributions kern_work_interval_create(thread_t thread, struct kern_work_interval_create_args *create_params); 74*d8b80295SApple OSS Distributions 75*d8b80295SApple OSS Distributions extern kern_return_t 76*d8b80295SApple OSS Distributions kern_work_interval_get_flags_from_port(mach_port_name_t port_name, uint32_t*flags); 77*d8b80295SApple OSS Distributions 78*d8b80295SApple OSS Distributions #if CONFIG_THREAD_GROUPS 79*d8b80295SApple OSS Distributions /* 80*d8b80295SApple OSS Distributions * A private interface for kevent subsystem. 81*d8b80295SApple OSS Distributions * Returns following scheduling policies associated with a work interval, if available. 82*d8b80295SApple OSS Distributions * : Priority 83*d8b80295SApple OSS Distributions * : Scheduling policy/mode 84*d8b80295SApple OSS Distributions * : +1 ref on the backing thread group 85*d8b80295SApple OSS Distributions */ 86*d8b80295SApple OSS Distributions extern kern_return_t 87*d8b80295SApple OSS Distributions kern_work_interval_get_policy_from_port(mach_port_name_t port_name, 88*d8b80295SApple OSS Distributions integer_t *policy, integer_t *priority, struct thread_group **tg); 89*d8b80295SApple OSS Distributions #endif /* CONFIG_THREAD_GROUPS */ 90*d8b80295SApple OSS Distributions 91*d8b80295SApple OSS Distributions 92*d8b80295SApple OSS Distributions extern kern_return_t 93*d8b80295SApple OSS Distributions kern_work_interval_destroy(thread_t thread, uint64_t work_interval_id); 94*d8b80295SApple OSS Distributions extern kern_return_t 95*d8b80295SApple OSS Distributions kern_work_interval_join(thread_t thread, mach_port_name_t port_name); 96*d8b80295SApple OSS Distributions 97*d8b80295SApple OSS Distributions extern kern_return_t 98*d8b80295SApple OSS Distributions kern_work_interval_notify(thread_t thread, struct kern_work_interval_args* kwi_args); 99*d8b80295SApple OSS Distributions extern kern_return_t 100*d8b80295SApple OSS Distributions kern_work_interval_set_name(mach_port_name_t port_name, char *name, size_t len); 101*d8b80295SApple OSS Distributions extern kern_return_t 102*d8b80295SApple OSS Distributions kern_work_interval_set_workload_id(mach_port_name_t port_name, 103*d8b80295SApple OSS Distributions struct kern_work_interval_workload_id_args *workload_id_args); 104*d8b80295SApple OSS Distributions 105*d8b80295SApple OSS Distributions #ifdef MACH_KERNEL_PRIVATE 106*d8b80295SApple OSS Distributions 107*d8b80295SApple OSS Distributions bool work_interval_port_type_render_server(mach_port_name_t port_name); 108*d8b80295SApple OSS Distributions 109*d8b80295SApple OSS Distributions #if CONFIG_SCHED_AUTO_JOIN 110*d8b80295SApple OSS Distributions bool work_interval_should_propagate(thread_t cthread, thread_t thread); 111*d8b80295SApple OSS Distributions void work_interval_auto_join_propagate(thread_t from, thread_t to); 112*d8b80295SApple OSS Distributions void work_interval_auto_join_unwind(thread_t thread); 113*d8b80295SApple OSS Distributions void work_interval_auto_join_demote(thread_t thread); 114*d8b80295SApple OSS Distributions #endif /* CONFIG_SCHED_AUTO_JOIN */ 115*d8b80295SApple OSS Distributions 116*d8b80295SApple OSS Distributions 117*d8b80295SApple OSS Distributions struct recount_track *work_interval_get_recount_tracks(struct work_interval *work_interval); 118*d8b80295SApple OSS Distributions 119*d8b80295SApple OSS Distributions extern kern_return_t work_interval_thread_terminate(thread_t thread); 120*d8b80295SApple OSS Distributions extern int work_interval_get_priority(thread_t thread); 121*d8b80295SApple OSS Distributions 122*d8b80295SApple OSS Distributions #endif /* MACH_KERNEL_PRIVATE */ 123*d8b80295SApple OSS Distributions 124*d8b80295SApple OSS Distributions #ifdef KERNEL_PRIVATE 125*d8b80295SApple OSS Distributions 126*d8b80295SApple OSS Distributions __enum_closed_decl(wi_class_t, uint8_t, { 127*d8b80295SApple OSS Distributions WI_CLASS_NONE = 0, 128*d8b80295SApple OSS Distributions WI_CLASS_DISCRETIONARY = 1, 129*d8b80295SApple OSS Distributions WI_CLASS_BEST_EFFORT = 2, 130*d8b80295SApple OSS Distributions WI_CLASS_APPLICATION = 3, 131*d8b80295SApple OSS Distributions WI_CLASS_SYSTEM = 4, 132*d8b80295SApple OSS Distributions WI_CLASS_SYSTEM_CRITICAL = 5, 133*d8b80295SApple OSS Distributions WI_CLASS_REALTIME = 6, 134*d8b80295SApple OSS Distributions WI_CLASS_REALTIME_CRITICAL = 7, 135*d8b80295SApple OSS Distributions WI_CLASS_APP_SUPPORT = 8, 136*d8b80295SApple OSS Distributions 137*d8b80295SApple OSS Distributions WI_CLASS_COUNT 138*d8b80295SApple OSS Distributions }); 139*d8b80295SApple OSS Distributions 140*d8b80295SApple OSS Distributions #endif 141*d8b80295SApple OSS Distributions 142*d8b80295SApple OSS Distributions __END_DECLS 143*d8b80295SApple OSS Distributions 144*d8b80295SApple OSS Distributions #endif /* !defined(_KERN_WORK_INTERVAL_H_) */ 145