All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gilles Chanteperdrix <gilles.chanteperdrix@xenomai.org>
To: Peter Pastor <peter.pastor@domain.hid>
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-help] detect mode switches to primary mode
Date: Sat, 06 Nov 2010 19:20:15 +0100	[thread overview]
Message-ID: <4CD59C5F.6030808@domain.hid> (raw)
In-Reply-To: <AANLkTinw+H2shS4SpxhTS7GNOZptjR8xLpcwpzDtKDmi@domain.hid>

Peter Pastor wrote:
> Hey Gilles,
> 
> Sorry for all the confusion. I hope my little example pseudo code of the
> boarder line thread makes things clear.
> 
> thread_loop()
> {
> 
> // access memory that is shared with a real-time thread (that does not
> mode switch)
> // calling pthread_mutex_lock causes the current thread to switch to
> primary mode (in case it is not already in primary mode)
> 
>   pthread_mutex_lock( &mutex1 );
> 
> // access shared memory, that is copy memory and nothing else !!
> 
>   pthread_mutex_unlock( &mutex1 );
> 
> // Now, I want the rest of the code to run in secondary mode !!
> // therefore I could simply do a printf or...
> 
> #ifdef __XENO__
>   pthread_set_mode_np(PTHREAD_PRIMARY, 0);
> #endif

This is not needed, the thread will swtich to secondary mode when needed.

> 
> // The thread switched to secondary mode.
> // Now, I process the data and e.g. display it using openGL or read from
> the command line. I want this part of the code to run in secondary mode !!
> 
> // I am using the posix skin (/usr/xenomai/bin/xeno-config --skin posix
> --cflags --ldflags) because I want to be able to compile the code in
> xenomai and ensure real-time capabilities and also compile on a linux
> only system for testing.
> 
> // However, the openGL code or libreadline for example might do a posix
> function call and cause the thread switch back to primary mode which I
> don't want !!! ...and want to detect.

No, dynamic libraries will not call xenomai posix skin functions,
unless, when making the .so, you passed the --wrap flag. Once the .so is
made, --wrap has no effect.

> 
> }
> 
> 
> My current approach to detect whether there was an unwanted mode switch
> from secondary to primary in the non-real-time part of the thread is to
> detect mode switches from primary to secondary using
> pthread_set_mode_np(0, PTHREAD_WARNSW) and signal(SIGXCPU,
> warn_upon_switch)... and do the following
> 
> 
> thread_loop()
> {
> 
> // to check there was an unwanted mode switches to primary mode (in the
> for example openGL code) I simply do a printf
> // and check whether this raises the SIGXCPU signal. If so, the thread
> was running in primary mode, otherwise, the thread was running in
> secondary mode (which is want I want)
> // If the thread switched back and force inside the openGL code, I
> should have noticed it since switching from primary to secondary is
> captured by the SIGXCPU (is it?)
> 
> // here is the code...
> 
> #ifdef __XENO__
>   printf("test\n");  // in case the thread is running in PRIMARY mode,
> this will raise a SIGXCPU signal and we conclude that there was an
> unwanted mode swicht from secondary to primary mode in the openGL code.
>   pthread_set_mode_np(0,PTHREAD_PRIMARY); // this is unnecessary !!!
> ...since calling pthread_mutex_lock switches the thread to primary mode
> automatically.
> #endif
> 
>   pthread_mutex_lock( &mutex1 );
> // access shared memory, that is copy memory and nothing else !!
>   pthread_mutex_unlock( &mutex1 );
> 
> // switch back to SECONDARY mode
> #ifdef __XENO__
>   pthread_set_mode_np(PTHREAD_PRIMARY, 0);
> #endif
> 
> // do non-real-time processing (e.g. openGL stuff, libreadline...).
> 
> }
> 
> The question is, is there a better way to detect this unwanted mode
> switches from secondary to primary mode ?

There is no such thing as unwanted mode switches from secondary mode to
primary mode.


-- 
                                                                Gilles.


  reply	other threads:[~2010-11-06 18:20 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-06  2:26 [Xenomai-help] detect mode switches to primary mode Peter Pastor
2010-11-06 13:51 ` Gilles Chanteperdrix
     [not found]   ` <AANLkTimhUUYDkHh6wJ_zL8dLJgCi+7F8kOXrA63LzTO9@domain.hid>
2010-11-06 15:34     ` Gilles Chanteperdrix
2010-11-06 16:08     ` Gilles Chanteperdrix
2010-11-06 17:03   ` Peter Pastor
2010-11-06 18:20     ` Gilles Chanteperdrix [this message]
2010-11-06 19:43       ` Peter Pastor
2010-11-06 19:48         ` Gilles Chanteperdrix

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4CD59C5F.6030808@domain.hid \
    --to=gilles.chanteperdrix@xenomai.org \
    --cc=peter.pastor@domain.hid \
    --cc=xenomai@xenomai.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.