rt_task_sleep_until question
Hi,
I've noticed that threads which, in my ignorant opinion, are supposed to be sleeping, get woken up much earlier than I expect them to be.
Please find attached a modified version of the trivial-periodic.c application, which creates a RT_TASK that should sleep as long as possible (i.e. until unblocked by a signal handler). However, the task gets woken up much earlier (and many times) _before_ that time it seems.
head /tmp/app.txtcurrent_time = 1207928393295939429
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 1, return code = -110current_time = 1207928393296000379
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 2, return code = -110current_time = 1207928393296005409
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 3, return code = -110current_time = 1207928393296009604
What did I overlook here?
Thx,
Klaas
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <sys/mman.h>
#include <native/task.h>
#include <native/timer.h>
RT_TASK demo_task;
char stop_timer=0;
#define TIMEVAL_MAX ~(RTIME)0
void demo(void *arg)
{
int ret;
int errors = 0;
do{
do{
printf("current_time = %llu\n",rt_timer_read());
printf("sleep until %llu\n", TIMEVAL_MAX);
}while ((ret = rt_task_sleep_until(TIMEVAL_MAX)) == 0);
// if (ret == -ETIMEDOUT){
printf("[TIMERLOOP] Total errors = %d, return code = %d\n",++errors,ret);
// } }while (!(stop_timer && ret == -EINTR));
printf("End of TimerLoop, code %d, Total errors = %d\n",ret,errors);
}
void catch_signal(int sig)
{
stop_timer = 1;
rt_task_unblock(&demo_task);
}
int main(int argc, char* argv[])
{
signal(SIGTERM, catch_signal);
signal(SIGINT, catch_signal);
/* Avoids memory swapping for this program */
mlockall(MCL_CURRENT|MCL_FUTURE);
/*
* Arguments: &task,
* name, * stack size (0=default), * priority, * mode (FPU, start suspended, ...)
*/
rt_task_create(&demo_task, "sleeping forever", 0, 50, 0);
/*
* Arguments: &task,
* task function,
* function argument
*/
rt_task_start(&demo_task, &demo, NULL);
pause();
rt_task_delete(&demo_task);
}
Quoted 23 lines · Klaas Gadeyne
Hi,
I've noticed that threads which, in my ignorant opinion, are supposed to be sleeping, get woken up much earlier than I expect them to be.
Please find attached a modified version of the
trivial-periodic.capplication, which creates aRT_TASKthat should sleep as long as possible (i.e. until unblocked by a signal handler). However, the task gets woken up much earlier (and many times) _before_ that time it seems.head
/tmp/app.txtcurrent_time= 1207928393295939429
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 1, return code = -110current_time= 1207928393296000379
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 2, return code = -110current_time= 1207928393296005409
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 3, return code = -110current_time= 1207928393296009604
Quoted 1 line
What did I overlook here?
Probably an overflow issue: (RTIME)~0 will be converted to TSCs, and if your box runs at > 1GHZ, the result of this conversion will by something < (RTIME)~0 due to the overflow. And this can result in an absolute timeout date (in TSC units) before the current date -> ETIMEDOUT. Can you confirm this?
Jan
Quoted 22 lines
Quoted 21 lines · Klaas Gadeyne
I've noticed that threads which, in my ignorant opinion, are supposed to be sleeping, get woken up much earlier than I expect them to be.
Please find attached a modified version of the
trivial-periodic.capplication, which creates aRT_TASKthat should sleep as long as possible (i.e. until unblocked by a signal handler). However, the task gets woken up much earlier (and many times) _before_ that time it seems.head
/tmp/app.txtcurrent_time= 1207928393295939429
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 1, return code = -110current_time= 1207928393296000379
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 2, return code = -110current_time= 1207928393296005409
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 3, return code = -110current_time= 1207928393296009604
Quoted 7 lines
Quoted 1 line
What did I overlook here?
Probably an overflow issue: (RTIME)~0 will be converted to TSCs, and if your box runs at > 1GHZ, the result of this conversion will by something < (RTIME)~0 due to the overflow. And this can result in an absolute timeout date (in TSC units) before the current date -> ETIMEDOUT. Can you confirm this?
I have no linux box at hand, but I noticed that [*] xntimer_do_start_aperiodic() passes its xnticks_t interval argument (which is an unsigned long long) to xnarch_ns_to_tsc, and that one expects a (signed) long long.
If I did not make any calculation errors (a very small chance...) in "my" case "interval" > LLONG_MAX so there's already an overflow there.
More on monday. Thx!
Klaas
[*]
<http://www.rts.uni-hannover.de/xenomai/lxr/source/ksrc/nucleus/timer.c?v=SVN-2.3.x#095>
<http://www.rts.uni-hannover.de/xenomai/lxr/source/include/asm-generic/system.h?v=SVN-2.3.x#174>
Quoted 30 lines · [email protected] wrote:
Quoted 22 lines
Quoted 21 lines · Klaas Gadeyne
I've noticed that threads which, in my ignorant opinion, are supposed to be sleeping, get woken up much earlier than I expect them to be.
Please find attached a modified version of the
trivial-periodic.capplication, which creates aRT_TASKthat should sleep as long as possible (i.e. until unblocked by a signal handler). However, the task gets woken up much earlier (and many times) _before_ that time it seems.head
/tmp/app.txtcurrent_time= 1207928393295939429
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 1, return code = -110current_time= 1207928393296000379
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 2, return code = -110current_time= 1207928393296005409
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 3, return code = -110current_time= 1207928393296009604Quoted 7 lines
Quoted 1 line
What did I overlook here?
Probably an overflow issue: (RTIME)~0 will be converted to TSCs, and if your box runs at > 1GHZ, the result of this conversion will by something < (RTIME)~0 due to the overflow. And this can result in an absolute timeout date (in TSC units) before the current date -> ETIMEDOUT. Can you confirm this?
Quoted 7 lines
I have no linux box at hand, but I noticed that [*]
xntimer_do_start_aperiodic()passes itsxnticks_tinterval argument (which is an unsigned long long) toxnarch_ns_to_tsc, and that one expects a (signed) long long.If I did not make any calculation errors (a very small chance...) in "my" case "interval" >
LLONG_MAXso there's already an overflow there.
The problem is that we can not change xnarch_ns_to_tsc to use xnarch_ullimd instead of xnarch_llimd: xnarch_ns_to_tsc may be used to convert negative differences. Anyway, I do not think there is an overflow in llimd, otherwise you would get a processor exception, not a silent truncation (at least on x86). To solve this issue, we should probably switch to saturation arithmetic, but it would probably have a huge impact on performance (and on code also, since we would have to use xnarch_saturated_add(foo, bar) instead of foo + bar).
Signature · 1 line
Gilles.
Quoted 39 lines · Gilles Chanteperdrix
Quoted 30 lines · [email protected] wrote:
Quoted 22 lines
Quoted 21 lines · Klaas Gadeyne
I've noticed that threads which, in my ignorant opinion, are supposed to be sleeping, get woken up much earlier than I expect them to be.
Please find attached a modified version of the
trivial-periodic.capplication, which creates aRT_TASKthat should sleep as long as possible (i.e. until unblocked by a signal handler). However, the task gets woken up much earlier (and many times) _before_ that time it seems.head
/tmp/app.txtcurrent_time= 1207928393295939429
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 1, return code = -110current_time= 1207928393296000379
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 2, return code = -110current_time= 1207928393296005409
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 3, return code = -110current_time= 1207928393296009604Quoted 7 lines
Quoted 1 line
What did I overlook here?
Probably an overflow issue: (RTIME)~0 will be converted to TSCs, and if your box runs at > 1GHZ, the result of this conversion will by something < (RTIME)~0 due to the overflow. And this can result in an absolute timeout date (in TSC units) before the current date -> ETIMEDOUT. Can you confirm this?
Quoted 7 lines
I have no linux box at hand, but I noticed that [*]
xntimer_do_start_aperiodic()passes itsxnticks_tinterval argument (which is an unsigned long long) toxnarch_ns_to_tsc, and that one expects a (signed) long long.If I did not make any calculation errors (a very small chance...) in "my" case "interval" >
LLONG_MAXso there's already an overflow there.
Quoted 8 lines
The problem is that we can not change
xnarch_ns_to_tscto usexnarch_ullimdinstead ofxnarch_llimd:xnarch_ns_to_tscmay be used to convert negative differences. Anyway, I do not think there is an overflow in llimd, otherwise you would get a processor exception, not a silent truncation (at least on x86). To solve this issue, we should probably switch to saturation arithmetic, but it would probably have a huge impact on performance (and on code also, since we would have to usexnarch_saturated_add(foo, bar)instead of foo + bar).
I see.
I noticed that xnpod_suspend_thread offers the possibility to suspend a thread "indefinitely" (until unblocked) via the (in the 2.4.x API, that is)
xnpod_suspend_thread(thread,XNDELAY,XN_INFINITE,XN_RELATIVE,NULL)
call.
However, since TM_INFINITE (and XN_INFINITE) are both defined as being zero, calls to rt_task_sleep(TM_INFINITE), are intercepted in the implementation of rt_task_sleep [1]. So in the latter case (which I would naively---i.e. without looking at API docs--- read as "sleep for an infinite amount of time), rt_task_sleep() returns *immediately*.
Would it make sense to change the current behaviour of rt_task_sleep(TM_INFINITE) and call xnpod_suspend_thread(thread,XNDELAY,XN_INFINITE,XN_RELATIVE,NULL) instead of returning 0?
One could either do that by
- altering rt_task_sleep()'s behaviour (not returning zero if delay is zero)
- redefining TM_INFINITE
Both changes might "break" existing applications however.
Any thoughts?
Klaas
[1] http://www.rts.uni-hannover.de/xenomai/lxr/source/ksrc/skins/native/task.c#921
Quoted 77 lines · Klaas Gadeyne
Quoted 9 lines · Gilles Chanteperdrix
Quoted 8 lines · [email protected] wrote:
Quoted 8 lines
Quoted 7 lines · Klaas Gadeyne
I've noticed that threads which, in my ignorant opinion, are supposed to be sleeping, get woken up much earlier than I expect them to be.
Please find attached a modified version of the
trivial-periodic.capplication, which creates aRT_TASKthat should sleep as long as possible (i.e. until unblocked by a signal handler). However, the task gets woken up much earlier (and many times) _before_ that timeit
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
seems.
head
/tmp/app.txtcurrent_time= 1207928393295939429
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 1, return code = -110current_time= 1207928393296000379
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 2, return code = -110current_time= 1207928393296005409
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 3, return code = -110current_time= 1207928393296009604Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
What did I overlook here?
Probably an overflow issue: (RTIME)~0 will be converted to TSCs, and
if
Quoted 1 line
Quoted 1 line
Quoted 1 line
your box runs at > 1GHZ, the result of this conversion will by
something
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
< (RTIME)~0 due to the overflow. And this can result in an absolute timeout date (in TSC units) before the current date -> ETIMEDOUT. Can you confirm this?
I have no linux box at hand, but I noticed that [*]
xntimer_do_start_aperiodic()passes itsxnticks_tinterval argument(which
Quoted 4 lines
Quoted 4 lines
is an unsigned long long) to
xnarch_ns_to_tsc, and that one expects a (signed) long long.If I did not make any calculation errors (a very small chance...) in
"my"
Quoted 11 lines
Quoted 1 line
case "interval" >
LLONG_MAXso there's already an overflow there.The problem is that we can not change
xnarch_ns_to_tscto usexnarch_ullimdinstead ofxnarch_llimd:xnarch_ns_to_tscmay be used to convert negative differences. Anyway, I do not think there is an overflow in llimd, otherwise you would get a processor exception, not a silent truncation (at least on x86). To solve this issue, we should probably switch to saturation arithmetic, but it would probably have a huge impact on performance (and on code also, since we would have to usexnarch_saturated_add(foo, bar)instead of foo + bar).I see.
I noticed that
xnpod_suspend_threadoffers the possibility to suspend a thread "indefinitely" (until unblocked) via the (in the 2.4.x API, that is)
xnpod_suspend_thread(thread,XNDELAY,XN_INFINITE,XN_RELATIVE,NULL)call.
However, sinceTM_INFINITE(andXN_INFINITE) are both defined as being zero, calls tort_task_sleep(TM_INFINITE), are intercepted in the implementation ofrt_task_sleep[1]. So in the latter case (which I would naively---i.e. without looking at API docs--- read as "sleep for an infinite amount of time),rt_task_sleep()returns *immediately*.Would it make sense to change the current behaviour of
rt_task_sleep(TM_INFINITE)and callxnpod_suspend_thread(thread,XNDELAY,XN_INFINITE,XN_RELATIVE,NULL)instead of returning 0?
Quoted 8 lines
One could either do that by
- altering rt_task_sleep()'s behaviour (not returning zero if delay is
zero)
- redefiningTM_INFINITEBoth changes might "break" existing applications however.
Any thoughts?
Well, I do not see how applications could find a useful use of the "rt_task_sleep(0) returns 0 immediately" behaviour.
Another useful use of rt_task_sleep(0) could have been to yield processor, like vxworks does, but there is already an rt_task_yield() service for this.
Signature · 1 line
Gilles
Quoted 84 lines · Gilles Chanteperdrix
Quoted 82 lines · Klaas Gadeyne
Quoted 9 lines · Gilles Chanteperdrix
Quoted 8 lines · [email protected] wrote:
Quoted 8 lines
Quoted 7 lines · Klaas Gadeyne
I've noticed that threads which, in my ignorant opinion, are supposed to be sleeping, get woken up much earlier than I expect them to be.
Please find attached a modified version of the
trivial-periodic.capplication, which creates aRT_TASKthat should sleep as long as possible (i.e. until unblocked by a signal handler). However, the task gets woken up much earlier (and many times) _before_ that timeit
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
seems.
head
/tmp/app.txtcurrent_time= 1207928393295939429
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 1, return code = -110current_time= 1207928393296000379
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 2, return code = -110current_time= 1207928393296005409
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 3, return code = -110current_time= 1207928393296009604Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
What did I overlook here?
Probably an overflow issue: (RTIME)~0 will be converted to TSCs, and
if
Quoted 1 line
Quoted 1 line
Quoted 1 line
your box runs at > 1GHZ, the result of this conversion will by
something
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
< (RTIME)~0 due to the overflow. And this can result in an absolute timeout date (in TSC units) before the current date -> ETIMEDOUT. Can you confirm this?
I have no linux box at hand, but I noticed that [*]
xntimer_do_start_aperiodic()passes itsxnticks_tinterval argument(which
Quoted 4 lines
Quoted 4 lines
is an unsigned long long) to
xnarch_ns_to_tsc, and that one expects a (signed) long long.If I did not make any calculation errors (a very small chance...) in
"my"
Quoted 11 lines
Quoted 1 line
case "interval" >
LLONG_MAXso there's already an overflow there.The problem is that we can not change
xnarch_ns_to_tscto usexnarch_ullimdinstead ofxnarch_llimd:xnarch_ns_to_tscmay be used to convert negative differences. Anyway, I do not think there is an overflow in llimd, otherwise you would get a processor exception, not a silent truncation (at least on x86). To solve this issue, we should probably switch to saturation arithmetic, but it would probably have a huge impact on performance (and on code also, since we would have to usexnarch_saturated_add(foo, bar)instead of foo + bar).I see.
I noticed that
xnpod_suspend_threadoffers the possibility to suspend a thread "indefinitely" (until unblocked) via the (in the 2.4.x API, that is)
xnpod_suspend_thread(thread,XNDELAY,XN_INFINITE,XN_RELATIVE,NULL)call.
However, sinceTM_INFINITE(andXN_INFINITE) are both defined as being zero, calls tort_task_sleep(TM_INFINITE), are intercepted in the implementation ofrt_task_sleep[1]. So in the latter case (which I would naively---i.e. without looking at API docs--- read as "sleep for an infinite amount of time),rt_task_sleep()returns *immediately*.Would it make sense to change the current behaviour of
rt_task_sleep(TM_INFINITE)and callxnpod_suspend_thread(thread,XNDELAY,XN_INFINITE,XN_RELATIVE,NULL)instead of returning 0?One could either do that by
- altering rt_task_sleep()'s behaviour (not returning zero if delay is
zero)
- redefiningTM_INFINITE
Quoted 6 lines
Quoted 3 lines
Both changes might "break" existing applications however.
Any thoughts?
Well, I do not see how applications could find a useful use of the "
rt_task_sleep(0)returns 0 immediately" behaviour.
Thinking more about it: there is a useful use, if the sleep duration is the result of rt_time_tsc2ns. Sleeping indefinitely would be a bit counter-intuitive.
Signature · 1 line
Gilles
Quoted 66 lines · Gilles Chanteperdrix
Quoted 64 lines · Gilles Chanteperdrix
Quoted 63 lines · Klaas Gadeyne
Quoted 9 lines · Gilles Chanteperdrix
Quoted 8 lines · [email protected] wrote:
Quoted 8 lines
Quoted 7 lines · Klaas Gadeyne
I've noticed that threads which, in my ignorant opinion, are supposed to be sleeping, get woken up much earlier than I expect them to be.
Please find attached a modified version of the
trivial-periodic.capplication, which creates aRT_TASKthat should sleep as long as possible (i.e. until unblocked by a signal handler). However, the task gets woken up much earlier (and many times) _before_ that timeit
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
seems.
head
/tmp/app.txtcurrent_time= 1207928393295939429
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 1, return code = -110current_time= 1207928393296000379
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 2, return code = -110current_time= 1207928393296005409
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 3, return code = -110current_time= 1207928393296009604Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
What did I overlook here?
Probably an overflow issue: (RTIME)~0 will be converted to TSCs, and
if
Quoted 1 line
Quoted 1 line
Quoted 1 line
your box runs at > 1GHZ, the result of this conversion will by
something
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
< (RTIME)~0 due to the overflow. And this can result in an absolute timeout date (in TSC units) before the current date -> ETIMEDOUT. Can you confirm this?
I have no linux box at hand, but I noticed that [*]
xntimer_do_start_aperiodic()passes itsxnticks_tinterval argument(which
Quoted 4 lines
Quoted 4 lines
is an unsigned long long) to
xnarch_ns_to_tsc, and that one expects a (signed) long long.If I did not make any calculation errors (a very small chance...) in
"my"
Quoted 11 lines
Quoted 1 line
case "interval" >
LLONG_MAXso there's already an overflow there.The problem is that we can not change
xnarch_ns_to_tscto usexnarch_ullimdinstead ofxnarch_llimd:xnarch_ns_to_tscmay be used to convert negative differences. Anyway, I do not think there is an overflow in llimd, otherwise you would get a processor exception, not a silent truncation (at least on x86). To solve this issue, we should probably switch to saturation arithmetic, but it would probably have a huge impact on performance (and on code also, since we would have to usexnarch_saturated_add(foo, bar)instead of foo + bar).I see.
I noticed that
xnpod_suspend_threadoffers the possibility to suspend a thread "indefinitely" (until unblocked) via the (in the 2.4.x API, that is)
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
xnpod_suspend_thread(thread,XNDELAY,XN_INFINITE,XN_RELATIVE,NULL)call.
However, sinceTM_INFINITE(andXN_INFINITE) are both defined as being zero, calls tort_task_sleep(TM_INFINITE), are intercepted in the implementation ofrt_task_sleep[1]. So in the latter case (which I would naively---i.e. without looking at API docs--- read as "sleep for an infinite amount of time),rt_task_sleep()returns *immediately*.
This behaviour is explicitly stated in the doc, though. So people should not be surprised.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Would it make sense to change the current behaviour of
rt_task_sleep(TM_INFINITE)and callxnpod_suspend_thread(thread,XNDELAY,XN_INFINITE,XN_RELATIVE,NULL)instead of returning 0?One could either do that by
- altering rt_task_sleep()'s behaviour (not returning zero if delay is
zero)
- redefiningTM_INFINITE
No way. You don't want to change "magic" values that lightly. This is why they are magic in the first place.
Quoted 12 lines
Quoted 7 lines
Quoted 4 lines
Both changes might "break" existing applications however.
Any thoughts?
Well, I do not see how applications could find a useful use of the "
rt_task_sleep(0)returns 0 immediately" behaviour.Thinking more about it: there is a useful use, if the sleep duration is the result of
rt_time_tsc2ns. Sleeping indefinitely would be a bit counter-intuitive.
Aside of this, the API has to be orthogonal, and having rt_task_sleep behave as rt_task_suspend is also counter-intuitive. Think about applications doing tick arithmetics to determine the remaining sleep time; at some point, they might hang unexpectedly with delay == 0 == TM_INFINITE.
Signature · 1 line
Philippe.
Quoted 11 lines · Philippe Gerum
Quoted 4 lines · Gilles Chanteperdrix
Thinking more about it: there is a useful use, if the sleep duration is the result of
rt_time_tsc2ns. Sleeping indefinitely would be a bit counter-intuitive.Aside of this, the API has to be orthogonal, and having
rt_task_sleepbehave asrt_task_suspendis also counter-intuitive. Think about applications doing tick arithmetics to determine the remaining sleep time; at some point, they might hang unexpectedly with delay == 0 ==TM_INFINITE.
We agree, this is what I was trying to say.
Signature · 1 line
Gilles
Quoted 76 lines · Philippe Gerum
Quoted 66 lines · Gilles Chanteperdrix
Quoted 64 lines · Gilles Chanteperdrix
Quoted 63 lines · Klaas Gadeyne
Quoted 9 lines · Gilles Chanteperdrix
Quoted 8 lines · [email protected] wrote:
Quoted 8 lines
Quoted 7 lines · Klaas Gadeyne
I've noticed that threads which, in my ignorant opinion, are supposed to be sleeping, get woken up much earlier than I expect them to be.
Please find attached a modified version of the
trivial-periodic.capplication, which creates aRT_TASKthat should sleep as long as possible (i.e. until unblocked by a signal handler). However, the task gets woken up much earlier (and many times) _before_ that timeit
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
seems.
head
/tmp/app.txtcurrent_time= 1207928393295939429
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 1, return code = -110current_time= 1207928393296000379
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 2, return code = -110current_time= 1207928393296005409
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 3, return code = -110current_time= 1207928393296009604Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
What did I overlook here?
Probably an overflow issue: (RTIME)~0 will be converted to TSCs, and
if
Quoted 1 line
Quoted 1 line
Quoted 1 line
your box runs at > 1GHZ, the result of this conversion will by
something
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
< (RTIME)~0 due to the overflow. And this can result in an absolute timeout date (in TSC units) before the current date -> ETIMEDOUT. Can you confirm this?
I have no linux box at hand, but I noticed that [*]
xntimer_do_start_aperiodic()passes itsxnticks_tinterval argument(which
Quoted 4 lines
Quoted 4 lines
is an unsigned long long) to
xnarch_ns_to_tsc, and that one expects a (signed) long long.If I did not make any calculation errors (a very small chance...) in
"my"
Quoted 11 lines
Quoted 1 line
case "interval" >
LLONG_MAXso there's already an overflow there.The problem is that we can not change
xnarch_ns_to_tscto usexnarch_ullimdinstead ofxnarch_llimd:xnarch_ns_to_tscmay be used to convert negative differences. Anyway, I do not think there is an overflow in llimd, otherwise you would get a processor exception, not a silent truncation (at least on x86). To solve this issue, we should probably switch to saturation arithmetic, but it would probably have a huge impact on performance (and on code also, since we would have to usexnarch_saturated_add(foo, bar)instead of foo + bar).I see.
I noticed that
xnpod_suspend_threadoffers the possibility to suspend a thread "indefinitely" (until unblocked) via the (in the 2.4.x API, that is)Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
xnpod_suspend_thread(thread,XNDELAY,XN_INFINITE,XN_RELATIVE,NULL)call.
However, sinceTM_INFINITE(andXN_INFINITE) are both defined as being zero, calls tort_task_sleep(TM_INFINITE), are intercepted in the implementation ofrt_task_sleep[1]. So in the latter case (which I would naively---i.e. without looking at API docs--- read as "sleep for an infinite amount of time),rt_task_sleep()returns *immediately*.
Quoted 2 lines
This behaviour is explicitly stated in the doc, though. So people should not be surprised.
That why I added the stuff between the long dashes above :-) However, if there's even one thing even better than well documented API's, it's well documented _and_ intuitive APIs.
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Would it make sense to change the current behaviour of
rt_task_sleep(TM_INFINITE)and callxnpod_suspend_thread(thread,XNDELAY,XN_INFINITE,XN_RELATIVE,NULL)instead of returning 0?
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
One could either do that by
- altering rt_task_sleep()'s behaviour (not returning zero if delay is
zero)
- redefiningTM_INFINITENo way. You don't want to change "magic" values that lightly. This is why they are magic in the first place.
I know none of them were ideal solutions. However (AFAIS, that is), * from a user point of view, I would find it convenient to be able to
sleep indefinitely until somebody wakes me up using rt_task_unblock(),
and this is currently not possible.
* the nucleus _does_ offer this functionality via the xnpod_suspend_thread(thread,XNDELAY,XN_INFINITE,XN_RELATIVE,NULL)
call, but I cannot access that functionality in the native skin.
So I was wondering if nothing (else) could be done to solve that
problem, the concrete use case being a thread which is woken up every
time a job has to be done, but which can safely sleep "forever" (until unblocked) if nothing has to be done.
[For those really interested, I ran into this situation debugging a
CanFestival setup on xenomai, see
<http://sourceforge.net/mailarchive/forum.php?thread_name=Pine.LNX.4.64.0804141120410.11027%40ampere.labo01.fmtc.be&forum_name=canfestival-devel> ]
Quoted 12 lines
Quoted 11 lines
Quoted 6 lines
Quoted 3 lines
Both changes might "break" existing applications however.
Any thoughts?
Well, I do not see how applications could find a useful use of the "
rt_task_sleep(0)returns 0 immediately" behaviour.Thinking more about it: there is a useful use, if the sleep duration is the result of
rt_time_tsc2ns. Sleeping indefinitely would be a bit counter-intuitive.
Quoted 4 lines
Aside of this, the API has to be orthogonal, and having
rt_task_sleepbehave asrt_task_suspendis also counter-intuitive. Think about applications doing tick arithmetics to determine the remaining sleep time; at some point, they might hang unexpectedly with delay == 0 ==TM_INFINITE.
Didn't I mention "intuitive" somewhere above yet? ;-)
Thx,
Klaas
Quoted 125 lines · Klaas Gadeyne
Quoted 90 lines · Philippe Gerum
Quoted 89 lines · Gilles Chanteperdrix
Quoted 87 lines · Gilles Chanteperdrix
Quoted 6 lines · Klaas Gadeyne
Quoted 3 lines · Gilles Chanteperdrix
Quoted 2 lines · [email protected] wrote:
Quoted 2 lines
Quoted 1 line · Klaas Gadeyne
I've noticed that threads which, in my ignorant opinion, are
supposed
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
to be sleeping, get woken up much earlier than I expect them
to be.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Please find attached a modified version of the
trivial-periodic.capplication, which creates aRT_TASKthat should sleep as long as possible (i.e. until unblocked by a signal handler). However,the
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
task gets woken up much earlier (and many times) _before_ that
time
Quoted 18 lines
it
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
Quoted 14 lines
seems.
head
/tmp/app.txtcurrent_time= 1207928393295939429
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 1, return code = -110current_time= 1207928393296000379
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 2, return code = -110current_time= 1207928393296005409
sleep until 18446744073709551615
[TIMERLOOP] Total errors = 3, return code = -110current_time= 1207928393296009604Quoted 1 line
What did I overlook here?
Probably an overflow issue: (RTIME)~0 will be converted to
TSCs, and
Quoted 4 lines
if
Quoted 1 line
Quoted 1 line
Quoted 1 line
your box runs at > 1GHZ, the result of this conversion will by
something
Quoted 1 line
Quoted 1 line
Quoted 1 line
< (RTIME)~0 due to the overflow. And this can result in an
absolute
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
timeout date (in TSC units) before the current date ->
ETIMEDOUT. Can
Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
you confirm this?
I have no linux box at hand, but I noticed that [*]
xntimer_do_start_aperiodic()passes itsxnticks_tinterval argument(which
Quoted 1 line
Quoted 1 line
is an unsigned long long) to
xnarch_ns_to_tsc, and that oneexpects a
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
(signed) long long.
If I did not make any calculation errors (a very small
chance...) in
Quoted 5 lines
"my"
Quoted 4 lines
Quoted 1 line
case "interval" >
LLONG_MAXso there's already an overflow there.The problem is that we can not change
xnarch_ns_to_tscto usexnarch_ullimdinstead ofxnarch_llimd:xnarch_ns_to_tscmay beused to
Quoted 2 lines
Quoted 2 lines
convert negative differences. Anyway, I do not think there is an overflow in llimd, otherwise you would get a processor exception,
not a
Quoted 2 lines
Quoted 2 lines
silent truncation (at least on x86). To solve this issue, we should probably switch to saturation arithmetic, but it would probably
have a
Quoted 1 line
Quoted 1 line
huge impact on performance (and on code also, since we would have
to use
Quoted 6 lines
Quoted 2 lines
xnarch_saturated_add(foo, bar)instead of foo + bar).I see.
I noticed that
xnpod_suspend_threadoffers the possibility tosuspend
Quoted 7 lines
a thread "indefinitely" (until unblocked) via the (in the 2.4.x API, that is)
xnpod_suspend_thread(thread,XNDELAY,XN_INFINITE,XN_RELATIVE,NULL)call.
However, sinceTM_INFINITE(andXN_INFINITE) are both defined asbeing
Quoted 3 lines
zero, calls to
rt_task_sleep(TM_INFINITE), are intercepted in the implementation ofrt_task_sleep[1]. So in the latter case (which I would naively---i.e. without looking at API docs--- read asQuoted 6 lines
Quoted 2 lines
Quoted 2 lines
"sleep for
Quoted 1 line
an infinite amount of time),
rt_task_sleep()returns *immediately*.This behaviour is explicitly stated in the doc, though. So people should not be
surprised.That why I added the stuff between the long dashes above :-) However, if there's even one thing even better than well documented API's, it's well documented _and_ intuitive APIs.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Would it make sense to change the current behaviour of
rt_task_sleep(TM_INFINITE)and callxnpod_suspend_thread(thread,XNDELAY,XN_INFINITE,XN_RELATIVE,NULL)instead of returning 0?One could either do that by
- altering rt_task_sleep()'s behaviour (not returning zero ifQuoted 7 lines
Quoted 3 lines
Quoted 3 lines
delay is
Quoted 2 lines
zero)
- redefiningTM_INFINITENo way. You don't want to change "magic" values that lightly. This is why they
are magic in the first place.I know none of them were ideal solutions. However (AFAIS, that is), * from a user point of view, I would find it convenient to be able to
sleep indefinitely until somebody wakes me up usingrt_task_unblock(), and this is currently not possible.
* the nucleus _does_ offer this functionality via thexnpod_suspend_thread(thread,XNDELAY,XN_INFINITE,XN_RELATIVE,NULL)call, but I cannot access that functionality in the native skin.
Quoted 5 lines
So I was wondering if nothing (else) could be done to solve that problem, the concrete use case being a thread which is woken up every time a job has to be done, but which can safely sleep "forever" (until unblocked) if nothing has to be done.
What's wrong with rt_task_suspend() ?
Quoted 34 lines
[For those really interested, I ran into this situation debugging a CanFestival setup on xenomai, see
<http://sourceforge.net/mailarchive/forum.php?thread_name=Pine.LNX.4.64.0804141120410.11027%40ampere.labo01.fmtc.be&forum_name=canfestival-devel>
]Quoted 12 lines
Quoted 11 lines
Quoted 6 lines
Quoted 3 lines
Both changes might "break" existing applications however.
Any thoughts?
Well, I do not see how applications could find a useful use of the "
rt_task_sleep(0)returns 0 immediately" behaviour.Thinking more about it: there is a useful use, if the sleep duration is the result of
rt_time_tsc2ns. Sleeping indefinitely would be a bit counter-intuitive.Quoted 7 lines
Aside of this, the API has to be orthogonal, and having
rt_task_sleepbehave asrt_task_suspendis also counter-intuitive. Think about applications doing tick
arithmetics to determine the remaining sleep time; at some point, they might
hang unexpectedly with delay == 0 ==TM_INFINITE.Didn't I mention "intuitive" somewhere above yet? ;-)
Thx,
Klaas
Signature · 1 line
Philippe.
Quoted 1 line · Philippe Gerum
Klaas Gadeyne wrote:
[snipping lots of context]
Quoted 47 lines
Quoted 47 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 1 line
I noticed that
xnpod_suspend_threadoffers the possibility tosuspend
Quoted 7 lines
a thread "indefinitely" (until unblocked) via the (in the 2.4.x API, that is)
xnpod_suspend_thread(thread,XNDELAY,XN_INFINITE,XN_RELATIVE,NULL)call.
However, sinceTM_INFINITE(andXN_INFINITE) are both defined asbeing
Quoted 3 lines
zero, calls to
rt_task_sleep(TM_INFINITE), are intercepted in the implementation ofrt_task_sleep[1]. So in the latter case (which I would naively---i.e. without looking at API docs--- read asQuoted 6 lines
Quoted 2 lines
Quoted 2 lines
"sleep for
Quoted 1 line
an infinite amount of time),
rt_task_sleep()returns *immediately*.This behaviour is explicitly stated in the doc, though. So people should not be
surprised.That why I added the stuff between the long dashes above :-) However, if there's even one thing even better than well documented API's, it's well documented _and_ intuitive APIs.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Would it make sense to change the current behaviour of
rt_task_sleep(TM_INFINITE)and callxnpod_suspend_thread(thread,XNDELAY,XN_INFINITE,XN_RELATIVE,NULL)instead of returning 0?One could either do that by
- altering rt_task_sleep()'s behaviour (not returning zero ifQuoted 7 lines
Quoted 3 lines
Quoted 3 lines
delay is
Quoted 2 lines
zero)
- redefiningTM_INFINITENo way. You don't want to change "magic" values that lightly. This is why they
are magic in the first place.I know none of them were ideal solutions. However (AFAIS, that is), * from a user point of view, I would find it convenient to be able to
sleep indefinitely until somebody wakes me up usingrt_task_unblock(), and this is currently not possible.
* the nucleus _does_ offer this functionality via thexnpod_suspend_thread(thread,XNDELAY,XN_INFINITE,XN_RELATIVE,NULL)call, but I cannot access that functionality in the native skin.
Quoted 7 lines
Quoted 5 lines
So I was wondering if nothing (else) could be done to solve that problem, the concrete use case being a thread which is woken up every time a job has to be done, but which can safely sleep "forever" (until unblocked) if nothing has to be done.
What's wrong with
rt_task_suspend()?
The current loop code is something like
void timerloop_task_proc(void *arg)
{
int ret;
int errors = 0;
do{
do{
last_occured_alarm = last_alarm_set;
EnterMutex();
TimeDispatch();
LeaveMutex();
}while ((ret = rt_task_sleep_until(last_alarm)) == 0);
if (ret == -ETIMEDOUT){
printf("[TIMERLOOP] Total errors = %d, return code = %d\n",++errors,ret);
}
}while (!(stop_timer && ret == -EINTR));
printf("End of TimerLoop, code %d, Total errors = %d\n",ret,errors);
}I could modify that code and put something like
if (last_alarm == TIMEVAL_MAX) // Nothing else to do, sleep forever
rt_task_suspend()
else
rt_task_sleep_until(last_alarm)
However, the one who wants to wake up this thread (e.g. for asking this thread to stop) doesn't know in what state the timerthread is. It seems clumsy to me if that the one who wants to wake up the thread has to try _unblock() first, and the _resume()?
thx,
Klaas
ps. Note that the original problem I sketched in this thread was due to an overflow situation, and that this suggestion to allow to make a thread *sleep* forever instead of suspending only tackles _my_ concrete problem, and doesn't solve the overflow issue.
Quoted 90 lines · Klaas Gadeyne
Quoted 1 line · Philippe Gerum
Klaas Gadeyne wrote:
[snipping lots of context]
Quoted 50 lines
Quoted 50 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 1 line
I noticed that
xnpod_suspend_threadoffers the possibility tosuspend
Quoted 8 lines
a thread "indefinitely" (until unblocked) via the (in the 2.4.x
API,
that is)
xnpod_suspend_thread(thread,XNDELAY,XN_INFINITE,XN_RELATIVE,NULL)call.
However, sinceTM_INFINITE(andXN_INFINITE) are both defined asbeing
Quoted 4 lines
zero, calls to
rt_task_sleep(TM_INFINITE), are intercepted in the implementation ofrt_task_sleep[1]. So in the latter case
(which I
would naively---i.e. without looking at API docs--- read asQuoted 6 lines
Quoted 2 lines
Quoted 2 lines
"sleep for
Quoted 1 line
an infinite amount of time),
rt_task_sleep()returns *immediately*.This behaviour is explicitly stated in the doc, though. So people should not be
surprised.That why I added the stuff between the long dashes above :-) However, if
there's even one thing even better than well documented API's, it's well documented _and_ intuitive APIs.Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Would it make sense to change the current behaviour of
rt_task_sleep(TM_INFINITE)and callxnpod_suspend_thread(thread,XNDELAY,XN_INFINITE,XN_RELATIVE,NULL)instead of returning 0?One could either do that by
- altering rt_task_sleep()'s behaviour (not returning zero ifQuoted 7 lines
Quoted 3 lines
Quoted 3 lines
delay is
Quoted 2 lines
zero)
- redefiningTM_INFINITENo way. You don't want to change "magic" values that lightly. This is why they
are magic in the first place.I know none of them were ideal solutions. However (AFAIS, that is), * from a user point of view, I would find it convenient to be able to
sleep indefinitely until somebody wakes me up usingrt_task_unblock(), and this is currently not possible.
* the nucleus _does_ offer this functionality via thexnpod_suspend_thread(thread,XNDELAY,XN_INFINITE,XN_RELATIVE,NULL)call, but I cannot access that functionality in the native skin.Quoted 7 lines
Quoted 5 lines
So I was wondering if nothing (else) could be done to solve that problem, the concrete use case being a thread which is woken up every time a job has to be done, but which can safely sleep "forever" (until unblocked) if nothing has to be done.
What's wrong with
rt_task_suspend()?The current loop code is something like
void
timerloop_task_proc(void *arg){ int ret; int errors = 0; do{ do{ last_occured_alarm = last_alarm_set; EnterMutex(); TimeDispatch(); LeaveMutex(); }while ((ret = rt_task_sleep_until(last_alarm)) == 0); if (ret == -ETIMEDOUT){ printf("[TIMERLOOP] Total errors = %d, return code = %d\n",++errors,ret); } }while (!(stop_timer && ret == -EINTR)); printf("End of TimerLoop, code %d, Total errors =%d\n",ret,errors);
}I could modify that code and put something like
if (last_alarm==TIMEVAL_MAX) // Nothing else to do, sleep forever
rt_task_suspend()
else
rt_task_sleep_until(last_alarm)
Quoted 5 lines
However, the one who wants to wake up this thread (e.g. for asking this thread to stop) doesn't know in what state the timerthread is. It seems clumsy to me if that the one who wants to wake up the thread has to try
_unblock()first, and the_resume()?
There has been a fair amount of misunderstanding. Past mails were apparently aiming at rt_task_sleep's behaviour (e.g. returning 0 on NULL delay etc.), but you actually care for rt_task_sleep_until, which is a totally different story (the subject line was right though).
Handling the special TM_INFINITE value as a valid timeout value for rt_task_sleep_until would not introduce the flaws I was concerned about regarding rt_task_sleep. We would just change the behaviour when receiving what used to be an utterly bugous date spec in the current implementation, and make it valid, which is ok -- i.e. I'm not particularly concerned by maintaining backward compatible behaviours when receiving utterly insane data specs like "0" for an absolute date.
If your loop was truly periodic, you could probably use rt_task_wait_period(), but I suspect last_alarm may not try to enforce a strictly periodic timeline, right?
The fact that we don't have any other blocking calls with absolute date specs is bothering me actually, and 2.5 will probably see some extensions like rt_sem_p_until(), in order to address patterns of this kind.
But well, back to rt_task_sleep_until, I see no reason not to handle the corner case you described a bit more gracefully. So let's try the Klaas Amendment to the native API. Does the following work for you?
skins/native/task.c +26 -15
@@ -958,8 +958,10 @@* reached. * * @param date The absolute date in clock ticks to wait before -* resuming the task (see note). Passing an already elapsed date -* causes the task to return immediately with no delay. +* resuming the task (see note). As a special case, TM_INFINITE is an +* acceptable value that makes the caller block indefinitely, until +* rt_task_unblock() is called against it. Otherwise, any wake up date +* in the past causes the task to return immediately with no delay. * * @return 0 is returned upon success. Otherwise: *
@@ -968,7 +970,8 @@* * - -ETIMEDOUT is returned if @a date has already elapsed. * -* - -EWOULDBLOCK is returned if the system timer is inactive. +* - -EWOULDBLOCK is returned if the system timer is inactive, and +* @date is valid but different from TM_INFINITE. * * - -EPERM is returned if this service was called from a context * which cannot sleep (e.g. interrupt, non-realtime or scheduler
@@ -990,8 +993,8 @@int rt_task_sleep_until (RTIME date) { +int err =0 , mode =XN_REALTIME ;xnthread_t *self; -int err =0 ;spl_t s;if (xnpod_unblockable_p ())
@@ -999,22 +1002,30 @@ self =xnpod_current_thread (); -if (!xnthread_timed_p (self)) -return -EWOULDBLOCK ; -xnlock_get_irqsave (&nklock, s); -/* Calling the suspension service on behalf of the current task -implicitely calls the rescheduling procedure. */ +if (date ==TM_INFINITE ) +/* i.e. will resume only upon rt_task_unblock(). */ + mode =XN_RELATIVE ; +else if (date <=xntbase_get_time (__native_tbase)) { + err = -ETIMEDOUT ; + goto unlock_and_exit; + }else if (!xnthread_timed_p (self)) { + err = -EWOULDBLOCK ; + goto unlock_and_exit; + } -if (date >xntbase_get_time (__native_tbase)) { -xnpod_suspend_thread (self,XNDELAY , date,XN_REALTIME ,NULL ); +/* +* Calling the suspension service on behalf of the current +* task implicitely calls the rescheduling procedure. +*/ +xnpod_suspend_thread (self,XNDELAY , date, mode,NULL ); -if (xnthread_test_info (self,XNBREAK )) - err = -EINTR ; - }else - err = -ETIMEDOUT ; +if (xnthread_test_info (self,XNBREAK )) + err = -EINTR ; + unlock_and_exit: +xnlock_put_irqrestore (&nklock, s);return err;
Signature · 1 line
Philippe.
On Tue, 22 Apr 2008, Philippe Gerum wrote:
[snipping even more context]
Quoted 36 lines
Quoted 30 lines
Quoted 1 line
What's wrong with
rt_task_suspend()?The current loop code is something like
void
timerloop_task_proc(void *arg){ int ret; int errors = 0; do{ do{ last_occured_alarm = last_alarm_set; EnterMutex(); TimeDispatch(); LeaveMutex(); }while ((ret = rt_task_sleep_until(last_alarm)) == 0); if (ret == -ETIMEDOUT){ printf("[TIMERLOOP] Total errors = %d, return code = %d\n",++errors,ret); } }while (!(stop_timer && ret == -EINTR)); printf("End of TimerLoop, code %d, Total errors =%d\n",ret,errors);
}I could modify that code and put something like
if (last_alarm==TIMEVAL_MAX) // Nothing else to do, sleep forever
rt_task_suspend()
else
rt_task_sleep_until(last_alarm)Quoted 5 lines
However, the one who wants to wake up this thread (e.g. for asking this thread to stop) doesn't know in what state the timerthread is. It seems clumsy to me if that the one who wants to wake up the thread has to try
_unblock()first, and the_resume()?
Quoted 4 lines
There has been a fair amount of misunderstanding. Past mails were apparently aiming at rt_task_sleep's behaviour (e.g. returning 0 on NULL delay etc.), but you actually care for
rt_task_sleep_until, which is a totally different story (the subject line was right though).
Sorry about that, during the debugging I ended up playing around with rt_task_sleep() to check if the overflow issues did occur there too.
Quoted 11 lines
Handling the special
TM_INFINITEvalue as a valid timeout value forrt_task_sleep_untilwould not introduce the flaws I was concerned about regardingrt_task_sleep. We would just change the behaviour when receiving what used to be an utterly bugous date spec in the current implementation, and make it valid, which is ok -- i.e. I'm not particularly concerned by maintaining backward compatible behaviours when receiving utterly insane data specs like "0" for an absolute date.If your loop was truly periodic, you could probably use
rt_task_wait_period(), but I suspectlast_alarmmay not try to enforce a strictly periodic timeline, right?
Quoted 7 lines
The fact that we don't have any other blocking calls with absolute date specs is bothering me actually, and 2.5 will probably see some extensions like
rt_sem_p_until(), in order to address patterns of this kind.But well, back to
rt_task_sleep_until, I see no reason not to handle the corner case you described a bit more gracefully. So let's try the Klaas Amendment to the native API.
I *really* like the way that sounds ;-)
Quoted 1 line
Does the following work for you?
[snipped patch]
It does! Tested on today's 2.4-branch on a 2.6.20.21-ipipe-1.12-03 kernel. Any chance this could still be merged in the 2.4 series?
Thx for your patience!
Klaas
Quoted 79 lines · Klaas Gadeyne
On Tue, 22 Apr 2008, Philippe Gerum wrote:
[snipping even more context]
Quoted 36 lines
Quoted 30 lines
Quoted 1 line
What's wrong with
rt_task_suspend()?The current loop code is something like
void
timerloop_task_proc(void *arg){ int ret; int errors = 0; do{ do{ last_occured_alarm = last_alarm_set; EnterMutex(); TimeDispatch(); LeaveMutex(); }while ((ret = rt_task_sleep_until(last_alarm)) == 0); if (ret == -ETIMEDOUT){ printf("[TIMERLOOP] Total errors = %d, return code = %d\n",++errors,ret); } }while (!(stop_timer && ret == -EINTR)); printf("End of TimerLoop, code %d, Total errors =%d\n",ret,errors);
}I could modify that code and put something like
if (last_alarm==TIMEVAL_MAX) // Nothing else to do, sleep forever
rt_task_suspend()
else
rt_task_sleep_until(last_alarm)Quoted 5 lines
However, the one who wants to wake up this thread (e.g. for asking this thread to stop) doesn't know in what state the timerthread is. It seems clumsy to me if that the one who wants to wake up the thread has to try
_unblock()first, and the_resume()?Quoted 7 lines
There has been a fair amount of misunderstanding. Past mails were apparently
aiming at rt_task_sleep's behaviour (e.g. returning 0 on NULL delay etc.), but
you actually care forrt_task_sleep_until, which is a totally different story
(the subject line was right though).Sorry about that, during the debugging I ended up playing around with
rt_task_sleep()to check if the overflow issues did occur there too.Quoted 22 lines
Handling the special
TM_INFINITEvalue as a valid timeout value forrt_task_sleep_untilwould not introduce the flaws I was concerned about regardingrt_task_sleep. We would just change the behaviour when receiving what
used to be an utterly bugous date spec in the current implementation, and make
it valid, which is ok -- i.e. I'm not particularly concerned by maintaining
backward compatible behaviours when receiving utterly insane data specs like "0"
for an absolute date.If your loop was truly periodic, you could probably use
rt_task_wait_period(),
but I suspectlast_alarmmay not try to enforce a strictly periodic timeline, right?The fact that we don't have any other blocking calls with absolute date specs is
bothering me actually, and 2.5 will probably see some extensions likert_sem_p_until(), in order to address patterns of this kind.Quoted 5 lines
But well, back to
rt_task_sleep_until, I see no reason not to handle the corner
case you described a bit more gracefully. So let's try the Klaas Amendment to
the native API.
Quoted 9 lines
I *really* like the way that sounds ;-)
Quoted 1 line
Does the following work for you?
[snipped patch]
It does! Tested on today's 2.4-branch on a 2.6.20.21-ipipe-1.12-03 kernel. Any chance this could still be merged in the 2.4 series?
Since this does not change the behaviour of documented and valid use cases, I will merge that patch into 2.4.4.
Quoted 2 lines
Thx for your patience!
You are welcome.
Quoted 3 lines
Klaas
Signature · 1 line
Philippe.
Are there any differences (in performance point of view) between using rt_task_sleep_until (TM_INFINITE) + rt_task_unblock() and rt_task_suspend() + rt_task_resume() ? I'm writting some kind of task manager and I'm using suspend + resume combination.
Quoted 114 lines · Philippe Gerum
Quoted 79 lines · Klaas Gadeyne
On Tue, 22 Apr 2008, Philippe Gerum wrote:
[snipping even more context]
Quoted 36 lines
Quoted 30 lines
Quoted 1 line
What's wrong with
rt_task_suspend()?The current loop code is something like
void
timerloop_task_proc(void *arg){ int ret; int errors = 0; do{ do{ last_occured_alarm = last_alarm_set; EnterMutex(); TimeDispatch(); LeaveMutex(); }while ((ret = rt_task_sleep_until(last_alarm)) == 0); if (ret == -ETIMEDOUT){ printf("[TIMERLOOP] Total errors = %d, return code = %d\n",++errors,ret); } }while (!(stop_timer && ret == -EINTR)); printf("End of TimerLoop, code %d, Total errors =%d\n",ret,errors);
}I could modify that code and put something like
if (last_alarm==TIMEVAL_MAX) // Nothing else to do, sleep forever
rt_task_suspend()
else
rt_task_sleep_until(last_alarm)Quoted 5 lines
However, the one who wants to wake up this thread (e.g. for asking this thread to stop) doesn't know in what state the timerthread is. It seems clumsy to me if that the one who wants to wake up the thread has to try
_unblock()first, and the_resume()?Quoted 7 lines
There has been a fair amount of misunderstanding. Past mails were apparently
aiming at rt_task_sleep's behaviour (e.g. returning 0 on NULL delay etc.), but
you actually care forrt_task_sleep_until, which is a totally different story
(the subject line was right though).Sorry about that, during the debugging I ended up playing around with
rt_task_sleep()to check if the overflow issues did occur there too.Quoted 22 lines
Handling the special
TM_INFINITEvalue as a valid timeout value forrt_task_sleep_untilwould not introduce the flaws I was concerned about regardingrt_task_sleep. We would just change the behaviour when receiving what
used to be an utterly bugous date spec in the current implementation, and make
it valid, which is ok -- i.e. I'm not particularly concerned by maintaining
backward compatible behaviours when receiving utterly insane data specs like "0"
for an absolute date.If your loop was truly periodic, you could probably use
rt_task_wait_period(),
but I suspectlast_alarmmay not try to enforce a strictly periodic timeline, right?The fact that we don't have any other blocking calls with absolute date specs is
bothering me actually, and 2.5 will probably see some extensions likert_sem_p_until(), in order to address patterns of this kind.Quoted 5 lines
But well, back to
rt_task_sleep_until, I see no reason not to handle the corner
case you described a bit more gracefully. So let's try the Klaas Amendment to
the native API.Quoted 9 lines
I *really* like the way that sounds ;-)
Quoted 1 line
Does the following work for you?
[snipped patch]
It does! Tested on today's 2.4-branch on a 2.6.20.21-ipipe-1.12-03 kernel. Any chance this could still be merged in the 2.4 series?
Since this does not change the behaviour of documented and valid use cases, I will merge that patch into 2.4.4.
Quoted 2 lines
Thx for your patience!
You are welcome.
Quoted 3 lines
Klaas
--
Philippe._______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help
Quoted 5 lines · Bosko Radivojevic
Are there any differences (in performance point of view) between using
rt_task_sleep_until(TM_INFINITE) +rt_task_unblock()andrt_task_suspend()+rt_task_resume()? I'm writting some kind of task manager and I'm using suspend + resume combination.
Internally, this boils down to running the same code.
Quoted 115 lines · Philippe Gerum
Quoted 113 lines
Quoted 79 lines · Klaas Gadeyne
On Tue, 22 Apr 2008, Philippe Gerum wrote:
[snipping even more context]
Quoted 36 lines
Quoted 30 lines
Quoted 1 line
What's wrong with
rt_task_suspend()?The current loop code is something like
void
timerloop_task_proc(void *arg){ int ret; int errors = 0; do{ do{ last_occured_alarm = last_alarm_set; EnterMutex(); TimeDispatch(); LeaveMutex(); }while ((ret = rt_task_sleep_until(last_alarm)) == 0); if (ret == -ETIMEDOUT){ printf("[TIMERLOOP] Total errors = %d, return code = %d\n",++errors,ret); } }while (!(stop_timer && ret == -EINTR)); printf("End of TimerLoop, code %d, Total errors =%d\n",ret,errors);
}I could modify that code and put something like
if (last_alarm==TIMEVAL_MAX) // Nothing else to do, sleep forever
rt_task_suspend()
else
rt_task_sleep_until(last_alarm)Quoted 5 lines
However, the one who wants to wake up this thread (e.g. for asking this thread to stop) doesn't know in what state the timerthread is. It seems clumsy to me if that the one who wants to wake up the thread has to try
_unblock()first, and the_resume()?Quoted 7 lines
There has been a fair amount of misunderstanding. Past mails were apparently
aiming at rt_task_sleep's behaviour (e.g. returning 0 on NULL delay etc.), but
you actually care forrt_task_sleep_until, which is a totally different story
(the subject line was right though).Sorry about that, during the debugging I ended up playing around with
rt_task_sleep()to check if the overflow issues did occur there too.Quoted 22 lines
Handling the special
TM_INFINITEvalue as a valid timeout value forrt_task_sleep_untilwould not introduce the flaws I was concerned about regardingrt_task_sleep. We would just change the behaviour when receiving what
used to be an utterly bugous date spec in the current implementation, and make
it valid, which is ok -- i.e. I'm not particularly concerned by maintaining
backward compatible behaviours when receiving utterly insane data specs like "0"
for an absolute date.If your loop was truly periodic, you could probably use
rt_task_wait_period(),
but I suspectlast_alarmmay not try to enforce a strictly periodic timeline, right?The fact that we don't have any other blocking calls with absolute date specs is
bothering me actually, and 2.5 will probably see some extensions likert_sem_p_until(), in order to address patterns of this kind.Quoted 5 lines
But well, back to
rt_task_sleep_until, I see no reason not to handle the corner
case you described a bit more gracefully. So let's try the Klaas Amendment to
the native API.Quoted 9 lines
I *really* like the way that sounds ;-)
Quoted 1 line
Does the following work for you?
[snipped patch]
It does! Tested on today's 2.4-branch on a 2.6.20.21-ipipe-1.12-03 kernel. Any chance this could still be merged in the 2.4 series?
Since this does not change the behaviour of documented and valid use cases, I will merge that patch into 2.4.4.
Quoted 2 lines
Thx for your patience!
You are welcome.
Quoted 3 lines
Klaas
--
Philippe._______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help
Signature · 1 line
Philippe.
[Xenomai-help] Recurring Interrupts
In reply to Philippe GerumHow do I setup xenomai so that my ISR can be re-entered even if I am currently in it.
I have an external edge interrupt wired and it occurs every 250usec. There are instances when the interrupt can occur while I am currently in my ISR.
If another interrupt occurs while I am currently in my ISR I want my ISR to be called again so I can flag that the condition occurred then exit the re-entered ISR and continue executing the originally called ISR.
I am using a board based off the AMCC 440EP Yosemite and a Denx Kit with 2.6.24 and Xenomai 2.4.2 This something I did with previously with RT Linux. I have converted a large project from FSM RT Linux to Xenomai and everything is functioning except this last item.
Re: [Xenomai-help] Recurring Interrupts
Quoted 3 lines · Henry Bausley
How do I setup xenomai so that my ISR can be re-entered even if I am currently in it.
Try this:
int your_isr(xnintr_t *intr)
{
unsigned long flags;
xnlock_clear_irqon(&nklock);
... your code ...
xnlock_get_irqsave(&nklock, flags); /* must re-lock on exit */
}We do take a per-IRQ lock internally as well, but this is a no-brainer for the issue at stake.
NOTE: this solution is only valid in uniprocessor mode. SMP would run into deadlocks; we would need to provide internal support to allow this.
Quoted 25 lines
I have an external edge interrupt wired and it occurs every 250usec. There are instances
when the interrupt can occur while I am currently in my ISR.If another interrupt occurs while I am currently in my ISR I want my ISR to be called again
so I can flag that the condition occurred then exit the re-entered ISR and continue executing
the originally called ISR.I am using a board based off the AMCC 440EP Yosemite and a Denx Kit with 2.6.24 and Xenomai 2.4.2
This something I did with previously with RT Linux. I have converted a large project from FSM RT Linux
to Xenomai and everything is functioning except this last item._______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help
Signature · 1 line
Philippe.
Re: [Xenomai-help] Recurring Interrupts
Quoted 7 lines · Philippe Gerum
Quoted 3 lines · Henry Bausley
How do I setup xenomai so that my ISR can be re-entered even if I am currently in it.
Try this:
The following is needed to allow the same interrupt to recurse as well.
Quoted 4 lines
int
your_isr(xnintr_t *intr){ unsigned long flags;
+ xnintr_enable(intr);
Quoted 5 lines
xnlock_clear_irqon(&nklock); ... your code ... xnlock_get_irqsave(&nklock, flags); /* must re-lock on exit */
+ return XN_ISR_HANDLED | XN_ISR_NOENABLE;
Quoted 36 lines
}
We do take a per-IRQ lock internally as well, but this is a no-brainer for the issue at stake.
NOTE: this solution is only valid in uniprocessor mode. SMP would run into deadlocks; we would need to provide internal support to allow this.
Quoted 25 lines
I have an external edge interrupt wired and it occurs every 250usec. There are instances
when the interrupt can occur while I am currently in my ISR.If another interrupt occurs while I am currently in my ISR I want my ISR to be called again
so I can flag that the condition occurred then exit the re-entered ISR and continue executing
the originally called ISR.I am using a board based off the AMCC 440EP Yosemite and a Denx Kit with 2.6.24 and Xenomai 2.4.2
This something I did with previously with RT Linux. I have converted a large project from FSM RT Linux
to Xenomai and everything is functioning except this last item._______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help
Signature · 1 line
Philippe.