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 | #ifdef HAVE_CONFIG_H |
---|
8 | #include "config.h" |
---|
9 | #endif |
---|
10 | |
---|
11 | #include <timesys.h> |
---|
12 | #include <rtems/btimer.h> |
---|
13 | |
---|
14 | const char rtems_test_name[] = "RHMLATENCY"; |
---|
15 | |
---|
16 | #define MESSAGE_SIZE (sizeof(long) * 4) |
---|
17 | #define BENCHMARKS 50000 |
---|
18 | |
---|
19 | rtems_task Init( rtems_task_argument ignored ); |
---|
20 | rtems_task Task01( rtems_task_argument ignored ); |
---|
21 | rtems_task Task02( rtems_task_argument ignored ); |
---|
22 | |
---|
23 | uint32_t telapsed; |
---|
24 | uint32_t tloop_overhead; |
---|
25 | uint32_t treceive_overhead; |
---|
26 | uint32_t count; |
---|
27 | rtems_id Task_id[2]; |
---|
28 | rtems_name Task_name[2]; |
---|
29 | rtems_id Queue_id; |
---|
30 | long Buffer[4]; |
---|
31 | |
---|
32 | void Init( |
---|
33 | rtems_task_argument argument |
---|
34 | ) |
---|
35 | { |
---|
36 | rtems_status_code status; |
---|
37 | |
---|
38 | Print_Warning(); |
---|
39 | |
---|
40 | TEST_BEGIN(); |
---|
41 | |
---|
42 | status = rtems_message_queue_create( |
---|
43 | rtems_build_name( 'M', 'Q', '1', ' ' ), |
---|
44 | 1, |
---|
45 | MESSAGE_SIZE, |
---|
46 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
47 | &Queue_id |
---|
48 | ); |
---|
49 | directive_failed( status, "rtems_message_queue_create" ); |
---|
50 | |
---|
51 | Task_name[0] = rtems_build_name( 'T','A','0','1' ); |
---|
52 | status = rtems_task_create( |
---|
53 | Task_name[0], |
---|
54 | 30, /* TA01 is low priority task */ |
---|
55 | RTEMS_MINIMUM_STACK_SIZE, |
---|
56 | RTEMS_DEFAULT_MODES, |
---|
57 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
58 | &Task_id[0] |
---|
59 | ); |
---|
60 | directive_failed( status, "rtems_task_create of TA01"); |
---|
61 | |
---|
62 | Task_name[1] = rtems_build_name( 'T','A','0','2' ); |
---|
63 | status = rtems_task_create( |
---|
64 | Task_name[1], |
---|
65 | 28, /* High priority task */ |
---|
66 | RTEMS_MINIMUM_STACK_SIZE, |
---|
67 | RTEMS_DEFAULT_MODES, |
---|
68 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
69 | &Task_id[1] |
---|
70 | ); |
---|
71 | directive_failed( status, "rtems_task_create of TA01" ); |
---|
72 | |
---|
73 | benchmark_timer_initialize(); |
---|
74 | for ( count = 0; count < BENCHMARKS - 1; count++ ) { |
---|
75 | /* message send/recieve */ |
---|
76 | } |
---|
77 | tloop_overhead = benchmark_timer_read(); |
---|
78 | |
---|
79 | status = rtems_task_start( Task_id[0], Task01, 0 ); |
---|
80 | directive_failed( status, "rtems_task_start of TA01" ); |
---|
81 | |
---|
82 | rtems_task_exit(); |
---|
83 | } |
---|
84 | |
---|
85 | rtems_task Task01( rtems_task_argument ignored ) |
---|
86 | { |
---|
87 | rtems_status_code status; |
---|
88 | |
---|
89 | /* Put a message in the queue so recieve overhead can be found. */ |
---|
90 | (void) rtems_message_queue_send( Queue_id, Buffer, MESSAGE_SIZE ); |
---|
91 | |
---|
92 | /* Start up second task, get preempted */ |
---|
93 | status = rtems_task_start( Task_id[1], Task02, 0 ); |
---|
94 | directive_failed( status, "rtems_task_start" ); |
---|
95 | |
---|
96 | for ( ; count < BENCHMARKS; count++ ) { |
---|
97 | (void) rtems_message_queue_send( Queue_id, Buffer, MESSAGE_SIZE ); |
---|
98 | } |
---|
99 | |
---|
100 | /* Should never reach here */ |
---|
101 | rtems_test_assert( false ); |
---|
102 | |
---|
103 | } |
---|
104 | |
---|
105 | rtems_task Task02( rtems_task_argument ignored ) |
---|
106 | { |
---|
107 | size_t size; |
---|
108 | |
---|
109 | /* find recieve overhead - no preempt or task switch */ |
---|
110 | benchmark_timer_initialize(); |
---|
111 | (void) rtems_message_queue_receive( |
---|
112 | Queue_id, |
---|
113 | (long (*)[4]) Buffer, |
---|
114 | &size, |
---|
115 | RTEMS_DEFAULT_OPTIONS, |
---|
116 | RTEMS_NO_TIMEOUT |
---|
117 | ); |
---|
118 | treceive_overhead = benchmark_timer_read(); |
---|
119 | |
---|
120 | /* Benchmark code */ |
---|
121 | benchmark_timer_initialize(); |
---|
122 | for ( count = 0; count < BENCHMARKS - 1; count++ ) { |
---|
123 | (void) rtems_message_queue_receive( |
---|
124 | Queue_id, |
---|
125 | (long (*)[4]) Buffer, |
---|
126 | &size, |
---|
127 | RTEMS_DEFAULT_OPTIONS, |
---|
128 | RTEMS_NO_TIMEOUT |
---|
129 | ); |
---|
130 | } |
---|
131 | telapsed = benchmark_timer_read(); |
---|
132 | |
---|
133 | put_time( |
---|
134 | "Rhealstone: Intertask Message Latency", |
---|
135 | telapsed, /* Total time of all benchmarks */ |
---|
136 | BENCHMARKS - 1, /* Total benchmarks */ |
---|
137 | tloop_overhead, /* Overhead of loops */ |
---|
138 | treceive_overhead /* Overhead of recieve call and task switch */ |
---|
139 | ); |
---|
140 | |
---|
141 | TEST_END(); |
---|
142 | rtems_test_exit( 0 ); |
---|
143 | } |
---|
144 | |
---|
145 | /* configuration information */ |
---|
146 | |
---|
147 | #define CONFIGURE_APPLICATION_NEEDS_SIMPLE_CONSOLE_DRIVER |
---|
148 | #define CONFIGURE_APPLICATION_NEEDS_TIMER_DRIVER |
---|
149 | |
---|
150 | #define CONFIGURE_MAXIMUM_TASKS 3 |
---|
151 | #define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 1 |
---|
152 | #define CONFIGURE_MESSAGE_BUFFER_MEMORY \ |
---|
153 | CONFIGURE_MESSAGE_BUFFERS_FOR_QUEUE(1, MESSAGE_SIZE) |
---|
154 | #define CONFIGURE_TICKS_PER_TIMESLICE 0 |
---|
155 | #define CONFIGURE_RTEMS_INIT_TASKS_TABLE |
---|
156 | |
---|
157 | #define CONFIGURE_INIT |
---|
158 | #include <rtems/confdefs.h> |
---|