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 <timesys.h> |
---|
8 | #include <rtems/timerdrv.h> |
---|
9 | #define BENCHMARKS 50000 /* Number of benchmarks to run and average over */ |
---|
10 | |
---|
11 | rtems_task Task02( rtems_task_argument ignored ); |
---|
12 | rtems_task Task01( rtems_task_argument ignored ); |
---|
13 | rtems_task Init( rtems_task_argument ignored ); |
---|
14 | |
---|
15 | rtems_id Task_id[2]; |
---|
16 | rtems_name Task_name[2]; |
---|
17 | |
---|
18 | uint32_t telapsed; /* total time elapsed during benchmark */ |
---|
19 | uint32_t tloop_overhead; /* overhead of loops */ |
---|
20 | uint32_t tswitch_overhead; /* overhead of time it takes to switch |
---|
21 | * from TA02 to TA01, includes rtems_suspend |
---|
22 | * overhead |
---|
23 | */ |
---|
24 | unsigned long count1; |
---|
25 | rtems_status_code status; |
---|
26 | |
---|
27 | rtems_task Task01( rtems_task_argument ignored ) |
---|
28 | { |
---|
29 | /* Start up TA02, get preempted */ |
---|
30 | status = rtems_task_start( Task_id[1], Task02, 0); |
---|
31 | directive_failed( status, "rtems_task_start of TA02"); |
---|
32 | |
---|
33 | tswitch_overhead = benchmark_timer_read(); |
---|
34 | |
---|
35 | benchmark_timer_initialize(); |
---|
36 | /* Benchmark code */ |
---|
37 | for ( count1 = 0; count1 < BENCHMARKS; count1++ ) { |
---|
38 | rtems_task_resume( Task_id[1] ); /* Awaken TA02, preemption occurs */ |
---|
39 | } |
---|
40 | |
---|
41 | /* Should never reach here */ |
---|
42 | rtems_test_assert( false ); |
---|
43 | } |
---|
44 | |
---|
45 | rtems_task Task02( rtems_task_argument ignored ) |
---|
46 | { |
---|
47 | /* Find overhead of task switch back to TA01 (not a preemption) */ |
---|
48 | benchmark_timer_initialize(); |
---|
49 | rtems_task_suspend( RTEMS_SELF ); |
---|
50 | |
---|
51 | /* Benchmark code */ |
---|
52 | for ( ; count1 < BENCHMARKS - 1; ) { |
---|
53 | rtems_task_suspend( RTEMS_SELF ); |
---|
54 | } |
---|
55 | |
---|
56 | telapsed = benchmark_timer_read(); |
---|
57 | put_time( |
---|
58 | "Rhealstone: Task Preempt", |
---|
59 | telapsed, /* Total time of all benchmarks */ |
---|
60 | BENCHMARKS - 1, /* BENCHMARKS - 1 total preemptions */ |
---|
61 | tloop_overhead, /* Overhead of loops */ |
---|
62 | tswitch_overhead /* Overhead of task switch back to TA01 */ |
---|
63 | ); |
---|
64 | |
---|
65 | rtems_test_exit( 0 ); |
---|
66 | } |
---|
67 | |
---|
68 | rtems_task Init( rtems_task_argument ignored ) |
---|
69 | { |
---|
70 | Print_Warning(); |
---|
71 | |
---|
72 | Task_name[0] = rtems_build_name( 'T','A','0','1' ); |
---|
73 | status = rtems_task_create( |
---|
74 | Task_name[0], |
---|
75 | 30, /* TA01 is low priority task */ |
---|
76 | RTEMS_MINIMUM_STACK_SIZE, |
---|
77 | RTEMS_DEFAULT_MODES, |
---|
78 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
79 | &Task_id[0] |
---|
80 | ); |
---|
81 | directive_failed( status, "rtems_task_create of TA01"); |
---|
82 | |
---|
83 | Task_name[1] = rtems_build_name( 'T','A','0','2' ); |
---|
84 | status = rtems_task_create( |
---|
85 | Task_name[1], |
---|
86 | 28, /* TA02 is high priority task */ |
---|
87 | RTEMS_MINIMUM_STACK_SIZE, |
---|
88 | RTEMS_DEFAULT_MODES, |
---|
89 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
90 | &Task_id[1] |
---|
91 | ); |
---|
92 | directive_failed( status, "rtems_task_create of TA02"); |
---|
93 | |
---|
94 | /* Find loop overhead */ |
---|
95 | benchmark_timer_initialize(); |
---|
96 | for ( count1 = 0; count1 < ( BENCHMARKS * 2 ) - 1; count1++ ); { |
---|
97 | /* rtems_task_resume( Task_id[1] ); */ |
---|
98 | } |
---|
99 | tloop_overhead = benchmark_timer_read(); |
---|
100 | |
---|
101 | status = rtems_task_start( Task_id[0], Task01, 0 ); |
---|
102 | directive_failed( status, "rtems_task_start of TA01"); |
---|
103 | |
---|
104 | status = rtems_task_delete( RTEMS_SELF ); |
---|
105 | directive_failed( status, "rtems_task_delete of INIT"); |
---|
106 | } |
---|
107 | |
---|
108 | /* configuration information */ |
---|
109 | #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER |
---|
110 | #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER |
---|
111 | #define CONFIGURE_TICKS_PER_TIMESLICE 0 |
---|
112 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
113 | #define CONFIGURE_MAXIMUM_TASKS 3 |
---|
114 | #define CONFIGURE_INIT |
---|
115 | #include <rtems/confdefs.h> |
---|