1 | /* Tasks_Periodic |
---|
2 | * |
---|
3 | * This routine serves as a test task for the CBS scheduler |
---|
4 | * implementation. |
---|
5 | * |
---|
6 | * Input parameters: |
---|
7 | * argument - task argument |
---|
8 | * |
---|
9 | * Output parameters: NONE |
---|
10 | * |
---|
11 | * The license and distribution terms for this file may be |
---|
12 | * found in the file LICENSE in this distribution or at |
---|
13 | * http://www.rtems.com/license/LICENSE. |
---|
14 | */ |
---|
15 | |
---|
16 | #ifdef HAVE_CONFIG_H |
---|
17 | #include "config.h" |
---|
18 | #endif |
---|
19 | |
---|
20 | #include "system.h" |
---|
21 | |
---|
22 | void overrun_handler_task_4 ( |
---|
23 | rtems_cbs_server_id server_id |
---|
24 | ) |
---|
25 | { |
---|
26 | printk( "Signal overrun, fixing the task\n" ); |
---|
27 | Violating_task[ 4 ] = 0; |
---|
28 | /* rtems_task_restart( RTEMS_SELF, 4 ); might be also possible*/ |
---|
29 | return; |
---|
30 | } |
---|
31 | |
---|
32 | rtems_task Tasks_Periodic( |
---|
33 | rtems_task_argument argument |
---|
34 | ) |
---|
35 | { |
---|
36 | rtems_id rmid; |
---|
37 | rtems_id test_rmid; |
---|
38 | rtems_status_code status; |
---|
39 | bool scenario_done = 0; |
---|
40 | |
---|
41 | int start, stop, now; |
---|
42 | |
---|
43 | rtems_cbs_server_id server_id, tsid; |
---|
44 | rtems_cbs_parameters params, tparams; |
---|
45 | |
---|
46 | params.deadline = Periods[ argument ]; |
---|
47 | params.budget = Execution[ argument ]+1; |
---|
48 | |
---|
49 | if ( argument == 4 ) { |
---|
50 | if ( rtems_cbs_create_server( ¶ms, &overrun_handler_task_4, &server_id )) |
---|
51 | printf( "ERROR: CREATE SERVER FAILED\n" ); |
---|
52 | } |
---|
53 | else { |
---|
54 | if ( rtems_cbs_create_server( ¶ms, NULL, &server_id ) ) |
---|
55 | printf( "ERROR: CREATE SERVER FAILED\n" ); |
---|
56 | } |
---|
57 | if ( rtems_cbs_attach_thread( server_id, Task_id[ argument ] ) ) |
---|
58 | printf( "ERROR: ATTACH THREAD FAILED\n" ); |
---|
59 | if ( rtems_cbs_get_server_id( Task_id[ argument ], &tsid ) ) |
---|
60 | printf( "ERROR: GET SERVER ID FAILED\n" ); |
---|
61 | if ( tsid != server_id ) |
---|
62 | printf( "ERROR: SERVER ID MISMATCH\n" ); |
---|
63 | if ( rtems_cbs_get_parameters( server_id, &tparams ) ) |
---|
64 | printf( "ERROR: GET PARAMETERS FAILED\n" ); |
---|
65 | if ( params.deadline != tparams.deadline || |
---|
66 | params.budget != tparams.budget ) |
---|
67 | printf( "ERROR: PARAMETERS MISMATCH\n" ); |
---|
68 | |
---|
69 | status = rtems_rate_monotonic_create( argument, &rmid ); |
---|
70 | directive_failed( status, "rtems_rate_monotonic_create" ); |
---|
71 | put_name( Task_name[ argument ], FALSE ); |
---|
72 | printf( "- rtems_rate_monotonic_create id = 0x%08" PRIxrtems_id "\n", |
---|
73 | rmid ); |
---|
74 | |
---|
75 | status = rtems_rate_monotonic_ident( argument, &test_rmid ); |
---|
76 | directive_failed( status, "rtems_rate_monotonic_ident" ); |
---|
77 | put_name( Task_name[ argument ], FALSE ); |
---|
78 | printf( "- rtems_rate_monotonic_ident id = 0x%08" PRIxrtems_id "\n", |
---|
79 | test_rmid ); |
---|
80 | |
---|
81 | if ( rmid != test_rmid ) { |
---|
82 | printf( "RMID's DO NOT MATCH (0x%" PRIxrtems_id " and 0x%" |
---|
83 | PRIxrtems_id ")\n", rmid, test_rmid ); |
---|
84 | rtems_test_exit( 0 ); |
---|
85 | } |
---|
86 | |
---|
87 | put_name( Task_name[ argument ], FALSE ); |
---|
88 | printf( "- (0x%08" PRIxrtems_id ") period %" PRIu32 "\n", |
---|
89 | rmid, Periods[ argument ] ); |
---|
90 | |
---|
91 | status = rtems_task_wake_after( 2 + Phases[argument] ); |
---|
92 | directive_failed( status, "rtems_task_wake_after" ); |
---|
93 | |
---|
94 | while (FOREVER) { |
---|
95 | if (rtems_rate_monotonic_period(rmid, Periods[argument])==RTEMS_TIMEOUT) |
---|
96 | printf("P%" PRIdPTR " - Deadline miss\n", argument); |
---|
97 | |
---|
98 | rtems_clock_get(RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &start); |
---|
99 | printf("P%" PRIdPTR "-S ticks:%d\n", argument, start); |
---|
100 | if ( start >= 2*HP_LENGTH ) break; /* stop */ |
---|
101 | |
---|
102 | /* Specific scenario for task 4: tries to exceed announced budget, |
---|
103 | the task priority has to be pulled down to background. */ |
---|
104 | if ( !scenario_done && argument == 4 && now >= 200 ) { |
---|
105 | Violating_task[ argument ] = 1; |
---|
106 | scenario_done = 1; |
---|
107 | } |
---|
108 | /* Specific scenario for task 3: changes scheduling parameters. */ |
---|
109 | if ( !scenario_done && argument == 3 && now >= 250 ) { |
---|
110 | Periods[ argument ] = Periods[ argument ] * 2; |
---|
111 | Execution[ argument ] = Execution[ argument ] * 2; |
---|
112 | params.deadline = Periods[ argument ]; |
---|
113 | params.budget = Execution[ argument ]+1; |
---|
114 | if ( rtems_cbs_set_parameters( server_id, ¶ms) ) |
---|
115 | printf( "ERROR: SET PARAMETERS FAILED\n" ); |
---|
116 | if ( rtems_cbs_get_parameters( server_id, &tparams ) ) |
---|
117 | printf( "ERROR: GET PARAMETERS FAILED\n" ); |
---|
118 | if ( params.deadline != tparams.deadline || |
---|
119 | params.budget != tparams.budget ) |
---|
120 | printf( "ERROR: PARAMETERS MISMATCH\n" ); |
---|
121 | scenario_done = 1; |
---|
122 | } |
---|
123 | /* Specific scenario for task 2: late unblock after being blocked by |
---|
124 | itself, the task priority has to be pulled down to background. */ |
---|
125 | if ( !scenario_done && argument == 2 && now >= 500 ) { |
---|
126 | Violating_task[ argument ] = 1; |
---|
127 | scenario_done = 1; |
---|
128 | } |
---|
129 | if (argument == 2 && Violating_task[ argument ]) |
---|
130 | rtems_task_wake_after( 10 ); |
---|
131 | |
---|
132 | /* active computing */ |
---|
133 | while(FOREVER) { |
---|
134 | rtems_clock_get(RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &now); |
---|
135 | if ( argument == 4 && !Violating_task[ argument ] && |
---|
136 | (now >= start + Execution[argument])) |
---|
137 | break; |
---|
138 | if ( argument != 4 && (now >= start + Execution[argument]) ) |
---|
139 | break; |
---|
140 | } |
---|
141 | rtems_clock_get(RTEMS_CLOCK_GET_TICKS_SINCE_BOOT, &stop); |
---|
142 | printf("P%" PRIdPTR "-F ticks:%d\n", argument, stop); |
---|
143 | } |
---|
144 | |
---|
145 | /* delete period and SELF */ |
---|
146 | status = rtems_rate_monotonic_delete( rmid ); |
---|
147 | if ( status != RTEMS_SUCCESSFUL ) { |
---|
148 | printf("rtems_rate_monotonic_delete failed with status of %d.\n",status); |
---|
149 | rtems_test_exit( 0 ); |
---|
150 | } |
---|
151 | if ( rtems_cbs_cleanup() ) |
---|
152 | printf( "ERROR: CBS CLEANUP\n" ); |
---|
153 | fflush(stdout); |
---|
154 | puts( "*** END OF TEST CBS SCHEDULER 3 ***" ); |
---|
155 | rtems_test_exit( 0 ); |
---|
156 | } |
---|