All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] Preemptive scheduling
@ 2007-03-28 20:31 Jack Whorn
  2007-03-28 21:20 ` Gilles Chanteperdrix
  0 siblings, 1 reply; 12+ messages in thread
From: Jack Whorn @ 2007-03-28 20:31 UTC (permalink / raw)
  To: xenomai

Hi,

I`m new to Xenomai and I`m experiencing some issues.

Why does a Xenomai thread (native skin) with an infinite loop hang the system, though there are higher-priority RT-threads present, and
rt_task_set_mode periodically clears T_LOCK and T_SHIELD and sets T_RRB?

Isn`t the scheduler preemptive, first considering the thread`s priority and subsequently the thread`s position in its priority`s ready queue?

I have attached some sample code.

Thanks for any hint,

Jack


#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <sys/time.h>
#include <sys/io.h>
#include <sys/mman.h>
#include <sys/types.h>

#include <native/task.h>
#include <native/queue.h>
#include <native/intr.h>
#include <native/timer.h>


#define STACK_SIZE 8192
#define PRIO 10


static RT_TASK timer_task_desc;

//		              ..s.ms.µs.ns
static RTIME task_period_ns =   0100000000llu;

static unsigned long overruns = 0;

static void clean_exit(int dummy) {

  rt_task_delete(&timer_task_desc);

}

static void thread(void *cookie) {

  int ret;
  int i;
  int c;


  ret = rt_task_set_mode(T_LOCK, T_RRB, &c);
  if (ret)
    return;

  ret = rt_task_set_periodic(NULL, TM_NOW, rt_timer_ns2ticks(task_period_ns));
  if (ret)
    return;

  while (1) {
    
    ret = rt_task_set_mode(T_LOCK | T_SHIELD, T_RRB | T_PRIMARY, NULL);
    if (ret)
      return;

    ret = rt_task_wait_period(&overruns);
    if (ret == -ETIMEDOUT) {
    } else if (ret) {
      clean_exit(0);
    }

    while (1);	/* infinite loop */

  }
  kill(0, SIGTERM);
}


int main(int argc, char** argv) {

  int err;

  signal(SIGTERM, clean_exit);
  signal(SIGINT, clean_exit);

  mlockall(MCL_CURRENT | MCL_FUTURE);

  err = rt_task_spawn(&timer_task_desc, "thread", STACK_SIZE, PRIO, 0, &thread, NULL);
  if (err)
    return 0;

  pause();

  return EXIT_SUCCESS;

}
-- 
"Feel free" - 10 GB Mailbox, 100 FreeSMS/Monat ...
Jetzt GMX TopMail testen: http://www.gmx.net/de/go/topmail


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

end of thread, other threads:[~2007-04-11  8:15 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-28 20:31 [Xenomai-help] Preemptive scheduling Jack Whorn
2007-03-28 21:20 ` Gilles Chanteperdrix
2007-03-29  3:17   ` Jack Whorn
2007-03-29  8:46     ` Gilles Chanteperdrix
2007-04-03 20:05       ` Jack Whorn
2007-04-03 20:24         ` Philippe Gerum
2007-04-03 20:55           ` Jack Whorn
2007-04-04  8:17             ` Philippe Gerum
2007-04-04 15:10               ` Jack Whorn
2007-04-05 18:38                 ` Philippe Gerum
2007-04-10 22:47                   ` Jack Whorn
2007-04-11  8:15                     ` Dmitry Adamushko

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.