1*e3723e1fSApple OSS Distributions /* 2*e3723e1fSApple OSS Distributions * Copyright (c) 2013 Apple Inc. All rights reserved. 3*e3723e1fSApple OSS Distributions * 4*e3723e1fSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*e3723e1fSApple OSS Distributions * 6*e3723e1fSApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7*e3723e1fSApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8*e3723e1fSApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9*e3723e1fSApple OSS Distributions * compliance with the License. The rights granted to you under the License 10*e3723e1fSApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11*e3723e1fSApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12*e3723e1fSApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13*e3723e1fSApple OSS Distributions * terms of an Apple operating system software license agreement. 14*e3723e1fSApple OSS Distributions * 15*e3723e1fSApple OSS Distributions * Please obtain a copy of the License at 16*e3723e1fSApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17*e3723e1fSApple OSS Distributions * 18*e3723e1fSApple OSS Distributions * The Original Code and all software distributed under the License are 19*e3723e1fSApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*e3723e1fSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*e3723e1fSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*e3723e1fSApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*e3723e1fSApple OSS Distributions * Please see the License for the specific language governing rights and 24*e3723e1fSApple OSS Distributions * limitations under the License. 25*e3723e1fSApple OSS Distributions * 26*e3723e1fSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*e3723e1fSApple OSS Distributions */ 28*e3723e1fSApple OSS Distributions 29*e3723e1fSApple OSS Distributions #ifndef _SYS_SFI_H_ 30*e3723e1fSApple OSS Distributions #define _SYS_SFI_H_ 31*e3723e1fSApple OSS Distributions 32*e3723e1fSApple OSS Distributions #include <stdint.h> 33*e3723e1fSApple OSS Distributions #include <sys/types.h> 34*e3723e1fSApple OSS Distributions #include <mach/sfi_class.h> 35*e3723e1fSApple OSS Distributions /* 36*e3723e1fSApple OSS Distributions * Selective Forced Idle (SFI) is a mechanism for doing 37*e3723e1fSApple OSS Distributions * phase-aligned modulation of runnable tasks 38*e3723e1fSApple OSS Distributions */ 39*e3723e1fSApple OSS Distributions 40*e3723e1fSApple OSS Distributions /* Flags for use with sfi_process_set_flags() */ 41*e3723e1fSApple OSS Distributions #define SFI_PROCESS_SET_MANAGED 0x00000001 42*e3723e1fSApple OSS Distributions #define SFI_PROCESS_SET_UNMANAGED 0x00000002 43*e3723e1fSApple OSS Distributions 44*e3723e1fSApple OSS Distributions #define SFI_PROCESS_SET_MANAGED_MASK 0x00000003 45*e3723e1fSApple OSS Distributions 46*e3723e1fSApple OSS Distributions #ifndef KERNEL 47*e3723e1fSApple OSS Distributions /* 48*e3723e1fSApple OSS Distributions * The system_set_sfi_window() call can be used to set "Selective 49*e3723e1fSApple OSS Distributions * Forced Idle" window for the system. sfi_window_usec is the 50*e3723e1fSApple OSS Distributions * interval in microseconds and when the "Selective Forced Idle" is 51*e3723e1fSApple OSS Distributions * active its "off phase" starts every sfi_window_usec. A nonzero 52*e3723e1fSApple OSS Distributions * value lower than MIN_SFI_WINDOW_USEC will be automatically changed 53*e3723e1fSApple OSS Distributions * to MIN_SFI_WINDOW_USEC. The actual window size used is 54*e3723e1fSApple OSS Distributions * implementation dependent and may be longer. 55*e3723e1fSApple OSS Distributions * 56*e3723e1fSApple OSS Distributions * system_get_sfi_window() can be used to determine the actual value. 57*e3723e1fSApple OSS Distributions * 58*e3723e1fSApple OSS Distributions * A value of 0 for sfi_window_usec can be used to disable "Selective 59*e3723e1fSApple OSS Distributions * Forced Idle". 60*e3723e1fSApple OSS Distributions */ 61*e3723e1fSApple OSS Distributions int system_set_sfi_window(uint64_t sfi_window_usec); 62*e3723e1fSApple OSS Distributions 63*e3723e1fSApple OSS Distributions int system_get_sfi_window(uint64_t *sfi_window_usec); 64*e3723e1fSApple OSS Distributions 65*e3723e1fSApple OSS Distributions /* 66*e3723e1fSApple OSS Distributions * sfi_set_class_offtime() can be used to set the "off time" interval 67*e3723e1fSApple OSS Distributions * for all threads placed in a "Selective Forced Idle" class class_id. 68*e3723e1fSApple OSS Distributions * A thread placed in class_id will not execute for offtime_usec 69*e3723e1fSApple OSS Distributions * microseconds at the beginning of each "Selective Forced Idle" 70*e3723e1fSApple OSS Distributions * window. A nonzero value lower than MIN_OFFTIME_USEC will be 71*e3723e1fSApple OSS Distributions * automatically changed to MIN_OFFTIME_USEC. The actual "off time" 72*e3723e1fSApple OSS Distributions * used is implementation dependent and may be 73*e3723e1fSApple OSS Distributions * longer. sfi_get_class_offtime() can be used to determine the actual 74*e3723e1fSApple OSS Distributions * value. 75*e3723e1fSApple OSS Distributions * 76*e3723e1fSApple OSS Distributions * A value of 0 for offtime_usec can be used to disable "Selective 77*e3723e1fSApple OSS Distributions * Forced Idle" for all the threads placed in class_id. 78*e3723e1fSApple OSS Distributions * 79*e3723e1fSApple OSS Distributions * A value of offtime_usec greater than the value of system wide 80*e3723e1fSApple OSS Distributions * "Selective Forced Idle" window will cause failure. 81*e3723e1fSApple OSS Distributions */ 82*e3723e1fSApple OSS Distributions int sfi_set_class_offtime(sfi_class_id_t class_id, uint64_t offtime_usec); 83*e3723e1fSApple OSS Distributions 84*e3723e1fSApple OSS Distributions int sfi_get_class_offtime(sfi_class_id_t class_id, uint64_t *offtime_usec); 85*e3723e1fSApple OSS Distributions 86*e3723e1fSApple OSS Distributions /* 87*e3723e1fSApple OSS Distributions * The sfi_process_set_class() can be used to place all the threads in 88*e3723e1fSApple OSS Distributions * a process ID pid in the "Selective Forced Idle" managed class, or clear 89*e3723e1fSApple OSS Distributions * the managed state. 90*e3723e1fSApple OSS Distributions */ 91*e3723e1fSApple OSS Distributions 92*e3723e1fSApple OSS Distributions int sfi_process_set_flags(pid_t pid, uint32_t flags); 93*e3723e1fSApple OSS Distributions 94*e3723e1fSApple OSS Distributions int sfi_process_get_flags(pid_t pid, uint32_t *flags); 95*e3723e1fSApple OSS Distributions 96*e3723e1fSApple OSS Distributions #endif /* !KERNEL */ 97*e3723e1fSApple OSS Distributions 98*e3723e1fSApple OSS Distributions #if PRIVATE 99*e3723e1fSApple OSS Distributions 100*e3723e1fSApple OSS Distributions /* This is the private system call interface between Libsyscall and xnu */ 101*e3723e1fSApple OSS Distributions #define SFI_CTL_OPERATION_SFI_SET_WINDOW 0x00000001 102*e3723e1fSApple OSS Distributions #define SFI_CTL_OPERATION_SFI_GET_WINDOW 0x00000002 103*e3723e1fSApple OSS Distributions #define SFI_CTL_OPERATION_SET_CLASS_OFFTIME 0x00000003 104*e3723e1fSApple OSS Distributions #define SFI_CTL_OPERATION_GET_CLASS_OFFTIME 0x00000004 105*e3723e1fSApple OSS Distributions 106*e3723e1fSApple OSS Distributions #define SFI_PIDCTL_OPERATION_PID_SET_FLAGS 0x00000001 107*e3723e1fSApple OSS Distributions #define SFI_PIDCTL_OPERATION_PID_GET_FLAGS 0x00000002 108*e3723e1fSApple OSS Distributions 109*e3723e1fSApple OSS Distributions int __sfi_ctl(uint32_t operation, uint32_t sfi_class, uint64_t time, uint64_t *out_time); 110*e3723e1fSApple OSS Distributions int __sfi_pidctl(uint32_t operation, pid_t pid, uint32_t sfi_flags, uint32_t *out_sfi_flags); 111*e3723e1fSApple OSS Distributions 112*e3723e1fSApple OSS Distributions #endif /* PRIVATE */ 113*e3723e1fSApple OSS Distributions 114*e3723e1fSApple OSS Distributions #endif /* _SYS_SFI_H_ */ 115