18#ifndef _COBALT_POSIX_CLOCK_H
19#define _COBALT_POSIX_CLOCK_H
21#include <linux/types.h>
22#include <linux/time.h>
23#include <linux/cpumask.h>
24#include <cobalt/uapi/time.h>
25#include <xenomai/posix/syscall.h>
27#define ONE_BILLION 1000000000
31static inline void ns2ts(
struct timespec64 *ts, xnticks_t nsecs)
33 ts->tv_sec = xnclock_divrem_billion(nsecs, &ts->tv_nsec);
36static inline xnticks_t ts2ns(
const struct timespec64 *ts)
38 xnticks_t nsecs = ts->tv_nsec;
41 nsecs += (xnticks_t)ts->tv_sec * ONE_BILLION;
46static inline xnticks_t xnts64_2ns(
const struct xn_ts64 *ts)
48 xnticks_t nsecs = ts->tv_nsec;
51 nsecs += (xnticks_t)ts->tv_sec * ONE_BILLION;
56static inline xnticks_t tv2ns(
const struct __kernel_old_timeval *tv)
58 xnticks_t nsecs = tv->tv_usec * 1000;
61 nsecs += (xnticks_t)tv->tv_sec * ONE_BILLION;
66static inline void ticks2ts64(
struct timespec64 *ts, xnticks_t ticks)
70 ts->tv_sec = xnclock_divrem_billion(ticks, &nsecs);
74static inline void ticks2xnts64(
struct xn_ts64 *ts, xnticks_t ticks)
78 ts->tv_sec = xnclock_divrem_billion(ticks, &nsecs);
82static inline xnticks_t clock_get_ticks(clockid_t clock_id)
84 return clock_id == CLOCK_REALTIME ?
85 xnclock_read_realtime(&nkclock) :
86 xnclock_read_monotonic(&nkclock);
89static inline int clock_flag(
int flag, clockid_t clock_id)
91 if ((flag & TIMER_ABSTIME) == 0)
94 if (clock_id == CLOCK_REALTIME)
100int __cobalt_clock_getres(clockid_t clock_id,
101 struct timespec64 *ts);
103int __cobalt_clock_gettime(clockid_t clock_id,
104 struct timespec64 *ts);
106int __cobalt_clock_settime(clockid_t clock_id,
107 const struct timespec64 *ts);
109int __cobalt_clock_adjtime(clockid_t clock_id,
110 struct __kernel_timex *tx);
112int __cobalt_clock_nanosleep(clockid_t clock_id,
int flags,
113 const struct timespec64 *rqt,
114 struct timespec64 *rmt);
116COBALT_SYSCALL_DECL(clock_getres,
117 (clockid_t clock_id,
struct __kernel_old_timespec __user *u_ts));
119COBALT_SYSCALL_DECL(clock_getres64,
120 (clockid_t clock_id,
struct __kernel_timespec __user *u_ts));
122COBALT_SYSCALL_DECL(clock_gettime,
123 (clockid_t clock_id,
struct __kernel_old_timespec __user *u_ts));
125COBALT_SYSCALL_DECL(clock_gettime64,
126 (clockid_t clock_id,
struct __kernel_timespec __user *u_ts));
128COBALT_SYSCALL_DECL(clock_settime,
129 (clockid_t clock_id,
const struct __kernel_old_timespec __user *u_ts));
131COBALT_SYSCALL_DECL(clock_settime64,
133 const struct __kernel_timespec __user *u_ts));
135COBALT_SYSCALL_DECL(clock_adjtime,
136 (clockid_t clock_id,
struct old_timex32 __user *u_tx));
138COBALT_SYSCALL_DECL(clock_adjtime64,
139 (clockid_t clock_id,
struct __kernel_timex __user *u_tx));
141COBALT_SYSCALL_DECL(clock_nanosleep,
142 (clockid_t clock_id,
int flags,
143 const struct __kernel_old_timespec __user *u_rqt,
144 struct __kernel_old_timespec __user *u_rmt));
146COBALT_SYSCALL_DECL(clock_nanosleep64,
147 (clockid_t clock_id,
int flags,
148 const struct __kernel_timespec __user *u_rqt,
149 struct __kernel_timespec __user *u_rmt));
151int cobalt_clock_register(
struct xnclock *clock,
152 const cpumask_t *affinity,
155void cobalt_clock_deregister(
struct xnclock *clock);
157struct xnclock *cobalt_clock_find(clockid_t clock_id);
159extern DECLARE_BITMAP(cobalt_clock_extids, COBALT_MAX_EXTCLOCKS);