Skip to contentSkip to conversation

help with porting simple posix application

Xenomai-help Leyrit Vincent 2 participants 6 messages Apr 30, 2010

lore
Share & tools
lore
#0 lore raw

Hello,

i would like to port a POSIX application on XENOMAI ..
i have try a very simple test to verify the xenomai functionnalities ... a thread call a recursive funtion which call clock_gettime() ... this thread is set with a SCHED_FIFO and has a priority of 10 ...

the binary is well linked with the xenomail pthread_rt library (in makefile i have used xeno-config with posix sking and cflags / ldflags)

when i execute the binary , i take a look on the /proc/xenomai/sched and i see that my thread is set as X 'related shadow'
i think it is a problem? For my opinion the flag show that my thread swich many time from the Xenomai domain to the Linux domain ...

Does someone can help me if my simple code is false? Thanks for help...

Alexandre... (xenomai )

xeno-info : xenomai 2.5.2 (kernel 2.6.32.11 | ipipe 2.6-03)

CODE -----------------------------------------------------------------------

int recursive_method(int cp)
{
struct timeval ta;
struct timespec ts_start, ts_end;

if(cp < n_recurs)

    {
      for(int i=0; i < 10;i++)
        {
          clock_gettime(CLOCK_REALTIME,&ts_start);
          xnprintf("%d\n", ts_start.tv_nsec);
        }
      recursive_method(cp++);
    }
}

void *producer(void *)
{
recursive_method(1);
return 0;
}

int xeno_user_init()
{
struct sched_param parm;
pthread_attr_t attr;
int rc = 0, fd = -1;
struct sigevent evt;

  pthread_attr_init(&attr);
  pthread_attr_setinheritsched(&attr, 1);
  pthread_attr_setschedpolicy(&attr, SCHED_FIFO);
  parm.sched_priority = 10;
  pthread_attr_setschedparam(&attr, &parm);

  rc = pthread_create(&producer_task, &attr, &producer, NULL);

if (rc)

    {
      xnprintf("pthread_create(producer_task): %d\n", rc);
    }

return rc;
}

int main (int ac, char *av[])
{
int rc, sig;
mlockall(MCL_CURRENT|MCL_FUTURE);

rc = xeno_user_init();
return 0;
}

CODE -----------------------------------------------------------------------

#1 lore raw
Quoted 3 lines · Leyrit Vincent

Hello,

i would like to port a POSIX application on XENOMAI ..

See:
http://www.xenomai.org/index.php/Porting_POSIX_applications_to_Xenomai

Quoted 7 lines

CODE -----------------------------------------------------------------------

int recursive_method(int cp)
{
struct timeval ta;
struct timespec ts_start, ts_end;

Quoted 6 lines
  if(cp < n_recurs)
    {
      for(int i=0; i < 10;i++)
        {
          clock_gettime(CLOCK_REALTIME,&ts_start);
          xnprintf("%d\n", ts_start.tv_nsec);

printf here causes a switch to secondary mode.

Signature · 1 line
					    Gilles.
#2 lore raw

Thanks you for the link, i have already have a look on it ... The only thing that i do not understand in the code i have posted, is that i never do any call to a linux domain syscall ...
but i don't see my thread in "runnable" (R) in the xenomai scheduler /proc/xenomai/sched...

Quoted 29 lines · Gilles Chanteperdrix
Quoted 3 lines · Leyrit Vincent

Hello,

i would like to port a POSIX application on XENOMAI ..

See:
http://www.xenomai.org/index.php/Porting_POSIX_applications_to_Xenomai

Quoted 1 line

CODE

-----------------------------------------------------------------------

Quoted 6 lines

int recursive_method(int cp)
{
struct timeval ta;
struct timespec ts_start, ts_end;

Quoted 6 lines
  if(cp < n_recurs)
    {
      for(int i=0; i < 10;i++)
        {
          clock_gettime(CLOCK_REALTIME,&ts_start);
          xnprintf("%d\n", ts_start.tv_nsec);

printf here causes a switch to secondary mode.

--
Gilles.

#3 lore raw
Quoted 3 lines · Leyrit Vincent

Thanks you for the link, i have already have a look on it ... The only thing that i do not understand in the code i have posted, is that i never do any call to a linux domain syscall ...

printf sometimes results in a linux domain syscall, it is mentioned in the howto.

Signature · 1 line
					    Gilles.
#4 lore raw

sorry i have forgot to post all the code :
here printf is a define to the one provided by xenomai library :

#define xnarch_printf printf

Quoted 11 lines · Gilles Chanteperdrix
Quoted 3 lines · Leyrit Vincent

Thanks you for the link, i have already have a look on it ... The only thing that i do not understand in the code i have posted, is that i never do any call to a linux domain syscall ...

printf sometimes results in a linux domain syscall, it is mentioned in the howto.

--
Gilles.

#5 lore raw
Quoted 4 lines · Leyrit Vincent

sorry i have forgot to post all the code :
here printf is a define to the one provided by xenomai library :

#define xnarch_printf printf

If you do not believe me, use pthread_set_mode_np as explained in the howto.

Signature · 1 line
					    Gilles.