1 | /* |
---|
2 | * Copyright (c) 2014 Daniel Ramirez. (javamonn@gmail.com) |
---|
3 | * |
---|
4 | * This file's license is 2-clause BSD as in this distribution's LICENSE file. |
---|
5 | */ |
---|
6 | |
---|
7 | #include <rtems/timerdrv.h> |
---|
8 | #include <timesys.h> |
---|
9 | |
---|
10 | #define BENCHMARKS 50000 |
---|
11 | |
---|
12 | rtems_task Task01( rtems_task_argument ignored ); |
---|
13 | rtems_task Task02( rtems_task_argument ignored ); |
---|
14 | rtems_task Init( rtems_task_argument ignored ); |
---|
15 | |
---|
16 | rtems_id Task_id[2]; |
---|
17 | rtems_name Task_name[2]; |
---|
18 | uint32_t loop_overhead; |
---|
19 | uint32_t dir_overhead; |
---|
20 | unsigned long count1, count2; |
---|
21 | rtems_status_code status; |
---|
22 | |
---|
23 | rtems_task Task02( rtems_task_argument ignored ) |
---|
24 | { |
---|
25 | uint32_t telapsed; |
---|
26 | |
---|
27 | /* All overhead accounted for now, we can begin benchmark */ |
---|
28 | benchmark_timer_initialize(); |
---|
29 | |
---|
30 | for ( count1 = 0; count1 < BENCHMARKS - 1; count1++ ) { |
---|
31 | rtems_task_wake_after( RTEMS_YIELD_PROCESSOR ); |
---|
32 | } |
---|
33 | |
---|
34 | telapsed = benchmark_timer_read(); |
---|
35 | put_time( |
---|
36 | "Rhealstone: Task switch", |
---|
37 | telapsed, |
---|
38 | ( BENCHMARKS * 2 ) - 1, /* ( BENCHMARKS * 2 ) - 1 total benchmarks */ |
---|
39 | loop_overhead, /* Overhead of loop */ |
---|
40 | dir_overhead /* Overhead of rtems_task_wake_after directive */ |
---|
41 | ); |
---|
42 | |
---|
43 | puts( "*** END OF RTASKSWITCH ***" ); |
---|
44 | rtems_test_exit( 0 ); |
---|
45 | } |
---|
46 | |
---|
47 | rtems_task Task01( rtems_task_argument ignored ) |
---|
48 | { |
---|
49 | status = rtems_task_start( Task_id[1], Task02, 0 ); |
---|
50 | directive_failed( status, "rtems_task_start of TA02" ); |
---|
51 | |
---|
52 | /* Yield processor so second task can startup and run */ |
---|
53 | rtems_task_wake_after( RTEMS_YIELD_PROCESSOR ); |
---|
54 | |
---|
55 | for ( count2 = 0; count2 < BENCHMARKS; count2++ ) { |
---|
56 | rtems_task_wake_after( RTEMS_YIELD_PROCESSOR ); |
---|
57 | } |
---|
58 | |
---|
59 | /* Should never reach here */ |
---|
60 | rtems_test_assert( false ); |
---|
61 | |
---|
62 | } |
---|
63 | |
---|
64 | rtems_task Init( rtems_task_argument ignored ) |
---|
65 | { |
---|
66 | Print_Warning(); |
---|
67 | |
---|
68 | puts( "*** START OF RHTASKSWITCH ***" ); |
---|
69 | |
---|
70 | Task_name[0] = rtems_build_name( 'T','A','0','1' ); |
---|
71 | status = rtems_task_create( |
---|
72 | Task_name[0], |
---|
73 | 30, |
---|
74 | RTEMS_MINIMUM_STACK_SIZE, |
---|
75 | RTEMS_DEFAULT_MODES, |
---|
76 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
77 | &Task_id[0] |
---|
78 | ); |
---|
79 | directive_failed( status, "rtems_task_create of TA01" ); |
---|
80 | |
---|
81 | Task_name[1] = rtems_build_name( 'T','A','0','2' ); |
---|
82 | status = rtems_task_create( |
---|
83 | Task_name[1], |
---|
84 | 30, |
---|
85 | RTEMS_MINIMUM_STACK_SIZE, |
---|
86 | RTEMS_DEFAULT_MODES, |
---|
87 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
88 | &Task_id[1] |
---|
89 | ); |
---|
90 | directive_failed( status, "rtems_task_create of TA02" ); |
---|
91 | |
---|
92 | /* find overhead of routine (no task switches) */ |
---|
93 | benchmark_timer_initialize(); |
---|
94 | for ( count1 = 0; count1 < BENCHMARKS - 1; count1++ ) { |
---|
95 | /* rtems_task_wake_after( RTEMS_YIELD_PROCESSOR ) */ |
---|
96 | } |
---|
97 | for ( count2 = 0; count2 < BENCHMARKS; count2++ ) { |
---|
98 | /* rtems_task_wake_after( RTEMS_YIELD_PROCESSOR ) */ |
---|
99 | } |
---|
100 | loop_overhead = benchmark_timer_read(); |
---|
101 | |
---|
102 | /* find overhead of rtems_task_wake_after call (no task switches) */ |
---|
103 | benchmark_timer_initialize(); |
---|
104 | rtems_task_wake_after( RTEMS_YIELD_PROCESSOR ); |
---|
105 | dir_overhead = benchmark_timer_read(); |
---|
106 | |
---|
107 | status = rtems_task_start( Task_id[0], Task01, 0); |
---|
108 | directive_failed( status, "rtems_task_start of TA01" ); |
---|
109 | |
---|
110 | status = rtems_task_delete( RTEMS_SELF); |
---|
111 | directive_failed( status, "rtems_task_delete of INIT" ); |
---|
112 | } |
---|
113 | |
---|
114 | /* configuration information */ |
---|
115 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
116 | #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER |
---|
117 | #define CONFIGURE_TICKS_PER_TIMESLICE 0 |
---|
118 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
119 | #define CONFIGURE_MAXIMUM_TASKS 3 |
---|
120 | #define CONFIGURE_INIT |
---|
121 | #include <rtems/confdefs.h> |
---|