1 /* master.h */
2
3 /*
4 * Copyright (c) 1997-2010, 2014-2015 Wind River Systems, Inc.
5 *
6 * SPDX-License-Identifier: Apache-2.0
7 */
8
9 #ifndef _MASTER_H
10 #define _MASTER_H
11
12 #include <zephyr/kernel.h>
13
14 #include <stdio.h>
15
16 #include "receiver.h"
17
18 #include <zephyr/timestamp.h>
19
20 #include <string.h>
21
22 #include <zephyr/sys/util.h>
23
24
25 /* uncomment the define below to use floating point arithmetic */
26 /* #define FLOAT */
27
28 /* printf format defines. */
29 #define FORMAT "| %-65s|%10u|\n"
30
31 /* length of the output line */
32 #define SLINE_LEN 256
33
34 #define SLEEP_TIME ((CONFIG_SYS_CLOCK_TICKS_PER_SEC / 4) > 0 ? \
35 CONFIG_SYS_CLOCK_TICKS_PER_SEC / 4 : 1)
36 #define WAIT_TIME ((CONFIG_SYS_CLOCK_TICKS_PER_SEC / 10) > 0 ? \
37 CONFIG_SYS_CLOCK_TICKS_PER_SEC / 10 : 1)
38 #define NR_OF_NOP_RUNS 10000
39 #define NR_OF_FIFO_RUNS 500
40 #define NR_OF_SEMA_RUNS 500
41 #define NR_OF_MUTEX_RUNS 1000
42 #define NR_OF_POOL_RUNS 1000
43 #define NR_OF_MAP_RUNS 1000
44 #define NR_OF_EVENT_RUNS 1000
45 #define NR_OF_MBOX_RUNS 128
46 #define NR_OF_PIPE_RUNS 256
47 /* #define SEMA_WAIT_TIME (5 * CONFIG_SYS_CLOCK_TICKS_PER_SEC) */
48 #define SEMA_WAIT_TIME (5000)
49 /* global data */
50 extern char msg[MAX_MSG];
51 extern char data_bench[MESSAGE_SIZE];
52 extern struct k_pipe *test_pipes[];
53 extern const char newline[];
54 extern char sline[];
55
56 #define dashline \
57 "|--------------------------------------" \
58 "---------------------------------------|\n"
59
60 /*
61 * To avoid divisions by 0 faults, wrap the divisor with this macro
62 */
63 #define SAFE_DIVISOR(a) (((a) != 0)?(a):1)
64
65
66 /* pipe amount of content to receive (0+, 1+, all) */
67 enum pipe_options {
68 _0_TO_N = 0x0,
69 _1_TO_N = 0x1,
70 _ALL_N = 0x2,
71 };
72
73 /* dummy_test is a function that is mapped when we */
74 /* do not want to test a specific Benchmark */
75 extern void dummy_test(void);
76
77 /* other external functions */
78
79 extern void bench_task(void *p1, void *p2, void *p3);
80 extern void recvtask(void *p1, void *p2, void *p3);
81
82 #ifdef MAILBOX_BENCH
83 extern void mailbox_test(void);
84 #else
85 #define mailbox_test dummy_test
86 #endif
87
88 #ifdef SEMA_BENCH
89 extern void sema_test(void);
90 #else
91 #define sema_test dummy_test
92 #endif
93
94 #ifdef FIFO_BENCH
95 extern void queue_test(void);
96 #else
97 #define queue_test dummy_test
98 #endif
99
100 #ifdef MUTEX_BENCH
101 extern void mutex_test(void);
102 #else
103 #define mutex_test dummy_test
104 #endif
105
106 #ifdef MEMMAP_BENCH
107 extern void memorymap_test(void);
108 #else
109 #define memorymap_test dummy_test
110 #endif
111
112 #ifdef MEMPOOL_BENCH
113 extern void mempool_test(void);
114 #else
115 #define mempool_test dummy_test
116 #endif
117
118 #ifdef PIPE_BENCH
119 extern void pipe_test(void);
120 #else
121 #define pipe_test dummy_test
122 #endif
123
124 /* kernel objects needed for benchmarking */
125 extern struct k_mutex DEMO_MUTEX;
126
127 extern struct k_sem SEM0;
128 extern struct k_sem SEM1;
129 extern struct k_sem SEM2;
130 extern struct k_sem SEM3;
131 extern struct k_sem SEM4;
132 extern struct k_sem STARTRCV;
133
134 extern struct k_msgq DEMOQX1;
135 extern struct k_msgq DEMOQX4;
136 extern struct k_msgq MB_COMM;
137 extern struct k_msgq CH_COMM;
138
139 extern struct k_mbox MAILB1;
140
141
142 extern struct k_pipe PIPE_NOBUFF;
143 extern struct k_pipe PIPE_SMALLBUFF;
144 extern struct k_pipe PIPE_BIGBUFF;
145
146
147 extern struct k_mem_slab MAP1;
148
149
150
151 /* PRINT_STRING
152 * Macro to print an ASCII NULL terminated string.
153 */
154 #define PRINT_STRING(string) printk("%s", string)
155
156 /* PRINT_F
157 * Macro to print a formatted output string.
158 * Assumed that sline character array of SLINE_LEN + 1 characters
159 * is defined in the main file
160 */
161
162 #define PRINT_F(fmt, ...) \
163 { \
164 snprintf(sline, SLINE_LEN, fmt, ##__VA_ARGS__); \
165 PRINT_STRING(sline); \
166 }
167
168 #define PRINT_OVERFLOW_ERROR() \
169 PRINT_F(__FILE__":%d Error: tick occurred\n", __LINE__)
170
BENCH_START(void)171 static inline uint32_t BENCH_START(void)
172 {
173 uint32_t et;
174
175 bench_test_start();
176 et = TIME_STAMP_DELTA_GET(0);
177 return et;
178 }
179
check_result(void)180 static inline void check_result(void)
181 {
182 if (bench_test_end() < 0) {
183 PRINT_OVERFLOW_ERROR();
184 return; /* error */
185 }
186 }
187
188 #endif /* _MASTER_H */
189