Clarification on Rate montonic
domenico.dileo at unina.it
domenico.dileo at unina.it
Wed Jun 6 09:05:48 UTC 2012
Dear Sebastian and Gedare,
thank you for your comments.
I updated the code according to your suggestions
(at least I hope so). The cods is at the end of this message (with an
execution log as well).
In the init function 2 tasks, TA0 and TA1 are crated.
TA0 starts a periodic task,PER0, similarly TA1.
PER0 has period 6000 ticks and sleeps for 4000 ticks
PER1 has period 4000 ticks and sleeps for 2000 ticks
I observer the following behavior:
TA0 and TA1 both created.
TA0 starts PER0.
PER0 executes (I choose to execute the task for 10 times)
Then everything stops.
Conversely, what I would like to see that
PR0 and PR1 are alternatively scheduled.
Can you help me out to understand where I'm mistaken?
Thank you in advance
******************************************************
init.c
******************************************************
int index = 0;
for ( index; index < 2 ; index++ ) {
task_names[ index ] = rtems_build_name( 'T', 'A', '0'+index, ' ' );
status = rtems_task_create(
task_names[ index ],
Priorities[ index ],
RTEMS_MINIMUM_STACK_SIZE,
RTEMS_DEFAULT_MODES,
RTEMS_DEFAULT_ATTRIBUTES,
&task_id[ index ]
);
if(status == RTEMS_SUCCESSFUL){
printf(" Task %s created with id %d \n",
rtems_object_get_name(task_id[index],NAME_LENGTH, task_name),
task_id[index]);
}else{
printf("Failed to create task %s with status %i \n",
task_name[index], status);
}
}
rtems_rate_monotonic_reset_all_statistics();
for ( index = 0 ; index < 2 ; index++ ) {
status = rtems_task_start( task_id[ index ], periodic_task, index );
if(status == RTEMS_SUCCESSFUL){
printf(" Task %s started \n",
rtems_object_get_name(task_id[index],NAME_LENGTH, task_name));
}else{
printf("Failed to start task %s with status %d \n",
task_name[index], status);
}
//wake up init after 20 seconds
status = rtems_task_wake_after(ticks_per_second*60);
// delete init task after starting the three working tasks
rtems_rate_monotonic_report_statistics();
status = rtems_task_delete( RTEMS_SELF );
rtems_shutdown_executive(result);
}
}
*************************************************************
tasks.c
*************************************************************
rtems_task periodic_task(
rtems_task_argument argument
)
{
rtems_name rm_name;
rtems_id rm_id;
rtems_time_of_day time;
rtems_status_code status;
rtems_interval interval;
uint32_t ticks_since_boot;
uint32_t count;
char rm_name_buffer[NAME_LENGTH];
count = 0;
rm_name = rtems_build_name( 'P', 'R', '0'+argument, ' ' );
status = rtems_rate_monotonic_create(rm_name, &rm_id);
if(status == RTEMS_SUCCESSFUL){
printf("Periodic Task %s created with id %d \n",
rtems_object_get_name(rm_id,NAME_LENGTH, rm_name_buffer), rm_id);
}else{
printf("Failed to create task %s with status %i \n", rm_name, status);
}
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(rm_id,NAME_LENGTH,rm_name_buffer));
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(rm_id,Periods[argument]);
if(status == RTEMS_TIMEOUT){
rtems_rate_monotonic_delete(rm_id);
}
printf("\n Iteraction %d \n", count);
status = rtems_task_wake_after(wake[argument]);
}
status = rtems_task_delete( RTEMS_SELF );
}
**************************************
Execution
**************************************
Ticks per second in your system: 2000
Ticks since boot: 306
Task TA0 created with id 167837698
Task TA1 created with id 167837699
Task TA0 started
Periodic Task PR0 created with id 1107361793
PR0 - is running
- current time - 00:00:00 05/05/2012
- Ticks since boot: 306
Iteraction 1
PR0 - is running
- current time - 00:00:02 05/05/2012
- Ticks since boot: 4393
Iteraction 2
PR0 - is running
- current time - 00:00:05 05/05/2012
- Ticks since boot: 10395
Iteraction 3
PR0 - is running
- current time - 00:00:08 05/05/2012
- Ticks since boot: 16420
Iteraction 4
PR0 - is running
- current time - 00:00:11 05/05/2012
- Ticks since boot: 22411
Iteraction 5
PR0 - is running
- current time - 00:00:14 05/05/2012
- Ticks since boot: 28421
Iteraction 6
PR0 - is running
- current time - 00:00:17 05/05/2012
- Ticks since boot: 34419
Iteraction 7
PR0 - is running
- current time - 00:00:20 05/05/2012
- Ticks since boot: 40411
Iteraction 8
PR0 - is running
- current time - 00:00:23 05/05/2012
- Ticks since boot: 46421
Iteraction 9
PR0 - is running
- current time - 00:00:26 05/05/2012
- Ticks since boot: 52414
Iteraction 10
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 9 0 0.053411/0.079910/0.069353
2.053487/2.080012/2.069391
Quoting Gedare Bloom <gedare at rtems.org>:
> 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
>
>
Domenico Di Leo, PhD student, Universit? degli Studi di Napoli Federico II
Ph: +39 081 676770
Fax: +39 081 676574
Web: http://wpage.unina.it/domenico.dileo
More information about the users
mailing list