Alchemy fixes around timeouts
cover Alchemy fixes around timeouts
See patches for details
Jan
Jan Kiszka (4):
lib/alchemy: Fix rt_pipe_read* with timeouts lib/alchemy/testsuite: Fix pipe-1 test case lib/alchemy/testsuite: Extend pipe-1 test by timeout checks lib/alchemy: Fix/clarify documentation of *_timed functions regarding
abs_timeout
include/alchemy/pipe.h | 8 +---- lib/alchemy/buffer.c | 28 ++++++---------- lib/alchemy/cond.c | 14 +++----- lib/alchemy/event.c | 16 ++++----- lib/alchemy/heap.c | 16 ++++----- lib/alchemy/mutex.c | 12 +++---- lib/alchemy/pipe.c | 61 +++++++++++++++++++++++++++------- lib/alchemy/queue.c | 32 +++++++----------- lib/alchemy/sem.c | 16 ++++----- lib/alchemy/task.c | 27 ++++++--------- lib/alchemy/testsuite/pipe-1.c | 35 ++++++++++++++++++- 11 files changed, 143 insertions(+), 122 deletions(-)
Signature · 1 line
2.31.1
PATCH 1/4 lib/alchemy: Fix rt_pipe_read* with timeouts
From: Jan Kiszka <[email protected]>
The underlying IPC driver takes relative timeouts, but rt_pipe_read_timed so far submitted absolute ones. This fixes this function and also adds a non-inline rt_pipe_read to avoid pointless conversions from relative to absolute and then to relative again.
--- include/alchemy/pipe.h | 8 +------- lib/alchemy/pipe.c | 45 ++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 9 deletions(-)
include/alchemy/pipe.h +1 -7
@@ -64,14 +64,8 @@ ssize_t rt_pipe_read_until(RT_PIPE *pipe, alchemy_abs_timeout(timeout, &ts)); } -static inline ssize_t rt_pipe_read (RT_PIPE *pipe, -void *buf,size_t size,RTIME timeout) -{ -struct timespec ts; -return rt_pipe_read_timed (pipe, buf, size, -alchemy_rel_timeout (timeout, &ts)); -} +void *buf,size_t size,RTIME timeout);ssize_t rt_pipe_write (RT_PIPE *pipe,const void *buf,size_t size,int mode);
lib/alchemy/pipe.c +43 -2
63 lines not on this page · raw message
Signature · 1 line
2.31.1
PATCH 2/4 lib/alchemy/testsuite: Fix pipe-1 test case
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
A missing initialization led to early termination and crashes.
--- lib/alchemy/testsuite/pipe-1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/alchemy/testsuite/pipe-1.c +1 -1
@@ -23,7 +23,7 @@ struct pipe_message {static void realtime_task (void *arg) {struct pipe_message m; -int ret, seq; +int ret, seq =0 ;traceobj_enter (&trobj);
Signature · 1 line
2.31.1
PATCH 3/4 lib/alchemy/testsuite: Extend pipe-1 test by timeout checks
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
Validates all three rt_pipe_read functions /wrt non-blocking read as well as timeouts.
--- lib/alchemy/testsuite/pipe-1.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
lib/alchemy/testsuite/pipe-1.c +33 -0
@@ -73,7 +73,10 @@ static void *regular_thread(void *arg)int main (int argc,char *const argv[]) { +struct timespec ts_start, ts_end, ts_timeout, ts_delta;struct pipe_message m; +RTIME start, end; +SRTIME timeout;int ret;traceobj_init (&trobj, argv[0 ],0 );
@@ -97,6 +100,36 @@ int main(int argc, char *const argv[]) ret =rt_pipe_read (&mpipe, &m,sizeof (m),TM_NONBLOCK );traceobj_check (&trobj, ret, -EWOULDBLOCK ); + ret =rt_pipe_read_until (&mpipe, &m,sizeof (m),TM_NONBLOCK ); +traceobj_check (&trobj, ret, -EWOULDBLOCK ); + + ts_timeout.tv_sec =0 ; + ts_timeout.tv_nsec =0 ; + ret =rt_pipe_read_timed (&mpipe, &m,sizeof (m), &ts_timeout); +traceobj_check (&trobj, ret, -EWOULDBLOCK ); + + start =rt_timer_read (); + timeout =rt_timer_ns2ticks (100000000 ); + ret =rt_pipe_read (&mpipe, &m,sizeof (m), timeout); + end =rt_timer_read (); +traceobj_assert (&trobj, end - start >= timeout); +traceobj_assert (&trobj, end - start < timeout +rt_timer_ns2ticks (5000000 )); + + start =rt_timer_read (); + timeout = start +rt_timer_ns2ticks (100000000 ); + ret =rt_pipe_read_until (&mpipe, &m,sizeof (m), timeout); + end =rt_timer_read (); +traceobj_assert (&trobj, end >= timeout); +traceobj_assert (&trobj, end < timeout +rt_timer_ns2ticks (5000000 )); + +clock_gettime (CLOCK_COPPERPLATE , &ts_start); +timespec_adds (&ts_timeout, &ts_start,100000000 ); + ret =rt_pipe_read_timed (&mpipe, &m,sizeof (m), &ts_timeout); +clock_gettime (CLOCK_COPPERPLATE , &ts_end); +timespec_sub (&ts_delta, &ts_end, &ts_timeout); +traceobj_assert (&trobj, ts_delta.tv_sec >=0 ); +traceobj_assert (&trobj, ts_delta.tv_nsec <5000000 ); + ret =pthread_create (&t_reg,NULL , regular_thread,NULL );traceobj_check (&trobj, ret,0 );
Signature · 1 line
2.31.1
PATCH 4/4 lib/alchemy: Fix/clarify documentation of *_timed functions regarding abs_timeout
In reply to Jan KiszkaFrom: Jan Kiszka <[email protected]>
abs_timeout is not provided in ticks but actually seconds/nanoseconds. Clarify this and remove the related wrong note from those functions headers.
--- lib/alchemy/buffer.c | 28 ++++++++++------------------ lib/alchemy/cond.c | 14 +++++--------- lib/alchemy/event.c | 16 ++++++---------- lib/alchemy/heap.c | 16 ++++++---------- lib/alchemy/mutex.c | 12 ++++-------- lib/alchemy/pipe.c | 16 ++++++---------- lib/alchemy/queue.c | 32 ++++++++++++-------------------- lib/alchemy/sem.c | 16 ++++++---------- lib/alchemy/task.c | 27 ++++++++++----------------- 9 files changed, 65 insertions(+), 112 deletions(-)
lib/alchemy/buffer.c +10 -18
@@ -396,12 +396,12 @@ out:* error value. However, short reads are allowed when a potential * deadlock situation is detected (see note below). * -* @param abs_timeout An absolute date expressed in clock ticks, -* specifying a time limit to wait for a message to be available from -* the buffer (see note). Passing NULL causes the caller to block -* indefinitely until enough data is available. Passing { .tv_sec = 0, -* .tv_nsec = 0 } causes the service to return immediately without -* blocking in case not enough data is available. +* @param abs_timeout An absolute date expressed in seconds / nanoseconds, +* based on the Alchemy clock, specifying a time limit to wait for a +* message to be available from the buffer. Passing NULL causes the caller +* to block indefinitely until enough data is available. Passing +* { .tv_sec = 0, .tv_nsec = 0 } causes the service to return immediately +* without blocking in case not enough data is available. * * @return The number of bytes read from the buffer is returned upon * success. Otherwise:
@@ -449,10 +449,6 @@ out:* should likely be fixed, in order to eliminate such condition. * * @apitags{xthread-nowait, switch-primary} -* -* @note @a abs_timeout is interpreted as a multiple of the Alchemy -* clock resolution (see --alchemy-clock-resolution option, defaults -* to 1 nanosecond). */ ssize_t rt_buffer_read_timed(RT_BUFFER *bf, void *ptr, size_t size,
@@ -638,10 +634,10 @@ out:* value, in which case the buffer is left untouched, and zero is * returned to the caller. * -* @param abs_timeout An absolute date expressed in clock ticks, -* specifying a time limit to wait for enough buffer space to be -* available to hold the message (see note). Passing NULL causes the -* caller to block indefinitely until enough buffer space is +* @param abs_timeout An absolute date expressed in seconds / nanoseconds, +* based on the Alchemy clock, specifying a time limit to wait for enough +* buffer space to be available to hold the message. Passing NULL causes +* the caller to block indefinitely until enough buffer space is * available. Passing { .tv_sec = 0, .tv_nsec = 0 } causes the service * to return immediately without blocking in case of buffer space * shortage.
@@ -672,10 +668,6 @@ out:* called from a Xenomai thread. * * @apitags{xthread-nowait, switch-primary} -* -* @note @a abs_timeout is interpreted as a multiple of the Alchemy -* clock resolution (see --alchemy-clock-resolution option, defaults -* to 1 nanosecond). */ ssize_t rt_buffer_write_timed(RT_BUFFER *bf, const void *ptr, size_t size,
lib/alchemy/cond.c +5 -9
@@ -332,11 +332,11 @@ int rt_cond_broadcast(RT_COND *cond)* @param mutex The address of the mutex serializing the access to the * shared data. * -* @param abs_timeout An absolute date expressed in clock ticks, -* specifying a time limit to wait for the condition variable to be -* signaled (see note). Passing NULL causes the caller to -* block indefinitely. Passing { .tv_sec = 0, .tv_nsec = 0 } causes -* the caller to return immediately without block. +* @param abs_timeout An absolute date expressed in seconds / nanoseconds, +* based on the Alchemy clock, specifying a time limit to wait for the +* condition variable to be signaled. Passing NULL causes the caller to +* block indefinitely. Passing { .tv_sec = 0, .tv_nsec = 0 } causes the +* caller to return immediately without block. * * @return Zero is returned upon success. Otherwise: *
@@ -360,10 +360,6 @@ int rt_cond_broadcast(RT_COND *cond)* called from a Xenomai thread. * * @apitags{xthread-only, switch-primary} -* -* @note @a abs_timeout is interpreted as a multiple of the Alchemy -* clock resolution (see --alchemy-clock-resolution option, defaults -* to 1 nanosecond). */ int rt_cond_wait_timed (RT_COND *cond,RT_MUTEX *mutex,const struct timespec *abs_timeout)
lib/alchemy/event.c +6 -10
@@ -352,12 +352,12 @@ out:* means that the request is fulfilled when at all bits set into @a * mask are set in the current event mask. * -* @param abs_timeout An absolute date expressed in clock ticks, -* specifying a time limit to wait for the request to be satisfied -* (see note). Passing NULL causes the caller to block indefinitely -* until the request is satisfied. Passing { .tv_sec = 0, .tv_nsec = 0 -* } causes the service to return without blocking in case the request -* cannot be satisfied immediately. +* @param abs_timeout An absolute date expressed in seconds / nanoseconds, +* based on the Alchemy clock, specifying a time limit to wait for the +* request to be satisfied. Passing NULL causes the caller to block +* indefinitely until the request is satisfied. Passing +* { .tv_sec = 0, .tv_nsec = 0 } causes the service to return without +* blocking in case the request cannot be satisfied immediately. * * @return Zero is returned upon success. Otherwise: *
@@ -382,10 +382,6 @@ out:* called from a Xenomai thread. * * @apitags{xthread-nowait, switch-primary} -* -* @note @a abs_timeout value is interpreted as a multiple of the -* Alchemy clock resolution (see --alchemy-clock-resolution option, -* defaults to 1 nanosecond). */ int rt_event_wait_timed(RT_EVENT *event, unsigned int mask, unsigned int *mask_r,
lib/alchemy/heap.c +6 -10
@@ -376,12 +376,12 @@ out:* case, the same block covering the entire heap space is returned to * all callers of this service. * -* @param abs_timeout An absolute date expressed in clock ticks, -* specifying a time limit to wait for a block of the requested size -* to be available from the heap (see note). Passing NULL causes the -* caller to block indefinitely until a block is available. Passing { -* .tv_sec = 0, .tv_nsec = 0 } causes the service to return -* immediately without blocking in case a block is not available. +* @param abs_timeout An absolute date expressed in seconds / nanoseconds, +* based on the Alchemy clock, specifying a time limit to wait for a block +* of the requested size to be available from the heap. Passing NULL causes +* the caller to block indefinitely until a block is available. Passing +* { .tv_sec = 0, .tv_nsec = 0 } causes the service to return immediately +* without blocking in case a block is not available. * * @param blockp A pointer to a memory location which will be written * upon success with the address of the allocated block, or the start
@@ -420,10 +420,6 @@ out:* next page size. The allocation page size is currently 512 bytes * long (HOBJ_PAGE_SIZE), which means that any request larger than 1k * will be rounded up to the next 512 byte boundary. -* -* @note @a abs_timeout is interpreted as a multiple of the Alchemy -* clock resolution (see --alchemy-clock-resolution option, defaults -* to 1 nanosecond). */ int rt_heap_alloc_timed(RT_HEAP *heap, size_t size, const struct timespec *abs_timeout,
lib/alchemy/mutex.c +4 -8
@@ -261,10 +261,10 @@ out:* * @param mutex The mutex descriptor. * -* @param abs_timeout An absolute date expressed in clock ticks, -* specifying a time limit to wait for the mutex to be available (see -* note). Passing NULL the caller to block indefinitely. Passing { -* .tv_sec = 0, .tv_nsec = 0 } causes the service to return +* @param abs_timeout An absolute date expressed in seconds / nanoseconds, +* based on the Alchemy clock, specifying a time limit to wait for the +* mutex to be available. Passing NULL the caller to block indefinitely. +* Passing { .tv_sec = 0, .tv_nsec = 0 } causes the service to return * immediately without blocking in case @a mutex is already locked by * another task. *
@@ -294,10 +294,6 @@ out:* Over the Cobalt core, an Alchemy task with priority zero keeps * running in primary mode until it releases the mutex, at which point * it is switched back to secondary mode automatically. -* -* @note @a abs_timeout is interpreted as a multiple of the Alchemy -* clock resolution (see --alchemy-clock-resolution option, defaults -* to 1 nanosecond). */ int rt_mutex_acquire_timed (RT_MUTEX *mutex,const struct timespec *abs_timeout)
lib/alchemy/pipe.c +6 -10
@@ -393,12 +393,12 @@ ssize_t rt_pipe_read(RT_PIPE *pipe,* be lost. If @a size is zero, this call returns immediately with no * other action. * -* @param abs_timeout An absolute date expressed in clock ticks, -* specifying a time limit to wait for a message to be available from -* the pipe (see note). Passing NULL causes the caller to block -* indefinitely until a message is available. Passing { .tv_sec = 0, -* .tv_nsec = 0 } causes the service to return immediately without -* blocking in case no message is available. +* @param abs_timeout An absolute date expressed in seconds / nanoseconds, +* based on the Alchemy clock, specifying a time limit to wait for a +* message to be available from the pipe. Passing NULL causes the caller +* to block indefinitely until a message is available. Passing +* { .tv_sec = 0, .tv_nsec = 0 } causes the service to return immediately +* without blocking in case no message is available. * * @return The number of bytes available from the received message is * returned upon success. Otherwise:
@@ -423,10 +423,6 @@ ssize_t rt_pipe_read(RT_PIPE *pipe,* called from a Xenomai thread. * * @apitags{xthread-nowait, switch-primary} -* -* @note @a abs_timeout is interpreted as a multiple of the Alchemy -* clock resolution (see --alchemy-clock-resolution option, defaults -* to 1 nanosecond). */ ssize_t rt_pipe_read_timed(RT_PIPE *pipe, void *buf, size_t size,
lib/alchemy/queue.c +12 -20
@@ -764,12 +764,12 @@ out:* with the address of the received message, upon success. Once * consumed, the message space should be freed using rt_queue_free(). * -* @param abs_timeout An absolute date expressed in clock ticks, -* specifying a time limit to wait for a message to be available from -* the queue (see note). Passing NULL causes the caller to block -* indefinitely until a message is available. Passing { .tv_sec = 0, -* .tv_nsec = 0 } causes the service to return immediately without -* blocking in case no message is available. +* @param abs_timeout An absolute date expressed in seconds / nanoseconds, +* based on the Alchemy clock, specifying a time limit to wait for a +* message to be available from the queue. Passing NULL causes the caller +* to block indefinitely until a message is available. Passing +* { .tv_sec = 0, .tv_nsec = 0 } causes the service to return immediately +* without blocking in case no message is available. * * @return The number of bytes available from the received message is * returned upon success. Zero is a possible value corresponding to a
@@ -796,10 +796,6 @@ out:* called from a Xenomai thread. * * @apitags{xthread-nowait, switch-primary} -* -* @note @a abs_timeout is interpreted as a multiple of the Alchemy -* clock resolution (see --alchemy-clock-resolution option, defaults -* to 1 nanosecond). */ ssize_t rt_queue_receive_timed (RT_QUEUE *queue,void **bufp,const struct timespec *abs_timeout)
@@ -929,12 +925,12 @@ out:* @param size The length in bytes of the memory area pointed to by @a * buf. Messages larger than @a size are truncated appropriately. * -* @param abs_timeout An absolute date expressed in clock ticks, -* specifying a time limit to wait for a message to be available from -* the queue (see note). Passing NULL causes the caller to block -* indefinitely until a message is available. Passing { .tv_sec = 0, -* .tv_nsec = 0 } causes the service to return immediately without -* blocking in case no message is available. +* @param abs_timeout An absolute date expressed in seconds / nanoseconds, +* based on the Alchemy clock, specifying a time limit to wait for a +* message to be available from the queue. Passing NULL causes the +* caller to block indefinitely until a message is available. Passing +* { .tv_sec = 0, .tv_nsec = 0 } causes the service to return immediately +* without blocking in case no message is available. * * @return The number of bytes copied to @a buf is returned upon * success. Zero is a possible value corresponding to a zero-sized
@@ -960,10 +956,6 @@ out:* called from a Xenomai thread. * * @apitags{xthread-nowait, switch-primary} -* -* @note @a abs_timeout is interpreted as a multiple of the Alchemy -* clock resolution (see --alchemy-clock-resolution option, defaults -* to 1 nanosecond). */ ssize_t rt_queue_read_timed(RT_QUEUE *queue, void *buf, size_t size,
lib/alchemy/sem.c +6 -10
@@ -336,12 +336,12 @@ out:* * @param sem The semaphore descriptor. * -* @param abs_timeout An absolute date expressed in clock ticks, -* specifying a time limit to wait for the request to be satisfied -* (see note). Passing NULL causes the caller to block indefinitely -* until the request is satisfied. Passing { .tv_sec = 0, .tv_nsec = 0 -* } causes the service to return without blocking in case the request -* cannot be satisfied immediately. +* @param abs_timeout An absolute date expressed in seconds / nanoseconds, +* based on the Alchemy clock, specifying a time limit to wait for the +* request to be satisfied. Passing NULL causes the caller to block +* indefinitely until the request is satisfied. Passing { .tv_sec = 0, +* .tv_nsec = 0 } causes the service to return without blocking in case +* the request cannot be satisfied immediately. * * @return Zero is returned upon success. Otherwise: *
@@ -365,10 +365,6 @@ out:* called from a Xenomai thread. * * @apitags{xthread-nowait, switch-primary} -* -* @note @a abs_timeout is interpreted as a multiple of the Alchemy -* clock resolution (see --alchemy-clock-resolution option, defaults -* to 1 nanosecond). */ int rt_sem_p_timed (RT_SEM *sem,const struct timespec *abs_timeout) {
lib/alchemy/task.c +10 -17
@@ -1678,13 +1678,13 @@ out:* Upon return, mcb_r->opcode will contain the status code sent back * from the remote task using rt_task_reply(), or zero if unspecified. * -* @param abs_timeout An absolute date expressed in clock ticks, -* specifying a time limit to wait for the recipient task to reply to -* the initial message (see note). Passing NULL causes the caller to -* block indefinitely until a reply is received. Passing { .tv_sec = -* 0, .tv_nsec = 0 } causes the service to return without blocking in -* case the recipient task is not waiting for messages at the time of -* the call. +* @param abs_timeout An absolute date expressed in seconds / nanoseconds, +* based on the Alchemy clock, specifying a time limit to wait for the +* recipient task to reply to the initial message. Passing NULL causes +* the caller to block indefinitely until a reply is received. Passing +* { .tv_sec = 0, .tv_nsec = 0 } causes the service to return without +* blocking in case the recipient task is not waiting for messages at +* the time of the call. * * @return A positive value is returned upon success, representing the * length (in bytes) of the reply message returned by the remote
@@ -1714,10 +1714,6 @@ out:* task. * * @apitags{xthread-only, switch-primary} -* -* @note @a abs_timeout is interpreted as a multiple of the Alchemy -* clock resolution (see --alchemy-clock-resolution option, defaults -* to 1 nanosecond). */ ssize_t rt_task_send_timed(RT_TASK *task, RT_TASK_MCB *mcb_s, RT_TASK_MCB *mcb_r,
@@ -1892,8 +1888,9 @@ out:* Upon return, mcb_r->opcode will contain the operation code sent * from the remote task using rt_task_send(). * -* @param abs_timeout The number of clock ticks to wait for receiving -* a message (see note). Passing NULL causes the caller to block +* @param abs_timeout An absolute date expressed in seconds / nanoseconds, +* based on the Alchemy clock, specifying the time limit to wait for +* receiving a message. Passing NULL causes the caller to block * indefinitely until a remote task eventually sends a message. * Passing { .tv_sec = 0, .tv_nsec = 0 } causes the service to return * immediately without waiting if no remote task is currently waiting
@@ -1921,10 +1918,6 @@ out:* timeout. * * @apitags{xthread-only, switch-primary} -* -* @note @a abs_timeout is interpreted as a multiple of the Alchemy -* clock resolution (see --alchemy-clock-resolution option, defaults -* to 1 nanosecond). */ int rt_task_receive_timed (RT_TASK_MCB *mcb_r,const struct timespec *abs_timeout)
Signature · 1 line
2.31.1