]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kern/timer.h
xnu-792.25.20.tar.gz
[apple/xnu.git] / osfmk / kern / timer.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
6601e61a 4 * @APPLE_LICENSE_HEADER_START@
8f6c56a5 5 *
6601e61a
A
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
8f6c56a5 11 *
6601e61a
A
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
6601e61a
A
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
8f6c56a5 19 *
6601e61a 20 * @APPLE_LICENSE_HEADER_END@
1c79356b
A
21 */
22/*
23 * @OSF_COPYRIGHT@
24 */
25/*
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
28 * All Rights Reserved.
29 *
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
35 *
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
39 *
40 * Carnegie Mellon requests users of this software to return to
41 *
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
46 *
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
49 */
50/*
51 */
52
53#ifndef _KERN_TIMER_H_
54#define _KERN_TIMER_H_
55
1c79356b
A
56#include <stat_time.h>
57
1c79356b
A
58#include <kern/kern_types.h>
59
1c79356b 60/*
91447636
A
61 * Definitions for high resolution timers. A check
62 * word on the high portion allows atomic updates.
1c79356b
A
63 */
64
65struct timer {
91447636
A
66 uint32_t low_bits;
67 uint32_t high_bits;
68 uint32_t high_bits_check;
69#if !STAT_TIME
70 uint32_t tstamp;
71#endif /* STAT_TIME */
1c79356b
A
72};
73
91447636 74typedef struct timer timer_data_t, *timer_t;
1c79356b
A
75
76/*
91447636 77 * Exported kernel interface to timers
1c79356b
A
78 */
79
91447636 80#if STAT_TIME
1c79356b 81
91447636 82#include <kern/macro_help.h>
1c79356b 83
91447636
A
84/* Advance a timer by the specified amount */
85#define TIMER_BUMP(timer, ticks) \
86MACRO_BEGIN \
87 uint32_t old_low, low; \
88 \
89 old_low = (timer)->low_bits; \
90 low = old_low + (ticks); \
91 if (low < old_low) \
92 timer_update((timer), (timer)->high_bits + 1, low); \
93 else \
94 (timer)->low_bits = low; \
95MACRO_END
1c79356b 96
91447636
A
97#define timer_switch(tstamp, new_timer)
98#define timer_event(tstamp, new_timer)
1c79356b 99
1c79356b 100#else /* STAT_TIME */
1c79356b 101
91447636 102/* Update the current timer and start a new one */
1c79356b 103extern void timer_switch(
91447636
A
104 uint32_t tstamp,
105 timer_t new_timer);
1c79356b 106
91447636 107#define TIMER_BUMP(timer, ticks)
1c79356b 108
91447636 109#endif /* STAT_TIME */
1c79356b 110
91447636
A
111/* Initialize a timer */
112extern void timer_init(
113 timer_t timer);
1c79356b 114
91447636
A
115/* Update a saved timer value and return delta to current value */
116extern uint64_t timer_delta(
117 timer_t timer,
118 uint64_t *save);
1c79356b 119
1c79356b
A
120/*
121 * Exported hardware interface to timers
122 */
1c79356b 123
91447636
A
124/* Read timer value */
125extern uint64_t timer_grab(
126 timer_t timer);
1c79356b 127
91447636
A
128/* Update timer value */
129extern void timer_update(
130 timer_t timer,
131 uint32_t new_high,
132 uint32_t new_low);
1c79356b 133
91447636 134#if !STAT_TIME
1c79356b 135
91447636
A
136/* Update the current timer at an event */
137extern void timer_event(
138 uint32_t tstamp,
139 timer_t new_timer);
1c79356b 140
91447636 141#endif /* STAT_TIME */
1c79356b
A
142
143#endif /* _KERN_TIMER_H_ */