L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
__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 * This file is part of TUD:OS and distributed under the terms of the
13 * GNU General Public License 2.
14 * Please see the COPYING-GPL-2 file for details.
15 *
16 * As a special exception, you may use this file as part of a free software
17 * library without restriction. Specifically, if other files instantiate
18 * templates or use macros or inline functions from this file, or you compile
19 * this file and link it with other files to produce an executable, this
20 * file does not by itself cause the resulting executable to be covered by
21 * the GNU General Public License. This exception does not however
22 * invalidate any other reasons why the executable file might be covered by
23 * the GNU General Public License.
24 */
25#ifndef L4_SYS_TIMEOUT_H__
26#define L4_SYS_TIMEOUT_H__
27
28#include <l4/sys/l4int.h>
29#include <l4/sys/compiler.h>
30
48typedef struct l4_timeout_s {
50} __attribute__((packed)) l4_timeout_s;
51
52
60typedef union l4_timeout_t
61{
63 struct
64 {
65#ifdef __BIG_ENDIAN__
68#else
71#endif
72 } p;
74
75
81#define L4_IPC_TIMEOUT_0 ((l4_timeout_s){0x0400})
82#define L4_IPC_TIMEOUT_NEVER ((l4_timeout_s){0})
83#define L4_IPC_NEVER_INITIALIZER {0}
84#define L4_IPC_NEVER ((l4_timeout_t){0})
85#define L4_IPC_RECV_TIMEOUT_0 ((l4_timeout_t){0x00000400})
86#define L4_IPC_SEND_TIMEOUT_0 ((l4_timeout_t){0x04000000})
87#define L4_IPC_BOTH_TIMEOUT_0 ((l4_timeout_t){0x04000400})
93#define L4_TIMEOUT_US_NEVER (~0ULL)
94
99#define L4_TIMEOUT_US_MAX ((1ULL << 41) - 1)
100
113l4_timeout_s l4_timeout_rel(unsigned man, unsigned exp) L4_NOTHROW;
114
115
126l4_timeout_t l4_ipc_timeout(unsigned snd_man, unsigned snd_exp,
127 unsigned rcv_man, unsigned rcv_exp) L4_NOTHROW;
128
140
150
160
171
172
183
195
204l4_timeout_s l4_timeout_from_us(l4_uint64_t us) L4_NOTHROW;
205
206/*
207 * Implementation
208 */
209
211l4_timeout_t l4_ipc_timeout(unsigned snd_man, unsigned snd_exp,
212 unsigned rcv_man, unsigned rcv_exp) L4_NOTHROW
213{
214 l4_uint16_t snd = (snd_man & 0x3ff) | ((snd_exp << 10) & 0x7c00);
215 l4_uint16_t rcv = (rcv_man & 0x3ff) | ((rcv_exp << 10) & 0x7c00);
216 return l4_timeout((l4_timeout_s){snd}, (l4_timeout_s){rcv});
217}
218
219
222{
223 return (l4_timeout_t){ ((l4_uint32_t){snd.t} << 16) | rcv.t };
224}
225
226
229{
230 to->p.snd = snd;
231}
232
233
236{
237 to->p.rcv = rcv;
238}
239
240
242l4_timeout_s l4_timeout_rel(unsigned man, unsigned exp) L4_NOTHROW
243{
244 return (l4_timeout_s){(l4_uint16_t)((man & 0x3ff) | ((exp << 10) & 0x7c00))};
245}
246
247
250{
251 if (to.t == 0)
252 return ~0ULL;
253 return (l4_kernel_clock_t)(to.t & 0x3ff) << ((to.t >> 10) & 0x1f);
254}
255
256
259{
260 return to.t & 0x8000;
261}
262
263
266{
268 return 0; /* We cannot retrieve the value ... */
269 else
270 return cur + l4_timeout_rel_get(to);
271}
272
274l4_timeout_s l4_timeout_from_us(l4_uint64_t us) L4_NOTHROW
275{
276 if (us == 0)
277 return L4_IPC_TIMEOUT_0;
278 else if (us == L4_TIMEOUT_US_NEVER || us > L4_TIMEOUT_US_MAX)
280 else
281 {
282 /* Here it is certain that at least one bit in 'us' is set. */
283
284 l4_uint16_t m = 0; // initialization required by constexpr, optimized away
285 l4_uint16_t v = 0; // initialization required by constexpr, optimized away
286 int e = (63 - __builtin_clzll(us)) - 9;
287 if (e < 0)
288 e = 0;
289
290 /* Here it is certain that '0 <= e <= 31' and '1 <= 2^e <= 2^31':
291 * L4_TIMEOUT_US_MAX = 2^41-1 = 0x000001ffffffffff => e = 31.
292 * Note: 2^41-1 (0x000001ffffffffff) > 1023*2^31 (0x00001ff800000000). */
293
294 m = us >> e;
295
296 /* Here it is certain that '1 <= m <= 1023. Consider the following cases:
297 * o 1 <= us <= 1023: e = 0; 2^e = 1; 1 <= us/1 <= 1023
298 * o 1024 <= us <= 2047: e = 1; 2^e = 2; 512 <= us/2 <= 1023
299 * o 2048 <= us <= 4095: e = 2; 2^e = 4; 512 <= us/4 <= 1023
300 * ...
301 * o 2^31 <= us <= 2^32-1: e = 22; 512 <= us/2^22 <= 1023
302 * o 2^40 <= us <= 2^41-1: e = 31; 512 <= us/2^31 <= 1023
303 *
304 * Dividing by (1<<e) ensures that for all us < 2^41: m < 2^10.
305 *
306 * Maximum possible timeout using this format: L4_TIMEOUT_US_MAX = 2^41-1:
307 * e = 31, m = 1023 => 2'196'875'771'904 us = 610h 14m 35s.
308 */
309
310 /* Without introducing 'v' we had to type-cast the expression to
311 * l4_uint16_t. This cannot be avoided by declaring m and e_pow_10 as
312 * l4_uint16_t due to C++ integer promotion. */
313 v = (e << 10) | m;
314 return (l4_timeout_s){v};
315 }
316}
317
318#endif
L4 compiler related defines.
l4_uint64_t l4_kernel_clock_t
Kernel clock type.
Definition l4int.h:64
unsigned int l4_uint32_t
Unsigned 32bit value.
Definition l4int.h:40
unsigned short int l4_uint16_t
Unsigned 16bit value.
Definition l4int.h:38
unsigned long long l4_uint64_t
Unsigned 64bit value.
Definition l4int.h:42
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:242
#define L4_IPC_TIMEOUT_NEVER
never timeout
Definition __timeout.h:82
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:235
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:265
#define L4_IPC_TIMEOUT_0
Timeout constants.
Definition __timeout.h:81
#define L4_TIMEOUT_US_NEVER
The waiting period in microseconds which is interpreted as "never" by l4_timeout_from_us().
Definition __timeout.h:93
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:211
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:221
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:228
#define L4_TIMEOUT_US_MAX
The longest waiting period in microseconds accepted by l4_timeout_from_us().
Definition __timeout.h:99
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:258
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:249
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition compiler.h:188
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:62
#define L4_CONSTEXPR
Constexpr function attribute.
Definition compiler.h:211
Basic timeout specification.
Definition __timeout.h:48
l4_uint16_t t
timeout value
Definition __timeout.h:49
Timeout pair.
Definition __timeout.h:61
l4_uint32_t raw
raw value
Definition __timeout.h:62
l4_timeout_s snd
send timeout
Definition __timeout.h:70
struct l4_timeout_t::@68 p
combined timeout
l4_timeout_s rcv
receive timeout
Definition __timeout.h:69