L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
__timeout.h
1
6/*
7 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
8 * Alexander Warg <warg@os.inf.tu-dresden.de>,
9 * Torsten Frenzel <frenzel@os.inf.tu-dresden.de>
10 * economic rights: Technische Universität Dresden (Germany)
11 *
12 * License: see LICENSE.spdx (in this directory or the directories above)
13 */
14#ifndef L4_SYS_TIMEOUT_H__
15#define L4_SYS_TIMEOUT_H__
16
17#include <l4/sys/l4int.h>
18#include <l4/sys/compiler.h>
19
40typedef struct l4_timeout_s {
42} __attribute__((packed)) l4_timeout_s;
43
44
52typedef union l4_timeout_t
53{
55 struct
56 {
57#ifdef __BIG_ENDIAN__
60#else
63#endif
64 } p;
66
67
73#define L4_IPC_TIMEOUT_0 ((l4_timeout_s){0x0400})
74#define L4_IPC_TIMEOUT_NEVER ((l4_timeout_s){0})
75#define L4_IPC_NEVER_INITIALIZER {0}
76#define L4_IPC_NEVER ((l4_timeout_t){0})
77#define L4_IPC_RECV_TIMEOUT_0 ((l4_timeout_t){0x00000400})
78#define L4_IPC_SEND_TIMEOUT_0 ((l4_timeout_t){0x04000000})
79#define L4_IPC_BOTH_TIMEOUT_0 ((l4_timeout_t){0x04000400})
85#define L4_TIMEOUT_US_NEVER (~0ULL)
86
91#define L4_TIMEOUT_US_MAX ((1ULL << 41) - 1)
92
105l4_timeout_s l4_timeout_rel(unsigned man, unsigned exp) L4_NOTHROW;
106
107
118l4_timeout_t l4_ipc_timeout(unsigned snd_man, unsigned snd_exp,
119 unsigned rcv_man, unsigned rcv_exp) L4_NOTHROW;
120
132
142
152
163
164
175
187
196l4_timeout_s l4_timeout_from_us(l4_uint64_t us) L4_NOTHROW;
197
198/*
199 * Implementation
200 */
201
203l4_timeout_t l4_ipc_timeout(unsigned snd_man, unsigned snd_exp,
204 unsigned rcv_man, unsigned rcv_exp) L4_NOTHROW
205{
206 l4_uint16_t snd = (snd_man & 0x3ff) | ((snd_exp << 10) & 0x7c00);
207 l4_uint16_t rcv = (rcv_man & 0x3ff) | ((rcv_exp << 10) & 0x7c00);
208 return l4_timeout((l4_timeout_s){snd}, (l4_timeout_s){rcv});
209}
210
211
214{
215 return (l4_timeout_t){ ((l4_uint32_t){snd.t} << 16) | rcv.t };
216}
217
218
221{
222 to->p.snd = snd;
223}
224
225
228{
229 to->p.rcv = rcv;
230}
231
232
234l4_timeout_s l4_timeout_rel(unsigned man, unsigned exp) L4_NOTHROW
235{
236 return (l4_timeout_s){(l4_uint16_t)((man & 0x3ff) | ((exp << 10) & 0x7c00))};
237}
238
239
242{
243 if (to.t == 0)
244 return ~0ULL;
245 return (l4_kernel_clock_t)(to.t & 0x3ff) << ((to.t >> 10) & 0x1f);
246}
247
248
251{
252 return to.t & 0x8000;
253}
254
255
258{
260 return 0; /* We cannot retrieve the value ... */
261 else
262 return cur + l4_timeout_rel_get(to);
263}
264
266l4_timeout_s l4_timeout_from_us(l4_uint64_t us) L4_NOTHROW
267{
268 if (us == 0)
269 return L4_IPC_TIMEOUT_0;
270 else if (us == L4_TIMEOUT_US_NEVER || us > L4_TIMEOUT_US_MAX)
272 else
273 {
274 /* Here it is certain that at least one bit in 'us' is set. */
275
276 l4_uint16_t m = 0; // initialization required by constexpr, optimized away
277 l4_uint16_t v = 0; // initialization required by constexpr, optimized away
278 int e = (63 - __builtin_clzll(us)) - 9;
279 if (e < 0)
280 e = 0;
281
282 /* Here it is certain that '0 <= e <= 31' and '1 <= 2^e <= 2^31':
283 * L4_TIMEOUT_US_MAX = 2^41-1 = 0x000001ffffffffff => e = 31.
284 * Note: 2^41-1 (0x000001ffffffffff) > 1023*2^31 (0x00001ff800000000). */
285
286 m = us >> e;
287
288 /* Here it is certain that '1 <= m <= 1023. Consider the following cases:
289 * o 1 <= us <= 1023: e = 0; 2^e = 1; 1 <= us/1 <= 1023
290 * o 1024 <= us <= 2047: e = 1; 2^e = 2; 512 <= us/2 <= 1023
291 * o 2048 <= us <= 4095: e = 2; 2^e = 4; 512 <= us/4 <= 1023
292 * ...
293 * o 2^31 <= us <= 2^32-1: e = 22; 512 <= us/2^22 <= 1023
294 * o 2^40 <= us <= 2^41-1: e = 31; 512 <= us/2^31 <= 1023
295 *
296 * Dividing by (1<<e) ensures that for all us < 2^41: m < 2^10.
297 *
298 * Maximum possible timeout using this format: L4_TIMEOUT_US_MAX = 2^41-1:
299 * e = 31, m = 1023 => 2'196'875'771'904 us = 610h 14m 35s.
300 */
301
302 /* Without introducing 'v' we had to type-cast the expression to
303 * l4_uint16_t. This cannot be avoided by declaring m and e_pow_10 as
304 * l4_uint16_t due to C++ integer promotion. */
305 v = (e << 10) | m;
306 return (l4_timeout_s){v};
307 }
308}
309
310#endif
L4 compiler related defines.
l4_uint64_t l4_kernel_clock_t
Kernel clock type.
Definition l4int.h:53
unsigned int l4_uint32_t
Unsigned 32bit value.
Definition l4int.h:29
unsigned short int l4_uint16_t
Unsigned 16bit value.
Definition l4int.h:27
unsigned long long l4_uint64_t
Unsigned 64bit value.
Definition l4int.h:31
L4_CONSTEXPR l4_timeout_s l4_timeout_rel(unsigned man, unsigned exp) L4_NOTHROW
Get relative timeout consisting of mantissa and exponent.
Definition __timeout.h:234
#define L4_IPC_TIMEOUT_NEVER
never timeout
Definition __timeout.h:74
L4_CONSTEXPR void l4_rcv_timeout(l4_timeout_s rcv, l4_timeout_t *to) L4_NOTHROW
Set receive timeout in given to timeout.
Definition __timeout.h:227
L4_CONSTEXPR l4_kernel_clock_t l4_timeout_get(l4_kernel_clock_t cur, l4_timeout_s to) L4_NOTHROW
Get clock value for a clock + a timeout.
Definition __timeout.h:257
#define L4_IPC_TIMEOUT_0
Timeout constants.
Definition __timeout.h:73
#define L4_TIMEOUT_US_NEVER
The waiting period in microseconds which is interpreted as "never" by l4_timeout_from_us().
Definition __timeout.h:85
L4_CONSTEXPR l4_timeout_t l4_ipc_timeout(unsigned snd_man, unsigned snd_exp, unsigned rcv_man, unsigned rcv_exp) L4_NOTHROW
Convert explicit timeout values to l4_timeout_t type.
Definition __timeout.h:203
L4_CONSTEXPR l4_timeout_t l4_timeout(l4_timeout_s snd, l4_timeout_s rcv) L4_NOTHROW
Combine send and receive timeout in a timeout.
Definition __timeout.h:213
L4_CONSTEXPR void l4_snd_timeout(l4_timeout_s snd, l4_timeout_t *to) L4_NOTHROW
Set send timeout in given to timeout.
Definition __timeout.h:220
#define L4_TIMEOUT_US_MAX
The longest waiting period in microseconds accepted by l4_timeout_from_us().
Definition __timeout.h:91
L4_CONSTEXPR unsigned l4_timeout_is_absolute(l4_timeout_s to) L4_NOTHROW
Return whether the given timeout is absolute or not.
Definition __timeout.h:250
L4_CONSTEXPR l4_kernel_clock_t l4_timeout_rel_get(l4_timeout_s to) L4_NOTHROW
Get clock value of out timeout.
Definition __timeout.h:241
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition compiler.h:159
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:51
#define L4_CONSTEXPR
Constexpr function attribute.
Definition compiler.h:190
Basic timeout specification.
Definition __timeout.h:40
l4_uint16_t t
timeout value
Definition __timeout.h:41
Timeout pair.
Definition __timeout.h:53
l4_uint32_t raw
raw value
Definition __timeout.h:54
l4_timeout_s snd
send timeout
Definition __timeout.h:62
l4_timeout_s rcv
receive timeout
Definition __timeout.h:61
struct l4_timeout_t::@32 p
combined timeout