1 /* msgq_b.c */
2
3 /*
4 * Copyright (c) 1997-2010, 2013-2014 Wind River Systems, Inc.
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 */
8
9 #include "master.h"
10
11 /**
12 * @brief Message queue transfer speed test
13 */
message_queue_test(void)14 void message_queue_test(void)
15 {
16 uint32_t et; /* elapsed time */
17 int i;
18 timing_t start;
19 timing_t end;
20
21 PRINT_STRING(dashline);
22 start = timing_timestamp_get();
23 for (i = 0; i < NR_OF_MSGQ_RUNS; i++) {
24 k_msgq_put(&DEMOQX1, data_bench, K_FOREVER);
25 }
26 end = timing_timestamp_get();
27 et = (uint32_t)timing_cycles_get(&start, &end);
28 PRINT_F(FORMAT, "enqueue 1 byte msg in MSGQ",
29 SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_MSGQ_RUNS));
30
31 start = timing_timestamp_get();
32 for (i = 0; i < NR_OF_MSGQ_RUNS; i++) {
33 k_msgq_get(&DEMOQX1, data_bench, K_FOREVER);
34 }
35 end = timing_timestamp_get();
36 et = (uint32_t)timing_cycles_get(&start, &end);
37
38 PRINT_F(FORMAT, "dequeue 1 byte msg from MSGQ",
39 SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_MSGQ_RUNS));
40
41 start = timing_timestamp_get();
42 for (i = 0; i < NR_OF_MSGQ_RUNS; i++) {
43 k_msgq_put(&DEMOQX4, data_bench, K_FOREVER);
44 }
45 end = timing_timestamp_get();
46 et = (uint32_t)timing_cycles_get(&start, &end);
47
48 PRINT_F(FORMAT, "enqueue 4 bytes msg in MSGQ",
49 SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_MSGQ_RUNS));
50
51 start = timing_timestamp_get();
52 for (i = 0; i < NR_OF_MSGQ_RUNS; i++) {
53 k_msgq_get(&DEMOQX4, data_bench, K_FOREVER);
54 }
55 end = timing_timestamp_get();
56 et = (uint32_t)timing_cycles_get(&start, &end);
57
58 PRINT_F(FORMAT, "dequeue 4 bytes msg in MSGQ",
59 SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_MSGQ_RUNS));
60
61 start = timing_timestamp_get();
62 for (i = 0; i < NR_OF_MSGQ_RUNS; i++) {
63 k_msgq_put(&DEMOQX192, data_bench, K_FOREVER);
64 }
65 end = timing_timestamp_get();
66 et = (uint32_t)timing_cycles_get(&start, &end);
67
68 PRINT_F(FORMAT, "enqueue 192 bytes msg in MSGQ",
69 SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_MSGQ_RUNS));
70
71 start = timing_timestamp_get();
72 for (i = 0; i < NR_OF_MSGQ_RUNS; i++) {
73 k_msgq_get(&DEMOQX192, data_bench, K_FOREVER);
74 }
75 end = timing_timestamp_get();
76 et = (uint32_t)timing_cycles_get(&start, &end);
77
78 PRINT_F(FORMAT, "dequeue 192 bytes msg in MSGQ",
79 SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_MSGQ_RUNS));
80
81 k_sem_give(&STARTRCV);
82
83 start = timing_timestamp_get();
84 for (i = 0; i < NR_OF_MSGQ_RUNS; i++) {
85 k_msgq_put(&DEMOQX1, data_bench, K_FOREVER);
86 }
87 end = timing_timestamp_get();
88 et = (uint32_t)timing_cycles_get(&start, &end);
89
90 PRINT_F(FORMAT,
91 "enqueue 1 byte msg in MSGQ to a waiting higher priority task",
92 SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_MSGQ_RUNS));
93
94 start = timing_timestamp_get();
95 for (i = 0; i < NR_OF_MSGQ_RUNS; i++) {
96 k_msgq_put(&DEMOQX4, data_bench, K_FOREVER);
97 }
98 end = timing_timestamp_get();
99 et = (uint32_t)timing_cycles_get(&start, &end);
100
101 PRINT_F(FORMAT,
102 "enqueue 4 bytes in MSGQ to a waiting higher priority task",
103 SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_MSGQ_RUNS));
104
105 start = timing_timestamp_get();
106 for (i = 0; i < NR_OF_MSGQ_RUNS; i++) {
107 k_msgq_put(&DEMOQX192, data_bench, K_FOREVER);
108 }
109 end = timing_timestamp_get();
110 et = (uint32_t)timing_cycles_get(&start, &end);
111
112 PRINT_F(FORMAT,
113 "enqueue 192 bytes in MSGQ to a waiting higher priority task",
114 SYS_CLOCK_HW_CYCLES_TO_NS_AVG(et, NR_OF_MSGQ_RUNS));
115 }
116