source: rtems/testsuites/tmtests/tm27/task1.c @ 9d47cd1

4.115
Last change on this file since 9d47cd1 was 9d47cd1, checked in by Joel Sherrill <joel.sherrill@…>, on 07/30/10 at 18:52:32

2010-07-30 Gedare Bloom <giddyup44@…>

PR 1599/cpukit

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