All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] how to stop a runaway task
@ 2007-10-30  8:40 Carsten Spieß
  2007-10-30  9:00 ` Philippe Gerum
  2007-12-22 19:11 ` Philippe Gerum
  0 siblings, 2 replies; 13+ messages in thread
From: Carsten Spieß @ 2007-10-30  8:40 UTC (permalink / raw)
  To: xenomai

[-- Attachment #1: Type: text/plain, Size: 902 bytes --]

Hello,

i'm running Xenomai 2.3.2 on a PPC target with Linux 2.4.25 kernel.
I trying to programm a supervising task, that detects a runaway task
and suspend it.

My aproach was to make a high priority periodic task to look if
the low prio task is running correctly and suspend it when it detects
failure.
But this approach didn't work, the higer prio task isn't called unless
the lower prio task gives up cpu (by calling e.g. rt_task_yield or
nanosleep) (see attached demo source)

When not being cooperative (removing the rt_task_yield in the demo)
my system is reset after some seconds.

Why isn't my supervising task scheduled?

Tanks for help, regards

Carsten
-- 
Dipl.-Ing. Carsten Spieß
Softwareentwicklung - Beratung - Schulung
Lauterlech 39d
D-86152 Augsburg
Tel.: +49(821)15 999 765
Fax.: +49(821)15 999 767
mailto://mail@domain.hid
http://www.carsten-spiess.de

[-- Attachment #2: demo.c --]
[-- Type: application/octet-stream, Size: 2733 bytes --]

#include <stdio.h>
#include <native/task.h>
#include <signal.h>
#include <sys/mman.h>

static int count;

static RT_TASK id_low;
static RT_TASK id_high;

#define LOW_PRIO 5
#define HIGH_PRIO 10

void init_task(int n);

void runaway_task(void* dummy)
{
   int i;
   struct timespec tstart;
   struct timespec tperiod;
   
   tstart.tv_sec = 0;
   tstart.tv_nsec = 0;
   tperiod.tv_sec = 0;
   tperiod.tv_nsec = 16000;  // zeit in ns, reset bei <16 µs 

   printf("runaway task\n");

   while (1)
   {
//      sleep(1);
//      nanosleep(&tperiod,&tstart);
      rt_task_yield();
      for(i=0;i<50000;i++)count++;
   }
}

void supervisor_task(void* dummy)
{
   unsigned long nOverrun;
   RTIME   tick, tick_old;
   
   int step = 0;
   int loop = 0;

   if (rt_task_set_periodic(&id_high,TM_NOW, rt_timer_ns2ticks(500000)) == 0)
   {
      printf("supervisor task\n");

      tick_old = rt_timer_tsc();
      while (1)
      {
         //nanosleep(&tperiod,&tstart);
         if (rt_task_wait_period(&nOverrun) != 0)
            printf("supervisor task overrun %lu\n", nOverrun);

         tick = rt_timer_tsc();
         
         loop ++;
         switch (step)
         {
         case 0:
            if(loop > 100)
            {
               loop = 0;
               step = 1;
               init_task(LOW_PRIO);
            }
            break;
         case 1:
            if(loop > 200)
            {
               loop = 0;
               step = 2;
               rt_task_suspend(&id_low);
               printf("count = %d %lu %llu\n", count,nOverrun,tick-tick_old);
            }
            break;
         case 2:
            if(loop > 20)
            {
               loop = 0;
               step = 1;
               rt_task_resume(&id_low);
            }
            break;
         }
         tick_old = tick;
      }
   }
}

void init_task(int prio)
{
   switch (prio)
   {
   case LOW_PRIO:
      rt_task_create(&id_low, "runaway", 8192,prio, 0);
      rt_task_start(&id_low,runaway_task,0);
      break;
   case HIGH_PRIO:
      rt_task_create(&id_high, "supervisor", 8192,prio, 0);
      rt_task_start(&id_high,supervisor_task,0);
      break;
   }
}

void init_signals(sigset_t *mask)
{
   sigemptyset(mask);
   sigaddset(mask,SIGINT);
   sigaddset(mask,SIGTERM);
   sigaddset(mask,SIGHUP);
   sigaddset(mask,SIGALRM);

   pthread_sigmask(SIG_BLOCK, mask, NULL);
}

int main(int ac, char *av[])
{
   sigset_t mask;
   int sig;

   mlockall(MCL_CURRENT|MCL_FUTURE);
   count = 0;
   
   init_signals(&mask);
   init_task(HIGH_PRIO);
   
   sigwait(&mask, &sig);

   return 0;
}

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

end of thread, other threads:[~2007-12-23 21:55 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-30  8:40 [Xenomai-help] how to stop a runaway task Carsten Spieß
2007-10-30  9:00 ` Philippe Gerum
2007-10-30  9:53   ` Carsten Spieß
2007-10-30 10:33     ` Philippe Gerum
2007-10-31 17:20       ` Carsten Spieß
2007-10-31 19:03         ` Gilles Chanteperdrix
2007-10-31 19:43         ` Gilles Chanteperdrix
2007-11-01  8:38           ` Carsten Spieß
2007-11-01 16:22             ` Gilles Chanteperdrix
2007-11-01 19:40               ` Carsten Spieß
2007-11-01 19:47                 ` Gilles Chanteperdrix
2007-12-22 19:11 ` Philippe Gerum
2007-12-23 21:55   ` Carsten Spieß

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.