1 /* 2 * Copyright (c) 2013 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_SFI_H_ 30 #define _KERN_SFI_H_ 31 32 #include <stdint.h> 33 #include <mach/mach_types.h> 34 #include <mach/kern_return.h> 35 #include <mach/sfi_class.h> 36 #include <kern/ast.h> 37 #include <kern/kern_types.h> 38 #include <kern/ledger.h> 39 40 #if KERNEL_PRIVATE 41 #if !XNU_KERNEL_PRIVATE 42 #error "This file is for internal use and will be deleted in future versions of the SDK." 43 #endif /* !XNU_KERNEL_PRIVATE */ 44 #endif /* KERNEL_PRIVATE */ 45 46 #if XNU_KERNEL_PRIVATE 47 extern void sfi_init(void); 48 extern sfi_class_id_t sfi_get_ledger_alias_for_class(sfi_class_id_t class_id); 49 50 kern_return_t sfi_set_window(uint64_t window_usecs); 51 kern_return_t sfi_window_cancel(void); 52 kern_return_t sfi_get_window(uint64_t *window_usecs); 53 54 kern_return_t sfi_set_class_offtime(sfi_class_id_t class_id, uint64_t offtime_usecs); 55 kern_return_t sfi_class_offtime_cancel(sfi_class_id_t class_id); 56 kern_return_t sfi_get_class_offtime(sfi_class_id_t class_id, uint64_t *offtime_usecs); 57 58 #ifdef MACH_KERNEL_PRIVATE 59 /* 60 * Classifying a thread requires no special locks to be held (although attribute 61 * changes that cause an inconsistent snapshot may cause a spurious AST). Final 62 * evaluation will happen at the AST boundary with the thread locked. If possible, 63 * 64 */ 65 sfi_class_id_t sfi_thread_classify(thread_t thread); 66 sfi_class_id_t sfi_processor_active_thread_classify(processor_t processor); 67 ast_t sfi_thread_needs_ast(thread_t thread, sfi_class_id_t *out_class /* optional */); 68 ast_t sfi_processor_needs_ast(processor_t processor); 69 70 void sfi_ast(thread_t thread); 71 void sfi_reevaluate(thread_t thread); 72 kern_return_t sfi_defer(uint64_t); 73 74 extern int sfi_ledger_entry_add(ledger_template_t template, sfi_class_id_t class_id); 75 #endif /* MACH_KERNEL_PRIVATE */ 76 #endif /* XNU_KERNEL_PRIVATE */ 77 78 #endif /* _KERN_SFI_H_ */ 79