All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] Calling rt_task_shadow from a POSIX thread with --enable-dlopen-skins
@ 2011-04-25  2:20 Simon Leonard
  2011-04-25  6:47 ` Gilles Chanteperdrix
  0 siblings, 1 reply; 2+ messages in thread
From: Simon Leonard @ 2011-04-25  2:20 UTC (permalink / raw)
  To: xenomai

I have code based on the POSIX skin. For a (python related) reason, I 
had to re-compile Xenomai with --enable-dlopen-skins. The result is that 
unless I call rt_task_shadow, my threads don't work like they used to.

Although I *think* my code works by mixing rt_task_shadow with the POSIX 
skin I'm not convinced that it is legit. Can anybody advise?

Essentially, I need a CAN object that is instantiated and configured 
from main(). Then that object (pointer) is passed to a thread that 
Read/Write from/to it. Here a simplified version.

A few questions:
1) Can I mix rt_task_shadow from a thread created from POSIX skin?
2) If yes, is there limitations to POSIX function? For example, are the 
attributes of any pthread_attr_t discarded after calling rt_task_shadow?
4) How about a thread that doesn't use RTDM? Will it have "RT" latencies 
or rt_task_shadow must be called for that too?
4) Is it just better to port everything to native skin?

class CANdevice{

   RT_TASK task; // Added this for calling rt_task_shadow

public:

   CANdevice(){
     // add this block to Read/Write from main()
     if( rt_task_self() == NULL )
       { rt_task_shadow( &task, "can", prio, flags); }
   }

   void Configure(){ /* Read()/Write() */ }
   void Read() { /* rt_dev_recv  */
   void Write(){ /* rt_dev_send */

};

void* thread( void* argv ){

   CANdevice* can = (CANdevice*)argv;

   /* add this block to Read/Write from thread(void*) */
   RT_TASK task;
   if( rt_task_self() == NULL ){
     printf( "NOT A XENOMAI TASK\n" );
     rt_task_shadow(&task, "thread", prio, flags );
   }

   pthread_make_periodic_np ( pthread_self(), &starttp, &periodtp );

   while(1){
     can->Read();
     can->Write();
     pthread_wait_np(&overruns_r);
   }

   return NULL;
}

int main(){
   CANdevice can;
   can.Configure(); // main() must be Xenomai task to use RTDM

   pthread_t tid;
   pthread_attr_t attr;
   struct sched_param param;
   param.sched_priority = prio;

   // attributes
   pthread_attr_init( &attr );
   pthread_attr_setschedpolicy( &attr, SCHED_FIFO );
   pthread_attr_setschedparam( &attr, &param );

   // thread must be Xenomai task to use RTDM
   pthread_create( &tid, &attr, thread, (void*)&can );

}

/sl


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Xenomai-help] Calling rt_task_shadow from a POSIX thread with --enable-dlopen-skins
  2011-04-25  2:20 [Xenomai-help] Calling rt_task_shadow from a POSIX thread with --enable-dlopen-skins Simon Leonard
@ 2011-04-25  6:47 ` Gilles Chanteperdrix
  0 siblings, 0 replies; 2+ messages in thread
From: Gilles Chanteperdrix @ 2011-04-25  6:47 UTC (permalink / raw)
  To: Simon Leonard; +Cc: xenomai

Simon Leonard wrote:
> I have code based on the POSIX skin. For a (python related) reason, I 
> had to re-compile Xenomai with --enable-dlopen-skins. The result is that 
> unless I call rt_task_shadow, my threads don't work like they used to.

Mmmm. Normally, without --enable-dlopen-skins, only the main thread is
automatically made real-time.

> 
> Although I *think* my code works by mixing rt_task_shadow with the POSIX 
> skin I'm not convinced that it is legit. Can anybody advise?

It works, but, there are services in the POSIX skin which will only work
if the thread is a posix skin thread, not if it is a native skin thread.
Anyway, you can use pthread_setschedparam instead of rt_task_shadow.


-- 
                                                                Gilles.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-04-25  6:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-25  2:20 [Xenomai-help] Calling rt_task_shadow from a POSIX thread with --enable-dlopen-skins Simon Leonard
2011-04-25  6:47 ` Gilles Chanteperdrix

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.