xref: /xnu-10063.141.1/bsd/sys/sfi.h (revision d8b80295118ef25ac3a784134bcf95cd8e88109f)
1*d8b80295SApple OSS Distributions /*
2*d8b80295SApple OSS Distributions  * Copyright (c) 2013 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_SFI_H_
30*d8b80295SApple OSS Distributions #define _SYS_SFI_H_
31*d8b80295SApple OSS Distributions 
32*d8b80295SApple OSS Distributions #include <stdint.h>
33*d8b80295SApple OSS Distributions #include <sys/types.h>
34*d8b80295SApple OSS Distributions #include <mach/sfi_class.h>
35*d8b80295SApple OSS Distributions /*
36*d8b80295SApple OSS Distributions  * Selective Forced Idle (SFI) is a mechanism for doing
37*d8b80295SApple OSS Distributions  * phase-aligned modulation of runnable tasks
38*d8b80295SApple OSS Distributions  */
39*d8b80295SApple OSS Distributions 
40*d8b80295SApple OSS Distributions /* Flags for use with sfi_process_set_flags() */
41*d8b80295SApple OSS Distributions #define SFI_PROCESS_SET_MANAGED         0x00000001
42*d8b80295SApple OSS Distributions #define SFI_PROCESS_SET_UNMANAGED       0x00000002
43*d8b80295SApple OSS Distributions 
44*d8b80295SApple OSS Distributions #define SFI_PROCESS_SET_MANAGED_MASK    0x00000003
45*d8b80295SApple OSS Distributions 
46*d8b80295SApple OSS Distributions #ifndef KERNEL
47*d8b80295SApple OSS Distributions /*
48*d8b80295SApple OSS Distributions  * The system_set_sfi_window() call can be used to set "Selective
49*d8b80295SApple OSS Distributions  * Forced Idle"  window for the system. sfi_window_usec is the
50*d8b80295SApple OSS Distributions  * interval in microseconds and when the "Selective Forced Idle" is
51*d8b80295SApple OSS Distributions  * active its "off phase" starts every sfi_window_usec.  A nonzero
52*d8b80295SApple OSS Distributions  * value lower than MIN_SFI_WINDOW_USEC will be automatically changed
53*d8b80295SApple OSS Distributions  * to MIN_SFI_WINDOW_USEC. The actual window size used is
54*d8b80295SApple OSS Distributions  * implementation dependent and may be longer.
55*d8b80295SApple OSS Distributions  *
56*d8b80295SApple OSS Distributions  * system_get_sfi_window() can be used to determine the actual value.
57*d8b80295SApple OSS Distributions  *
58*d8b80295SApple OSS Distributions  * A value of 0 for sfi_window_usec can be used to disable "Selective
59*d8b80295SApple OSS Distributions  * Forced Idle".
60*d8b80295SApple OSS Distributions  */
61*d8b80295SApple OSS Distributions int system_set_sfi_window(uint64_t sfi_window_usec);
62*d8b80295SApple OSS Distributions 
63*d8b80295SApple OSS Distributions int system_get_sfi_window(uint64_t *sfi_window_usec);
64*d8b80295SApple OSS Distributions 
65*d8b80295SApple OSS Distributions /*
66*d8b80295SApple OSS Distributions  * sfi_set_class_offtime() can be used to set the "off time" interval
67*d8b80295SApple OSS Distributions  * for all threads placed in a "Selective Forced Idle" class class_id.
68*d8b80295SApple OSS Distributions  * A thread placed in class_id will not execute for offtime_usec
69*d8b80295SApple OSS Distributions  * microseconds at the beginning of each "Selective Forced Idle"
70*d8b80295SApple OSS Distributions  * window.  A nonzero value lower than MIN_OFFTIME_USEC will be
71*d8b80295SApple OSS Distributions  * automatically changed to MIN_OFFTIME_USEC. The actual "off time"
72*d8b80295SApple OSS Distributions  * used is implementation dependent and may be
73*d8b80295SApple OSS Distributions  * longer. sfi_get_class_offtime() can be used to determine the actual
74*d8b80295SApple OSS Distributions  * value.
75*d8b80295SApple OSS Distributions  *
76*d8b80295SApple OSS Distributions  * A value of 0 for offtime_usec can be used to disable "Selective
77*d8b80295SApple OSS Distributions  * Forced Idle" for all the threads placed in class_id.
78*d8b80295SApple OSS Distributions  *
79*d8b80295SApple OSS Distributions  * A value of offtime_usec greater than the value of system wide
80*d8b80295SApple OSS Distributions  * "Selective Forced Idle" window will cause failure.
81*d8b80295SApple OSS Distributions  */
82*d8b80295SApple OSS Distributions int sfi_set_class_offtime(sfi_class_id_t class_id, uint64_t offtime_usec);
83*d8b80295SApple OSS Distributions 
84*d8b80295SApple OSS Distributions int sfi_get_class_offtime(sfi_class_id_t class_id, uint64_t *offtime_usec);
85*d8b80295SApple OSS Distributions 
86*d8b80295SApple OSS Distributions /*
87*d8b80295SApple OSS Distributions  * The sfi_process_set_class() can be used to place all the threads in
88*d8b80295SApple OSS Distributions  * a process ID pid in the "Selective Forced Idle" managed class, or clear
89*d8b80295SApple OSS Distributions  * the managed state.
90*d8b80295SApple OSS Distributions  */
91*d8b80295SApple OSS Distributions 
92*d8b80295SApple OSS Distributions int sfi_process_set_flags(pid_t pid, uint32_t flags);
93*d8b80295SApple OSS Distributions 
94*d8b80295SApple OSS Distributions int sfi_process_get_flags(pid_t pid, uint32_t *flags);
95*d8b80295SApple OSS Distributions 
96*d8b80295SApple OSS Distributions #endif /* !KERNEL */
97*d8b80295SApple OSS Distributions 
98*d8b80295SApple OSS Distributions #if PRIVATE
99*d8b80295SApple OSS Distributions 
100*d8b80295SApple OSS Distributions /* This is the private system call interface between Libsyscall and xnu */
101*d8b80295SApple OSS Distributions #define SFI_CTL_OPERATION_SFI_SET_WINDOW        0x00000001
102*d8b80295SApple OSS Distributions #define SFI_CTL_OPERATION_SFI_GET_WINDOW        0x00000002
103*d8b80295SApple OSS Distributions #define SFI_CTL_OPERATION_SET_CLASS_OFFTIME     0x00000003
104*d8b80295SApple OSS Distributions #define SFI_CTL_OPERATION_GET_CLASS_OFFTIME     0x00000004
105*d8b80295SApple OSS Distributions 
106*d8b80295SApple OSS Distributions #define SFI_PIDCTL_OPERATION_PID_SET_FLAGS      0x00000001
107*d8b80295SApple OSS Distributions #define SFI_PIDCTL_OPERATION_PID_GET_FLAGS      0x00000002
108*d8b80295SApple OSS Distributions 
109*d8b80295SApple OSS Distributions int __sfi_ctl(uint32_t operation, uint32_t sfi_class, uint64_t time, uint64_t *out_time);
110*d8b80295SApple OSS Distributions int __sfi_pidctl(uint32_t operation, pid_t pid, uint32_t sfi_flags, uint32_t *out_sfi_flags);
111*d8b80295SApple OSS Distributions 
112*d8b80295SApple OSS Distributions #endif /* PRIVATE */
113*d8b80295SApple OSS Distributions 
114*d8b80295SApple OSS Distributions #endif  /* _SYS_SFI_H_ */
115