source: rtems/testsuites/tmtests/tm27/task1.c @ a1a5f92

4.115
Last change on this file since a1a5f92 was a1a5f92, checked in by Joel Sherrill <joel.sherrill@…>, on 03/16/11 at 17:11:32

2011-03-16 Jennifer Averett <jennifer.averett@…>

PR 1743/cpu

  • tm26/task1.c, tm27/task1.c: Add Simple Priority Scheduler as complement to existing Deterministic Priority Scheduler. Modify these tests to verify the scheduler they are designed to work with is the default scheduler.
  • Property mode set to 100644
File size: 6.2 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2011.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12/*
13 *  WARNING!!!!!!!!!
14 *
15 *  THIS TEST USES INTERNAL RTEMS VARIABLES!!!
16 */
17
18#ifdef HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#define CONFIGURE_INIT
23#include "system.h"
24
25#include <bsp.h>
26
27#define _RTEMS_TMTEST27
28#include <tm27.h>
29
30rtems_task Task_1(
31  rtems_task_argument argument
32);
33
34rtems_task Task_2(
35  rtems_task_argument argument
36);
37
38volatile uint32_t   Interrupt_occurred;
39volatile uint32_t   Interrupt_enter_time, Interrupt_enter_nested_time;
40volatile uint32_t   Interrupt_return_time, Interrupt_return_nested_time;
41uint32_t   Interrupt_nest;
42uint32_t   timer_overhead;
43
44rtems_isr Isr_handler(
45  rtems_vector_number vector
46);
47
48rtems_task Init(
49  rtems_task_argument argument
50)
51{
52  rtems_status_code status;
53
54  Print_Warning();
55
56  puts( "\n\n*** TIME TEST 27 ***" );
57  if (_Scheduler.Operations.initialize != _Scheduler_priority_Initialize) {
58    puts("  Error ==> " );
59    puts("Test only supported for deterministic priority scheduler\n" );
60    puts( "*** END OF TEST 26 ***" );
61    rtems_test_exit( 0 );
62  }
63
64#define LOW_PRIORITY (RTEMS_MAXIMUM_PRIORITY - 1u)
65  status = rtems_task_create(
66    rtems_build_name( 'T', 'A', '1', ' ' ),
67    LOW_PRIORITY,
68    RTEMS_MINIMUM_STACK_SIZE,
69    RTEMS_DEFAULT_MODES,
70    RTEMS_DEFAULT_ATTRIBUTES,
71    &Task_id[ 1 ]
72  );
73  directive_failed( status, "rtems_task_create Task_1" );
74
75  status = rtems_task_start( Task_id[ 1 ], Task_1, 0 );
76  directive_failed( status, "rtems_task_start Task_1" );
77
78  status = rtems_task_create(
79    rtems_build_name( 'T', 'A', '2', ' ' ),
80    LOW_PRIORITY,
81    RTEMS_MINIMUM_STACK_SIZE,
82    RTEMS_DEFAULT_MODES,
83    RTEMS_DEFAULT_ATTRIBUTES,
84    &Task_id[ 2 ]
85  );
86  directive_failed( status, "rtems_task_create of Task_2" );
87
88  status = rtems_task_start( Task_id[ 2 ], Task_2, 0 );
89  directive_failed( status, "rtems_task_start of Task_2" );
90
91  benchmark_timer_initialize();
92  benchmark_timer_read();
93  benchmark_timer_initialize();
94  timer_overhead = benchmark_timer_read();
95
96  status = rtems_task_delete( RTEMS_SELF );
97  directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
98}
99
100rtems_task Task_1(
101  rtems_task_argument argument
102)
103{
104  Chain_Control   *ready_queues;
105
106  Install_tm27_vector( Isr_handler );
107
108  /*
109   *  No preempt .. no nesting
110   */
111
112  Interrupt_nest = 0;
113
114  _Thread_Dispatch_disable_level = 0;
115
116  Interrupt_occurred = 0;
117
118  benchmark_timer_initialize();
119  Cause_tm27_intr();
120  /* goes to Isr_handler */
121
122#if (MUST_WAIT_FOR_INTERRUPT == 1)
123  while ( Interrupt_occurred == 0 );
124#endif
125  Interrupt_return_time = benchmark_timer_read();
126
127  put_time(
128    "interrupt entry overhead: returns to interrupted task",
129    Interrupt_enter_time,
130    1,
131    0,
132    timer_overhead
133  );
134
135  put_time(
136    "interrupt exit overhead: returns to interrupted task",
137    Interrupt_return_time,
138    1,
139    0,
140    timer_overhead
141  );
142
143  /*
144   *  No preempt .. nested
145   */
146
147  _Thread_Dispatch_disable_level = 1;
148
149  Interrupt_nest = 1;
150
151  Interrupt_occurred = 0;
152  benchmark_timer_initialize();
153  Cause_tm27_intr();
154  /* goes to Isr_handler */
155
156#if (MUST_WAIT_FOR_INTERRUPT == 1)
157  while ( Interrupt_occurred == 0 );
158#endif
159  Interrupt_return_time = benchmark_timer_read();
160
161  _Thread_Dispatch_disable_level = 0;
162
163  put_time(
164    "interrupt entry overhead: returns to nested interrupt",
165    Interrupt_enter_nested_time,
166    1,
167    0,
168    0
169  );
170
171  put_time(
172    "interrupt exit overhead: returns to nested interrupt",
173    Interrupt_return_nested_time,
174    1,
175    0,
176    0
177  );
178
179  /*
180   *  Does a preempt .. not nested
181   */
182
183  _Thread_Dispatch_disable_level = 0;
184
185  ready_queues      = (Chain_Control *) _Scheduler.information;
186  _Thread_Executing =
187        (Thread_Control *) _Chain_First(&ready_queues[LOW_PRIORITY]);
188
189  _Thread_Dispatch_necessary = 1;
190
191  Interrupt_occurred = 0;
192  benchmark_timer_initialize();
193  Cause_tm27_intr();
194
195  /*
196   *  goes to Isr_handler and then returns
197   */
198
199  puts( "*** END OF TEST 27 ***" );
200  rtems_test_exit( 0 );
201}
202
203/*
204 *  NOTE:  When this task is executing, some of the assumptions made
205 *         regarding the placement of the currently executing task's TCB
206 *         on the ready chains have been violated.  At least the assumption
207 *         that this task is at the head of the chain for its priority
208 *         has been violated.
209 */
210
211rtems_task Task_2(
212  rtems_task_argument argument
213)
214{
215  Chain_Control   *ready_queues;
216
217#if (MUST_WAIT_FOR_INTERRUPT == 1)
218  while ( Interrupt_occurred == 0 );
219#endif
220  end_time = benchmark_timer_read();
221
222  put_time(
223    "interrupt entry overhead: returns to preempting task",
224    Interrupt_enter_time,
225    1,
226    0,
227    timer_overhead
228  );
229
230  put_time(
231    "interrupt exit overhead: returns to preempting task",
232    end_time,
233    1,
234    0,
235    0
236  );
237
238  fflush( stdout );
239
240  /*
241   *  Switch back to the other task to exit the test.
242   */
243
244  _Thread_Dispatch_disable_level = 0;
245
246  ready_queues      = (Chain_Control *) _Scheduler.information;
247  _Thread_Executing =
248        (Thread_Control *) _Chain_First(&ready_queues[LOW_PRIORITY]);
249
250  _Thread_Dispatch_necessary = 1;
251
252  _Thread_Dispatch();
253
254}
255
256/*  The Isr_handler() and Isr_handler_inner() routines are structured
257 *  so that there will be as little entry overhead as possible included
258 *  in the interrupt entry time.
259 */
260
261void Isr_handler_inner( void );
262
263rtems_isr Isr_handler(
264  rtems_vector_number vector
265)
266{
267  end_time = benchmark_timer_read();
268
269  Interrupt_occurred = 1;
270  Isr_handler_inner();
271}
272
273void Isr_handler_inner( void )
274{
275
276  /*enable_tracing();*/
277  Clear_tm27_intr();
278  switch ( Interrupt_nest ) {
279    case 0:
280      Interrupt_enter_time = end_time;
281      break;
282    case 1:
283      Interrupt_enter_time = end_time;
284      Interrupt_nest = 2;
285      Interrupt_occurred = 0;
286      Lower_tm27_intr();
287      benchmark_timer_initialize();
288      Cause_tm27_intr();
289      /* goes to a nested copy of Isr_handler */
290#if (MUST_WAIT_FOR_INTERRUPT == 1)
291       while ( Interrupt_occurred == 0 );
292#endif
293      Interrupt_return_nested_time = benchmark_timer_read();
294      break;
295    case 2:
296      Interrupt_enter_nested_time = end_time;
297      break;
298  }
299
300  benchmark_timer_initialize();
301}
Note: See TracBrowser for help on using the repository browser.