| 1 | /* |
| 2 | * Copyright (c) 2008 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 | * Timer queue support routines. |
| 30 | */ |
| 31 | |
| 32 | #ifndef _KERN_TIMER_QUEUE_H_ |
| 33 | #define _KERN_TIMER_QUEUE_H_ |
| 34 | |
| 35 | #include <mach/mach_types.h> |
| 36 | |
| 37 | #ifdef MACH_KERNEL_PRIVATE |
| 38 | |
| 39 | #include <kern/mpqueue.h> |
| 40 | #include <kern/queue.h> |
| 41 | |
| 42 | /* |
| 43 | * Invoked by kernel, implemented by platform. |
| 44 | */ |
| 45 | |
| 46 | /* Request an expiration deadline, returns queue association */ |
| 47 | extern mpqueue_head_t * timer_queue_assign( |
| 48 | uint64_t deadline); |
| 49 | |
| 50 | extern uint64_t timer_call_slop( |
| 51 | uint64_t deadline, |
| 52 | uint64_t armtime, |
| 53 | uint32_t urgency, |
| 54 | thread_t arming_thread, |
| 55 | boolean_t *rlimited); |
| 56 | extern boolean_t timer_resort_threshold(uint64_t); |
| 57 | |
| 58 | /* Cancel an associated expiration deadline and specify new deadline */ |
| 59 | extern void timer_queue_cancel( |
| 60 | mpqueue_head_t *queue, |
| 61 | uint64_t deadline, |
| 62 | uint64_t new_deadline); |
| 63 | |
| 64 | /* Return a pointer to the local timer queue for a given cpu */ |
| 65 | extern mpqueue_head_t * timer_queue_cpu( |
| 66 | int cpu); |
| 67 | |
| 68 | /* Call a function with argument on a cpu */ |
| 69 | extern void timer_call_cpu( |
| 70 | int cpu, |
| 71 | void (*fn)(void *), |
| 72 | void *arg); |
| 73 | |
| 74 | /* Queue a function to be called with argument on a cpu */ |
| 75 | extern void timer_call_nosync_cpu( |
| 76 | int cpu, |
| 77 | void (*fn)(void *), |
| 78 | void *arg); |
| 79 | |
| 80 | /* |
| 81 | * Invoked by platform, implemented by kernel. |
| 82 | */ |
| 83 | |
| 84 | /* |
| 85 | * Invoked by kernel, implemented by platform. |
| 86 | */ |
| 87 | |
| 88 | #define NUM_LATENCY_QOS_TIERS (6) |
| 89 | |
| 90 | typedef struct { |
| 91 | uint32_t idle_entry_timer_processing_hdeadline_threshold_ns; |
| 92 | uint32_t interrupt_timer_coalescing_ilat_threshold_ns; |
| 93 | uint32_t timer_resort_threshold_ns; |
| 94 | |
| 95 | int32_t timer_coalesce_rt_shift; |
| 96 | int32_t timer_coalesce_bg_shift; |
| 97 | int32_t timer_coalesce_kt_shift; |
| 98 | int32_t timer_coalesce_fp_shift; |
| 99 | int32_t timer_coalesce_ts_shift; |
| 100 | |
| 101 | uint64_t timer_coalesce_rt_ns_max; |
| 102 | uint64_t timer_coalesce_bg_ns_max; |
| 103 | uint64_t timer_coalesce_kt_ns_max; |
| 104 | uint64_t timer_coalesce_fp_ns_max; |
| 105 | uint64_t timer_coalesce_ts_ns_max; |
| 106 | |
| 107 | uint32_t latency_qos_scale[NUM_LATENCY_QOS_TIERS]; |
| 108 | uint64_t latency_qos_ns_max[NUM_LATENCY_QOS_TIERS]; |
| 109 | boolean_t latency_tier_rate_limited[NUM_LATENCY_QOS_TIERS]; |
| 110 | } timer_coalescing_priority_params_ns_t; |
| 111 | |
| 112 | extern timer_coalescing_priority_params_ns_t * timer_call_get_priority_params(void); |
| 113 | |
| 114 | |
| 115 | extern uint64_t timer_call_slop( |
| 116 | uint64_t deadline, |
| 117 | uint64_t armtime, |
| 118 | uint32_t urgency, |
| 119 | thread_t arming_thread, |
| 120 | boolean_t *rlimited); |
| 121 | |
| 122 | /* Process deadline expiration for queue, returns new deadline */ |
| 123 | extern uint64_t timer_queue_expire( |
| 124 | mpqueue_head_t *queue, |
| 125 | uint64_t deadline); |
| 126 | |
| 127 | extern uint64_t timer_queue_expire_with_options( |
| 128 | mpqueue_head_t *, |
| 129 | uint64_t, |
| 130 | boolean_t); |
| 131 | |
| 132 | /* Shutdown a timer queue and reassign existing activities */ |
| 133 | extern void timer_queue_shutdown( |
| 134 | mpqueue_head_t *queue); |
| 135 | |
| 136 | /* Move timer requests from one queue to another */ |
| 137 | extern int timer_queue_migrate( |
| 138 | mpqueue_head_t *from, |
| 139 | mpqueue_head_t *to); |
| 140 | |
| 141 | /* |
| 142 | * Invoked by platform, implemented by platfrom. |
| 143 | */ |
| 144 | |
| 145 | extern void timer_intr(int inuser, uint64_t iaddr); |
| 146 | |
| 147 | #if defined(i386) || defined(x86_64) |
| 148 | extern uint64_t setPop(uint64_t time); |
| 149 | #else |
| 150 | extern int setPop(uint64_t time); |
| 151 | #endif |
| 152 | |
| 153 | extern void timer_resync_deadlines(void); |
| 154 | |
| 155 | extern void timer_queue_expire_local(void *arg); |
| 156 | |
| 157 | extern void timer_set_deadline(uint64_t deadline); |
| 158 | |
| 159 | /* Migrate the local timer queue of a given cpu to the master cpu */ |
| 160 | extern uint32_t timer_queue_migrate_cpu(int target_cpu); |
| 161 | |
| 162 | extern void timer_queue_trace( |
| 163 | mpqueue_head_t *queue); |
| 164 | extern void timer_queue_trace_cpu(int cpu); |
| 165 | |
| 166 | extern uint64_t timer_sysctl_get(int oid); |
| 167 | extern int timer_sysctl_set(int oid, uint64_t value); |
| 168 | |
| 169 | #endif /* MACH_KERNEL_PRIVATE */ |
| 170 | |
| 171 | #endif /* _KERN_TIMER_QUEUE_H_ */ |
| 172 | |