source: rtems/testsuites/tmtests/tm27/task1.c @ 4b04cb61

5
Last change on this file since 4b04cb61 was 4b04cb61, checked in by Sebastian Huber <sebastian.huber@…>, on 05/18/16 at 06:03:05

score: Rename _ISR_Disable_without_giant()

Rename _ISR_Disable_without_giant() into _ISR_Local_disable(). Rename
_ISR_Enable_without_giant() into _ISR_Local_enable().

This is a preparation to remove the Giant lock.

Update #2555.

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