OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [tests/] [tmtests/] [tm26/] [task1.c] - Blame information for rev 173

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
2
 *
3
 *  COPYRIGHT (c) 1989-1999.
4
 *  On-Line Applications Research Corporation (OAR).
5
 *
6
 *  The license and distribution terms for this file may be
7
 *  found in the file LICENSE in this distribution or at
8
 *  http://www.OARcorp.com/rtems/license.html.
9
 *
10
 *  $Id: task1.c,v 1.2 2001-09-27 12:02:44 chris Exp $
11
 */
12
 
13
#define TEST_INIT
14
#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
15
#include <rtems.h>
16
#include "system.h"
17
#include "fptest.h"
18
#include <coverhd.h>
19
#include <tmacros.h>
20
#include <timesys.h>
21
 
22
 
23
/* TEST DATA */
24
rtems_id Semaphore_id;
25
 
26
Objects_Locations location;   /* uses internal RTEMS type */
27
 
28
Thread_Control *Middle_tcb;   /* uses internal RTEMS type */
29
 
30
Thread_Control *Low_tcb;      /* uses internal RTEMS type */
31
 
32
/*
33
 *  Variables to hold execution times until they are printed
34
 *  at the end of the test.
35
 */
36
 
37
rtems_unsigned32 isr_disable_time;
38
rtems_unsigned32 isr_flash_time;
39
rtems_unsigned32 isr_enable_time;
40
rtems_unsigned32 thread_disable_dispatch_time;
41
rtems_unsigned32 thread_enable_dispatch_time;
42
rtems_unsigned32 thread_set_state_time;
43
rtems_unsigned32 thread_dispatch_no_fp_time;
44
rtems_unsigned32 context_switch_no_fp_time;
45
rtems_unsigned32 context_switch_self_time;
46
rtems_unsigned32 context_switch_another_task_time;
47
rtems_unsigned32 context_switch_restore_1st_fp_time;
48
rtems_unsigned32 context_switch_save_idle_restore_initted_time;
49
rtems_unsigned32 context_switch_save_restore_idle_time;
50
rtems_unsigned32 context_switch_save_restore_initted_time;
51
rtems_unsigned32 thread_resume_time;
52
rtems_unsigned32 thread_unblock_time;
53
rtems_unsigned32 thread_ready_time;
54
rtems_unsigned32 thread_get_time;
55
rtems_unsigned32 semaphore_get_time;
56
rtems_unsigned32 thread_get_invalid_time;
57
 
58
rtems_task High_task(
59
  rtems_task_argument argument
60
);
61
 
62
rtems_task Middle_task(
63
  rtems_task_argument argument
64
);
65
 
66
rtems_task Low_task(
67
  rtems_task_argument argument
68
);
69
 
70
rtems_task Floating_point_task_1(
71
  rtems_task_argument argument
72
);
73
 
74
rtems_task Floating_point_task_2(
75
  rtems_task_argument argument
76
);
77
 
78
void complete_test( void );
79
 
80
rtems_task null_task(
81
  rtems_task_argument argument
82
)
83
{
84
}
85
 
86
rtems_task Init(
87
  rtems_task_argument argument
88
)
89
{
90
  rtems_unsigned32  index;
91
  rtems_id          task_id;
92
  rtems_status_code status;
93
 
94
  Print_Warning();
95
 
96
  puts( "\n\n*** TIME TEST 26 ***" );
97
 
98
  status = rtems_task_create(
99
    rtems_build_name( 'F', 'P', '1', ' ' ),
100
    201,
101
    RTEMS_MINIMUM_STACK_SIZE,
102
    RTEMS_DEFAULT_MODES,
103
    RTEMS_FLOATING_POINT,
104
    &task_id
105
  );
106
  directive_failed( status, "rtems_task_create of FP1" );
107
 
108
  status = rtems_task_start( task_id, Floating_point_task_1, 0 );
109
  directive_failed( status, "rtems_task_start of FP1" );
110
 
111
  status = rtems_task_create(
112
    rtems_build_name( 'F', 'P', '2', ' ' ),
113
    202,
114
    RTEMS_MINIMUM_STACK_SIZE,
115
    RTEMS_DEFAULT_MODES,
116
    RTEMS_FLOATING_POINT,
117
    &task_id
118
  );
119
  directive_failed( status, "rtems_task_create of FP2" );
120
 
121
  status = rtems_task_start( task_id, Floating_point_task_2, 0 );
122
  directive_failed( status, "rtems_task_start of FP2" );
123
 
124
  status = rtems_task_create(
125
    rtems_build_name( 'L', 'O', 'W', ' ' ),
126
    200,
127
    RTEMS_MINIMUM_STACK_SIZE,
128
    RTEMS_DEFAULT_MODES,
129
    RTEMS_DEFAULT_ATTRIBUTES,
130
    &task_id
131
  );
132
  directive_failed( status, "rtems_task_create of LOW" );
133
 
134
  status = rtems_task_start( task_id, Low_task, 0 );
135
  directive_failed( status, "rtems_task_start of LOW" );
136
 
137
  status = rtems_task_create(
138
    rtems_build_name( 'M', 'I', 'D', ' ' ),
139
    128,
140
    RTEMS_MINIMUM_STACK_SIZE,
141
    RTEMS_DEFAULT_MODES,
142
    RTEMS_DEFAULT_ATTRIBUTES,
143
    &task_id
144
  );
145
  directive_failed( status, "rtems_task_create of MIDDLE" );
146
 
147
  status = rtems_task_start( task_id, Middle_task, 0 );
148
  directive_failed( status, "rtems_task_start of MIDDLE" );
149
 
150
  status = rtems_task_create(
151
    rtems_build_name( 'H', 'I', 'G', 'H' ),
152
    5,
153
    RTEMS_MINIMUM_STACK_SIZE,
154
    RTEMS_DEFAULT_MODES,
155
    RTEMS_DEFAULT_ATTRIBUTES,
156
    &task_id
157
  );
158
  directive_failed( status, "rtems_task_create of HIGH" );
159
 
160
  status = rtems_task_start( task_id, High_task, 0 );
161
  directive_failed( status, "rtems_task_start of HIGH" );
162
 
163
  status = rtems_semaphore_create(
164
    rtems_build_name( 'S', 'E', 'M', '1' ),
165
    OPERATION_COUNT,
166
    RTEMS_DEFAULT_ATTRIBUTES,
167
    RTEMS_NO_PRIORITY,
168
    &Semaphore_id
169
  );
170
  directive_failed( status, "rtems_semaphore_create" );
171
 
172
  for ( index = 1 ; index <= OPERATION_COUNT ; index++ ) {
173
    status = rtems_task_create(
174
      rtems_build_name( 'N', 'U', 'L', 'L' ),
175
      254,
176
      RTEMS_MINIMUM_STACK_SIZE,
177
      RTEMS_DEFAULT_MODES,
178
      RTEMS_DEFAULT_ATTRIBUTES,
179
      &task_id
180
    );
181
    directive_failed( status, "rtems_task_create LOOP" );
182
 
183
    status = rtems_task_start( task_id, null_task, 0 );
184
    directive_failed( status, "rtems_task_start LOOP" );
185
  }
186
 
187
  status = rtems_task_delete( RTEMS_SELF );
188
  directive_failed( status, "rtems_task_delete of RTEMS_SELF" );
189
}
190
 
191
rtems_task High_task(
192
  rtems_task_argument argument
193
)
194
{
195
  rtems_interrupt_level level;
196
 
197
  Timer_initialize();
198
    rtems_interrupt_disable( level );
199
  isr_disable_time = Read_timer();
200
 
201
  Timer_initialize();
202
    rtems_interrupt_flash( level );
203
  isr_flash_time = Read_timer();
204
 
205
  Timer_initialize();
206
    rtems_interrupt_enable( level );
207
  isr_enable_time = Read_timer();
208
 
209
  Timer_initialize();
210
    _Thread_Disable_dispatch();
211
  thread_disable_dispatch_time = Read_timer();
212
 
213
  Timer_initialize();
214
    _Thread_Enable_dispatch();
215
  thread_enable_dispatch_time = Read_timer();
216
 
217
  Timer_initialize();
218
    _Thread_Set_state( _Thread_Executing, STATES_SUSPENDED );
219
  thread_set_state_time = Read_timer();
220
 
221
  _Context_Switch_necessary = TRUE;
222
 
223
  Timer_initialize();
224
    _Thread_Dispatch();           /* dispatches Middle_task */
225
}
226
 
227
rtems_task Middle_task(
228
  rtems_task_argument argument
229
)
230
{
231
  thread_dispatch_no_fp_time = Read_timer();
232
 
233
  _Thread_Set_state( _Thread_Executing, STATES_SUSPENDED );
234
 
235
  Middle_tcb   = _Thread_Executing;
236
 
237
  _Thread_Executing =
238
        (Thread_Control *) _Thread_Ready_chain[200].first;
239
 
240
  /* do not force context switch */
241
 
242
  _Context_Switch_necessary = FALSE;
243
 
244
  _Thread_Disable_dispatch();
245
 
246
  Timer_initialize();
247
    _Context_Switch( &Middle_tcb->Registers, &_Thread_Executing->Registers );
248
 
249
  Timer_initialize();
250
    _Context_Switch(&Middle_tcb->Registers, &Low_tcb->Registers);
251
}
252
 
253
rtems_task Low_task(
254
  rtems_task_argument argument
255
)
256
{
257
  Thread_Control *executing;
258
 
259
  context_switch_no_fp_time = Read_timer();
260
 
261
  executing    = _Thread_Executing;
262
 
263
  Low_tcb = executing;
264
 
265
  Timer_initialize();
266
    _Context_Switch( &executing->Registers, &executing->Registers );
267
 
268
  context_switch_self_time = Read_timer();
269
 
270
  _Context_Switch(&executing->Registers, &Middle_tcb->Registers);
271
 
272
  context_switch_another_task_time = Read_timer();
273
 
274
  _Thread_Executing =
275
        (Thread_Control *) _Thread_Ready_chain[201].first;
276
 
277
  /* do not force context switch */
278
 
279
  _Context_Switch_necessary = FALSE;
280
 
281
  _Thread_Disable_dispatch();
282
 
283
  Timer_initialize();
284
    _Context_Restore_fp( &_Thread_Executing->fp_context );
285
    _Context_Switch( &executing->Registers, &_Thread_Executing->Registers );
286
}
287
 
288
rtems_task Floating_point_task_1(
289
  rtems_task_argument argument
290
)
291
{
292
  Thread_Control *executing;
293
  FP_DECLARE;
294
 
295
  context_switch_restore_1st_fp_time = Read_timer();
296
 
297
  executing = _Thread_Executing;
298
 
299
  _Thread_Executing =
300
        (Thread_Control *) _Thread_Ready_chain[202].first;
301
 
302
  /* do not force context switch */
303
 
304
  _Context_Switch_necessary = FALSE;
305
 
306
  _Thread_Disable_dispatch();
307
 
308
  Timer_initialize();
309
    _Context_Save_fp( &executing->fp_context );
310
    _Context_Restore_fp( &_Thread_Executing->fp_context );
311
    _Context_Switch( &executing->Registers, &_Thread_Executing->Registers );
312
  /* switch to Floating_point_task_2 */
313
 
314
  context_switch_save_idle_restore_initted_time = Read_timer();
315
 
316
  FP_LOAD( 1.0 );
317
 
318
  executing = _Thread_Executing;
319
 
320
  _Thread_Executing =
321
       (Thread_Control *) _Thread_Ready_chain[202].first;
322
 
323
  /* do not force context switch */
324
 
325
  _Context_Switch_necessary = FALSE;
326
 
327
  _Thread_Disable_dispatch();
328
 
329
  Timer_initialize();
330
    _Context_Save_fp( &executing->fp_context );
331
    _Context_Restore_fp( &_Thread_Executing->fp_context );
332
    _Context_Switch( &executing->Registers, &_Thread_Executing->Registers );
333
  /* switch to Floating_point_task_2 */
334
}
335
 
336
rtems_task Floating_point_task_2(
337
  rtems_task_argument argument
338
)
339
{
340
  Thread_Control *executing;
341
  FP_DECLARE;
342
 
343
  context_switch_save_restore_idle_time = Read_timer();
344
 
345
  executing = _Thread_Executing;
346
 
347
  _Thread_Executing =
348
       (Thread_Control *) _Thread_Ready_chain[201].first;
349
 
350
  FP_LOAD( 1.0 );
351
 
352
  /* do not force context switch */
353
 
354
  _Context_Switch_necessary = FALSE;
355
 
356
  _Thread_Disable_dispatch();
357
 
358
  Timer_initialize();
359
    _Context_Save_fp( &executing->fp_context );
360
    _Context_Restore_fp( &_Thread_Executing->fp_context );
361
    _Context_Switch( &executing->Registers, &_Thread_Executing->Registers );
362
  /* switch to Floating_point_task_1 */
363
 
364
  context_switch_save_restore_initted_time = Read_timer();
365
 
366
  complete_test();
367
}
368
 
369
void complete_test( void )
370
{
371
  rtems_unsigned32  index;
372
  rtems_id          task_id;
373
 
374
  Timer_initialize();
375
    _Thread_Resume( Middle_tcb, TRUE );
376
  thread_resume_time = Read_timer();
377
 
378
  _Thread_Set_state( Middle_tcb, STATES_WAITING_FOR_MESSAGE );
379
 
380
  Timer_initialize();
381
    _Thread_Unblock( Middle_tcb );
382
  thread_unblock_time = Read_timer();
383
 
384
  _Thread_Set_state( Middle_tcb, STATES_WAITING_FOR_MESSAGE );
385
 
386
  Timer_initialize();
387
    _Thread_Ready( Middle_tcb );
388
  thread_ready_time = Read_timer();
389
 
390
  Timer_initialize();
391
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
392
      (void) Empty_function();
393
  overhead = Read_timer();
394
 
395
  task_id = Middle_tcb->Object.id;
396
 
397
  Timer_initialize();
398
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
399
      (void) _Thread_Get( task_id, &location );
400
  thread_get_time = Read_timer();
401
 
402
  Timer_initialize();
403
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
404
      (void) _Semaphore_Get( Semaphore_id, &location );
405
  semaphore_get_time = Read_timer();
406
 
407
  Timer_initialize();
408
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
409
      (void) _Thread_Get( 0x3, &location );
410
  thread_get_invalid_time = Read_timer();
411
 
412
  /*
413
   *  Now dump all the times
414
   */
415
 
416
  put_time(
417
    "_ISR_Disable",
418
    isr_disable_time,
419
    1,
420
    0,
421
 
422
  );
423
 
424
  put_time(
425
    "_ISR_Flash",
426
    isr_flash_time,
427
    1,
428
    0,
429
 
430
  );
431
 
432
  put_time(
433
    "_ISR_Enable",
434
    isr_enable_time,
435
    1,
436
    0,
437
 
438
  );
439
 
440
  put_time(
441
    "_Thread_Disable_dispatch",
442
    thread_disable_dispatch_time,
443
    1,
444
    0,
445
 
446
  );
447
 
448
  put_time(
449
    "_Thread_Enable_dispatch",
450
    thread_enable_dispatch_time,
451
    1,
452
    0,
453
 
454
  );
455
 
456
  put_time(
457
    "_Thread_Set_state",
458
    thread_set_state_time,
459
    1,
460
    0,
461
 
462
  );
463
 
464
  put_time(
465
    "_Thread_Disptach (NO FP)",
466
    thread_dispatch_no_fp_time,
467
    1,
468
    0,
469
 
470
  );
471
 
472
  put_time(
473
    "context switch: no floating point contexts",
474
    context_switch_no_fp_time,
475
    1,
476
    0,
477
 
478
  );
479
 
480
  put_time(
481
    "context switch: self",
482
    context_switch_self_time,
483
    1,
484
    0,
485
 
486
  );
487
 
488
  put_time(
489
    "context switch: to another task",
490
    context_switch_another_task_time,
491
    1,
492
    0,
493
 
494
  );
495
 
496
  put_time(
497
    "fp context switch: restore 1st FP task",
498
    context_switch_restore_1st_fp_time,
499
    1,
500
    0,
501
 
502
  );
503
 
504
  put_time(
505
    "fp context switch: save idle, restore initialized",
506
    context_switch_save_idle_restore_initted_time,
507
    1,
508
    0,
509
 
510
  );
511
 
512
  put_time(
513
    "fp context switch: save idle, restore idle",
514
    context_switch_save_restore_idle_time,
515
    1,
516
    0,
517
 
518
  );
519
 
520
  put_time(
521
    "fp context switch: save initialized, restore initialized",
522
    context_switch_save_restore_initted_time,
523
    1,
524
    0,
525
 
526
  );
527
 
528
  put_time(
529
    "_Thread_Resume",
530
    thread_resume_time,
531
    1,
532
    0,
533
 
534
  );
535
 
536
  put_time(
537
    "_Thread_Unblock",
538
    thread_unblock_time,
539
    1,
540
    0,
541
 
542
  );
543
 
544
  put_time(
545
    "_Thread_Ready",
546
    thread_ready_time,
547
    1,
548
    0,
549
 
550
  );
551
 
552
  put_time(
553
    "_Thread_Get",
554
    thread_get_time,
555
    OPERATION_COUNT,
556
    0,
557
 
558
  );
559
 
560
  put_time(
561
    "_Semaphore_Get",
562
    semaphore_get_time,
563
    OPERATION_COUNT,
564
    0,
565
 
566
  );
567
 
568
  put_time(
569
    "_Thread_Get: invalid id",
570
    thread_get_invalid_time,
571
    OPERATION_COUNT,
572
    0,
573
 
574
  );
575
 
576
  puts( "*** END OF TEST 26 ***" );
577
  exit( 0 );
578
}
579
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.