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
47typedef struct l4_timeout_s {
49} __attribute__((packed)) l4_timeout_s;
50
51
59typedef union l4_timeout_t {
61 struct
62 {
63#ifdef __BIG_ENDIAN__
66#else
69#endif
70 } p;
72
73
79#define L4_IPC_TIMEOUT_0 ((l4_timeout_s){0x0400})
80#define L4_IPC_TIMEOUT_NEVER ((l4_timeout_s){0})
81#define L4_IPC_NEVER_INITIALIZER {0}
82#define L4_IPC_NEVER ((l4_timeout_t){0})
83#define L4_IPC_RECV_TIMEOUT_0 ((l4_timeout_t){0x00000400})
84#define L4_IPC_SEND_TIMEOUT_0 ((l4_timeout_t){0x04000000})
85#define L4_IPC_BOTH_TIMEOUT_0 ((l4_timeout_t){0x04000400})
91#define L4_TIMEOUT_US_NEVER (~0U)
92
96#define L4_TIMEOUT_US_MAX (~0U - 1)
97
110l4_timeout_s l4_timeout_rel(unsigned man, unsigned exp) L4_NOTHROW;
111
112
123l4_timeout_t l4_ipc_timeout(unsigned snd_man, unsigned snd_exp,
124 unsigned rcv_man, unsigned rcv_exp) L4_NOTHROW;
125
137
147
157
168
169
180
192
201l4_timeout_s l4_timeout_from_us(l4_uint32_t us) L4_NOTHROW;
202
203/*
204 * Implementation
205 */
206
208l4_timeout_t l4_ipc_timeout(unsigned snd_man, unsigned snd_exp,
209 unsigned rcv_man, unsigned rcv_exp) L4_NOTHROW
210{
211 l4_timeout_t t;
212 t.p.snd.t = (snd_man & 0x3ff) | ((snd_exp << 10) & 0x7c00);
213 t.p.rcv.t = (rcv_man & 0x3ff) | ((rcv_exp << 10) & 0x7c00);
214 return t;
215}
216
217
220{
221 l4_timeout_t t;
222 t.p.snd = snd;
223 t.p.rcv = rcv;
224 return t;
225}
226
227
230{
231 to->p.snd = snd;
232}
233
234
237{
238 to->p.rcv = rcv;
239}
240
241
243l4_timeout_s l4_timeout_rel(unsigned man, unsigned exp) L4_NOTHROW
244{
245 return (l4_timeout_s){(l4_uint16_t)((man & 0x3ff) | ((exp << 10) & 0x7c00))};
246}
247
248
251{
252 if (to.t == 0)
253 return ~0ULL;
254 return (l4_kernel_clock_t)(to.t & 0x3ff) << ((to.t >> 10) & 0x1f);
255}
256
257
260{
261 return to.t & 0x8000;
262}
263
264
267{
269 return 0; /* We cannot retrieve the value ... */
270 else
271 return cur + l4_timeout_rel_get(to);
272}
273
275l4_timeout_s l4_timeout_from_us(l4_uint32_t us) L4_NOTHROW
276{
277 static_assert(sizeof(us) <= 4,
278 "Verify the correctness of log2(us) and the number of bits for e!");
279 l4_timeout_s t;
280 if (us == 0)
282 else if (us == L4_TIMEOUT_US_NEVER)
284 else
285 {
286 /* Here it is certain that at least one bit in 'us' is set. */
287
288 unsigned m;
289 int e = (31 - __builtin_clz(us)) - 9;
290 if (e < 0) e = 0;
291
292 /* Here it is certain that '0 <= e <= 22' and '1 <= 2^e <= 2^22'. */
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 *
303 * Dividing by (1<<e) ensures that for all us < 2^32: m < 2^10.
304 *
305 * What about sizeof(us) == 8? 'e = log2(us) - 9':
306 * o 2^63 <= us <= 2^64-1: e = 54; 512 <= us/2^54 <= 1023.
307 *
308 * That means that this function would even work for 64-bit values of
309 * 'us' as long as __builtin_clz(us) works correctly for that range.
310 * But the number of bits available for the exponent is limited:
311 * o bits 0..9 (10 bits) are used for 'm'
312 * o bits 10..14 (5 bits) are used for 'e'
313 * o bit 15 is used to distinguish between absolute timeouts and
314 * relative timeouts (see l4_timeout_is_absolute())
315 *
316 * That means 'e <= 31' and thus it's not possible to encode timeouts
317 * represented by 64-bit values.
318 */
319
320 t.t = (e << 10) | m;
321 }
322 return t;
323}
324
325#endif
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
#define L4_IPC_TIMEOUT_NEVER
never timeout
Definition __timeout.h:80
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:208
#define L4_IPC_TIMEOUT_0
Timeout constants.
Definition __timeout.h:79
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:266
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:219
#define L4_TIMEOUT_US_NEVER
The waiting period in microseconds which is interpreted as "never" by l4_timeout_from_us().
Definition __timeout.h:91
void l4_snd_timeout(l4_timeout_s snd, l4_timeout_t *to) L4_NOTHROW
Set send timeout in given to timeout.
Definition __timeout.h:229
void l4_rcv_timeout(l4_timeout_s rcv, l4_timeout_t *to) L4_NOTHROW
Set receive timeout in given to timeout.
Definition __timeout.h:236
l4_kernel_clock_t l4_timeout_rel_get(l4_timeout_s to) L4_NOTHROW
Get clock value of out timeout.
Definition __timeout.h:250
unsigned l4_timeout_is_absolute(l4_timeout_s to) L4_NOTHROW
Return whether the given timeout is absolute or not.
Definition __timeout.h:259
l4_timeout_s l4_timeout_rel(unsigned man, unsigned exp) L4_NOTHROW
Get relative timeout consisting of mantissa and exponent.
Definition __timeout.h:243
#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
Basic timeout specification.
Definition __timeout.h:47
l4_uint16_t t
timeout value
Definition __timeout.h:48
Timeout pair.
Definition __timeout.h:59
l4_uint32_t raw
raw value
Definition __timeout.h:60
struct l4_timeout_t::@16 p
combined timeout
l4_timeout_s snd
send timeout
Definition __timeout.h:68
l4_timeout_s rcv
receive timeout
Definition __timeout.h:67