Ticket #2772: tasks.c

File tasks.c, 3.7 KB (added by Kuan-Hsun Chen, on 08/05/16 at 16:36:33)

Example file

Line 
1/**
2 * @file sprmsched01/tasks.c
3 *
4 * @brief A heuristic example to demonstrate how the postponed jobs are handled.
5 *
6 * Given two tasks with implicit deadline. To force deadline misses, we reverse
7 * the rate-monotonic priority assignment and only execute the highest priority
8 * task twice. In the original implementation, no matter how many periods are
9 * expired, RMS manager only releases a job with a shifted deadline assignment
10 * in the watchdog.
11 *
12 * In more general real-time task model, e.g., soft real-time task, the postponed
13 * jobs are still required to be released when the task is available to execute.
14 */
15
16/*
17 *  COPYRIGHT (c) 2016 Kuan-Hsun Chen, TU Dortmund University (TUDo).
18 *
19 *  The license and distribution terms for this file may be
20 *  found in the file LICENSE in this distribution or at
21 *  http://www.rtems.com/license/LICENSE.
22 */
23
24#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif
27
28#include "system.h"
29
30/* CPU usage and Rate monotonic manger statistics */
31#include "rtems/cpuuse.h"
32
33/* Periods for the various tasks [ticks] */
34#define PERIOD_TASK_1          10000
35#define PERIOD_TASK_2          2000
36
37/* Task Id */
38#define ID_TASK_1           0
39#define ID_TASK_2               1
40
41/* Execution time for each task [ticks] */
42#define task_1_normal_et        6000
43#define task_2_normal_et        1000
44
45/**
46 * @brief Task 1 body
47 */
48rtems_task Task_1(
49  rtems_task_argument unused
50)
51{
52  rtems_status_code status;
53  rtems_name        period_name;
54  rtems_id          RM_period;
55  rtems_id          selfid=rtems_task_self();
56  int               start, end;
57  int                         tsk_counter = 0;
58
59  /*create period*/
60  period_name = rtems_build_name( 'P', 'E', 'R', '1' );
61  status = rtems_rate_monotonic_create( period_name, &RM_period );
62  if( RTEMS_SUCCESSFUL != status ) {
63    printf("RM failed with status: %d\n", status);
64    rtems_test_exit(0);
65  }
66
67        while( 1 ) {
68                if(tsk_counter == 2){           
69                                status = rtems_rate_monotonic_delete(RM_period);
70                                if(status != RTEMS_SUCCESSFUL){
71                                        printf("BUG: Cannot delete the period 1\n");
72          rtems_test_exit(0);
73                                }
74       
75        status=rtems_task_delete(selfid);
76        if(status != RTEMS_SUCCESSFUL){
77          printf("BUG: Cannot delete the task 1\n");
78          rtems_test_exit(0);
79        }
80       
81    }
82                status = rtems_rate_monotonic_period( RM_period,PERIOD_TASK_1);
83    start = rtems_clock_get_ticks_since_boot();   
84    printf("Task 1 starts at tick %d.\n", start);
85    LOOP(task_1_normal_et,task_id);
86    end = rtems_clock_get_ticks_since_boot();
87    printf("                                    Task 1 ends at tick %d.\n", end);
88    tsk_counter += 1;
89        }
90}
91
92/**
93 * @brief Task 2 body
94 */
95rtems_task Task_2(
96  rtems_task_argument unused
97)
98{
99  rtems_status_code status;
100  rtems_name        period_name;
101  rtems_id          RM_period;
102  int               start, end;
103  int                       tsk_counter = 0;
104
105  /*create period*/
106
107  period_name = rtems_build_name( 'P', 'E', 'R', '2' );
108  status = rtems_rate_monotonic_create( period_name, &RM_period );
109  if( RTEMS_SUCCESSFUL != status ) {
110    printf("RM failed with status: %d\n", status);
111    exit( 0 );
112  }
113
114        while( 1 ) {
115       
116                status = rtems_rate_monotonic_period( RM_period, PERIOD_TASK_2);
117        if(tsk_counter == testnumber){       
118                  rtems_rate_monotonic_report_statistics();
119                        status = rtems_rate_monotonic_delete(RM_period);
120                        if(status != RTEMS_SUCCESSFUL){
121                                printf("BUG: Cannot delete the period 2\n");
122        rtems_test_exit(0);
123                        }
124                        /* The example is finished */
125      TEST_END();
126      rtems_test_exit(0);
127                }
128    start = rtems_clock_get_ticks_since_boot();
129    printf("Task 2 starts at tick %d.\n", start);
130    LOOP(task_2_normal_et,task_id);
131    end = rtems_clock_get_ticks_since_boot();
132    printf("                                    Job %d Task 2 ends at tick %d.\n", tsk_counter+1, end);
133    tsk_counter += 1;
134        }
135}
136