19#ifndef _COBALT_KERNEL_CLOCK_H
20#define _COBALT_KERNEL_CLOCK_H
22#include <pipeline/pipeline.h>
23#include <pipeline/clock.h>
24#include <cobalt/kernel/list.h>
25#include <cobalt/kernel/vfile.h>
26#include <cobalt/uapi/kernel/types.h>
27#include <asm/xenomai/wrappers.h>
38struct xnclock_gravity {
46 xnsticks_t wallclock_offset;
50 struct xnclock_gravity gravity;
54#ifdef CONFIG_XENO_OPT_EXTCLOCK
55 xnticks_t (*read_raw)(
struct xnclock *clock);
56 xnticks_t (*read_monotonic)(
struct xnclock *clock);
57 int (*set_time)(
struct xnclock *clock,
58 const struct timespec64 *ts);
59 xnsticks_t (*ns_to_ticks)(
struct xnclock *clock,
61 xnsticks_t (*ticks_to_ns)(
struct xnclock *clock,
63 xnsticks_t (*ticks_to_ns_rounded)(
struct xnclock *clock,
65 void (*program_local_shot)(
struct xnclock *clock,
67 void (*program_remote_shot)(
struct xnclock *clock,
70 int (*adjust_time)(
struct xnclock *clock,
71 struct __kernel_timex *tx);
72 int (*set_gravity)(
struct xnclock *clock,
73 const struct xnclock_gravity *p);
74 void (*reset_gravity)(
struct xnclock *clock);
75#ifdef CONFIG_XENO_OPT_VFILE
76 void (*print_status)(
struct xnclock *clock,
81 struct xntimerdata __percpu *timerdata;
87#ifdef CONFIG_XENO_OPT_STATS
90 struct list_head timerq;
93#ifdef CONFIG_XENO_OPT_VFILE
94 struct xnvfile_regular vfile;
98struct xnclock_ratelimit_state {
106extern struct xnclock nkclock;
109 const cpumask_t *affinity);
115void xnclock_core_local_shot(
struct xnsched *sched);
117void xnclock_core_remote_shot(
struct xnsched *sched);
119xnsticks_t xnclock_core_ns_to_ticks(xnsticks_t ns);
121xnsticks_t xnclock_core_ticks_to_ns(xnsticks_t ticks);
123xnsticks_t xnclock_core_ticks_to_ns_rounded(xnsticks_t ticks);
125xnticks_t xnclock_core_read_monotonic(
void);
127static inline xnticks_t xnclock_core_read_raw(
void)
129 return pipeline_read_cycle_counter();
133#define XN_RATELIMIT_INTERVAL 5000000000LL
134#define XN_RATELIMIT_BURST 10
136int __xnclock_ratelimit(
struct xnclock_ratelimit_state *rs,
const char *func);
138#define xnclock_ratelimit() ({ \
139 static struct xnclock_ratelimit_state __state = { \
140 .interval = XN_RATELIMIT_INTERVAL, \
141 .burst = XN_RATELIMIT_BURST, \
143 __xnclock_ratelimit(&__state, __func__); \
146#ifdef CONFIG_XENO_OPT_EXTCLOCK
148static inline void xnclock_program_shot(
struct xnclock *clock,
151 if (likely(clock == &nkclock))
152 xnclock_core_local_shot(sched);
153 else if (clock->ops.program_local_shot)
154 clock->ops.program_local_shot(clock, sched);
157static inline void xnclock_remote_shot(
struct xnclock *clock,
161 if (likely(clock == &nkclock))
162 xnclock_core_remote_shot(sched);
163 else if (clock->ops.program_remote_shot)
164 clock->ops.program_remote_shot(clock, sched);
168static inline xnticks_t xnclock_read_raw(
struct xnclock *clock)
170 if (likely(clock == &nkclock))
171 return xnclock_core_read_raw();
173 return clock->ops.read_raw(clock);
176static inline xnsticks_t xnclock_ns_to_ticks(
struct xnclock *clock,
179 if (likely(clock == &nkclock))
180 return xnclock_core_ns_to_ticks(ns);
182 return clock->ops.ns_to_ticks(clock, ns);
185static inline xnsticks_t xnclock_ticks_to_ns(
struct xnclock *clock,
188 if (likely(clock == &nkclock))
189 return xnclock_core_ticks_to_ns(ticks);
191 return clock->ops.ticks_to_ns(clock, ticks);
194static inline xnsticks_t xnclock_ticks_to_ns_rounded(
struct xnclock *clock,
197 if (likely(clock == &nkclock))
198 return xnclock_core_ticks_to_ns_rounded(ticks);
200 return clock->ops.ticks_to_ns_rounded(clock, ticks);
203static inline xnticks_t xnclock_read_monotonic(
struct xnclock *clock)
205 if (likely(clock == &nkclock))
206 return xnclock_core_read_monotonic();
208 return clock->ops.read_monotonic(clock);
211static inline int xnclock_set_time(
struct xnclock *clock,
212 const struct timespec64 *ts)
214 if (likely(clock == &nkclock))
217 return clock->ops.set_time(clock, ts);
222static inline void xnclock_program_shot(
struct xnclock *clock,
225 xnclock_core_local_shot(sched);
228static inline void xnclock_remote_shot(
struct xnclock *clock,
232 xnclock_core_remote_shot(sched);
236static inline xnticks_t xnclock_read_raw(
struct xnclock *clock)
238 return xnclock_core_read_raw();
241static inline xnsticks_t xnclock_ns_to_ticks(
struct xnclock *clock,
244 return xnclock_core_ns_to_ticks(ns);
247static inline xnsticks_t xnclock_ticks_to_ns(
struct xnclock *clock,
250 return xnclock_core_ticks_to_ns(ticks);
253static inline xnsticks_t xnclock_ticks_to_ns_rounded(
struct xnclock *clock,
256 return xnclock_core_ticks_to_ns_rounded(ticks);
259static inline xnticks_t xnclock_read_monotonic(
struct xnclock *clock)
261 return xnclock_core_read_monotonic();
264static inline int xnclock_set_time(
struct xnclock *clock,
265 const struct timespec64 *ts)
275static inline int xnclock_adjust_time(
struct xnclock *clock,
276 struct __kernel_timex *tx)
278 if (clock->ops.adjust_time == NULL)
281 return clock->ops.adjust_time(clock, tx);
284static inline xnticks_t xnclock_get_offset(
struct xnclock *clock)
286 return clock->wallclock_offset;
289static inline xnticks_t xnclock_get_resolution(
struct xnclock *clock)
291 return clock->resolution;
294static inline void xnclock_set_resolution(
struct xnclock *clock,
295 xnticks_t resolution)
297 clock->resolution = resolution;
300static inline int xnclock_set_gravity(
struct xnclock *clock,
301 const struct xnclock_gravity *gravity)
303 if (clock->ops.set_gravity)
304 return clock->ops.set_gravity(clock, gravity);
309static inline void xnclock_reset_gravity(
struct xnclock *clock)
311 if (clock->ops.reset_gravity)
312 clock->ops.reset_gravity(clock);
315#define xnclock_get_gravity(__clock, __type) ((__clock)->gravity.__type)
317static inline xnticks_t xnclock_read_realtime(
struct xnclock *clock)
319 if (likely(clock == &nkclock))
320 return pipeline_read_wallclock();
325 return xnclock_read_monotonic(clock) + xnclock_get_offset(clock);
328void xnclock_apply_offset(
struct xnclock *clock,
329 xnsticks_t delta_ns);
331void xnclock_set_wallclock(xnticks_t epoch_ns);
333unsigned long long xnclock_divrem_billion(
unsigned long long value,
336#ifdef CONFIG_XENO_OPT_VFILE
338void xnclock_init_proc(
void);
340void xnclock_cleanup_proc(
void);
342static inline void xnclock_print_status(
struct xnclock *clock,
345 if (clock->ops.print_status)
346 clock->ops.print_status(clock, it);
350static inline void xnclock_init_proc(
void) { }
351static inline void xnclock_cleanup_proc(
void) { }
354int xnclock_init(
void);
356void xnclock_cleanup(
void);
void xnclock_tick(struct xnclock *clock)
Process a clock tick.
Definition clock.c:681
void xnclock_deregister(struct xnclock *clock)
Deregister a Xenomai clock.
Definition clock.c:647
int xnclock_register(struct xnclock *clock, const cpumask_t *affinity)
Register a Xenomai clock.
Definition clock.c:584
Scheduling information structure.
Definition sched.h:64
Regular vfile iterator .
Definition vfile.h:270
Snapshot revision tag .
Definition vfile.h:483
Snapshot vfile descriptor .
Definition vfile.h:507