Clarification on Rate montonic

Gedare Bloom gedare at rtems.org
Tue Jun 5 15:20:36 UTC 2012


Hi,

Your code has a couple of bugs. See for example sp20 for how to
structure a typical RM application. One problem I see is that your
init task calls the periodic_task() function directly. Instead you
should be setting up a normal rtems_task_create/rtems_task_start with
periodic_task as the entry point, and periodic_task would: create an
rm timer, self-suspend so that all periodic tasks release
simultaneously (critical instant), and execute the periodic loops.
Init should either suspend indefinitely/delete itself or can be used
to stop the application similarly to how you have set it up with
wake_after.

-Gedare


On Mon, Jun 4, 2012 at 5:29 PM,  <domenico.dileo at unina.it> wrote:
> Hello,
> With the code hereafter, I run two periodic tasks (PER0 and PER1)
> and scheduled them with the rate monotonic.
> Also, a log of the excution follows the code.
> PER0 has period 6000 ticks, while PER1 215.
> Questions:
> a) Since PER0 's pariod >> PER1's period should be PER1
> the first to be scheduled?
> According to the log, PER0 is the first one
> b) how should I modify the code in order to have
> PER1 scheduled before PER0?
> Of course if I swap periodic_task(task_id[0], 6000);
> with periodic_task(task_id[0], 215) I can observer
> PER1 scheuled before PER0.
> It seems that the first task to be scheduled
> is the first to execute (with the call to the function
> rtems_rata_monotonic_period).
> Thank you in advance,
>
> ****************************************************
> init.c code
> ****************************************************
>
> ...
>
>  int i = 0;
>  int l = 1;
>  for(i; i< 3; i++){
>        task_names[ i ] = rtems_build_name( 'P', 'R', '0'+i , ' ' );
>        status = rtems_rate_monotonic_create(task_names[i], &task_id[i]);
>        if(status == RTEMS_SUCCESSFUL){
>        printf("Task %s created with id %d \n",
> rtems_object_get_name(task_id[i],sizeof(task_names[i]),task_name),
> task_id[i]);
>                }else{
>                printf("Failed to create task %s  with status %i \n",
> rtems_object_get_name(task_id[i],NAME_LENGTH,task_name), status);
>        }
>
>
>  }
> //rtems_rate_monotonic_reset_all_statistics();
>
> //for(i = 0; i < 3; i++)
> periodic_task(task_id[0], 6000);
> periodic_task(task_id[1], 215);
>
>
> //wake up init after 5 seconds
>  status = rtems_task_wake_after(ticks_per_second*10);
>
>  // delete init task after starting the three working tasks
>   rtems_rate_monotonic_report_statistics();
> int j = 0;
> for(j; j<=3;j++){
>        rtems_rate_monotonic_delete(task_id[j]);
> }
>  status = rtems_task_delete( RTEMS_SELF );
>  rtems_shutdown_executive(result);
> }
>
> **********************************************
> tasks.c
> **********************************************
>
> rtems_task periodic_task(
>  rtems_id task_id,
>  rtems_interval period
> )
> {
>  rtems_time_of_day time;
>  rtems_status_code status;
>  rtems_interval interval;
>  uint32_t          ticks_since_boot;
>  uint32_t          count;
>  char task_name[NAME_LENGTH];
>  count = 0;
>  //task_id = rtems_task_self();
>  while( count < 10 ) {
>    count++;
>    status = rtems_clock_get_tod( &time );
>    if(status != RTEMS_SUCCESSFUL){
>        printf("\n FAILED TO GET TIME OF THE DAY \n");
>    }
>
>  printf("\n\n %s - is running \n",
> rtems_object_get_name(task_id,NAME_LENGTH,task_name));
>  print_time( " - current time - ", &time, "\n" );
>  ticks_since_boot = rtems_clock_get_ticks_since_boot();
>  printf(" - Ticks since boot: %" PRIu32 "\n", ticks_since_boot);
>  status = rtems_rate_monotonic_period(task_id,period);
>        if(status == RTEMS_TIMEOUT){
>                rtems_rate_monotonic_delete(task_id);
>        }
>
>  }
> }
> ****************************************************************
> LOG
> ****************************************************************
>
> Task PR0 created with id 1107361793
>
> Task PR1 created with id 1107361794
>
> Task PR2 created with id 1107361795
>
>
>
>
>
>  PR0  - is running
>
>  - current time - 00:00:00   05/05/2012
>
>  - Ticks since boot: 0
>
>
>
>
>
>  PR0  - is running
>
>  - current time - 00:00:00   05/05/2012
>
>  - Ticks since boot: 0
>
>
>
>
>
>  PR0  - is running
>
>  - current time - 00:00:03   05/05/2012
>
>  - Ticks since boot: 6076
>
>
>
>
>
>  PR0  - is running
>
>  - current time - 00:00:06   05/05/2012
>
>  - Ticks since boot: 12055
>
>
>
>
>
>  PR0  - is running
>
>  - current time - 00:00:09   05/05/2012
>
>  - Ticks since boot: 18087
>
>
>
>
>
>  PR0  - is running
>
>  - current time - 00:00:12   05/05/2012
>
>  - Ticks since boot: 24068
>
>
>
>
>
>  PR0  - is running
>
>  - current time - 00:00:15   05/05/2012
>
>  - Ticks since boot: 30099
>
>
>
>
>
>  PR0  - is running
>
>  - current time - 00:00:18   05/05/2012
>
>  - Ticks since boot: 36098
>
>
>
>
>
>  PR0  - is running
>
>  - current time - 00:00:21   05/05/2012
>
>  - Ticks since boot: 42071
>
>
>
>
>
>  PR0  - is running
>
>  - current time - 00:00:24   05/05/2012
>
>  - Ticks since boot: 48072
>
>
>
>
>
>  PR1  - is running
>
>  - current time - 00:00:27   05/05/2012
>
>  - Ticks since boot: 54096
>
>
>
>
>
>  PR1  - is running
>
>  - current time - 00:00:27   05/05/2012
>
>  - Ticks since boot: 54200
>
>
>
>
>
>  PR1  - is running
>
>  - current time - 00:00:27   05/05/2012
>
>  - Ticks since boot: 54423
>
>
>
>
>
>  PR1  - is running
>
>  - current time - 00:00:27   05/05/2012
>
>  - Ticks since boot: 54655
>
>
>
>
>
>  PR1  - is running
>
>  - current time - 00:00:27   05/05/2012
>
>  - Ticks since boot: 54840
>
>
>
>
>
>  PR1  - is running
>
>  - current time - 00:00:27   05/05/2012
>
>  - Ticks since boot: 55104
>
>
>
>
>
>  PR1  - is running
>
>  - current time - 00:00:27   05/05/2012
>
>  - Ticks since boot: 55271
>
>
>
>
>
>  PR1  - is running
>
>  - current time - 00:00:27   05/05/2012
>
>  - Ticks since boot: 55526
>
>
>
>
>
>  PR1  - is running
>
>  - current time - 00:00:27   05/05/2012
>
>  - Ticks since boot: 55712
>
>
>
>
>
>  PR1  - is running
>
>  - current time - 00:00:27   05/05/2012
>
>  - Ticks since boot: 55937
>
> Period information by period
>
> --- CPU times are in seconds ---
>
> --- Wall times are in seconds ---
>
>   ID     OWNER COUNT MISSED          CPU TIME                  WALL TIME
>
>                                    MIN/MAX/AVG                MIN/MAX/AVG
>
> 0x42010001 UI1      9      0 0.000000/0.065991/0.047860
> 0.000000/0.066002/0.047885
>
> 0x42010002 UI1      9      0 0.044008/0.078422/0.058316
> 0.044010/0.078501/0.058371
>
> 0x42010003 UI1      0      0
>
>
>
>
>
>
> _______________________________________________
> rtems-users mailing list
> rtems-users at rtems.org
> http://www.rtems.org/mailman/listinfo/rtems-users




More information about the users mailing list