1 | /* SPDX-License-Identifier: BSD-2-Clause */ |
---|
2 | |
---|
3 | /* |
---|
4 | * COPYRIGHT (c) 1989-2013. |
---|
5 | * On-Line Applications Research Corporation (OAR). |
---|
6 | * |
---|
7 | * Redistribution and use in source and binary forms, with or without |
---|
8 | * modification, are permitted provided that the following conditions |
---|
9 | * are met: |
---|
10 | * 1. Redistributions of source code must retain the above copyright |
---|
11 | * notice, this list of conditions and the following disclaimer. |
---|
12 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
13 | * notice, this list of conditions and the following disclaimer in the |
---|
14 | * documentation and/or other materials provided with the distribution. |
---|
15 | * |
---|
16 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
17 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
18 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
---|
20 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
23 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
24 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
25 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
26 | * POSSIBILITY OF SUCH DAMAGE. |
---|
27 | */ |
---|
28 | |
---|
29 | #if !defined(OPERATION_COUNT) |
---|
30 | #define OPERATION_COUNT 100 |
---|
31 | #endif |
---|
32 | |
---|
33 | #ifdef HAVE_CONFIG_H |
---|
34 | #include "config.h" |
---|
35 | #endif |
---|
36 | |
---|
37 | #include <rtems/btimer.h> |
---|
38 | |
---|
39 | #define CONFIGURE_INIT |
---|
40 | #include "system.h" |
---|
41 | |
---|
42 | const char rtems_test_name[] = "TIME TEST 9"; |
---|
43 | |
---|
44 | rtems_id Queue_id; |
---|
45 | |
---|
46 | rtems_task Test_task( |
---|
47 | rtems_task_argument argument |
---|
48 | ); |
---|
49 | void queue_test(void); |
---|
50 | |
---|
51 | rtems_task Init( |
---|
52 | rtems_task_argument argument |
---|
53 | ) |
---|
54 | { |
---|
55 | rtems_status_code status; |
---|
56 | |
---|
57 | Print_Warning(); |
---|
58 | |
---|
59 | TEST_BEGIN(); |
---|
60 | |
---|
61 | status = rtems_task_create( |
---|
62 | 1, |
---|
63 | (RTEMS_MAXIMUM_PRIORITY / 2u) + 1u, |
---|
64 | RTEMS_MINIMUM_STACK_SIZE * 2, |
---|
65 | RTEMS_DEFAULT_MODES, |
---|
66 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
67 | &Task_id[ 1 ] |
---|
68 | ); |
---|
69 | directive_failed( status, "rtems_task_create" ); |
---|
70 | |
---|
71 | status = rtems_task_start( Task_id[ 1 ], Test_task, 0 ); |
---|
72 | directive_failed( status, "rtems_task_start" ); |
---|
73 | |
---|
74 | rtems_task_exit(); |
---|
75 | } |
---|
76 | |
---|
77 | rtems_task Test_task ( |
---|
78 | rtems_task_argument argument |
---|
79 | ) |
---|
80 | { |
---|
81 | benchmark_timer_initialize(); |
---|
82 | rtems_message_queue_create( |
---|
83 | 1, |
---|
84 | OPERATION_COUNT, |
---|
85 | MESSAGE_SIZE, |
---|
86 | RTEMS_DEFAULT_ATTRIBUTES, |
---|
87 | &Queue_id |
---|
88 | ); |
---|
89 | end_time = benchmark_timer_read(); |
---|
90 | |
---|
91 | put_time( |
---|
92 | "rtems_message_queue_create: only case", |
---|
93 | end_time, |
---|
94 | 1, |
---|
95 | 0, |
---|
96 | 0 |
---|
97 | ); |
---|
98 | |
---|
99 | queue_test(); |
---|
100 | |
---|
101 | benchmark_timer_initialize(); |
---|
102 | rtems_message_queue_delete( Queue_id ); |
---|
103 | end_time = benchmark_timer_read(); |
---|
104 | |
---|
105 | put_time( |
---|
106 | "rtems_message_queue_delete: only case", |
---|
107 | end_time, |
---|
108 | 1, |
---|
109 | 0, |
---|
110 | 0 |
---|
111 | ); |
---|
112 | |
---|
113 | TEST_END(); |
---|
114 | rtems_test_exit( 0 ); |
---|
115 | } |
---|
116 | |
---|
117 | void queue_test(void) |
---|
118 | { |
---|
119 | uint32_t send_loop_time; |
---|
120 | uint32_t urgent_loop_time; |
---|
121 | uint32_t receive_loop_time; |
---|
122 | uint32_t send_time; |
---|
123 | uint32_t urgent_time; |
---|
124 | uint32_t receive_time; |
---|
125 | uint32_t empty_flush_time; |
---|
126 | uint32_t flush_time; |
---|
127 | uint32_t empty_flush_count; |
---|
128 | uint32_t flush_count; |
---|
129 | uint32_t index; |
---|
130 | uint32_t iterations; |
---|
131 | long buffer[4]; |
---|
132 | rtems_status_code status; |
---|
133 | size_t size; |
---|
134 | |
---|
135 | send_loop_time = 0; |
---|
136 | urgent_loop_time = 0; |
---|
137 | receive_loop_time = 0; |
---|
138 | send_time = 0; |
---|
139 | urgent_time = 0; |
---|
140 | receive_time = 0; |
---|
141 | empty_flush_time = 0; |
---|
142 | flush_time = 0; |
---|
143 | flush_count = 0; |
---|
144 | empty_flush_count = 0; |
---|
145 | |
---|
146 | for ( iterations = 1 ; iterations <= OPERATION_COUNT ; iterations++ ) { |
---|
147 | |
---|
148 | benchmark_timer_initialize(); |
---|
149 | for ( index=1 ; index <= OPERATION_COUNT ; index++ ) |
---|
150 | (void) benchmark_timer_empty_function(); |
---|
151 | send_loop_time += benchmark_timer_read(); |
---|
152 | |
---|
153 | benchmark_timer_initialize(); |
---|
154 | for ( index=1 ; index <= OPERATION_COUNT ; index++ ) |
---|
155 | (void) benchmark_timer_empty_function(); |
---|
156 | urgent_loop_time += benchmark_timer_read(); |
---|
157 | |
---|
158 | benchmark_timer_initialize(); |
---|
159 | for ( index=1 ; index <= OPERATION_COUNT ; index++ ) |
---|
160 | (void) benchmark_timer_empty_function(); |
---|
161 | receive_loop_time += benchmark_timer_read(); |
---|
162 | |
---|
163 | benchmark_timer_initialize(); |
---|
164 | for ( index=1 ; index <= OPERATION_COUNT ; index++ ) |
---|
165 | (void) rtems_message_queue_send( Queue_id, buffer, MESSAGE_SIZE ); |
---|
166 | send_time += benchmark_timer_read(); |
---|
167 | |
---|
168 | benchmark_timer_initialize(); |
---|
169 | for ( index=1 ; index <= OPERATION_COUNT ; index++ ) |
---|
170 | (void) rtems_message_queue_receive( |
---|
171 | Queue_id, |
---|
172 | (long (*)[4])buffer, |
---|
173 | &size, |
---|
174 | RTEMS_DEFAULT_OPTIONS, |
---|
175 | RTEMS_NO_TIMEOUT |
---|
176 | ); |
---|
177 | receive_time += benchmark_timer_read(); |
---|
178 | |
---|
179 | benchmark_timer_initialize(); |
---|
180 | for ( index=1 ; index <= OPERATION_COUNT ; index++ ) |
---|
181 | (void) rtems_message_queue_urgent( Queue_id, buffer, MESSAGE_SIZE ); |
---|
182 | urgent_time += benchmark_timer_read(); |
---|
183 | |
---|
184 | benchmark_timer_initialize(); |
---|
185 | for ( index=1 ; index <= OPERATION_COUNT ; index++ ) |
---|
186 | (void) rtems_message_queue_receive( |
---|
187 | Queue_id, |
---|
188 | (long (*)[4])buffer, |
---|
189 | &size, |
---|
190 | RTEMS_DEFAULT_OPTIONS, |
---|
191 | RTEMS_NO_TIMEOUT |
---|
192 | ); |
---|
193 | receive_time += benchmark_timer_read(); |
---|
194 | |
---|
195 | benchmark_timer_initialize(); |
---|
196 | rtems_message_queue_flush( Queue_id, &empty_flush_count ); |
---|
197 | empty_flush_time += benchmark_timer_read(); |
---|
198 | |
---|
199 | /* send one message to flush */ |
---|
200 | status = rtems_message_queue_send( |
---|
201 | Queue_id, |
---|
202 | (long (*)[4])buffer, |
---|
203 | MESSAGE_SIZE |
---|
204 | ); |
---|
205 | directive_failed( status, "rtems_message_queue_send" ); |
---|
206 | |
---|
207 | benchmark_timer_initialize(); |
---|
208 | rtems_message_queue_flush( Queue_id, &flush_count ); |
---|
209 | flush_time += benchmark_timer_read(); |
---|
210 | } |
---|
211 | |
---|
212 | put_time( |
---|
213 | "rtems_message_queue_send: no waiting tasks", |
---|
214 | send_time, |
---|
215 | OPERATION_COUNT * OPERATION_COUNT, |
---|
216 | send_loop_time, |
---|
217 | 0 |
---|
218 | ); |
---|
219 | |
---|
220 | put_time( |
---|
221 | "rtems_message_queue_urgent: no waiting tasks", |
---|
222 | urgent_time, |
---|
223 | OPERATION_COUNT * OPERATION_COUNT, |
---|
224 | urgent_loop_time, |
---|
225 | 0 |
---|
226 | ); |
---|
227 | |
---|
228 | put_time( |
---|
229 | "rtems_message_queue_receive: available", |
---|
230 | receive_time, |
---|
231 | OPERATION_COUNT * OPERATION_COUNT * 2, |
---|
232 | receive_loop_time * 2, |
---|
233 | 0 |
---|
234 | ); |
---|
235 | |
---|
236 | put_time( |
---|
237 | "rtems_message_queue_flush: no messages flushed", |
---|
238 | empty_flush_time, |
---|
239 | OPERATION_COUNT, |
---|
240 | 0, |
---|
241 | 0 |
---|
242 | ); |
---|
243 | |
---|
244 | put_time( |
---|
245 | "rtems_message_queue_flush: messages flushed", |
---|
246 | flush_time, |
---|
247 | OPERATION_COUNT, |
---|
248 | 0, |
---|
249 | 0 |
---|
250 | ); |
---|
251 | |
---|
252 | } |
---|