1*d8b80295SApple OSS Distributions /* 2*d8b80295SApple OSS Distributions * Copyright (c) 2015-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 _SYS_WORK_INTERVAL_H 30*d8b80295SApple OSS Distributions #define _SYS_WORK_INTERVAL_H 31*d8b80295SApple OSS Distributions 32*d8b80295SApple OSS Distributions #include <stdint.h> 33*d8b80295SApple OSS Distributions #include <sys/cdefs.h> 34*d8b80295SApple OSS Distributions #include <sys/_types/_size_t.h> 35*d8b80295SApple OSS Distributions 36*d8b80295SApple OSS Distributions #include <mach/port.h> 37*d8b80295SApple OSS Distributions 38*d8b80295SApple OSS Distributions __BEGIN_DECLS 39*d8b80295SApple OSS Distributions 40*d8b80295SApple OSS Distributions /* 41*d8b80295SApple OSS Distributions * A work interval is a repeatable unit of work characterized by a 42*d8b80295SApple OSS Distributions * start, finish, and deadline. 43*d8b80295SApple OSS Distributions * 44*d8b80295SApple OSS Distributions * Trusted clients with deadline-sensitive work may report information 45*d8b80295SApple OSS Distributions * about the execution of their work using the work interval facility. 46*d8b80295SApple OSS Distributions * This is intended to be a higher-level semantic than realtime scheduling, 47*d8b80295SApple OSS Distributions * which operates at the level of thread block/unblock. A high level 48*d8b80295SApple OSS Distributions * operation may have many blocking points, including IPC to other tasks, 49*d8b80295SApple OSS Distributions * and this this metric will capture the overall time to complete a unit of 50*d8b80295SApple OSS Distributions * work. 51*d8b80295SApple OSS Distributions * 52*d8b80295SApple OSS Distributions * A work interval is defined by several timestamps, namely (S)tart, 53*d8b80295SApple OSS Distributions * (F)inish, (D)eadline, and (N)ext start. 54*d8b80295SApple OSS Distributions * 55*d8b80295SApple OSS Distributions * ... ----+==================+--------+--+==== ... 56*d8b80295SApple OSS Distributions * | | | | 57*d8b80295SApple OSS Distributions * S F D N 58*d8b80295SApple OSS Distributions * 59*d8b80295SApple OSS Distributions * \__________________/ 60*d8b80295SApple OSS Distributions * Active 61*d8b80295SApple OSS Distributions * \___________________________/ 62*d8b80295SApple OSS Distributions * Work Interval 63*d8b80295SApple OSS Distributions * 64*d8b80295SApple OSS Distributions * \_________/ 65*d8b80295SApple OSS Distributions * | 66*d8b80295SApple OSS Distributions * report information here ---------+ 67*d8b80295SApple OSS Distributions * 68*d8b80295SApple OSS Distributions * Definitions: 69*d8b80295SApple OSS Distributions * 70*d8b80295SApple OSS Distributions * Start: Absolute time when the current deadline-oriented work began. Due 71*d8b80295SApple OSS Distributions * to scheduling latency, preemption, and blocking points, the 72*d8b80295SApple OSS Distributions * thread controlling the work interval may actually begin 73*d8b80295SApple OSS Distributions * executing after this ideal time (which may be the previous work 74*d8b80295SApple OSS Distributions * interval's "next start") 75*d8b80295SApple OSS Distributions * Finish: Absolute time when the current deadline-oriented work finished. 76*d8b80295SApple OSS Distributions * This will typically be a timestamp taken before reporting using 77*d8b80295SApple OSS Distributions * the work interval interface. 78*d8b80295SApple OSS Distributions * Deadline: Absolute time by which the current work was expected to finish. 79*d8b80295SApple OSS Distributions * In cases where the amount of computation (or preemption, or time 80*d8b80295SApple OSS Distributions * spent blocked) causes the active period to take longer than 81*d8b80295SApple OSS Distributions * expected, F may be greater than D. 82*d8b80295SApple OSS Distributions * Next start: Absolute time when the next deadline-oriented work is 83*d8b80295SApple OSS Distributions * expected to begin. This is typically the same as Deadline. 84*d8b80295SApple OSS Distributions * Active: The fraction of the work interval spent completing the work. In 85*d8b80295SApple OSS Distributions * cases where the Finish time exceeded the Deadline, this fraction 86*d8b80295SApple OSS Distributions * will be >1.0. 87*d8b80295SApple OSS Distributions * 88*d8b80295SApple OSS Distributions * Basic Use: 89*d8b80295SApple OSS Distributions * 90*d8b80295SApple OSS Distributions * Clients should report information for a work interval after finishing 91*d8b80295SApple OSS Distributions * work for the current interval but before the next work interval begins. 92*d8b80295SApple OSS Distributions * 93*d8b80295SApple OSS Distributions * If Finish far exceeds the previously expected Deadline, the 94*d8b80295SApple OSS Distributions * caller may adjust Next Start to align to a multiple of the period 95*d8b80295SApple OSS Distributions * (and skip over several work intervals that could not be 96*d8b80295SApple OSS Distributions * executed). 97*d8b80295SApple OSS Distributions * 98*d8b80295SApple OSS Distributions * Caution (!): 99*d8b80295SApple OSS Distributions * 100*d8b80295SApple OSS Distributions * Because the information supplied via this facility directly influences power 101*d8b80295SApple OSS Distributions * management decisions, clients should strive to be as accurate as possible. 102*d8b80295SApple OSS Distributions * Failure to do so will adversely impact system power and performance. 103*d8b80295SApple OSS Distributions * 104*d8b80295SApple OSS Distributions * Work Interval Auto Join Support: 105*d8b80295SApple OSS Distributions * 106*d8b80295SApple OSS Distributions * Work intervals support an optional flag WORK_INTERVAL_FLAG_ENABLE_AUTO_JOIN 107*d8b80295SApple OSS Distributions * which allows RT threads from the same home thread group to join work 108*d8b80295SApple OSS Distributions * intervals via wakeup relationship tracking. Based on the join policy, 109*d8b80295SApple OSS Distributions * RT threads can temporarily join the work interval of other RT threads 110*d8b80295SApple OSS Distributions * which make them runnable. The auto joined thread remains in the work 111*d8b80295SApple OSS Distributions * interval until it blocks or terminates. The mechanism works through 112*d8b80295SApple OSS Distributions * make runnable heuristic and it should be used with extreme caution. 113*d8b80295SApple OSS Distributions * If a client specifies this flag, it gives up explicit control over its 114*d8b80295SApple OSS Distributions * thread group membership and threads unrelated to the work interval 115*d8b80295SApple OSS Distributions * could become part of the thread group. This could lead to serious power 116*d8b80295SApple OSS Distributions * and performance issues. If the make runnable heuristic does not work 117*d8b80295SApple OSS Distributions * for a client use case, it should adopt work_interval_join_port() or 118*d8b80295SApple OSS Distributions * work_interval_join() to explicitly declare its intent. 119*d8b80295SApple OSS Distributions * 120*d8b80295SApple OSS Distributions * Work Interval Deferred Finish Support: 121*d8b80295SApple OSS Distributions * 122*d8b80295SApple OSS Distributions * Another advanced feature for work intervals is the ability to defer the finish 123*d8b80295SApple OSS Distributions * calls for the work interval until all auto-joined threads for the work interval 124*d8b80295SApple OSS Distributions * have blocked or terminated. This feature is enabled via an optional flag 125*d8b80295SApple OSS Distributions * WORK_INTERVAL_FLAG_ENABLE_DEFERRED_FINISH and is valid only if the work interval 126*d8b80295SApple OSS Distributions * is configured with the WORK_INTERVAL_FLAG_ENABLE_AUTO_JOIN flag as well. The 127*d8b80295SApple OSS Distributions * deferred finish mechanism allows the work interval to defer the finish call 128*d8b80295SApple OSS Distributions * for the work interval until all auto-join threads have blocked/terminated 129*d8b80295SApple OSS Distributions * (and have therefore un-joined the work interval) or one of the work interval 130*d8b80295SApple OSS Distributions * threads calls start for the next frame. The deferred finish works only for 131*d8b80295SApple OSS Distributions * workloads that have no temporal overlap across frames i.e. previous frame has to 132*d8b80295SApple OSS Distributions * finish before next frame can start. This feature should be used with caution 133*d8b80295SApple OSS Distributions * since auto-joined threads would delay finish calls to the performance controller 134*d8b80295SApple OSS Distributions * which could lead to poor performance and battery life. 135*d8b80295SApple OSS Distributions */ 136*d8b80295SApple OSS Distributions 137*d8b80295SApple OSS Distributions /* Flags to be passed with work_interval_create() */ 138*d8b80295SApple OSS Distributions 139*d8b80295SApple OSS Distributions /* If interval is joinable, create no longer implicitly joins, you must use work_interval_join */ 140*d8b80295SApple OSS Distributions #define WORK_INTERVAL_FLAG_JOINABLE (0x1) 141*d8b80295SApple OSS Distributions /* Only threads that join the group are measured together, otherwise the group is the creator's home group */ 142*d8b80295SApple OSS Distributions #define WORK_INTERVAL_FLAG_GROUP (0x2) 143*d8b80295SApple OSS Distributions /* Specifies that the work interval is being created by a client who doesn't 144*d8b80295SApple OSS Distributions * necessarily have the PRIV_WORK_INTERVAL entitlement. Skip privilege checks. 145*d8b80295SApple OSS Distributions * This can only be masked in for work intervals of types COREAUDIO, CA_CLIENT 146*d8b80295SApple OSS Distributions * and DEFAULT */ 147*d8b80295SApple OSS Distributions #define WORK_INTERVAL_FLAG_UNRESTRICTED (0x4) 148*d8b80295SApple OSS Distributions 149*d8b80295SApple OSS Distributions /* [Advanced Flag] Read section on "Work Interval Auto Join Support" above for details */ 150*d8b80295SApple OSS Distributions #define WORK_INTERVAL_FLAG_ENABLE_AUTO_JOIN (0x8) 151*d8b80295SApple OSS Distributions /* [Advanced Flag] Read section on "Work Interval Deferred Finish Support" above for details */ 152*d8b80295SApple OSS Distributions #define WORK_INTERVAL_FLAG_ENABLE_DEFERRED_FINISH (0x10) 153*d8b80295SApple OSS Distributions 154*d8b80295SApple OSS Distributions /* Kernel-supplied flag: Work interval has been ignored by the kernel */ 155*d8b80295SApple OSS Distributions #define WORK_INTERVAL_FLAG_IGNORED (0x20) 156*d8b80295SApple OSS Distributions 157*d8b80295SApple OSS Distributions /* Specifies that the work interval requests the system to provide just enough performance 158*d8b80295SApple OSS Distributions * to be able to finish at the provided deadline and no sooner. */ 159*d8b80295SApple OSS Distributions #define WORK_INTERVAL_FLAG_FINISH_AT_DEADLINE (0x40) 160*d8b80295SApple OSS Distributions 161*d8b80295SApple OSS Distributions /* Internal-only flag: workinterval will have the SET_WORKLOAD_ID operation called on it immediately 162*d8b80295SApple OSS Distributions * after creation. */ 163*d8b80295SApple OSS Distributions #define WORK_INTERVAL_FLAG_HAS_WORKLOAD_ID (0x80) 164*d8b80295SApple OSS Distributions 165*d8b80295SApple OSS Distributions /* Internal-only flag: Telemetry data will be aggregated from threads while they are joined to 166*d8b80295SApple OSS Distributions * the work interval. */ 167*d8b80295SApple OSS Distributions #define WORK_INTERVAL_FLAG_ENABLE_TELEMETRY_DATA (0x100) 168*d8b80295SApple OSS Distributions 169*d8b80295SApple OSS Distributions /* Flags to describe the interval flavor to the performance controller */ 170*d8b80295SApple OSS Distributions #define WORK_INTERVAL_TYPE_MASK (0xF0000000) 171*d8b80295SApple OSS Distributions #define WORK_INTERVAL_TYPE_DEFAULT (0x0 << 28) 172*d8b80295SApple OSS Distributions #define WORK_INTERVAL_TYPE_COREAUDIO (0x1 << 28) 173*d8b80295SApple OSS Distributions #define WORK_INTERVAL_TYPE_COREANIMATION (0x2 << 28) 174*d8b80295SApple OSS Distributions #define WORK_INTERVAL_TYPE_CA_RENDER_SERVER (0x2 << 28) 175*d8b80295SApple OSS Distributions #define WORK_INTERVAL_TYPE_CA_CLIENT (0x3 << 28) 176*d8b80295SApple OSS Distributions #define WORK_INTERVAL_TYPE_HID_DELIVERY (0x4 << 28) 177*d8b80295SApple OSS Distributions #define WORK_INTERVAL_TYPE_COREMEDIA (0x5 << 28) 178*d8b80295SApple OSS Distributions #define WORK_INTERVAL_TYPE_ARKIT (0x6 << 28) 179*d8b80295SApple OSS Distributions #define WORK_INTERVAL_TYPE_FRAME_COMPOSITOR (0x7 << 28) 180*d8b80295SApple OSS Distributions #define WORK_INTERVAL_TYPE_LAST (0xF << 28) 181*d8b80295SApple OSS Distributions 182*d8b80295SApple OSS Distributions #ifndef KERNEL 183*d8b80295SApple OSS Distributions 184*d8b80295SApple OSS Distributions typedef struct work_interval *work_interval_t; 185*d8b80295SApple OSS Distributions typedef struct work_interval_instance *work_interval_instance_t; 186*d8b80295SApple OSS Distributions typedef struct work_interval_data *work_interval_data_t; 187*d8b80295SApple OSS Distributions 188*d8b80295SApple OSS Distributions /* 189*d8b80295SApple OSS Distributions * Create a new work interval handle. 190*d8b80295SApple OSS Distributions * 191*d8b80295SApple OSS Distributions * May fail with EALREADY if the current group already has a work interval. 192*d8b80295SApple OSS Distributions * 193*d8b80295SApple OSS Distributions * With no flags: 194*d8b80295SApple OSS Distributions * Auto-joins the work interval to the creating thread 195*d8b80295SApple OSS Distributions * May only use interval_handle from creating thread 196*d8b80295SApple OSS Distributions * Data provided affects native thread group 197*d8b80295SApple OSS Distributions * 198*d8b80295SApple OSS Distributions * With the JOINABLE flag 199*d8b80295SApple OSS Distributions * interval_handle is usable by the process 200*d8b80295SApple OSS Distributions * creating thread does not auto-join 201*d8b80295SApple OSS Distributions * notifying thread must have joined when notifying 202*d8b80295SApple OSS Distributions * 203*d8b80295SApple OSS Distributions * With the GROUP flag 204*d8b80295SApple OSS Distributions * creates a new thread group to isolate the joined threads from 205*d8b80295SApple OSS Distributions * the rest of the process for performance controller analysis 206*d8b80295SApple OSS Distributions * Threads which join the work interval become members of this new group 207*d8b80295SApple OSS Distributions * 208*d8b80295SApple OSS Distributions * TODO: Add a name parameter so that clients can name the work interval 209*d8b80295SApple OSS Distributions * Can also take the thread name from the notifying thread 210*d8b80295SApple OSS Distributions * 211*d8b80295SApple OSS Distributions * Requires the 'com.apple.private.kernel.work-interval' entitlement (PRIV_WORK_INTERVAL) 212*d8b80295SApple OSS Distributions * 213*d8b80295SApple OSS Distributions * Note that joining a work interval supersedes automatic thread group management via vouchers 214*d8b80295SApple OSS Distributions */ 215*d8b80295SApple OSS Distributions int work_interval_create(work_interval_t *interval_handle, uint32_t flags); 216*d8b80295SApple OSS Distributions 217*d8b80295SApple OSS Distributions /* Returns the flags used for the work interval when it was created. 218*d8b80295SApple OSS Distributions * 219*d8b80295SApple OSS Distributions * May fail with EINVAL if the port isn't from a prior call to 220*d8b80295SApple OSS Distributions * work_interval_copy_port. 221*d8b80295SApple OSS Distributions */ 222*d8b80295SApple OSS Distributions int work_interval_get_flags_from_port(mach_port_t port, uint32_t *flags); 223*d8b80295SApple OSS Distributions 224*d8b80295SApple OSS Distributions 225*d8b80295SApple OSS Distributions /* 226*d8b80295SApple OSS Distributions * Notify the power management subsystem that the work for a current interval has completed 227*d8b80295SApple OSS Distributions * 228*d8b80295SApple OSS Distributions * Only the process which created the work interval may notify 229*d8b80295SApple OSS Distributions */ 230*d8b80295SApple OSS Distributions int work_interval_notify(work_interval_t interval_handle, 231*d8b80295SApple OSS Distributions uint64_t start, uint64_t finish, 232*d8b80295SApple OSS Distributions uint64_t deadline, uint64_t next_start, 233*d8b80295SApple OSS Distributions uint32_t flags); 234*d8b80295SApple OSS Distributions 235*d8b80295SApple OSS Distributions /* 236*d8b80295SApple OSS Distributions * Notify, with "finish" implicitly set to the current time 237*d8b80295SApple OSS Distributions * 238*d8b80295SApple OSS Distributions * Only the process which created the work interval may notify 239*d8b80295SApple OSS Distributions */ 240*d8b80295SApple OSS Distributions int work_interval_notify_simple(work_interval_t interval_handle, 241*d8b80295SApple OSS Distributions uint64_t start, uint64_t deadline, 242*d8b80295SApple OSS Distributions uint64_t next_start); 243*d8b80295SApple OSS Distributions 244*d8b80295SApple OSS Distributions /* 245*d8b80295SApple OSS Distributions * Deallocate work interval handle 246*d8b80295SApple OSS Distributions * For non-JOINABLE, also removes thread from work interval 247*d8b80295SApple OSS Distributions * For JOINABLE, does not remove thread (needs a leave as well) 248*d8b80295SApple OSS Distributions */ 249*d8b80295SApple OSS Distributions int work_interval_destroy(work_interval_t interval_handle); 250*d8b80295SApple OSS Distributions 251*d8b80295SApple OSS Distributions /* 252*d8b80295SApple OSS Distributions * Join work interval via work interval handle 253*d8b80295SApple OSS Distributions * Only allowed if interval is using the joinable and group flags 254*d8b80295SApple OSS Distributions * 255*d8b80295SApple OSS Distributions * Supersedes automatic thread group management via vouchers 256*d8b80295SApple OSS Distributions */ 257*d8b80295SApple OSS Distributions int work_interval_join(work_interval_t interval_handle); 258*d8b80295SApple OSS Distributions 259*d8b80295SApple OSS Distributions /* 260*d8b80295SApple OSS Distributions * extract Mach send right representing work interval thread group 261*d8b80295SApple OSS Distributions * Returns a +1 send right ref, which must be deallocated via mach_port_deallocate 262*d8b80295SApple OSS Distributions * Only allowed if interval is joinable, otherwise returns ENOTSUP 263*d8b80295SApple OSS Distributions * 264*d8b80295SApple OSS Distributions * Supersedes automatic thread group management via vouchers 265*d8b80295SApple OSS Distributions */ 266*d8b80295SApple OSS Distributions int work_interval_copy_port(work_interval_t interval_handle, mach_port_t *port); 267*d8b80295SApple OSS Distributions 268*d8b80295SApple OSS Distributions /* 269*d8b80295SApple OSS Distributions * Join work interval via Mach send right 270*d8b80295SApple OSS Distributions * 271*d8b80295SApple OSS Distributions * Does NOT consume Mach send right, must deallocate with mach_port_deallocate after using 272*d8b80295SApple OSS Distributions * It's safe to deallocate the right after joining, the thread will stay joined 273*d8b80295SApple OSS Distributions * 274*d8b80295SApple OSS Distributions * Can be sent to clients via xpc_dictionary_copy_mach_send, and similar 275*d8b80295SApple OSS Distributions * 276*d8b80295SApple OSS Distributions * Supersedes automatic thread group management via vouchers 277*d8b80295SApple OSS Distributions * 278*d8b80295SApple OSS Distributions * If the underlying work interval object is terminated then this may return ENOENT 279*d8b80295SApple OSS Distributions * <rdar://problem/31819320> 280*d8b80295SApple OSS Distributions */ 281*d8b80295SApple OSS Distributions int work_interval_join_port(mach_port_t port); 282*d8b80295SApple OSS Distributions 283*d8b80295SApple OSS Distributions /* 284*d8b80295SApple OSS Distributions * Leave the current thread's work interval 285*d8b80295SApple OSS Distributions */ 286*d8b80295SApple OSS Distributions int work_interval_leave(void); 287*d8b80295SApple OSS Distributions 288*d8b80295SApple OSS Distributions #endif /* !KERNEL */ 289*d8b80295SApple OSS Distributions 290*d8b80295SApple OSS Distributions 291*d8b80295SApple OSS Distributions #if PRIVATE 292*d8b80295SApple OSS Distributions 293*d8b80295SApple OSS Distributions /* Private interface between Libsyscall and xnu */ 294*d8b80295SApple OSS Distributions #define WORK_INTERVAL_OPERATION_CREATE 0x00000001 /* deprecated */ 295*d8b80295SApple OSS Distributions #define WORK_INTERVAL_OPERATION_DESTROY 0x00000002 /* arg is NULL */ 296*d8b80295SApple OSS Distributions #define WORK_INTERVAL_OPERATION_NOTIFY 0x00000003 /* arg is a work_interval_notification_t */ 297*d8b80295SApple OSS Distributions #define WORK_INTERVAL_OPERATION_CREATE2 0x00000004 /* arg is a work_interval_create_params */ 298*d8b80295SApple OSS Distributions #define WORK_INTERVAL_OPERATION_JOIN 0x00000005 /* arg is a port_name */ 299*d8b80295SApple OSS Distributions #define WORK_INTERVAL_OPERATION_GET_FLAGS 0x00000009 /* arg is a port name */ 300*d8b80295SApple OSS Distributions #define WORK_INTERVAL_OPERATION_SET_NAME 0x0000000a /* arg is name string (char[WORK_INTERVAL_NAME_MAX])*/ 301*d8b80295SApple OSS Distributions #define WORK_INTERVAL_OPERATION_SET_WORKLOAD_ID 0x0000000b /* arg is a work_interval_workload_id_params */ 302*d8b80295SApple OSS Distributions #define WORK_INTERVAL_NAME_MAX 32 303*d8b80295SApple OSS Distributions #define WORK_INTERVAL_WORKLOAD_ID_NAME_MAX 64 304*d8b80295SApple OSS Distributions 305*d8b80295SApple OSS Distributions /* Flags passed in work_interval_workload_id_params wlidp_flags field */ 306*d8b80295SApple OSS Distributions #define WORK_INTERVAL_WORKLOAD_ID_HAS_ID (1u << 0) 307*d8b80295SApple OSS Distributions #define WORK_INTERVAL_WORKLOAD_ID_RT_ALLOWED (1u << 1) 308*d8b80295SApple OSS Distributions #define WORK_INTERVAL_WORKLOAD_ID_RT_CRITICAL (1u << 2) 309*d8b80295SApple OSS Distributions 310*d8b80295SApple OSS Distributions /* Flags allowed to be passed in from userspace as part of kern_work_interval_set_workload_id() */ 311*d8b80295SApple OSS Distributions #define WORK_INTERVAL_SET_WORKLOAD_ID_FLAGS_MASK (WORK_INTERVAL_WORKLOAD_ID_RT_CRITICAL | WORK_INTERVAL_WORKLOAD_ID_RT_ALLOWED) 312*d8b80295SApple OSS Distributions 313*d8b80295SApple OSS Distributions #ifdef XNU_KERNEL_PRIVATE 314*d8b80295SApple OSS Distributions 315*d8b80295SApple OSS Distributions /* Marker that workinterval was joined before workload ID was set */ 316*d8b80295SApple OSS Distributions #define WORK_INTERVAL_WORKLOAD_ID_ALREADY_JOINED (1u << 31) 317*d8b80295SApple OSS Distributions /* Work interval is allowed to provide complexity values per frame as part of {start, update, finish} calls */ 318*d8b80295SApple OSS Distributions #define WORK_INTERVAL_WORKLOAD_ID_COMPLEXITY_ALLOWED (1u << 30) 319*d8b80295SApple OSS Distributions 320*d8b80295SApple OSS Distributions #endif /* XNU_KERNEL_PRIVATE */ 321*d8b80295SApple OSS Distributions 322*d8b80295SApple OSS Distributions struct work_interval_notification { 323*d8b80295SApple OSS Distributions uint64_t start; 324*d8b80295SApple OSS Distributions uint64_t finish; 325*d8b80295SApple OSS Distributions uint64_t deadline; 326*d8b80295SApple OSS Distributions uint64_t next_start; 327*d8b80295SApple OSS Distributions uint32_t notify_flags; 328*d8b80295SApple OSS Distributions uint32_t create_flags; 329*d8b80295SApple OSS Distributions }; 330*d8b80295SApple OSS Distributions typedef struct work_interval_notification *work_interval_notification_t; 331*d8b80295SApple OSS Distributions 332*d8b80295SApple OSS Distributions struct work_interval_create_params { 333*d8b80295SApple OSS Distributions uint64_t wicp_id; /* in/out param */ 334*d8b80295SApple OSS Distributions mach_port_name_t wicp_port; /* in/out param */ 335*d8b80295SApple OSS Distributions uint32_t wicp_create_flags; 336*d8b80295SApple OSS Distributions }; 337*d8b80295SApple OSS Distributions 338*d8b80295SApple OSS Distributions struct work_interval_workload_id_params { 339*d8b80295SApple OSS Distributions uint32_t wlidp_flags; /* in/out param */ 340*d8b80295SApple OSS Distributions uint32_t wlidp_wicreate_flags; /* in/out param */ 341*d8b80295SApple OSS Distributions uint64_t wlidp_name; /* in param (pointer to char[WORK_INTERVAL_WORKLOAD_ID_NAME_MAX])*/ 342*d8b80295SApple OSS Distributions uint64_t wlidp_syscall_mask[2]; /* out param (needs to fit MACH_TRAP_TABLE_COUNT + nsysent bits) */ 343*d8b80295SApple OSS Distributions }; 344*d8b80295SApple OSS Distributions 345*d8b80295SApple OSS Distributions 346*d8b80295SApple OSS Distributions int __work_interval_ctl(uint32_t operation, uint64_t work_interval_id, void *arg, size_t len); 347*d8b80295SApple OSS Distributions 348*d8b80295SApple OSS Distributions #endif /* PRIVATE */ 349*d8b80295SApple OSS Distributions 350*d8b80295SApple OSS Distributions __END_DECLS 351*d8b80295SApple OSS Distributions 352*d8b80295SApple OSS Distributions #endif /* _SYS_WORK_INTERVAL_H */ 353