19 #ifndef _COBALT_KERNEL_CLOCK_H
20 #define _COBALT_KERNEL_CLOCK_H
22 #include <linux/ipipe.h>
23 #include <cobalt/kernel/list.h>
24 #include <cobalt/kernel/vfile.h>
25 #include <cobalt/uapi/kernel/types.h>
35 struct xnclock_gravity {
43 xnticks_t wallclock_offset;
47 struct xnclock_gravity gravity;
50 #ifdef CONFIG_XENO_OPT_EXTCLOCK
51 xnticks_t (*read_raw)(
struct xnclock *clock);
52 xnticks_t (*read_monotonic)(
struct xnclock *clock);
53 int (*set_time)(
struct xnclock *clock,
54 const struct timespec *ts);
55 xnsticks_t (*ns_to_ticks)(
struct xnclock *clock,
57 xnsticks_t (*ticks_to_ns)(
struct xnclock *clock,
59 xnsticks_t (*ticks_to_ns_rounded)(
struct xnclock *clock,
61 void (*program_local_shot)(
struct xnclock *clock,
63 void (*program_remote_shot)(
struct xnclock *clock,
66 int (*set_gravity)(
struct xnclock *clock,
67 const struct xnclock_gravity *p);
68 void (*reset_gravity)(
struct xnclock *clock);
69 #ifdef CONFIG_XENO_OPT_VFILE
70 void (*print_status)(
struct xnclock *clock,
75 struct xntimerdata *timerdata;
77 #ifdef CONFIG_XENO_OPT_STATS
80 struct list_head timerq;
83 #ifdef CONFIG_XENO_OPT_VFILE
84 struct xnvfile_regular vfile;
88 extern struct xnclock nkclock;
90 extern unsigned long nktimerlat;
92 extern unsigned int nkclock_lock;
103 void xnclock_core_local_shot(
struct xnsched *sched);
105 void xnclock_core_remote_shot(
struct xnsched *sched);
107 xnsticks_t xnclock_core_ns_to_ticks(xnsticks_t ns);
109 xnsticks_t xnclock_core_ticks_to_ns(xnsticks_t ticks);
111 xnsticks_t xnclock_core_ticks_to_ns_rounded(xnsticks_t ticks);
113 xnticks_t xnclock_core_read_monotonic(
void);
115 static inline xnticks_t xnclock_core_read_raw(
void)
117 unsigned long long t;
122 #ifdef CONFIG_XENO_OPT_EXTCLOCK
124 static inline void xnclock_program_shot(
struct xnclock *clock,
127 if (likely(clock == &nkclock))
128 xnclock_core_local_shot(sched);
129 else if (clock->ops.program_local_shot)
130 clock->ops.program_local_shot(clock, sched);
133 static inline void xnclock_remote_shot(
struct xnclock *clock,
137 if (likely(clock == &nkclock))
138 xnclock_core_remote_shot(sched);
139 else if (clock->ops.program_remote_shot)
140 clock->ops.program_remote_shot(clock, sched);
144 static inline xnticks_t xnclock_read_raw(
struct xnclock *clock)
146 if (likely(clock == &nkclock))
147 return xnclock_core_read_raw();
149 return clock->ops.read_raw(clock);
152 static inline xnsticks_t xnclock_ns_to_ticks(
struct xnclock *clock,
155 if (likely(clock == &nkclock))
156 return xnclock_core_ns_to_ticks(ns);
158 return clock->ops.ns_to_ticks(clock, ns);
161 static inline xnsticks_t xnclock_ticks_to_ns(
struct xnclock *clock,
164 if (likely(clock == &nkclock))
165 return xnclock_core_ticks_to_ns(ticks);
167 return clock->ops.ticks_to_ns(clock, ticks);
170 static inline xnsticks_t xnclock_ticks_to_ns_rounded(
struct xnclock *clock,
173 if (likely(clock == &nkclock))
174 return xnclock_core_ticks_to_ns_rounded(ticks);
176 return clock->ops.ticks_to_ns_rounded(clock, ticks);
179 static inline xnticks_t xnclock_read_monotonic(
struct xnclock *clock)
181 if (likely(clock == &nkclock))
182 return xnclock_core_read_monotonic();
184 return clock->ops.read_monotonic(clock);
187 static inline int xnclock_set_time(
struct xnclock *clock,
188 const struct timespec *ts)
190 if (likely(clock == &nkclock))
193 return clock->ops.set_time(clock, ts);
198 static inline void xnclock_program_shot(
struct xnclock *clock,
201 xnclock_core_local_shot(sched);
204 static inline void xnclock_remote_shot(
struct xnclock *clock,
208 xnclock_core_remote_shot(sched);
212 static inline xnticks_t xnclock_read_raw(
struct xnclock *clock)
214 return xnclock_core_read_raw();
217 static inline xnsticks_t xnclock_ns_to_ticks(
struct xnclock *clock,
220 return xnclock_core_ns_to_ticks(ns);
223 static inline xnsticks_t xnclock_ticks_to_ns(
struct xnclock *clock,
226 return xnclock_core_ticks_to_ns(ticks);
229 static inline xnsticks_t xnclock_ticks_to_ns_rounded(
struct xnclock *clock,
232 return xnclock_core_ticks_to_ns_rounded(ticks);
235 static inline xnticks_t xnclock_read_monotonic(
struct xnclock *clock)
237 return xnclock_core_read_monotonic();
240 static inline int xnclock_set_time(
struct xnclock *clock,
241 const struct timespec *ts)
251 static inline xnticks_t xnclock_get_offset(
struct xnclock *clock)
253 return clock->wallclock_offset;
256 static inline xnticks_t xnclock_get_resolution(
struct xnclock *clock)
258 return clock->resolution;
261 static inline int xnclock_set_gravity(
struct xnclock *clock,
262 const struct xnclock_gravity *gravity)
264 if (clock->ops.set_gravity)
265 return clock->ops.set_gravity(clock, gravity);
270 static inline void xnclock_reset_gravity(
struct xnclock *clock)
272 if (clock->ops.reset_gravity)
273 clock->ops.reset_gravity(clock);
276 #define xnclock_get_gravity(__clock, __type) ((__clock)->gravity.__type)
278 static inline xnticks_t xnclock_read_realtime(
struct xnclock *clock)
284 return xnclock_read_monotonic(clock) + xnclock_get_offset(clock);
287 unsigned long long xnclock_divrem_billion(
unsigned long long value,
290 xnticks_t xnclock_get_host_time(
void);
292 #ifdef CONFIG_XENO_OPT_VFILE
294 void xnclock_init_proc(
void);
296 void xnclock_cleanup_proc(
void);
298 static inline void xnclock_print_status(
struct xnclock *clock,
301 if (clock->ops.print_status)
302 clock->ops.print_status(clock, it);
306 static inline void xnclock_init_proc(
void) { }
307 static inline void xnclock_cleanup_proc(
void) { }
310 int xnclock_init(
unsigned long long freq);
312 void xnclock_cleanup(
void);
Snapshot revision tag.
Definition: vfile.h:482
void xnclock_deregister(struct xnclock *clock)
Deregister a Xenomai clock.
Definition: clock.c:642
int xnclock_register(struct xnclock *clock)
Register a Xenomai clock.
Definition: clock.c:601
Scheduling information structure.
Definition: sched.h:57
Regular vfile iterator.
Definition: vfile.h:269
void xnclock_adjust(struct xnclock *clock, xnsticks_t delta)
Adjust a clock time.
Definition: clock.c:301
void xnclock_tick(struct xnclock *clock)
Process a clock tick.
Definition: clock.c:675
Snapshot vfile descriptor.
Definition: vfile.h:506