Skip to contentSkip to conversation

Detecting switch to secondary mode

Xenomai-help J. Niehaus 4 participants 4 messages Jul 6, 2006

lore
Share & tools
lore

J. Niehaus

author
#0 lore raw

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

#1 lore raw
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/xenomai would 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

#2 lore raw
In reply to J. Niehaus
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/xenomai would 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.
#3 lore raw
In reply to J. Niehaus
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/xenomai would 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.