All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] When startup the preemptive priority-base scheduling, at the start pont, I observed the output with wrong order.
@ 2011-12-13  2:48 Lifeng Wang
  2011-12-13  9:03 ` Gilles Chanteperdrix
  0 siblings, 1 reply; 3+ messages in thread
From: Lifeng Wang @ 2011-12-13  2:48 UTC (permalink / raw)
  To: xenomai

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

/*****************************************************************************/
//#include <stdio.h>
//#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>

#include <native/task.h>
#include <native/timer.h>
#include <native/sem.h>

#include <rtdk.h>
/*****************************************************************************/

#define Task_00_TASK_STKSZ 0     /* Stack size (use default one) */
#define Task_00_TASK_PRIO  2     /* RT priority */
#define Task_00_TASK_MODE  T_FPU /* No flags */

#define Task_01_TASK_STKSZ 0     /* Stack size (use default one) */
#define Task_01_TASK_PRIO  7     /* RT priority */
#define Task_01_TASK_MODE  T_FPU /* No flags */

#define Task_02_TASK_STKSZ 0     /* Stack size (use default one) */
#define Task_02_TASK_PRIO  5     /* RT priority */
#define Task_02_TASK_MODE  T_FPU /* No flags */

#define Task_03_TASK_STKSZ 0     /* Stack size (use default one) */
#define Task_03_TASK_PRIO  6     /* RT priority */
#define Task_03_TASK_MODE  T_FPU /* No flags */

#define Task_04_TASK_STKSZ 0     /* Stack size (use default one) */
#define Task_04_TASK_PRIO  4     /* RT priority */
#define Task_04_TASK_MODE  T_FPU /* No flags */

#define Task_05_TASK_STKSZ 0     /* Stack size (use default one) */
#define Task_05_TASK_PRIO  8     /* RT priority */
#define Task_05_TASK_MODE  T_FPU /* No flags */

#define Task_06_TASK_STKSZ 0     /* Stack size (use default one) */
#define Task_06_TASK_PRIO  9     /* RT priority */
#define Task_06_TASK_MODE  T_FPU /* No flags */

#define Task_07_TASK_STKSZ 0     /* Stack size (use default one) */
#define Task_07_TASK_PRIO  3     /* RT priority */
#define Task_07_TASK_MODE  T_FPU /* No flags */

#define BASEPERIOD 0    // baseperiod 0 to get ns
#define SPINTIME   1e7  // spin time in ns

static int Task_00_Prio;
static int Task_01_Prio;
static int Task_02_Prio;
static int Task_03_Prio;
static int Task_04_Prio;
static int Task_05_Prio;
static int Task_06_Prio;
static int Task_07_Prio;

static RT_TASK Task_00;
static RT_TASK Task_01;
static RT_TASK Task_02;
static RT_TASK Task_03;
static RT_TASK Task_04;
static RT_TASK Task_05;
static RT_TASK Task_06;
static RT_TASK Task_07;

static int Task_00_Counts = 0;
static int Task_01_Counts = 0;
static int Task_02_Counts = 0;
static int Task_03_Counts = 0;
static int Task_04_Counts = 0;
static int Task_05_Counts = 0;
static int Task_06_Counts = 0;
static int Task_07_Counts = 0;

static RT_SEM mainsync;


#if 1
static void Task_00_00 (void *cookie)
{
  int err;
  RTIME period = 4000000000LL;

  rt_sem_p(&mainsync,TM_INFINITE);

#if 0
  rt_task_set_periodic(NULL, TM_NOW, period);
#endif

  for (;;) {
#if 0
    err = rt_task_wait_period(NULL);
    if (err != 0) rt_printf("Task_00 rt_task_wait_period(): Error\n");
#endif

    rt_printf("Task_00 is runned:%dtimes; Task_00_Prio:%d\n",
++Task_00_Counts, Task_00_Prio);

#if 1
    err = rt_task_sleep(1000000000LL);
    if (err != 0) {
      rt_printf("Task_00: Error for delayed\n");
    }
#endif
  }
}
#endif


#if 1
static void Task_01_01 (void *cookie)
{
  int err;
  RTIME period = 2000000000LL;

  rt_sem_p(&mainsync,TM_INFINITE);

#if 0
  rt_task_set_periodic(NULL, TM_NOW, period);
#endif

  for (;;) {
#if 0
    err = rt_task_wait_period(NULL);
    if (err != 0) rt_printf("Task_01 rt_task_wait_period(): Error\n");
#endif

    rt_printf("Task_01 is runned:%dtimes; Task_01_Prio:%d\n",
++Task_01_Counts, Task_01_Prio);

#if 1
    err = rt_task_sleep(1000000000LL);
    if (err != 0) {
      rt_printf("Task_01: Error for delayed\n");
    }
#endif
  }
}
#endif


#if 1
static void Task_02_02 (void *cookie)
{
  int err;
  RTIME period = 1000000000LL;

  rt_sem_p(&mainsync,TM_INFINITE);

#if 0
  rt_task_set_periodic(NULL, TM_NOW, period);
#endif

  for (;;) {
#if 0
    err = rt_task_wait_period(NULL);
    if (err != 0) rt_printf("rt_task_wait_period(): Error\n");
#endif

    rt_printf("Task_02 is runned:%dtimes; Task_02_Prio:%d\n",
++Task_02_Counts, Task_02_Prio);

#if 1
    err = rt_task_sleep(1000000000LL);
    if (err != 0) {
      rt_printf("Task_02: Error for delayed\n");
     }
#endif
  }
}
#endif


#if 1
static void Task_03_03 (void *cookie)
{
  int err;
  RTIME period = 1000000000LL;
  RTIME runtime;

  rt_sem_p(&mainsync,TM_INFINITE);

#if 0
  rt_task_set_periodic(NULL, TM_NOW, period);
#endif

  for (;;) {
#if 0
    err = rt_task_wait_period(NULL);
    if (err != 0) rt_printf("rt_task_wait_period(): Error\n");
#endif

    rt_printf("Task_03 is runned:%dtimes; Task_03_Prio:%d\n",
++Task_03_Counts, Task_03_Prio);

#if 1
    err = rt_task_sleep(1000000000LL);
    if (err != 0) {
      rt_printf("Task_03: Error for delayed\n");
    }
#endif
  }
}
#endif


#if 1
static void Task_04_04 (void *cookie)
{
  int err;
  RTIME period = 1000000000LL;

  rt_sem_p(&mainsync,TM_INFINITE);

//  rt_task_set_periodic(NULL, TM_NOW, period);

  for (;;) {
#if 0
    err = rt_task_wait_period(NULL);
    if (err != 0) rt_printf("rt_task_wait_period(): Error\n");
#endif

    rt_printf("Task_04 is runned:%dtimes; Task_04_Prio:%d\n",
++Task_04_Counts, Task_04_Prio);

#if 1
    err = rt_task_sleep(1000000000LL);
    if (err != 0) {
      rt_printf("Task_04: Error for delayed\n");
     }
#endif
  }
}
#endif


#if 1
static void Task_05_05 (void *cookie)
{
  int err;
  RTIME period = 1000000000LL;

  rt_sem_p(&mainsync,TM_INFINITE);

#if 0
  rt_task_set_periodic(NULL, TM_NOW, period);
#endif

  for (;;) {
#if 0
    err = rt_task_wait_period(NULL);
    if (err != 0) rt_printf("rt_task_wait_period(): Error\n");
#endif

    rt_printf("Task_05 is runned:%dtimes; Task_05_Prio:%d\n",
++Task_05_Counts, Task_05_Prio);

#if 1
    err = rt_task_sleep(1000000000LL);
    if (err != 0) {
      rt_printf("Task_05: Error for delayed\n");
    }
#endif
  }
}
#endif


#if 1
static void Task_06_06 (void *cookie)
{
  int err;
  RTIME period = 1000000000LL;

  rt_sem_p(&mainsync,TM_INFINITE);

//  rt_task_set_periodic(NULL, TM_NOW, period);

  for (;;) {
#if 0
    err = rt_task_wait_period(NULL);
    if (err != 0) rt_printf("rt_task_wait_period(): Error\n");
#endif

    rt_printf("Task_06 is runned:%dtimes; Task_06_Prio:%d\n",
++Task_06_Counts, Task_06_Prio);

#if 1
    err = rt_task_sleep(1000000000LL);
    if (err != 0) rt_printf("rt_task_sleep(): Error\n");
#endif
  }
}
#endif


#if 1
static void Task_07_07 (void *cookie)
{
  int err;
  RTIME period = 1000000000LL;

  rt_sem_p(&mainsync,TM_INFINITE);

//  rt_task_set_periodic(NULL, TM_NOW, period);

  for (;;) {
#if 0
    err = rt_task_wait_period(NULL);
    if (err != 0) rt_printf("rt_task_wait_period(): Error\n");
#endif

    rt_printf("Task_07 is runned:%dtimes; Task_07_Prio:%d\n",
++Task_07_Counts, Task_07_Prio);
    rt_printf("\n");

#if 1
    err = rt_task_sleep(1000000000LL);
    if (err != 0) rt_printf("rt_task_sleep(): Error\n");
#endif
  }
}
#endif


void xenomai_init(void)
{
  int err;
  err = mlockall(MCL_CURRENT|MCL_FUTURE);
  if(err != 0) rt_printf("Error for mlcokall()\n");

  /* Perform auto-init of rt_print buffers if the task doesn't do so */
  rt_print_auto_init(1);
  rt_printf("Xenomai: Initialization successed\n\n");
}


int main (int argc, char *argv[])
{
  int err;

  printf("\nPlease press Ctrl-c to end the program\n");

  xenomai_init(); //Xenomai RT enviroment initialize

  //semaphore to sync task startup on
  err = rt_sem_create(&mainsync,"Main_Sem",0,/*S_FIFO*/S_PRIO);

  //set timing to ns
  err = rt_timer_set_mode(BASEPERIOD);

/*****************************************************************************/

#if 1
  rt_printf("Multi-tasking creat and start now.\n");

  err = rt_task_create(&Task_00,
                       "Task_00_Name",
                       Task_00_TASK_STKSZ,
                       Task_00_TASK_PRIO,
                       Task_00_TASK_MODE);
  if (err != 0) {
    rt_printf("Task_00: Error for creating task.\n");
    return (-1);
  }

  err = rt_task_start(&Task_00,&Task_00_00,NULL);
  if (err != 0) {
    rt_printf("Task_00: Error for starting task.\n");
    return (-1);
  }

  rt_printf("Task_00: Creat and Start now.\n");
#endif

#if 1
  err = rt_task_create(&Task_01,
                       "Task_01_Name",
                       Task_01_TASK_STKSZ,
                       Task_01_TASK_PRIO,
                       Task_01_TASK_MODE);
  if (err != 0) {
    rt_printf("Task_01: Error for creating task.\n");
    return (-1);
  }

  err = rt_task_start(&Task_01,&Task_01_01,NULL);
  if (err != 0) {
    rt_printf("Task_01: Error for starting task.\n");
    return (-1);
  }

  rt_printf("Task_01: Creat and Start now.\n");
#endif

#if 1
  err = rt_task_create(&Task_02,
                       "Task_02_Name",
                       Task_02_TASK_STKSZ,
                       Task_02_TASK_PRIO,
                       Task_02_TASK_MODE);
  if (err != 0) {
    rt_printf("Task_02: Error for creating task.\n");
    return (-1);
  }

  err = rt_task_start(&Task_02,&Task_02_02,NULL);
  if (err != 0) {
    rt_printf("Task_02: Error for starting task.\n");
    return (-1);
  }

  rt_printf("Task_02: Creat and Start now.\n");
#endif

#if 1
  err = rt_task_create(&Task_03,
                       "Task_03_Name",
                       Task_03_TASK_STKSZ,
                       Task_03_TASK_PRIO,
                       Task_03_TASK_MODE);
  if (err != 0) {
    rt_printf("Task_03: Error for creating task.\n");
    return (-1);
  }

  err = rt_task_start(&Task_03,&Task_03_03,NULL);
  if (err != 0) {
    rt_printf("Task_03: Error for starting task.\n");
    return (-1);
  }

  rt_printf("Task_03: Creat and Start now.\n");
#endif

#if 1
  err = rt_task_create(&Task_04,
                       "Task_04_Name",
                       Task_04_TASK_STKSZ,
                       Task_04_TASK_PRIO,
                       Task_04_TASK_MODE);
  if (err != 0) {
    rt_printf("Task_04: Error for creating task.\n");
    return (-1);
  }

  err = rt_task_start(&Task_04,&Task_04_04,NULL);
  if (err != 0) {
    rt_printf("Task_04: Error for starting task.\n");
    return (-1);
  }

  rt_printf("Task_04: Creat and Start now.\n");
#endif

#if 1
  err = rt_task_create(&Task_05,
                       "Task_05_Name",
                       Task_05_TASK_STKSZ,
                       Task_05_TASK_PRIO,
                       Task_05_TASK_MODE);
  if (err != 0) {
    rt_printf("Task_05: Error for creating task.\n");
    return (-1);
  }

  err = rt_task_start(&Task_05,&Task_05_05,NULL);
  if (err != 0) {
    rt_printf("Task_05: Error for starting task.\n");
    return (-1);
  }

  rt_printf("Task_05: Creat and Start now.\n");
#endif

#if 1
  err = rt_task_create(&Task_06,
                       "Task_06_Name",
                       Task_06_TASK_STKSZ,
                       Task_06_TASK_PRIO,
                       Task_06_TASK_MODE);
  if (err != 0) {
    rt_printf("Task_06: Error for creating task.\n");
    return (-1);
  }

  err = rt_task_start(&Task_06,&Task_06_06,NULL);
  if (err != 0) {
    rt_printf("Task_06: Error for starting task.\n");
    return (-1);
  }

  rt_printf("Task_06: Creat and Start now.\n");
#endif

#if 1
  err = rt_task_create(&Task_07,
                       "Task_07_Name",
                       Task_07_TASK_STKSZ,
                       Task_07_TASK_PRIO,
                       Task_07_TASK_MODE);
  if (err != 0) {
    rt_printf("Task_07: Error for creating task.\n");
    return (-1);
  }

  err = rt_task_start(&Task_07,&Task_07_07,NULL);
  if (err != 0) {
    rt_printf("Task_07: Error for starting task.\n");
    return (-1);
  }

  rt_printf("Task_07: Creat and Start now.\n");
#endif

/*****************************************************************************/
#if 1
  #if 1
  Task_00_Prio = 90;
  Task_01_Prio = 80;
  Task_02_Prio = 70;
  Task_03_Prio = 60;
  Task_04_Prio = 50;
  Task_05_Prio = 40;
  Task_06_Prio = 30;
  Task_07_Prio = 20;
  #endif

  rt_task_set_priority(&Task_00, Task_00_Prio);
  rt_task_set_priority(&Task_01, Task_01_Prio);
  rt_task_set_priority(&Task_02, Task_02_Prio);
  rt_task_set_priority(&Task_03, Task_03_Prio);
  rt_task_set_priority(&Task_04, Task_04_Prio);
  rt_task_set_priority(&Task_05, Task_05_Prio);
  rt_task_set_priority(&Task_06, Task_06_Prio);
  rt_task_set_priority(&Task_07, Task_07_Prio);
#endif

/*****************************************************************************/
  rt_printf("\nMulti-tasking scheduling now. Have fun.\n");

  rt_sem_broadcast(&mainsync);

  pause(); // Plese press the key of "Ctrl-c" to end the program

  return 0;
}


########################################################
[root@domain.hid examples]# make
--xeno-cflags is deprecated, use --skin=name --cflags instead
--xeno-ldflags is deprecated, use --skin=name --ldflags instead
gcc -I/usr/xenomai/include -D_GNU_SOURCE -D_REENTRANT -Wall
-Werror-implicit-function-declaration -pipe -D__XENO__   -L/usr/xenomai/lib
-lxenomai -lpthread -lrt  -lnative -Xlinker -rpath -Xlinker
/usr/xenomai/lib  test.c   -o test

[root@domain.hid examples]# ./test

Please press Ctrl-c to end the program
Xenomai: Initialization successed

Multi-tasking creat and start now.
Task_00: Creat and Start now.
Task_01: Creat and Start now.
Task_02: Creat and Start now.
Task_03: Creat and Start now.
Task_04: Creat and Start now.
Task_05: Creat and Start now.
Task_06: Creat and Start now.
Task_07: Creat and Start now.

Multi-tasking scheduling now. Have fun.
Task_00 is runned:1times; Task_00_Prio:90
Task_01 is runned:1times; Task_01_Prio:80
Task_02 is runned:1times; Task_02_Prio:70
Task_05 is runned:1times; Task_05_Prio:40
Task_03 is runned:1times; Task_03_Prio:60
Task_06 is runned:1times; Task_06_Prio:30
Task_04 is runned:1times; Task_04_Prio:50
Task_07 is runned:1times; Task_07_Prio:20

Task_00 is runned:2times; Task_00_Prio:90
Task_01 is runned:2times; Task_01_Prio:80
Task_02 is runned:2times; Task_02_Prio:70
Task_03 is runned:2times; Task_03_Prio:60
Task_04 is runned:2times; Task_04_Prio:50
Task_05 is runned:2times; Task_05_Prio:40
Task_06 is runned:2times; Task_06_Prio:30
Task_07 is runned:2times; Task_07_Prio:20

Task_00 is runned:3times; Task_00_Prio:90
Task_01 is runned:3times; Task_01_Prio:80
Task_02 is runned:3times; Task_02_Prio:70
Task_03 is runned:3times; Task_03_Prio:60
Task_04 is runned:3times; Task_04_Prio:50
Task_05 is runned:3times; Task_05_Prio:40
Task_06 is runned:3times; Task_06_Prio:30
Task_07 is runned:3times; Task_07_Prio:20

^C
[root@domain.hid examples]#

##################################################################
Fedora 14 Linux kernel-2.6.35.9
Xenomai-2.6.0

This example program contains eight tasks with different prioities.
The Task_00 has the highest priority. The Task_07 has the lowest priority.
Each task can run and delay the same time of 1 second.

My question is that. When startup the preemptive priority-base
scheduling,at the start pont,
I observed the output:
Multi-tasking scheduling now. Have fun.
Task_00 is runned:1times; Task_00_Prio:90
Task_01 is runned:1times; Task_01_Prio:80
Task_02 is runned:1times; Task_02_Prio:70
Task_05 is runned:1times; Task_05_Prio:40  :Why?
Task_03 is runned:1times; Task_03_Prio:60  :Why?
Task_06 is runned:1times; Task_06_Prio:30  :Why?
Task_04 is runned:1times; Task_04_Prio:50  :Why?
Task_07 is runned:1times; Task_07_Prio:20

But I think that,the correct output shoud be that and must be that:
Task_00 is runned:1times; Task_00_Prio:90
Task_01 is runned:1times; Task_01_Prio:80
Task_02 is runned:1times; Task_02_Prio:70
Task_03 is runned:1times; Task_03_Prio:60
Task_04 is runned:1times; Task_04_Prio:50
Task_05 is runned:1times; Task_05_Prio:40
Task_06 is runned:1times; Task_06_Prio:30
Task_07 is runned:1times; Task_07_Prio:20

Why is it not?
Can someone tell me why and tell me how to write the correct code for the
preemptive priority-base scheduling.

Happy new year to everyone.

Wang Lifeng
lfwangcn@domain.hid
>From Suzhou,China

[-- Attachment #2: Type: text/html, Size: 77887 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread
* [Xenomai-help] When startup the preemptive priority-base scheduling, at the start pont, I observed the output with wrong order.
@ 2011-12-13  4:08 Lifeng Wang
  0 siblings, 0 replies; 3+ messages in thread
From: Lifeng Wang @ 2011-12-13  4:08 UTC (permalink / raw)
  To: Xenomai-help

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

########################################################
[root@domain.hid examples]# make
--xeno-cflags is deprecated, use --skin=name --cflags instead
--xeno-ldflags is deprecated, use --skin=name --ldflags instead
gcc -I/usr/xenomai/include -D_GNU_SOURCE -D_REENTRANT -Wall
-Werror-implicit-function-declaration -pipe -D__XENO__   -L/usr/xenomai/lib
-lxenomai -lpthread -lrt  -lnative -Xlinker -rpath -Xlinker
/usr/xenomai/lib  test.c   -o test

[root@domain.hid examples]# ./test

Please press Ctrl-c to end the program
Xenomai: Initialization successed

Multi-tasking creat and start now.
Task_00: Creat and Start now.
Task_01: Creat and Start now.
Task_02: Creat and Start now.
Task_03: Creat and Start now.
Task_04: Creat and Start now.
Task_05: Creat and Start now.
Task_06: Creat and Start now.
Task_07: Creat and Start now.

Multi-tasking scheduling now. Have fun.
Task_00 is runned:1times; Task_00_Prio:90
Task_01 is runned:1times; Task_01_Prio:80
Task_02 is runned:1times; Task_02_Prio:70
Task_05 is runned:1times; Task_05_Prio:40
Task_03 is runned:1times; Task_03_Prio:60
Task_06 is runned:1times; Task_06_Prio:30
Task_04 is runned:1times; Task_04_Prio:50
Task_07 is runned:1times; Task_07_Prio:20

Task_00 is runned:2times; Task_00_Prio:90
Task_01 is runned:2times; Task_01_Prio:80
Task_02 is runned:2times; Task_02_Prio:70
Task_03 is runned:2times; Task_03_Prio:60
Task_04 is runned:2times; Task_04_Prio:50
Task_05 is runned:2times; Task_05_Prio:40
Task_06 is runned:2times; Task_06_Prio:30
Task_07 is runned:2times; Task_07_Prio:20

Task_00 is runned:3times; Task_00_Prio:90
Task_01 is runned:3times; Task_01_Prio:80
Task_02 is runned:3times; Task_02_Prio:70
Task_03 is runned:3times; Task_03_Prio:60
Task_04 is runned:3times; Task_04_Prio:50
Task_05 is runned:3times; Task_05_Prio:40
Task_06 is runned:3times; Task_06_Prio:30
Task_07 is runned:3times; Task_07_Prio:20

^C
[root@domain.hid examples]#

##################################################################
Fedora 14 Linux kernel-2.6.35.9
Xenomai-2.6.0

This example program contains eight tasks with different prioities.
The Task_00 has the highest priority. The Task_07 has the lowest priority.
Each task can run and delay the same time of 1 second.

My question is that. When startup the preemptive priority-base
scheduling,at the start pont,
I observed the output:
Multi-tasking scheduling now. Have fun.
Task_00 is runned:1times; Task_00_Prio:90
Task_01 is runned:1times; Task_01_Prio:80
Task_02 is runned:1times; Task_02_Prio:70
Task_05 is runned:1times; Task_05_Prio:40  :Why?
Task_03 is runned:1times; Task_03_Prio:60  :Why?
Task_06 is runned:1times; Task_06_Prio:30  :Why?
Task_04 is runned:1times; Task_04_Prio:50  :Why?
Task_07 is runned:1times; Task_07_Prio:20

But I think that,the correct output shoud be that and must be that:
Task_00 is runned:1times; Task_00_Prio:90
Task_01 is runned:1times; Task_01_Prio:80
Task_02 is runned:1times; Task_02_Prio:70
Task_03 is runned:1times; Task_03_Prio:60
Task_04 is runned:1times; Task_04_Prio:50
Task_05 is runned:1times; Task_05_Prio:40
Task_06 is runned:1times; Task_06_Prio:30
Task_07 is runned:1times; Task_07_Prio:20

Why is it not?
Can someone tell me why and tell me how to write the correct code for the
preemptive priority-base scheduling.

Happy new year to everyone.

Wang Lifeng
lfwangcn@domain.hid
>From Suzhou,China

[-- Attachment #2: Type: text/html, Size: 3862 bytes --]

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

end of thread, other threads:[~2011-12-13  9:03 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-13  2:48 [Xenomai-help] When startup the preemptive priority-base scheduling, at the start pont, I observed the output with wrong order Lifeng Wang
2011-12-13  9:03 ` Gilles Chanteperdrix
  -- strict thread matches above, loose matches on Subject: below --
2011-12-13  4:08 Lifeng Wang

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.