Detecting switch to secondary mode
Hello,
I have written a xenomai application (posix-skin) with several tasks. All of them should normally use primary mode (SCHED_FIFO). While some are allowed to switch to secondary mode for stuff like I/O and memory allocation others must not switch due to hard realtime constraints.
Is there a way to check if and how often a thread has switched to secondary mode and maybe even what system call caused the switch? While a test from within the program itself would be great some information from /proc/xenomai would also do.
Thanks,
Jens
Quoted 6 lines · J. Niehaus
Hello,
I have written a xenomai application (posix-skin) with several tasks. All of them should normally use primary mode (
SCHED_FIFO). While some are allowed to switch to secondary mode for stuff like I/O and memory allocation others must not switch due to hard realtime constraints.Is there a way to check if and how often a thread has switched to secondary mode and maybe even what system call caused the switch? While a test from within the program itself would be great some information from
/proc/xenomaiwould also do.
Yes, see this example:
http://www.rts.uni-hannover.de/xenomai/lxr/source/ksrc/skins/native/snippets/sigxcpu.c
We have the following code snippet in the signal handler of our RACK framework:
void signal_handler(int sig)
{
[...]
switch(sig)
{
case SIGXCPU:
if (signal_flags & HANDLING_TERM) // ignore while
cleaning // up
return;
printf("\n");
printf("---=== SIGNAL HANDLER of %s ===---\n", classname);
printf(" -> SIGXCPU (%02d)\n", sig);
printf(" !!! WARNING unexpected switch to secondary mode "
"!!!\n");
nentries = backtrace (array, 10);
strings = backtrace_symbols (array, nentries);
for (i = 0; i < nentries; i++)
{
printf (" %s\n", strings[i]);
}
free (strings);
printf("---=== END OF %s SIGNAL HANDLER ===---\n",
classname);
return;[...]
I.e. it does a back-trace to show what happened in user-space (debug symbols are required). It's VERY useful when letting beginners hack their first RT applications.
Jan
Quoted 6 lines · J. Niehaus
Hello,
I have written a xenomai application (posix-skin) with several tasks. All of them should normally use primary mode (
SCHED_FIFO). While some are allowed to switch to secondary mode for stuff like I/O and memory allocation others must not switch due to hard realtime constraints.Is there a way to check if and how often a thread has switched to secondary mode and maybe even what system call caused the switch? While a test from within the program itself would be great some information from
/proc/xenomaiwould also do.
The MSW ("mode switch") column from /proc/xenomai/stats tells you how many times any given thread switched to secondary mode; there is no finer detail given though. Also, setting the PTHREAD_TRAPSW switch for a thread using pthread_set_mode_np() makes Xenomai send this thread a SIGXCPU signal upon switch from primary to secondary - it's a useful debug tool when used along with GDB for instance.
Quoted 7 lines
Thanks,
Jens_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help
Signature · 1 line
Philippe.
Quoted 5 lines · J. Niehaus
Hello,
I have written a xenomai application (posix-skin) with several tasks. All of them should normally use primary mode (
SCHED_FIFO). While some are allowed to switch to secondary mode for stuff like I/O and memory allocation others must not switch due to hard realtime constraints.Is there a way to check if and how often a thread has switched to secondary mode and maybe even what system call caused the switch? While a test from within the program itself would be great some information from
/proc/xenomaiwould also do.
You may want to use pthread_set_mode_np:
http://www.xenomai.org/documentation/trunk/html/api/group__posix__thread.html#ga14
Signature · 1 line
Gilles Chanteperdrix.