TR: rt_change_priority weird error..

Manoel Trapier godzil at godzil.net
Fri Jun 9 15:29:27 CEST 2006


I made some more precise test, and it seems like that changing the priority
of a task waiting on a mailbox tend to crash the task who trying to change
the priority.

 

I make a simple test case :

 

I made two tasks, the first creating a mailbox, and waiting on it:
(tache1.c)           

 

/* Standards Header */

#include <stdio.h>

#include <errno.h>

#include <unistd.h>

#include <sys/types.h>

#include <sys/mman.h>

#include <pthread.h>

#include <signal.h>

 

 

/* RTAI / LXRT Specifics headers */

#include <rtai_lxrt.h>

#include <rtai_bits.h>

 

#include <rtai_mbx.h>

 

 

int main(int argc, char *argv[])

{

  RT_TASK *pMain;

  void *mbx;

  char buffer[256];

  unsigned long TOTO = nam2num("TACHE1");

 

  printf("Starting main...\n");

 

  printf("0\n");

  /* Disable paging !!! REALLY IMPORTANT */

  mlockall(MCL_CURRENT | MCL_FUTURE);

  printf("1\n");

  /* Swith to RT mode */ 

  pMain = rt_task_init_schmod( TOTO , /* The name */

                         255,                 /* Priority */

                         0,                 /* Stack Size */

                         0,                 /* Max_msg_size */

                         SCHED_FIFO,        /* Policy */

                         0 );               /* cpus_allowed */

  rt_make_soft_real_time();

  printf("Init.\n");

  if (pMain == NULL)

  {

    fprintf( stderr, "%s: Error switching to RTAI/LXRT mode!!\n", argv[0]);

    exit(1);

  }

  mbx = rt_mbx_init(nam2num("DAMBX"),2048);

  printf("Waiting on mailbox...\n");

  /* Here do what a module is aout to do... */

 

  while(1)

  {

   rt_mbx_receive((struct rt_mailbox*) mbx, buffer, 10);

   printf("%lld ",rt_get_time());

  }

  

 

  if (pMain != NULL) // In case of....

    rt_task_delete( pMain);

  printf("Stopping....\n");

  return 0;

} /* EOM */

 

 

And a second task who try to change constantly the priority of the first
one: (tache2.c)

 

/* Standards Header */

#include <stdio.h>

#include <errno.h>

#include <unistd.h>

#include <sys/types.h>

#include <sys/mman.h>

#include <pthread.h>

#include <signal.h>

 

 

/* RTAI / LXRT Specifics headers */

#include <rtai_lxrt.h>

#include <rtai_bits.h>

 

#include <rtai_mbx.h>

 

 

int main(int argc, char *argv[])

{

  RT_TASK *pMain, *pTache1;

  unsigned long TOTO = nam2num("TACHE2");

  int NewVal = 30;

  printf("Starting main...\n");

 

  printf("0\n");

  /* Disable paging !!! REALLY IMPORTANT */

  mlockall(MCL_CURRENT | MCL_FUTURE);

  printf("1\n");

  /* Swith to RT mode */ 

  pMain = rt_task_init_schmod( TOTO , /* The name */

                         20,                 /* Priority */

                         0,                 /* Stack Size */

                         0,                 /* Max_msg_size */

                         SCHED_FIFO,        /* Policy */

                         0 );               /* cpus_allowed */

 

  printf("Init.\n");

  if (pMain == NULL)

  {

    fprintf( stderr, "%s: Error switching to RTAI/LXRT mode!!\n", argv[0]);

    exit(1);

  }

 

  printf("Changin TACHE1 priority..\n");

  /* Here do what a module is aout to do... */

  pTache1 = (RT_TASK *)rt_get_adr(nam2num("TACHE1"));

  while(1)

  {

  rt_change_prio(pTache1,1000000000+NewVal);

  sleep(1);

  NewVal--;

  if (NewVal < 0) 

      NewVal += 30;

  

  }

  

 

  if (pMain != NULL) // In case of....

    rt_task_delete( pMain);

  printf("Stopping....\n");

  return 0;

} /* EOM */

 

 

The makefile is as simple as:

 

RTAI_CONFIG=/usr/realtime/bin/rtai-config

LDFLAGS_LXRT=`$(RTAI_CONFIG) --lxrt-ldflags`

CFLAGS_LXRT=`$(RTAI_CONFIG) --lxrt-cflags` -g -c

CC=`$(RTAI_CONFIG) --cc`

CXX=`$(RTAI_CONFIG) --cxx`

 

all: tache1 tache2

 

tache2: tache2.o

        $(CC) $(LDFLAGS_LXRT) -o $(@) $(?)

 

tache1: tache1.o

        $(CC) $(LDFLAGS_LXRT) -o $(@) $(?)

 

tache2.o: tache2.c

        $(CC) $(CFLAGS_LXRT) -o $(@) $(?)

 

tache1.o: tache1.c

        $(CC) $(CFLAGS_LXRT) -o $(@) $(?)

 

clean:

        rm -f *.o *~  tache1 tache2

 

 

 

--

 

What I get during after executing “tache1”:

 

On /proc/rtai/names:

 

Every 0.1s: cat /proc/rtai/names                        Fri Jun  9 16:27:19
2006

 

 

RTAI LXRT Information.

 

    MAX_SLOTS = 100

 

                                         Linux_Owner         Parent PID

Slot Name   ID         Type   RT_Handle    Pointer   Tsk_PID   MEM_Sz   USG
Cnt

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

  85 TACHE1 0xa2e5db87 TASK   0xf0c4f220 0x00000000        0      18152
1

  90 DAMBX  0x01f8b3ca MBX    0xf0c4e4a0 0xd4ea2060    18152          0
1

 

 

On /proc/rtai/scheduler:

 

Every 0.1s: cat /proc/rtai/scheduler                    Fri Jun  9 16:29:08
2006

 

 

RTAI LXRT Real Time Task Scheduler.

 

    Calibrated CPU Frequency: 1000065000 Hz

    Calibrated interrupt to scheduler latency: 2688 ns

    Calibrated oneshot timer setup_to_firing time: 2010 ns

 

Number of RT CPUs in system: 1

 

Number of forced hard/soft/hard transitions: traps 0, syscalls 2

 

Priority  Period(ns)  FPU  Sig  State  CPU  Task  HD/SF  PID  RT_TASK *
TIME

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

1000000255 0           Yes  No  0x101  0:1   1      0    18152  f0c4f220   0

TIMED

 

READY

 

On tache1 tty:

nausicaa ~ # ./tache1

Starting main...

0

1

Init.

Waiting for 2minutes...

 

 

Now after running tache2:

 

tache2 tty:

nausicaa ~ # ./tache2

Starting main...

0

1

Init.

Waiting for 2minutes...

 

 

/proc/rtai/names:

 

Every 0.1s: cat /proc/rtai/names                        Fri Jun  9 16:30:42
2006

 

 

RTAI LXRT Information.

 

    MAX_SLOTS = 100

 

                                         Linux_Owner         Parent PID

Slot Name   ID         Type   RT_Handle    Pointer   Tsk_PID   MEM_Sz   USG
Cnt

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

  85 TACHE1 0xa2e5db87 TASK   0xf0c4f220 0x00000000        0      18152
1

  86 TACHE2 0xa2e5db88 TASK   0xf0c51220 0x00000000        0      21547
1

  90 DAMBX  0x01f8b3ca MBX    0xf0c4e4a0 0xd4ea2060    18152          0
1

 

 

And /proc/rtai/scheduler:

 

Every 0.1s: cat /proc/rtai/scheduler                    Fri Jun  9 16:31:03
2006

 

 

RTAI LXRT Real Time Task Scheduler.

 

    Calibrated CPU Frequency: 1000065000 Hz

    Calibrated interrupt to scheduler latency: 2688 ns

    Calibrated oneshot timer setup_to_firing time: 2010 ns

 

Number of RT CPUs in system: 1

 

Number of forced hard/soft/hard transitions: traps 0, syscalls 2

 

Priority  Period(ns)  FPU  Sig  State  CPU  Task  HD/SF  PID  RT_TASK *
TIME

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

1000000030 0           Yes  No  0x101  0:1   1      0    18152  f0c4f220   0

TIMED

 

READY

 

 

It seems like the priority is changed, BUT the task tache2 is no more on the
lxrt scheduler, but linux still see it, the process can’t be killed by any
linux way


 

And, if I remove the “rt_mbx_receive” from the task tache1 everything goes
well
. Even if I replace it by a rt_sleep.

 

 

 

 

Manoël

 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.rtai.org/pipermail/rtai/attachments/20060609/151bfc3c/attachment.htm 


More information about the Rtai mailing list