Sleeping function called from invalid context
Quoted 2 lines
That is strange, are these tasks
running with theSCHED_OTHERpolicy ?
No, they are running with sched fifo.
Quoted 3 lines · Christoph
Quoted 2 lines
That is strange, are these tasks
running with theSCHED_OTHERpolicy ?No, they are running with sched fifo.
Ok, next, are they usingrt_timer_mode_set
or
RT drivers which return -ENOSYS in their rt handlers ?
Signature · 1 line
Gilles.
Quoted 9 lines
Quoted 4 lines
Quoted 3 lines
That is strange, are these tasks
running with theSCHED_OTHERpolicy ?No, they are running with sched fifo.
Ok, next, are they using
rt_timer_mode_set
or
RT drivers which return-ENOSYSin their rt handlers ?
Assumedly you mean rt_timer_set_mode() instead of rt_timer_mode_set(). This function is not called since we are using our own skin. Also our own skin does not use xntbase_switch(). Maybe it is interesting to know that our skin is configured with periodic timing (1ms).
RT drivers are also not installed on our system.
Regards,
Christoph
Quoted 5 lines · Christoph
Quoted 5 lines
Quoted 4 lines
Quoted 3 lines
That is strange, are these tasks
running with theSCHED_OTHERpolicy ?No, they are running with sched fifo.
Quoted 8 lines
Quoted 4 lines
Ok, next, are they using
rt_timer_mode_set
or
RT drivers which return-ENOSYSin their rt handlers ?Assumedly you mean
rt_timer_set_mode()instead ofrt_timer_mode_set(). This function is not called since we are using our own skin. Also our own skin does not usexntbase_switch(). Maybe it is interesting to know that our skin is configured with periodic timing (1ms).RT drivers are also not installed on our system.
Maybe I look wrong at nucleus/shadow.c, but I see only two reasons for for xnshadow_relax being called for a secondary mode syscall:
- a call requiring primary mode was made and the switchback flag is set (which itself can have two reasons, either the fact that the syscall uses it, the only one being currently rt_timer_set_mode, or the fact that the caller runs with the SCHED_OTHER policy and does not hold a mutex)
- a call with the adaptive flag was made, handled in primary mode, but returned -ENOSYS, which means the call needs to be retried in secondary mode.
Signature · 1 line
Gilles.
Quoted 23 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 3 lines
That is strange, are these tasks
running with theSCHED_OTHERpolicy ?No, they are running with sched fifo.
Quoted 8 lines
Quoted 4 lines
Ok, next, are they using
rt_timer_mode_set
or
RT drivers which return-ENOSYSin their rt handlers ?Assumedly you mean
rt_timer_set_mode()instead ofrt_timer_mode_set(). This function is not called since we are >using our own skin. Also our own skin does not usexntbase_switch(). Maybe it is interesting to know that our skin is >configured with periodic timing (1ms).RT drivers are also not installed on our system.
Maybe I look wrong at
nucleus/shadow.c, but I see only two reasons for forxnshadow_relaxbeing called for a secondary mode syscall:- a call requiring primary mode was made and the switchback flag is set (which itself can have two reasons, either the fact that the syscall uses it, the only one being currently
rt_timer_set_mode, or the fact that the caller runs with theSCHED_OTHERpolicy and does not hold a mutex)
Quoted 4 lines
- a call with the adaptive flag was made, handled in primary mode, but returned
-ENOSYS, which means the call needs to be retried in secondary mode.
You are right. We have implemented some syscalls the require primary mode (since they could block) but should switch back to secondary. These syscalls are using attributes
__xn_exec_primary | __xn_exec_switchback
Regards,
Christoph
Quoted 23 lines · Christoph
Quoted 23 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
Quoted 3 lines
That is strange, are these tasks
running with theSCHED_OTHERpolicy ?No, they are running with sched fifo.
Quoted 8 lines
Quoted 4 lines
Ok, next, are they using
rt_timer_mode_set
or
RT drivers which return-ENOSYSin their rt handlers ?Assumedly you mean
rt_timer_set_mode()instead ofrt_timer_mode_set(). This function is not called since we are >using our own skin. Also our own skin does not usexntbase_switch(). Maybe it is interesting to know that our skin is >configured with periodic timing (1ms).RT drivers are also not installed on our system.
Maybe I look wrong at
nucleus/shadow.c, but I see only two reasons for forxnshadow_relaxbeing called for a secondary mode syscall:- a call requiring primary mode was made and the switchback flag is set (which itself can have two reasons, either the fact that the syscall uses it, the only one being currently
rt_timer_set_mode, or the fact that the caller runs with theSCHED_OTHERpolicy and does not hold a mutex)
Quoted 8 lines
Quoted 4 lines
- a call with the adaptive flag was made, handled in primary mode, but returned
-ENOSYS, which means the call needs to be retried in secondary mode.You are right. We have implemented some syscalls the require primary mode (since they could block) but should switch back to secondary. These syscalls are using attributes
__xn_exec_primary|__xn_exec_switchback
Well then the tasks blocked with a stack trace like what you showed are blocked when coming back from such syscalls. Does this happen often, or are these syscall seldom used?
Signature · 1 line
Gilles.
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 1 line
RT drivers are also not installed on our system.
Maybe I look wrong at
nucleus/shadow.c, but I see only two reasons for forxnshadow_relaxbeing called for a secondary mode syscall:- a call requiring primary mode was made and the switchback flag is set (which itself can have two reasons, either the fact that the syscall uses it, the only one being currently
rt_timer_set_mode, or the fact that the caller runs with theSCHED_OTHERpolicy and does not hold a mutex)- a call with the adaptive flag was made, handled in primary mode, but returned
-ENOSYS, which means the call needs to be retried in secondary mode.
Quoted 7 lines
Quoted 3 lines
You are right. We have implemented some syscalls the require primary mode (since they could block) but should switch back to secondary. These syscalls are using attributes
__xn_exec_primary|__xn_exec_switchbackWell then the tasks blocked with a stack trace like what you showed are blocked when coming back from such syscalls. Does this happen often, or are these syscall seldom used?
In this application the switchback syscalls are used rather often.
Regards,
Christoph
Quoted 18 lines · Christoph
Quoted 18 lines
Quoted 18 lines
Quoted 11 lines
Quoted 1 line
RT drivers are also not installed on our system.
Maybe I look wrong at
nucleus/shadow.c, but I see only two reasons for forxnshadow_relaxbeing called for a secondary mode syscall:- a call requiring primary mode was made and the switchback flag is set (which itself can have two reasons, either the fact that the syscall uses it, the only one being currently
rt_timer_set_mode, or the fact that the caller runs with theSCHED_OTHERpolicy and does not hold a mutex)Quoted 4 lines
- a call with the adaptive flag was made, handled in primary mode, but returned
-ENOSYS, which means the call needs to be retried in secondary mode.You are right. We have implemented some syscalls the require primary mode (since they could block) but should switch back to secondary. These syscalls are using attributes
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
__xn_exec_primary|__xn_exec_switchbackWell then the tasks blocked with a stack trace like what you showed are blocked when coming back from such syscalls. Does this happen often, or are these syscall seldom used?
In this application the switchback syscalls are used rather often.
Two things to note:
- mode switches do not go without some overhead, it is almost never a good idea to force the switchback, since the nucleus will switch the target thread to secondary mode when needed anyway, all that you risk is to introduce useless mode switches, so, if you do it, you must have a good reason for it;
- there is a risk of overflowing the nucleus queue for relax requests, you will see a message in the kernel logs when this happens if you enable debugging of the nucleus (CONFIG_XENO_OPT_DEBUG_NUCLEUS).
Signature · 1 line
Gilles.
Quoted 10 lines
Quoted 2 lines
In this application the switchback syscalls are used rather often.
Two things to note:
- mode switches do not go without some overhead, it is almost never a good idea to force the switchback, since the nucleus will switch the target thread to secondary mode when needed anyway, all that you risk is to introduce useless mode switches, so, if you do it, you must have a good reason for it;
Yes I know. However we need to assure that the task switches back to secondary domain after using skin's call, since otherwise it would affect other linux tasks which actual have a higher linux-priority. In general we try to simulate something like "priority coupling" since this is marked as deprecated.
Quoted 4 lines
- there is a risk of overflowing the nucleus queue for relax requests, you will see a message in the kernel logs when this happens if you enable debugging of the nucleus (
CONFIG_XENO_OPT_DEBUG_NUCLEUS).
I have enabled CONFIG_XENO_OPT_DEBUG_NUCLEUS now but I do not see any according message.
Regards,
Christoph
Quoted 11 lines · Christoph
Quoted 10 lines
Quoted 2 lines
In this application the switchback syscalls are used rather often.
Two things to note:
- mode switches do not go without some overhead, it is almost never a good idea to force the switchback, since the nucleus will switch the target thread to secondary mode when needed anyway, all that you risk is to introduce useless mode switches, so, if you do it, you must have a good reason for it;
Quoted 5 lines
Yes I know. However we need to assure that the task switches back to secondary domain after using skin's call, since otherwise it would affect other linux tasks which actual have a higher linux-priority. In general we try to simulate something like "priority coupling" since this is marked as deprecated.
I understand, I guess this is the reason why xenomai-3 introduced the XNWEAK scheduling class (which does the same thing by the way, automatically switches back to secondary mode). I am not sure this can compare to priority coupling though, since priority coupling does the reverse: a task running in secondary mode may prevent other tasks running in primary mode from running.
Quoted 8 lines
Quoted 5 lines
- there is a risk of overflowing the nucleus queue for relax requests, you will see a message in the kernel logs when this happens if you enable debugging of the nucleus (
CONFIG_XENO_OPT_DEBUG_NUCLEUS).I have enabled
CONFIG_XENO_OPT_DEBUG_NUCLEUSnow but I do not see any according message.
Ok, maybe we have some hope with the tracer though. What should trigger a trace is the fact that a relax request has been sent, but that the next linux scheduling point does not wake up the said task. This is all debug code, so it does not need to be clean. You can define a per-cpu variable (if running on SMP systems, otherwise a global variable will do) with the last request posted. And when a linux scheduling happens, test that the newly scheduled task is the task that was passed to the relax, if that is not the case, trigger a trace freeze. The point where the nucleus is informed of a Linux task switch is do_schedule_event(). The trick is that if you have some tasks with a higher priority than the relaxed task, it is normal that the relaxed task is not scheduled immediately, so if you want the condition to hold, you need to run the xenomai tasks which relax with the highest priority. Also, obviously, after the test, the pointer should be reset to NULL, because there are several task queued, and with a global variable you have no way of knowing which is next.
Signature · 1 line
Gilles.
Quoted 10 lines
Ok, maybe we have some hope with the tracer though. What should trigger a trace is the fact that a relax request has been sent, but that the next linux scheduling point does not wake up the said task. This is all debug code, so it does not need to be clean. You can define a per-cpu variable (if running on SMP systems, otherwise a global variable will do) with the last request posted. And when a linux scheduling happens, test that the newly scheduled task is the task that was passed to the relax, if that is not the case, trigger a trace freeze. The point where the nucleus is informed of a Linux
Quoted 8 lines
task switch is
do_schedule_event(). The trick is that if you have some tasks with a higher priority than the relaxed task, it is normal that the relaxed task is not scheduled immediately, so if you want the condition to hold, you need to run the xenomai tasks which relax with the highest priority. Also, obviously, after the test, the pointer should be reset to NULL, because there are several task queued, and with a global variable you have no way of knowing which is next.
I will do so. Do I have to change the gatekeeper's priority behind the relaxing task to assure that the gatekeeper would be scheduled before?
Regards,
Christoph
Quoted 19 lines · Christoph
Quoted 10 lines
Ok, maybe we have some hope with the tracer though. What should trigger a trace is the fact that a relax request has been sent, but that the next linux scheduling point does not wake up the said task. This is all debug code, so it does not need to be clean. You can define a per-cpu variable (if running on SMP systems, otherwise a global variable will do) with the last request posted. And when a linux scheduling happens, test that the newly scheduled task is the task that was passed to the relax, if that is not the case, trigger a trace freeze. The point where the nucleus is informed of a Linux
Quoted 8 lines
task switch is
do_schedule_event(). The trick is that if you have some tasks with a higher priority than the relaxed task, it is normal that the relaxed task is not scheduled immediately, so if you want the condition to hold, you need to run the xenomai tasks which relax with the highest priority. Also, obviously, after the test, the pointer should be reset to NULL, because there are several task queued, and with a global variable you have no way of knowing which is next.
Quoted 2 lines
I will do so. Do I have to change the gatekeeper's priority behind the relaxing task to assure that the gatekeeper would be scheduled before?
The gatekeeper is not involved.
Signature · 1 line
Gilles.
Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Ok, maybe we have some hope with the tracer though. What should trigger a trace is the fact that a relax request has been sent, but that the next linux scheduling point does not wake up the said task. This is all debug code, so it does not need to be clean. You can define a per-cpu variable (if running on SMP systems, otherwise a global variable will do) with the last request posted. And when a linux scheduling happens, test that the newly scheduled task is the task that was passed to the relax, if that is not the case, trigger a trace freeze. The point where the nucleus is informed of a Linux task switch is
do_schedule_event(). The trick is that if you have some tasks with a higher priority than the relaxed task, it is normal that the relaxed task is not scheduled immediately, so if you want the condition to hold, you need to run the xenomai tasks which relax with the highest priority. Also, obviously, after the test, the pointer should be reset to NULL, because there are several task queued, and with a global variable you have no way of knowing which is next.
Quoted 4 lines
Quoted 2 lines
I will do so. Do I have to change the gatekeeper's priority behind the relaxing task to assure that the gatekeeper would be scheduled before?
The gatekeeper is not involved.
Sorry, I wanted to say: "that gatekeeper would NOT be scheduled before?". Otherwise we see possibly the gatekeeper instead of the relaxed task? Or am I wrong?
Regards,
Christoph
Quoted 18 lines · Christoph
Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Ok, maybe we have some hope with the tracer though. What should trigger a trace is the fact that a relax request has been sent, but that the next linux scheduling point does not wake up the said task. This is all debug code, so it does not need to be clean. You can define a per-cpu variable (if running on SMP systems, otherwise a global variable will do) with the last request posted. And when a linux scheduling happens, test that the newly scheduled task is the task that was passed to the relax, if that is not the case, trigger a trace freeze. The point where the nucleus is informed of a Linux task switch is
do_schedule_event(). The trick is that if you have some tasks with a higher priority than the relaxed task, it is normal that the relaxed task is not scheduled immediately, so if you want the condition to hold, you need to run the xenomai tasks which relax with the highest priority. Also, obviously, after the test, the pointer should be reset to NULL, because there are several task queued, and with a global variable you have no way of knowing which is next.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
I will do so. Do I have to change the gatekeeper's priority behind the relaxing task to assure that the gatekeeper would be scheduled before?
The gatekeeper is not involved.
Sorry, I wanted to say: "that gatekeeper would NOT be scheduled before?". Otherwise we see possibly the gatekeeper instead of the relaxed task? Or am I wrong?
I meant to say the gatekeeper is not involved in the primary to secondary mode switches, only in the secondary to primary mode switches. But yes, since it runs with the highest priority, it may be the one scheduled when back to primary mode. Though I would say it is probably very unlikely, since the events activating the gatekeeper is a secondary mode event, which by definition could not have happened while another task was in primary mode. So what could happen is that one task running in secondary mode tries to switch to primary mode, at which point, before the gatekeeper is even activated, another task running in primary mode is activated (perhaps because it is waiting for an interrupt, may it be atimer).
Signature · 1 line
Gilles.
Quoted 26 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 17 lines
Ok, maybe we have some hope with the tracer though. What should trigger a trace is the fact that a relax request has been sent, but that the next linux scheduling point does not wake up the said task. This is all debug code, so it does not need to be clean. You can define a per-cpu variable (if running on SMP systems, otherwise a global variable will do) with the last request posted. And when a linux scheduling happens, test that the newly scheduled task is the task that was passed to the relax, if that is not the case, trigger a trace freeze. The point where the nucleus is informed of a Linux task switch is
do_schedule_event(). The trick is that if you have some tasks with a higher priority than the relaxed task, it is normal that the relaxed task is not scheduled immediately, so if you want the condition to hold, you need to run the xenomai tasks which relax with the highest priority. Also, obviously, after the test, the pointer should be reset to NULL, because there are several task queued, and with a global variable you have no way of knowing which is next.Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
I will do so. Do I have to change the gatekeeper's priority behind the relaxing task to assure that the gatekeeper would be scheduled before?
The gatekeeper is not involved.
Sorry, I wanted to say: "that gatekeeper would NOT be scheduled before?". Otherwise we see possibly the gatekeeper instead of the relaxed task? Or am I wrong?
Quoted 11 lines
I meant to say the gatekeeper is not involved in the primary to secondary mode switches, only in the secondary to primary mode switches. But yes, since it runs with the highest priority, it may be the one scheduled when back to primary mode. Though I would say it is probably very unlikely, since the events activating the gatekeeper is a secondary mode event, which by definition could not have happened while another task was in primary mode. So what could happen is that one task running in secondary mode tries to switch to primary mode, at which point, before the gatekeeper is even activated, another task running in primary mode is activated (perhaps because it is waiting for an interrupt, may it be atimer).
I have added debug code as described by you. Unfortunately I am not sure if I catch the correct point in time to trigger the trace. The problem is that beside gatekeeper their are also some kernel interrupt tasks that have a higher priority.
Because of that and to understand whats happening here I have added some other debug code. Thereby my goal was to verify if all requests of schedule_linux_call() are processed by lostage_handler(). This is realized as below:
1) In schedule_linux_call() I check if it's the request for my highest prio task. If yes I keep the tasks's pointer in a global variable.
2) In lostage_handler() before wake_up_process() call I check if the global pointer is equal to the current request. If true it's the wakeup for my high prio task. In that case I keep that information by clearing the global pointer with NULL.
3) In do_schedule_event() I output some printk() message when the global pointer is unequal to NULL.
What I would expect now is to see no message from do_schedule_event(), since lostage_handler() should be called before do_schedule_event(). However after some run-time I see the printk() message of do_schedule_event(). After that all tasks are freezed.
Is my assumption from above wrong or is the outputted printk() message the indication that the problem has occurred?
For better understanding find my debug-changes below:
*** tmp/xenomai-2.6.3/ksrc/nucleus/shadow.c 2013-08-20 13:14:38.000000000 +0200
--- xenomai-2.6.3/ksrc/nucleus/shadow.c 2014-12-11 20:03:22.885493756 +0100
***************
*** 752,757 ****
--- 752,758 ----
}
}
+ static volatile struct task_struct *__last_requested_task = NULL; static void lostage_handler(void *cookie)
{
int cpu, reqnum, type, arg, sig, sigarg;***************
*** 795,800 ****
--- 796,803 ----
/* fall through */
case LO_START_REQ:
+ if (__last_requested_task && p==__last_requested_task)
+ __last_requested_task = NULL;
wake_up_process(p);
break;***************
*** 843,848 ****
--- 846,854 ----
rq->req[reqnum].task = p;
rq->req[reqnum].arg = arg;+ if (strcmp(p->comm, "LApp") == 0)
+ __last_requested_task = p;
+
__rthal_apc_schedule(lostage_apc);
splexit(s);
***************
*** 2606,2611 ****
--- 2612,2623 ----
if (!xnpod_active_p())
return;+ if (__last_requested_task)
+ {
+ printk("===================== lostage_handler() was not called before!\n");
+ __last_requested_task = NULL;
+ }
+
prev_task = current;
next = xnshadow_thread(next_task);
set_switch_lock_owner(prev_task);Regards,
Christoph
Hi Gilles,
it seems to me as APC interrupts on ipipe got lost. I have added two counters: One increments in schedule_linux_call() when a request for a specific application task is queued. Another one is incremented in lostage_handler() when the specific task was waked up. When I output the counter's values after tasks have freezed the counter of lostage_handler is exactly one value less than schedule_linux_call's counter.
And then, when I wake-up APC thread manually all freezed tasks continue for a moment, until all are freezing again.
Do you have any idea what could lead to that behaviour?
Regards,
Christoph
Quoted 10 lines
it seems to me as APC interrupts on ipipe got lost. I have added two counters:
One increments inschedule_linux_call()when a request for a specific application task is queued. Another one is incremented inlostage_handler()when the specific task was waked up. When I output the counter's values after tasks have freezed the counter oflostage_handleris exactly one value less than schedule_linux_call's counter.And then, when I wake-up APC thread manually all freezed tasks continue for a moment, until all are freezing again.
As said above waking APC thread using
wake_up_process(rthal_apc_servers[smp_processor_id()]);
does reactivate all Xenomai threads for scheduling. Incontrast using
rthal_apc_schedule(lostage_apc);
does not help. So it seems as APC interrupt is pending but won't be executed.
Any idea?
Regards,
Christoph
Quoted 15 lines · Christoph
Quoted 10 lines
it seems to me as APC interrupts on ipipe got lost. I have added two counters:
One increments inschedule_linux_call()when a request for a specific application task is queued. Another one is incremented inlostage_handler()when the specific task was waked up. When I output the counter's values after tasks have freezed the counter oflostage_handleris exactly one value less than schedule_linux_call's counter.And then, when I wake-up APC thread manually all freezed tasks continue for a moment, until all are freezing again.
As said above waking APC thread using
wake_up_process(rthal_apc_servers[smp_processor_id()]);
Quoted 7 lines
does reactivate all Xenomai threads for scheduling. Incontrast using
rthal_apc_schedule(lostage_apc);does not help. So it seems as APC interrupt is pending but won't be executed.
Any idea?
Do you have the same issue if you run a kernel patched with Xenomai and without the PREEMPT_RT patch?
Signature · 1 line
Gilles.
Quoted 16 lines
Quoted 16 lines
Quoted 9 lines
it seems to me as APC interrupts on ipipe got lost. I have added two counters:
One increments inschedule_linux_call()when a request for a specific application task is queued. Another one is incremented inlostage_handler()when the specific task was waked up. When I output the counter's values after tasks have freezed the counter oflostage_handleris exactly one value less than schedule_linux_call's counter.And then, when I wake-up APC thread manually all freezed tasks continue for a moment, until all are freezing again.
As said above waking APC thread using
wake_up_process(rthal_apc_servers[smp_processor_id()]);does reactivate all Xenomai threads for scheduling. Incontrast using
Quoted 8 lines
Quoted 5 lines
rthal_apc_schedule(lostage_apc);does not help. So it seems as APC interrupt is pending but won't be executed.
Any idea?
Do you have the same issue if you run a kernel patched with Xenomai and without the
PREEMPT_RTpatch?
No, without PREEMPT_RT the problem did not yet occur.
Regards,
Christoph
Quoted 18 lines · Christoph
Quoted 18 lines
Quoted 18 lines
Quoted 9 lines
it seems to me as APC interrupts on ipipe got lost. I have added two counters:
One increments inschedule_linux_call()when a request for a specific application task is queued. Another one is incremented inlostage_handler()when the specific task was waked up. When I output the counter's values after tasks have freezed the counter oflostage_handleris exactly one value less than schedule_linux_call's counter.And then, when I wake-up APC thread manually all freezed tasks continue for a moment, until all are freezing again.
As said above waking APC thread using
wake_up_process(rthal_apc_servers[smp_processor_id()]);does reactivate all Xenomai threads for scheduling. Incontrast using
rthal_apc_schedule(lostage_apc);
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
does not help. So it seems as APC interrupt is pending but won't be executed.
Any idea?
Do you have the same issue if you run a kernel patched with Xenomai and without the
PREEMPT_RTpatch?No, without
PREEMPT_RTthe problem did not yet occur.
Have you tried to follow the path from rthal_apc_schedule to rthal_apc_handler to see where the notification gets lost?
Also note that calling wake_up_process from primary mode is not a good idea.
Signature · 1 line
Gilles.
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
Quoted 22 lines
Quoted 10 lines
it seems to me as APC interrupts on ipipe got lost. I have added two counters:
One increments inschedule_linux_call()when a request for a specific application task is queued. Another one is incremented inlostage_handler()when the specific task was waked up. When I output the counter's values after tasks have freezed the counter oflostage_handleris exactly one value less than schedule_linux_call's counter.And then, when I wake-up APC thread manually all freezed tasks continue for a moment, until all are freezing again.
As said above waking APC thread using
wake_up_process(rthal_apc_servers[smp_processor_id()]);does reactivate all Xenomai threads for scheduling. Incontrast using
rthal_apc_schedule(lostage_apc);does not help. So it seems as APC interrupt is pending but won't be executed.
Any idea?
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Do you have the same issue if you run a kernel patched with Xenomai and without the
PREEMPT_RTpatch?No, without
PREEMPT_RTthe problem did not yet occur.Have you tried to follow the path from
rthal_apc_scheduletorthal_apc_handlerto see where the notification gets lost?
I am about to do that. Unfortunately I am not very familiar with ipipe implementation. Do you know if there are some tracing or debug features that could help me here?
Quoted 2 lines
Also note that calling
wake_up_processfrom primary mode is not a good idea.
Thank for the hint. Actually I had used wake_up_process() only from 2nd domain to test if this APC thread was broken or not.
Thanks and regards,
Christoph
Quoted 26 lines · Christoph
Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
Quoted 15 lines
Quoted 10 lines
it seems to me as APC interrupts on ipipe got lost. I have added two counters:
One increments inschedule_linux_call()when a request for a specific application task is queued. Another one is incremented inlostage_handler()when the specific task was waked up. When I output the counter's values after tasks have freezed the counter oflostage_handleris exactly one value less than schedule_linux_call's counter.And then, when I wake-up APC thread manually all freezed tasks continue for a moment, until all are freezing again.
As said above waking APC thread using
wake_up_process(rthal_apc_servers[smp_processor_id()]);Quoted 7 lines
does reactivate all Xenomai threads for scheduling. Incontrast using
rthal_apc_schedule(lostage_apc);does not help. So it seems as APC interrupt is pending but won't be executed.
Any idea?
Do you have the same issue if you run a kernel patched with Xenomai and without the
PREEMPT_RTpatch?
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
No, without
PREEMPT_RTthe problem did not yet occur.Have you tried to follow the path from
rthal_apc_scheduletorthal_apc_handlerto see where the notification gets lost?I am about to do that. Unfortunately I am not very familiar with ipipe implementation. Do you know if there are some tracing or debug features that could help me here?
The APC code mostly happens in ksrc/arch/generic/hal.c and the PREEMPT_RT path is distinct from the non PREEMPT_RT one, so, I would tend to believe that the problem is in that code. As for tracing, same as usual, you can use the I-pipe tracer, injecting some calls to ipipe_trace_special() perhaps, to save some values in the trace.
Signature · 1 line
Gilles.
After some research I have ended up now in APC'c thread handling (see code snipped below, out of ksrc/arch/generic/hal.c). From my point of view there could be occur the "lost wakeup problem". That means in detail that rthal_kicker() calls wakeup when rthal_apc_thread() has returned from rthal_apc_handler() but not yet called set_current_state(). After that, when kicker has finished, the APC thread calls set_current_state() and goes to sleep. Thus, the wakeup is lost. Or do I overlook something? Maybe we should use a waitqueue here?
static int rthal_apc_thread(void *data)
{
unsigned cpu = (unsigned)(unsigned long)data;
set_cpus_allowed(current, cpumask_of_cpu(cpu));
sigfillset(¤t->blocked);
current->flags |= PF_NOFREEZE;
/* Use highest priority here, since some apc handlers might
require to run as soon as possible after the request has been
pended. */
rthal_setsched_root(current, SCHED_FIFO, MAX_RT_PRIO - 1);
while (!kthread_should_stop()) {
set_current_state(TASK_INTERRUPTIBLE);
schedule();
rthal_apc_handler(0, NULL);
}
__set_current_state(TASK_RUNNING);
return 0;
}void rthal_apc_kicker(unsigned virq, void *cookie)
{
wake_up_process(rthal_apc_servers[smp_processor_id()]);
}Regards,
Christoph
Quoted 10 lines · Christoph
After some research I have ended up now in APC'c thread handling (see code snipped below, out of
ksrc/arch/generic/hal.c). From my point of view there could be occur the "lost wakeup problem". That means in detail thatrthal_kicker()calls wakeup whenrthal_apc_thread()has returned fromrthal_apc_handler()but not yet calledset_current_state(). After that, when kicker has finished, the APC thread callsset_current_state()and goes to sleep. Thus, the wakeup is lost. Or do I overlook something? Maybe we should use a waitqueue here?
Indeed, this looks suspicious. Please try the wait queue.
Signature · 1 line
Gilles.
Quoted 5 lines · Christoph
After some research I have ended up now in APC'c thread handling (see code snipped below, out of
ksrc/arch/generic/hal.c). From my point of view there could be occur the "lost wakeup problem". That means in detail thatrthal_kicker()calls wakeup whenrthal_apc_thread()has returned fromrthal_apc_handler()but not yet calledset_current_state(). After that, when kicker has finished, the APC thread callsset_current_state()and goes to sleep. Thus, the wakeup is lost. Or do I overlook something? Maybe we should use a waitqueue here?static int
rthal_apc_thread(void *data)
Quoted 14 lines
{
unsigned cpu = (unsigned)(unsigned long)data;
set_cpus_allowed(current, cpumask_of_cpu(cpu));
sigfillset(¤t->blocked);
current->flags |= PF_NOFREEZE;
/* Use highest priority here, since some apc handlers might
require to run as soon as possible after the request has been
pended. */
rthal_setsched_root(current, SCHED_FIFO, MAX_RT_PRIO - 1);
while (!kthread_should_stop()) {
set_current_state(TASK_INTERRUPTIBLE);
schedule();You can obtain the same effect as with a wait queue by replacing the schedule() above with:
if (rthal_apc_pending[cpu] == 0) schedule();
However, using a wait queue will make the code easier to read.
Quoted 12 lines
rthal_apc_handler(0, NULL); } __set_current_state(TASK_RUNNING); return 0; }void
rthal_apc_kicker(unsigned virq, void *cookie){ wake_up_process(rthal_apc_servers[smp_processor_id()]); }
Signature · 1 line
Gilles.
Quoted 21 lines · Gilles Chanteperdrix
Quoted 5 lines · Christoph
After some research I have ended up now in APC'c thread handling (see code snipped below, out of
ksrc/arch/generic/hal.c). From my point of view there could be occur the "lost wakeup problem". That means in detail thatrthal_kicker()calls wakeup whenrthal_apc_thread()has returned fromrthal_apc_handler()but not yet calledset_current_state(). After that, when kicker has finished, the APC thread callsset_current_state()and goes to sleep. Thus, the wakeup is lost. Or do I overlook something? Maybe we should use a waitqueue here?static int
rthal_apc_thread(void *data)Quoted 14 lines
{ unsigned cpu = (unsigned)(unsigned long)data; set_cpus_allowed(current, cpumask_of_cpu(cpu)); sigfillset(¤t->blocked); current->flags |= PF_NOFREEZE; /* Use highest priority here, since some apc handlers might require to run as soon as possible after the request has been pended. */ rthal_setsched_root(current, SCHED_FIFO, MAX_RT_PRIO - 1); while (!kthread_should_stop()) { set_current_state(TASK_INTERRUPTIBLE); schedule();
Quoted 5 lines
You can obtain the same effect as with a wait queue by replacing the
schedule()above with:if (rthal_apc_pending[cpu] == 0) schedule();
else set_current_state(TASK_RUNNING);
Signature · 1 line
Gilles.
Quoted 26 lines
Quoted 26 lines
After some research I have ended up now in APC'c thread handling
Quoted 24 lines
(see code snipped below, out of
ksrc/arch/generic/hal.c). From my point of view there could be occur the "lost wakeup problem". That means in detail thatrthal_kicker()calls wakeup whenrthal_apc_thread()has returned fromrthal_apc_handler()but not yet calledset_current_state(). After that, when kicker has finished, the APC thread callsset_current_state()and goes to sleep. Thus, the wakeup is lost. Or do I overlook something? Maybe we should use a waitqueue here?static int
rthal_apc_thread(void *data){ unsigned cpu = (unsigned)(unsigned long)data; set_cpus_allowed(current, cpumask_of_cpu(cpu)); sigfillset(¤t->blocked); current->flags |= PF_NOFREEZE; /* Use highest priority here, since some apc handlers might require to run as soon as possible after the request has been pended. */ rthal_setsched_root(current, SCHED_FIFO, MAX_RT_PRIO - 1); while (!kthread_should_stop()) { set_current_state(TASK_INTERRUPTIBLE); schedule();
Quoted 7 lines
Quoted 5 lines
You can obtain the same effect as with a wait queue by replacing the
schedule()above with:if (rthal_apc_pending[cpu] == 0) schedule();else set_current_state(TASK_RUNNING);
Thanks for the hint, I like your approach. There we do not need to allocate a waitqueue resource. Moreover the task wont be scheduled for every wakup call but only as often as required. I will check if my application runs stable now with that fix. If true I will publish the patch here.
Regards,
Christoph