]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kern/timer_queue.h
xnu-6153.11.26.tar.gz
[apple/xnu.git] / osfmk / kern / timer_queue.h
CommitLineData
c910b4d9
A
1/*
2 * Copyright (c) 2008 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 5 *
c910b4d9
A
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.
0a7de745 14 *
c910b4d9
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
0a7de745 17 *
c910b4d9
A
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.
0a7de745 25 *
c910b4d9
A
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
0a7de745 39#include <kern/mpqueue.h>
c910b4d9
A
40#include <kern/queue.h>
41
39236c6e 42/* Kernel trace events associated with timers and timer queues */
0a7de745
A
43#define DECR_TRAP_LATENCY MACHDBG_CODE(DBG_MACH_EXCP_DECI, 0)
44#define DECR_SET_DEADLINE MACHDBG_CODE(DBG_MACH_EXCP_DECI, 1)
45#define DECR_TIMER_CALLOUT MACHDBG_CODE(DBG_MACH_EXCP_DECI, 2)
46#define DECR_PM_DEADLINE MACHDBG_CODE(DBG_MACH_EXCP_DECI, 3)
47#define DECR_TIMER_MIGRATE MACHDBG_CODE(DBG_MACH_EXCP_DECI, 4)
39236c6e 48#if defined(i386) || defined(x86_64)
0a7de745
A
49#define DECR_RDHPET MACHDBG_CODE(DBG_MACH_EXCP_DECI, 5)
50#define DECR_SET_TSC_DEADLINE MACHDBG_CODE(DBG_MACH_EXCP_DECI, 6)
51#define DECR_SET_APIC_DEADLINE MACHDBG_CODE(DBG_MACH_EXCP_DECI, 16)
39236c6e 52#endif
0a7de745
A
53#define DECR_TIMER_ENTER MACHDBG_CODE(DBG_MACH_EXCP_DECI, 7)
54#define DECR_TIMER_CANCEL MACHDBG_CODE(DBG_MACH_EXCP_DECI, 8)
55#define DECR_TIMER_QUEUE MACHDBG_CODE(DBG_MACH_EXCP_DECI, 9)
56#define DECR_TIMER_EXPIRE MACHDBG_CODE(DBG_MACH_EXCP_DECI,10)
57#define DECR_TIMER_ASYNC_DEQ MACHDBG_CODE(DBG_MACH_EXCP_DECI,11)
58#define DECR_TIMER_UPDATE MACHDBG_CODE(DBG_MACH_EXCP_DECI,12)
59#define DECR_TIMER_ESCALATE MACHDBG_CODE(DBG_MACH_EXCP_DECI,13)
60#define DECR_TIMER_OVERDUE MACHDBG_CODE(DBG_MACH_EXCP_DECI,14)
61#define DECR_TIMER_RESCAN MACHDBG_CODE(DBG_MACH_EXCP_DECI,15)
39236c6e 62
c910b4d9
A
63/*
64 * Invoked by kernel, implemented by platform.
65 */
66
67/* Request an expiration deadline, returns queue association */
0a7de745
A
68extern mpqueue_head_t * timer_queue_assign(
69 uint64_t deadline);
6d2010ae 70
0a7de745
A
71extern uint64_t timer_call_slop(
72 uint64_t deadline,
73 uint64_t armtime,
74 uint32_t urgency,
75 thread_t arming_thread,
76 boolean_t *rlimited);
77extern boolean_t timer_resort_threshold(uint64_t);
c910b4d9
A
78
79/* Cancel an associated expiration deadline and specify new deadline */
0a7de745
A
80extern void timer_queue_cancel(
81 mpqueue_head_t *queue,
82 uint64_t deadline,
83 uint64_t new_deadline);
c910b4d9 84
39236c6e 85/* Return a pointer to the local timer queue for a given cpu */
0a7de745
A
86extern mpqueue_head_t * timer_queue_cpu(
87 int cpu);
39236c6e
A
88
89/* Call a function with argument on a cpu */
0a7de745
A
90extern void timer_call_cpu(
91 int cpu,
92 void (*fn)(void *),
93 void *arg);
39236c6e
A
94
95/* Queue a function to be called with argument on a cpu */
0a7de745
A
96extern void timer_call_nosync_cpu(
97 int cpu,
98 void (*fn)(void *),
99 void *arg);
39236c6e 100
c910b4d9
A
101/*
102 * Invoked by platform, implemented by kernel.
103 */
104
fe8ab488
A
105/*
106 * Invoked by kernel, implemented by platform.
107 */
108
109#define NUM_LATENCY_QOS_TIERS (6)
110
111typedef struct {
112 uint32_t idle_entry_timer_processing_hdeadline_threshold_ns;
113 uint32_t interrupt_timer_coalescing_ilat_threshold_ns;
114 uint32_t timer_resort_threshold_ns;
115
116 int32_t timer_coalesce_rt_shift;
117 int32_t timer_coalesce_bg_shift;
118 int32_t timer_coalesce_kt_shift;
119 int32_t timer_coalesce_fp_shift;
120 int32_t timer_coalesce_ts_shift;
121
122 uint64_t timer_coalesce_rt_ns_max;
123 uint64_t timer_coalesce_bg_ns_max;
124 uint64_t timer_coalesce_kt_ns_max;
125 uint64_t timer_coalesce_fp_ns_max;
126 uint64_t timer_coalesce_ts_ns_max;
127
128 uint32_t latency_qos_scale[NUM_LATENCY_QOS_TIERS];
129 uint64_t latency_qos_ns_max[NUM_LATENCY_QOS_TIERS];
130 boolean_t latency_tier_rate_limited[NUM_LATENCY_QOS_TIERS];
131} timer_coalescing_priority_params_ns_t;
132
133extern timer_coalescing_priority_params_ns_t * timer_call_get_priority_params(void);
134
135
0a7de745
A
136extern uint64_t timer_call_slop(
137 uint64_t deadline,
138 uint64_t armtime,
139 uint32_t urgency,
140 thread_t arming_thread,
141 boolean_t *rlimited);
fe8ab488 142
c910b4d9 143/* Process deadline expiration for queue, returns new deadline */
0a7de745
A
144extern uint64_t timer_queue_expire(
145 mpqueue_head_t *queue,
146 uint64_t deadline);
c910b4d9 147
0a7de745
A
148extern uint64_t timer_queue_expire_with_options(
149 mpqueue_head_t *,
150 uint64_t,
151 boolean_t);
39236c6e 152
0a7de745
A
153extern void quantum_timer_expire(
154 uint64_t deadline);
5ba3f43e 155
c910b4d9 156/* Shutdown a timer queue and reassign existing activities */
0a7de745
A
157extern void timer_queue_shutdown(
158 mpqueue_head_t *queue);
6d2010ae
A
159
160/* Move timer requests from one queue to another */
0a7de745
A
161extern int timer_queue_migrate(
162 mpqueue_head_t *from,
163 mpqueue_head_t *to);
c910b4d9 164
39236c6e
A
165/*
166 * Invoked by platform, implemented by platfrom.
167 */
168
0a7de745 169extern void timer_intr(int inuser, uint64_t iaddr);
39236c6e
A
170
171#if defined(i386) || defined(x86_64)
0a7de745 172extern uint64_t setPop(uint64_t time);
39236c6e 173#else
0a7de745 174extern int setPop(uint64_t time);
39236c6e
A
175#endif
176
0a7de745 177extern void timer_resync_deadlines(void);
39236c6e 178
cb323159
A
179extern void timer_queue_expire_local(void *arg);
180
0a7de745 181extern void timer_set_deadline(uint64_t deadline);
39236c6e 182
0a7de745 183extern void quantum_timer_set_deadline(uint64_t deadline);
5ba3f43e 184
39236c6e 185/* Migrate the local timer queue of a given cpu to the master cpu */
0a7de745 186extern uint32_t timer_queue_migrate_cpu(int target_cpu);
39236c6e 187
0a7de745
A
188extern void timer_queue_trace(
189 mpqueue_head_t *queue);
190extern void timer_queue_trace_cpu(int cpu);
39236c6e 191
0a7de745
A
192extern uint64_t timer_sysctl_get(int oid);
193extern int timer_sysctl_set(int oid, uint64_t value);
39236c6e 194
0a7de745 195#endif /* MACH_KERNEL_PRIVATE */
c910b4d9 196
0a7de745 197#endif /* _KERN_TIMER_QUEUE_H_ */