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;
51 #ifdef CONFIG_XENO_OPT_EXTCLOCK 52 xnticks_t (*read_raw)(
struct xnclock *clock);
53 xnticks_t (*read_monotonic)(
struct xnclock *clock);
54 int (*set_time)(
struct xnclock *clock,
55 const struct timespec *ts);
56 xnsticks_t (*ns_to_ticks)(
struct xnclock *clock,
58 xnsticks_t (*ticks_to_ns)(
struct xnclock *clock,
60 xnsticks_t (*ticks_to_ns_rounded)(
struct xnclock *clock,
62 void (*program_local_shot)(
struct xnclock *clock,
64 void (*program_remote_shot)(
struct xnclock *clock,
67 int (*adjust_time)(
struct xnclock *clock,
69 int (*set_gravity)(
struct xnclock *clock,
70 const struct xnclock_gravity *p);
71 void (*reset_gravity)(
struct xnclock *clock);
72 #ifdef CONFIG_XENO_OPT_VFILE 73 void (*print_status)(
struct xnclock *clock,
78 struct xntimerdata *timerdata;
84 #ifdef CONFIG_XENO_OPT_STATS 87 struct list_head timerq;
90 #ifdef CONFIG_XENO_OPT_VFILE 91 struct xnvfile_regular vfile;
95 struct xnclock_ratelimit_state {
103 extern struct xnclock nkclock;
105 extern unsigned long nktimerlat;
108 const cpumask_t *affinity);
117 void xnclock_core_local_shot(
struct xnsched *sched);
119 void xnclock_core_remote_shot(
struct xnsched *sched);
121 xnsticks_t xnclock_core_ns_to_ticks(xnsticks_t ns);
123 xnsticks_t xnclock_core_ticks_to_ns(xnsticks_t ticks);
125 xnsticks_t xnclock_core_ticks_to_ns_rounded(xnsticks_t ticks);
127 xnticks_t xnclock_core_read_monotonic(
void);
129 static inline xnticks_t xnclock_core_read_raw(
void)
131 unsigned long long t;
137 #define XN_RATELIMIT_INTERVAL 5000000000LL 138 #define XN_RATELIMIT_BURST 10 140 int __xnclock_ratelimit(
struct xnclock_ratelimit_state *rs,
const char *func);
142 #define xnclock_ratelimit() ({ \ 143 static struct xnclock_ratelimit_state __state = { \ 144 .interval = XN_RATELIMIT_INTERVAL, \ 145 .burst = XN_RATELIMIT_BURST, \ 147 __xnclock_ratelimit(&__state, __func__); \ 150 #ifdef CONFIG_XENO_OPT_EXTCLOCK 152 static inline void xnclock_program_shot(
struct xnclock *clock,
155 if (likely(clock == &nkclock))
156 xnclock_core_local_shot(sched);
157 else if (clock->ops.program_local_shot)
158 clock->ops.program_local_shot(clock, sched);
161 static inline void xnclock_remote_shot(
struct xnclock *clock,
165 if (likely(clock == &nkclock))
166 xnclock_core_remote_shot(sched);
167 else if (clock->ops.program_remote_shot)
168 clock->ops.program_remote_shot(clock, sched);
172 static inline xnticks_t xnclock_read_raw(
struct xnclock *clock)
174 if (likely(clock == &nkclock))
175 return xnclock_core_read_raw();
177 return clock->ops.read_raw(clock);
180 static inline xnsticks_t xnclock_ns_to_ticks(
struct xnclock *clock,
183 if (likely(clock == &nkclock))
184 return xnclock_core_ns_to_ticks(ns);
186 return clock->ops.ns_to_ticks(clock, ns);
189 static inline xnsticks_t xnclock_ticks_to_ns(
struct xnclock *clock,
192 if (likely(clock == &nkclock))
193 return xnclock_core_ticks_to_ns(ticks);
195 return clock->ops.ticks_to_ns(clock, ticks);
198 static inline xnsticks_t xnclock_ticks_to_ns_rounded(
struct xnclock *clock,
201 if (likely(clock == &nkclock))
202 return xnclock_core_ticks_to_ns_rounded(ticks);
204 return clock->ops.ticks_to_ns_rounded(clock, ticks);
207 static inline xnticks_t xnclock_read_monotonic(
struct xnclock *clock)
209 if (likely(clock == &nkclock))
210 return xnclock_core_read_monotonic();
212 return clock->ops.read_monotonic(clock);
215 static inline int xnclock_set_time(
struct xnclock *clock,
216 const struct timespec *ts)
218 if (likely(clock == &nkclock))
221 return clock->ops.set_time(clock, ts);
226 static inline void xnclock_program_shot(
struct xnclock *clock,
229 xnclock_core_local_shot(sched);
232 static inline void xnclock_remote_shot(
struct xnclock *clock,
236 xnclock_core_remote_shot(sched);
240 static inline xnticks_t xnclock_read_raw(
struct xnclock *clock)
242 return xnclock_core_read_raw();
245 static inline xnsticks_t xnclock_ns_to_ticks(
struct xnclock *clock,
248 return xnclock_core_ns_to_ticks(ns);
251 static inline xnsticks_t xnclock_ticks_to_ns(
struct xnclock *clock,
254 return xnclock_core_ticks_to_ns(ticks);
257 static inline xnsticks_t xnclock_ticks_to_ns_rounded(
struct xnclock *clock,
260 return xnclock_core_ticks_to_ns_rounded(ticks);
263 static inline xnticks_t xnclock_read_monotonic(
struct xnclock *clock)
265 return xnclock_core_read_monotonic();
268 static inline int xnclock_set_time(
struct xnclock *clock,
269 const struct timespec *ts)
279 static inline int xnclock_adjust_time(
struct xnclock *clock,
282 if (clock->ops.adjust_time == NULL)
285 return clock->ops.adjust_time(clock, tx);
288 static inline xnticks_t xnclock_get_offset(
struct xnclock *clock)
290 return clock->wallclock_offset;
293 static inline xnticks_t xnclock_get_resolution(
struct xnclock *clock)
295 return clock->resolution;
298 static inline void xnclock_set_resolution(
struct xnclock *clock,
299 xnticks_t resolution)
301 clock->resolution = resolution;
304 static inline int xnclock_set_gravity(
struct xnclock *clock,
305 const struct xnclock_gravity *gravity)
307 if (clock->ops.set_gravity)
308 return clock->ops.set_gravity(clock, gravity);
313 static inline void xnclock_reset_gravity(
struct xnclock *clock)
315 if (clock->ops.reset_gravity)
316 clock->ops.reset_gravity(clock);
319 #define xnclock_get_gravity(__clock, __type) ((__clock)->gravity.__type) 321 static inline xnticks_t xnclock_read_realtime(
struct xnclock *clock)
327 return xnclock_read_monotonic(clock) + xnclock_get_offset(clock);
330 unsigned long long xnclock_divrem_billion(
unsigned long long value,
333 xnticks_t xnclock_get_host_time(
void);
335 #ifdef CONFIG_XENO_OPT_VFILE 337 void xnclock_init_proc(
void);
339 void xnclock_cleanup_proc(
void);
341 static inline void xnclock_print_status(
struct xnclock *clock,
344 if (clock->ops.print_status)
345 clock->ops.print_status(clock, it);
349 static inline void xnclock_init_proc(
void) { }
350 static inline void xnclock_cleanup_proc(
void) { }
353 void xnclock_update_freq(
unsigned long long freq);
355 int xnclock_init(
unsigned long long freq);
357 void xnclock_cleanup(
void);
Snapshot revision tag.
Definition: vfile.h:482
void xnclock_deregister(struct xnclock *clock)
Deregister a Xenomai clock.
Definition: clock.c:710
Scheduling information structure.
Definition: sched.h:58
Regular vfile iterator.
Definition: vfile.h:269
void xnclock_adjust(struct xnclock *clock, xnsticks_t delta)
Adjust a clock time.
Definition: clock.c:341
void xnclock_tick(struct xnclock *clock)
Process a clock tick.
Definition: clock.c:745
int xnclock_register(struct xnclock *clock, const cpumask_t *affinity)
Register a Xenomai clock.
Definition: clock.c:646
Snapshot vfile descriptor.
Definition: vfile.h:506