Skip to content

Commit 4c5a96e

Browse files
peter-mitsishenrikbrixandersen
authored andcommitted
tests: latency_measure: Configurable iterations
Updates the latency_measure benchmark to make the number of iterations for which each test executes to be configurable. This allows someone to make a tradeoff between accuracy and execution time (can be useful for simulators). Signed-off-by: Peter Mitsis <[email protected]>
1 parent 8317f9e commit 4c5a96e

File tree

2 files changed

+44
-36
lines changed

2 files changed

+44
-36
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright (c) 2024 Intel Corporation
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
mainmenu "Latency Measure Benchmark"
5+
6+
source "Kconfig.zephyr"
7+
8+
config BENCHMARK_NUM_ITERATIONS
9+
int "Number of iterations to gather data"
10+
default 1000

tests/benchmarks/latency_measure/src/main.c

Lines changed: 34 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
#include "timing_sc.h"
1717
#include <zephyr/tc_util.h>
1818

19-
#define NUM_ITERATIONS 10000
20-
2119
#define STACK_SIZE (1024 + CONFIG_TEST_EXTRA_STACK_SIZE)
2220

2321
uint32_t tm_off;
@@ -79,77 +77,77 @@ static void test_thread(void *arg1, void *arg2, void *arg3)
7977
TC_START("Time Measurement");
8078
TC_PRINT("Timing results: Clock frequency: %u MHz\n", freq);
8179

82-
timestamp_overhead_init(NUM_ITERATIONS);
80+
timestamp_overhead_init(CONFIG_BENCHMARK_NUM_ITERATIONS);
8381

8482
/* Preemptive threads context switching */
85-
thread_switch_yield(NUM_ITERATIONS, false);
83+
thread_switch_yield(CONFIG_BENCHMARK_NUM_ITERATIONS, false);
8684

8785
/* Cooperative threads context switching */
88-
thread_switch_yield(NUM_ITERATIONS, true);
86+
thread_switch_yield(CONFIG_BENCHMARK_NUM_ITERATIONS, true);
8987

90-
int_to_thread(NUM_ITERATIONS);
88+
int_to_thread(CONFIG_BENCHMARK_NUM_ITERATIONS);
9189

9290
/* Thread creation, starting, suspending, resuming and aborting. */
9391

94-
thread_ops(NUM_ITERATIONS, 0, 0);
92+
thread_ops(CONFIG_BENCHMARK_NUM_ITERATIONS, 0, 0);
9593
#ifdef CONFIG_USERSPACE
96-
thread_ops(NUM_ITERATIONS, 0, K_USER);
97-
thread_ops(NUM_ITERATIONS, K_USER, K_USER);
98-
thread_ops(NUM_ITERATIONS, K_USER, 0);
94+
thread_ops(CONFIG_BENCHMARK_NUM_ITERATIONS, 0, K_USER);
95+
thread_ops(CONFIG_BENCHMARK_NUM_ITERATIONS, K_USER, K_USER);
96+
thread_ops(CONFIG_BENCHMARK_NUM_ITERATIONS, K_USER, 0);
9997
#endif
10098

101-
fifo_ops(NUM_ITERATIONS, 0);
99+
fifo_ops(CONFIG_BENCHMARK_NUM_ITERATIONS, 0);
102100
#ifdef CONFIG_USERSPACE
103-
fifo_ops(NUM_ITERATIONS, K_USER);
101+
fifo_ops(CONFIG_BENCHMARK_NUM_ITERATIONS, K_USER);
104102
#endif
105103

106-
fifo_blocking_ops(NUM_ITERATIONS, 0, 0);
104+
fifo_blocking_ops(CONFIG_BENCHMARK_NUM_ITERATIONS, 0, 0);
107105
#ifdef CONFIG_USERSPACE
108-
fifo_blocking_ops(NUM_ITERATIONS, 0, K_USER);
109-
fifo_blocking_ops(NUM_ITERATIONS, K_USER, 0);
110-
fifo_blocking_ops(NUM_ITERATIONS, K_USER, K_USER);
106+
fifo_blocking_ops(CONFIG_BENCHMARK_NUM_ITERATIONS, 0, K_USER);
107+
fifo_blocking_ops(CONFIG_BENCHMARK_NUM_ITERATIONS, K_USER, 0);
108+
fifo_blocking_ops(CONFIG_BENCHMARK_NUM_ITERATIONS, K_USER, K_USER);
111109
#endif
112110

113111

114-
lifo_ops(NUM_ITERATIONS, 0);
112+
lifo_ops(CONFIG_BENCHMARK_NUM_ITERATIONS, 0);
115113
#ifdef CONFIG_USERSPACE
116-
lifo_ops(NUM_ITERATIONS, K_USER);
114+
lifo_ops(CONFIG_BENCHMARK_NUM_ITERATIONS, K_USER);
117115
#endif
118116

119-
lifo_blocking_ops(NUM_ITERATIONS, 0, 0);
117+
lifo_blocking_ops(CONFIG_BENCHMARK_NUM_ITERATIONS, 0, 0);
120118
#ifdef CONFIG_USERSPACE
121-
lifo_blocking_ops(NUM_ITERATIONS, 0, K_USER);
122-
lifo_blocking_ops(NUM_ITERATIONS, K_USER, 0);
123-
lifo_blocking_ops(NUM_ITERATIONS, K_USER, K_USER);
119+
lifo_blocking_ops(CONFIG_BENCHMARK_NUM_ITERATIONS, 0, K_USER);
120+
lifo_blocking_ops(CONFIG_BENCHMARK_NUM_ITERATIONS, K_USER, 0);
121+
lifo_blocking_ops(CONFIG_BENCHMARK_NUM_ITERATIONS, K_USER, K_USER);
124122
#endif
125123

126-
event_ops(NUM_ITERATIONS, 0);
124+
event_ops(CONFIG_BENCHMARK_NUM_ITERATIONS, 0);
127125
#ifdef CONFIG_USERSPACE
128-
event_ops(NUM_ITERATIONS, K_USER);
126+
event_ops(CONFIG_BENCHMARK_NUM_ITERATIONS, K_USER);
129127
#endif
130128

131-
event_blocking_ops(NUM_ITERATIONS, 0, 0);
129+
event_blocking_ops(CONFIG_BENCHMARK_NUM_ITERATIONS, 0, 0);
132130
#ifdef CONFIG_USERSPACE
133-
event_blocking_ops(NUM_ITERATIONS, 0, K_USER);
134-
event_blocking_ops(NUM_ITERATIONS, K_USER, 0);
135-
event_blocking_ops(NUM_ITERATIONS, K_USER, K_USER);
131+
event_blocking_ops(CONFIG_BENCHMARK_NUM_ITERATIONS, 0, K_USER);
132+
event_blocking_ops(CONFIG_BENCHMARK_NUM_ITERATIONS, K_USER, 0);
133+
event_blocking_ops(CONFIG_BENCHMARK_NUM_ITERATIONS, K_USER, K_USER);
136134
#endif
137135

138-
sema_test_signal(NUM_ITERATIONS, 0);
136+
sema_test_signal(CONFIG_BENCHMARK_NUM_ITERATIONS, 0);
139137
#ifdef CONFIG_USERSPACE
140-
sema_test_signal(NUM_ITERATIONS, K_USER);
138+
sema_test_signal(CONFIG_BENCHMARK_NUM_ITERATIONS, K_USER);
141139
#endif
142140

143-
sema_context_switch(NUM_ITERATIONS, 0, 0);
141+
sema_context_switch(CONFIG_BENCHMARK_NUM_ITERATIONS, 0, 0);
144142
#ifdef CONFIG_USERSPACE
145-
sema_context_switch(NUM_ITERATIONS, 0, K_USER);
146-
sema_context_switch(NUM_ITERATIONS, K_USER, 0);
147-
sema_context_switch(NUM_ITERATIONS, K_USER, K_USER);
143+
sema_context_switch(CONFIG_BENCHMARK_NUM_ITERATIONS, 0, K_USER);
144+
sema_context_switch(CONFIG_BENCHMARK_NUM_ITERATIONS, K_USER, 0);
145+
sema_context_switch(CONFIG_BENCHMARK_NUM_ITERATIONS, K_USER, K_USER);
148146
#endif
149147

150-
mutex_lock_unlock(NUM_ITERATIONS, 0);
148+
mutex_lock_unlock(CONFIG_BENCHMARK_NUM_ITERATIONS, 0);
151149
#ifdef CONFIG_USERSPACE
152-
mutex_lock_unlock(NUM_ITERATIONS, K_USER);
150+
mutex_lock_unlock(CONFIG_BENCHMARK_NUM_ITERATIONS, K_USER);
153151
#endif
154152

155153
heap_malloc_free();

0 commit comments

Comments
 (0)