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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [c/] [src/] [tests/] [tmtests/] [tm26/] [task1.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
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
 *  task1.c,v 1.18 2002/08/02 00:52:37 joel 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
#if (CPU_HARDWARE_FP == 1) || (CPU_SOFTWARE_FP == 1)
285
    _Context_Restore_fp( &_Thread_Executing->fp_context );
286
#endif
287
    _Context_Switch( &executing->Registers, &_Thread_Executing->Registers );
288
}
289
 
290
rtems_task Floating_point_task_1(
291
  rtems_task_argument argument
292
)
293
{
294
  Thread_Control *executing;
295
  FP_DECLARE;
296
 
297
  context_switch_restore_1st_fp_time = Read_timer();
298
 
299
  executing = _Thread_Executing;
300
 
301
  _Thread_Executing =
302
        (Thread_Control *) _Thread_Ready_chain[202].first;
303
 
304
  /* do not force context switch */
305
 
306
  _Context_Switch_necessary = FALSE;
307
 
308
  _Thread_Disable_dispatch();
309
 
310
  Timer_initialize();
311
#if (CPU_HARDWARE_FP == 1) || (CPU_SOFTWARE_FP == 1)
312
    _Context_Save_fp( &executing->fp_context );
313
    _Context_Restore_fp( &_Thread_Executing->fp_context );
314
#endif
315
    _Context_Switch( &executing->Registers, &_Thread_Executing->Registers );
316
  /* switch to Floating_point_task_2 */
317
 
318
  context_switch_save_idle_restore_initted_time = Read_timer();
319
 
320
  FP_LOAD( 1.0 );
321
 
322
  executing = _Thread_Executing;
323
 
324
  _Thread_Executing =
325
       (Thread_Control *) _Thread_Ready_chain[202].first;
326
 
327
  /* do not force context switch */
328
 
329
  _Context_Switch_necessary = FALSE;
330
 
331
  _Thread_Disable_dispatch();
332
 
333
  Timer_initialize();
334
#if (CPU_HARDWARE_FP == 1) || (CPU_SOFTWARE_FP == 1)
335
    _Context_Save_fp( &executing->fp_context );
336
    _Context_Restore_fp( &_Thread_Executing->fp_context );
337
#endif
338
    _Context_Switch( &executing->Registers, &_Thread_Executing->Registers );
339
  /* switch to Floating_point_task_2 */
340
}
341
 
342
rtems_task Floating_point_task_2(
343
  rtems_task_argument argument
344
)
345
{
346
  Thread_Control *executing;
347
  FP_DECLARE;
348
 
349
  context_switch_save_restore_idle_time = Read_timer();
350
 
351
  executing = _Thread_Executing;
352
 
353
  _Thread_Executing =
354
       (Thread_Control *) _Thread_Ready_chain[201].first;
355
 
356
  FP_LOAD( 1.0 );
357
 
358
  /* do not force context switch */
359
 
360
  _Context_Switch_necessary = FALSE;
361
 
362
  _Thread_Disable_dispatch();
363
 
364
  Timer_initialize();
365
#if (CPU_HARDWARE_FP == 1) || (CPU_SOFTWARE_FP == 1)
366
    _Context_Save_fp( &executing->fp_context );
367
    _Context_Restore_fp( &_Thread_Executing->fp_context );
368
#endif
369
    _Context_Switch( &executing->Registers, &_Thread_Executing->Registers );
370
  /* switch to Floating_point_task_1 */
371
 
372
  context_switch_save_restore_initted_time = Read_timer();
373
 
374
  complete_test();
375
}
376
 
377
void complete_test( void )
378
{
379
  rtems_unsigned32  index;
380
  rtems_id          task_id;
381
 
382
  Timer_initialize();
383
    _Thread_Resume( Middle_tcb, TRUE );
384
  thread_resume_time = Read_timer();
385
 
386
  _Thread_Set_state( Middle_tcb, STATES_WAITING_FOR_MESSAGE );
387
 
388
  Timer_initialize();
389
    _Thread_Unblock( Middle_tcb );
390
  thread_unblock_time = Read_timer();
391
 
392
  _Thread_Set_state( Middle_tcb, STATES_WAITING_FOR_MESSAGE );
393
 
394
  Timer_initialize();
395
    _Thread_Ready( Middle_tcb );
396
  thread_ready_time = Read_timer();
397
 
398
  Timer_initialize();
399
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
400
      (void) Empty_function();
401
  overhead = Read_timer();
402
 
403
  task_id = Middle_tcb->Object.id;
404
 
405
  Timer_initialize();
406
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
407
      (void) _Thread_Get( task_id, &location );
408
  thread_get_time = Read_timer();
409
 
410
  Timer_initialize();
411
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
412
      (void) _Semaphore_Get( Semaphore_id, &location );
413
  semaphore_get_time = Read_timer();
414
 
415
  Timer_initialize();
416
    for ( index=1 ; index <= OPERATION_COUNT ; index++ )
417
      (void) _Thread_Get( 0x3, &location );
418
  thread_get_invalid_time = Read_timer();
419
 
420
  /*
421
   *  Now dump all the times
422
   */
423
 
424
  put_time(
425
    "_ISR_Disable",
426
    isr_disable_time,
427
    1,
428
    0,
429
 
430
  );
431
 
432
  put_time(
433
    "_ISR_Flash",
434
    isr_flash_time,
435
    1,
436
    0,
437
 
438
  );
439
 
440
  put_time(
441
    "_ISR_Enable",
442
    isr_enable_time,
443
    1,
444
    0,
445
 
446
  );
447
 
448
  put_time(
449
    "_Thread_Disable_dispatch",
450
    thread_disable_dispatch_time,
451
    1,
452
    0,
453
 
454
  );
455
 
456
  put_time(
457
    "_Thread_Enable_dispatch",
458
    thread_enable_dispatch_time,
459
    1,
460
    0,
461
 
462
  );
463
 
464
  put_time(
465
    "_Thread_Set_state",
466
    thread_set_state_time,
467
    1,
468
    0,
469
 
470
  );
471
 
472
  put_time(
473
    "_Thread_Disptach (NO FP)",
474
    thread_dispatch_no_fp_time,
475
    1,
476
    0,
477
 
478
  );
479
 
480
  put_time(
481
    "context switch: no floating point contexts",
482
    context_switch_no_fp_time,
483
    1,
484
    0,
485
 
486
  );
487
 
488
  put_time(
489
    "context switch: self",
490
    context_switch_self_time,
491
    1,
492
    0,
493
 
494
  );
495
 
496
  put_time(
497
    "context switch: to another task",
498
    context_switch_another_task_time,
499
    1,
500
    0,
501
 
502
  );
503
 
504
#if (CPU_HARDWARE_FP == 1) || (CPU_SOFTWARE_FP == 1)
505
  put_time(
506
    "fp context switch: restore 1st FP task",
507
    context_switch_restore_1st_fp_time,
508
    1,
509
    0,
510
 
511
  );
512
 
513
  put_time(
514
    "fp context switch: save idle, restore initialized",
515
    context_switch_save_idle_restore_initted_time,
516
    1,
517
    0,
518
 
519
  );
520
 
521
  put_time(
522
    "fp context switch: save idle, restore idle",
523
    context_switch_save_restore_idle_time,
524
    1,
525
    0,
526
 
527
  );
528
 
529
  put_time(
530
    "fp context switch: save initialized, restore initialized",
531
    context_switch_save_restore_initted_time,
532
    1,
533
    0,
534
 
535
  );
536
#else
537
    puts( "fp context switch: restore 1st FP task - NA" );
538
    puts( "fp context switch: save idle, restore initialized - NA" );
539
    puts( "fp context switch: save idle, restore idle - NA" );
540
    puts( "fp context switch: save initialized, restore initialized - NA" );
541
#endif
542
 
543
  put_time(
544
    "_Thread_Resume",
545
    thread_resume_time,
546
    1,
547
    0,
548
 
549
  );
550
 
551
  put_time(
552
    "_Thread_Unblock",
553
    thread_unblock_time,
554
    1,
555
    0,
556
 
557
  );
558
 
559
  put_time(
560
    "_Thread_Ready",
561
    thread_ready_time,
562
    1,
563
    0,
564
 
565
  );
566
 
567
  put_time(
568
    "_Thread_Get",
569
    thread_get_time,
570
    OPERATION_COUNT,
571
    0,
572
 
573
  );
574
 
575
  put_time(
576
    "_Semaphore_Get",
577
    semaphore_get_time,
578
    OPERATION_COUNT,
579
    0,
580
 
581
  );
582
 
583
  put_time(
584
    "_Thread_Get: invalid id",
585
    thread_get_invalid_time,
586
    OPERATION_COUNT,
587
    0,
588
 
589
  );
590
 
591
  puts( "*** END OF TEST 26 ***" );
592
  rtems_test_exit( 0 );
593
}
594
 

powered by: WebSVN 2.1.0

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