FreeBSD/Linux Kernel Cross Reference
sys/kern/clock.h
1 /*
2 * Mach Operating System
3 * Copyright (c) 1993,1992 Carnegie Mellon University
4 * All Rights Reserved.
5 *
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
11 *
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15 *
16 * Carnegie Mellon requests users of this software to return to
17 *
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
22 *
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
25 */
26 /*
27 * HISTORY
28 * $Log: clock.h,v $
29 * Revision 2.2 93/11/17 17:07:22 dbg
30 * Added check_seconds and clock_time, so that time can be
31 * read without having to lock the clock.
32 * [93/06/18 dbg]
33 *
34 * Added correction_delta, correction_count.
35 * [93/06/02 dbg]
36 *
37 * Moved timer element definitions to kern/mach_timer.h.
38 * [93/04/09 dbg]
39 *
40 * Moved user-visible definitions to kern/clock.h.
41 *
42 * Created
43 * [92/07/12 savage]
44 *
45 */
46 /*
47 * File: kern/clock.h
48 * Author:
49 * Stefan Savage and David Golub, 1993
50 *
51 * This file contains the definition for kernel clock objects.
52 * A clock is a time keeper that increments periodically and
53 * may have an associated queue of timer elements for alarms,
54 * periodic wakeups, and the like.
55 */
56 #ifndef _KERN_CLOCK_H_
57 #define _KERN_CLOCK_H_
58
59 #include <mach/time_spec.h>
60 #include <kern/lock.h>
61 #include <kern/queue.h>
62 #include <kern/mach_timer.h>
63 #include <ipc/ipc_port.h>
64
65 struct clock_ops; /* forward */
66
67 /*
68 * A clock.
69 */
70 struct mach_clock {
71 volatile time_spec_t time; /* current time */
72 volatile unsigned int check_seconds; /* to read time without lock */
73 mapped_time_spec_t *mtime; /* pointer to mapped time */
74 int resolution; /* nanoseconds per 'tick' */
75 int skew; /* difference from desired
76 resolution */
77 int correction_delta;
78 /* add to clock every tick */
79 int correction_count;
80 /* for this many ticks */
81 struct timer_elt_head head; /* queue of timers */
82 decl_simple_lock_data(,queue_lock) /* lock for queue */
83 int new_resolution; /* new resolution requested */
84 int new_skew; /* skew for new resolution */
85 struct clock_ops *ops; /* operations on clock */
86 struct mach_clock * next; /* list of all clocks */
87 };
88
89 typedef struct mach_clock *mach_clock_t;
90 typedef struct mach_clock mach_clock_data_t;
91
92 #define CLOCK_NULL ((mach_clock_t)0)
93 #define D_INFO_CLOCK 2 /* for d_dev_info */
94
95 #define clock_queue_head(clock) (&(clock)->head)
96 #define clock_queue_lock(clock) simple_lock(&(clock)->queue_lock)
97 #define clock_queue_unlock(clock) simple_unlock(&(clock)->queue_lock)
98
99 extern mach_clock_t convert_device_port_to_clock(ipc_port_t);
100 extern ipc_port_t convert_clock_to_device_port(mach_clock_t);
101
102 /*
103 * Operations on a clock
104 */
105 struct clock_ops {
106 void (*set_resolution)(mach_clock_t);
107 /* set hardware resolution from
108 clock->resolution */
109 void (*set_time)(mach_clock_t, time_spec_t);
110 /* set new time */
111 void (*enable_interrupts)(mach_clock_t);
112 /* enable interrupts from clock */
113 };
114
115 /*
116 * Initialize a clock
117 */
118 extern void clock_init(mach_clock_t clock, struct clock_ops *ops);
119
120 /*
121 * Adjust the timers on a clock if the clock's time is
122 * changed
123 */
124 extern void clock_timer_adjust(mach_clock_t clock, time_spec_t delta);
125
126 /*
127 * One of the clocks is the distinguished system time-of-day clock.
128 */
129 extern mach_clock_t sys_clock;
130
131 /*
132 * Normal and system clock interrupt service routines.
133 */
134 extern void
135 clock_interrupt(
136 mach_clock_t clock);
137
138 extern void
139 sys_clock_interrupt(
140 boolean_t usermode);
141
142 /*
143 * Enable system clock interrupts for the current CPU.
144 */
145 extern void
146 enable_clock_interrupts(void);
147
148 /*
149 * void clock_read(time_spec_t& result,
150 * mach_clock_t clock)
151 *
152 * Read the clock`s time, without locking the clock,
153 * and produce a consistent time reading.
154 *
155 * Results are passed by lvalue.
156 */
157 #define clock_read(result, clock) \
158 do { \
159 (result).seconds = (clock)->time.seconds; \
160 (result).nanoseconds = (clock)->time.nanoseconds; \
161 } while ((result).seconds != (clock)->check_seconds)
162
163 /*
164 * Set the mapped time from the current clock reading,
165 * obeying the update protocol (set check_seconds first).
166 */
167 #define clock_set_mtime(clock) \
168 MACRO_BEGIN \
169 mapped_time_spec_t *mtime = (clock)->mtime; \
170 if (mtime != 0) { \
171 mtime->check_seconds = (clock)->time.seconds; \
172 mtime->nanoseconds = (clock)->time.nanoseconds; \
173 mtime->seconds = (clock)->time.seconds; \
174 } \
175 MACRO_END
176
177 #endif /* _KERN_CLOCK_H_ */
Cache object: 1549683f01b1dbae39f9e4bf978abb6f
|