source: rtems/testsuites/tmtests/tm27/task1.c @ 24934e36

4.115
Last change on this file since 24934e36 was 24934e36, checked in by Sebastian Huber <sebastian.huber@…>, on 04/03/14 at 13:03:35

score: Add scheduler control to scheduler ops

Scheduler operations must be free of a global scheduler context to
enable partitioned/clustered scheduling.

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