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

4.11
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on Mar 20, 2014 at 9:10:47 PM

Change all references of rtems.com to rtems.org.

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