Xenomai 3.3.2
Loading...
Searching...
No Matches
clock.h
1/*
2 * Written by Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18#ifndef _COBALT_POSIX_CLOCK_H
19#define _COBALT_POSIX_CLOCK_H
20
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>
26
27#define ONE_BILLION 1000000000
28
29struct xnclock;
30
31static inline void ns2ts(struct timespec64 *ts, xnticks_t nsecs)
32{
33 ts->tv_sec = xnclock_divrem_billion(nsecs, &ts->tv_nsec);
34}
35
36static inline xnticks_t ts2ns(const struct timespec64 *ts)
37{
38 xnticks_t nsecs = ts->tv_nsec;
39
40 if (ts->tv_sec)
41 nsecs += (xnticks_t)ts->tv_sec * ONE_BILLION;
42
43 return nsecs;
44}
45
46static inline xnticks_t xnts64_2ns(const struct xn_ts64 *ts)
47{
48 xnticks_t nsecs = ts->tv_nsec;
49
50 if (ts->tv_sec)
51 nsecs += (xnticks_t)ts->tv_sec * ONE_BILLION;
52
53 return nsecs;
54}
55
56static inline xnticks_t tv2ns(const struct __kernel_old_timeval *tv)
57{
58 xnticks_t nsecs = tv->tv_usec * 1000;
59
60 if (tv->tv_sec)
61 nsecs += (xnticks_t)tv->tv_sec * ONE_BILLION;
62
63 return nsecs;
64}
65
66static inline void ticks2ts64(struct timespec64 *ts, xnticks_t ticks)
67{
68 unsigned long nsecs;
69
70 ts->tv_sec = xnclock_divrem_billion(ticks, &nsecs);
71 ts->tv_nsec = nsecs;
72}
73
74static inline void ticks2xnts64(struct xn_ts64 *ts, xnticks_t ticks)
75{
76 unsigned long nsecs;
77
78 ts->tv_sec = xnclock_divrem_billion(ticks, &nsecs);
79 ts->tv_nsec = nsecs;
80}
81
82static inline xnticks_t clock_get_ticks(clockid_t clock_id)
83{
84 return clock_id == CLOCK_REALTIME ?
85 xnclock_read_realtime(&nkclock) :
86 xnclock_read_monotonic(&nkclock);
87}
88
89static inline int clock_flag(int flag, clockid_t clock_id)
90{
91 if ((flag & TIMER_ABSTIME) == 0)
92 return XN_RELATIVE;
93
94 if (clock_id == CLOCK_REALTIME)
95 return XN_REALTIME;
96
97 return XN_ABSOLUTE;
98}
99
100int __cobalt_clock_getres(clockid_t clock_id,
101 struct timespec64 *ts);
102
103int __cobalt_clock_gettime(clockid_t clock_id,
104 struct timespec64 *ts);
105
106int __cobalt_clock_settime(clockid_t clock_id,
107 const struct timespec64 *ts);
108
109int __cobalt_clock_adjtime(clockid_t clock_id,
110 struct __kernel_timex *tx);
111
112int __cobalt_clock_nanosleep(clockid_t clock_id, int flags,
113 const struct timespec64 *rqt,
114 struct timespec64 *rmt);
115
116COBALT_SYSCALL_DECL(clock_getres,
117 (clockid_t clock_id, struct __kernel_old_timespec __user *u_ts));
118
119COBALT_SYSCALL_DECL(clock_getres64,
120 (clockid_t clock_id, struct __kernel_timespec __user *u_ts));
121
122COBALT_SYSCALL_DECL(clock_gettime,
123 (clockid_t clock_id, struct __kernel_old_timespec __user *u_ts));
124
125COBALT_SYSCALL_DECL(clock_gettime64,
126 (clockid_t clock_id, struct __kernel_timespec __user *u_ts));
127
128COBALT_SYSCALL_DECL(clock_settime,
129 (clockid_t clock_id, const struct __kernel_old_timespec __user *u_ts));
130
131COBALT_SYSCALL_DECL(clock_settime64,
132 (clockid_t clock_id,
133 const struct __kernel_timespec __user *u_ts));
134
135COBALT_SYSCALL_DECL(clock_adjtime,
136 (clockid_t clock_id, struct old_timex32 __user *u_tx));
137
138COBALT_SYSCALL_DECL(clock_adjtime64,
139 (clockid_t clock_id, struct __kernel_timex __user *u_tx));
140
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));
145
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));
150
151int cobalt_clock_register(struct xnclock *clock,
152 const cpumask_t *affinity,
153 clockid_t *clk_id);
154
155void cobalt_clock_deregister(struct xnclock *clock);
156
157struct xnclock *cobalt_clock_find(clockid_t clock_id);
158
159extern DECLARE_BITMAP(cobalt_clock_extids, COBALT_MAX_EXTCLOCKS);
160
161#endif /* !_COBALT_POSIX_CLOCK_H */