Skip to content

Commit fc32f1c

Browse files
teburdstephanosio
authored andcommitted
rtio: Add throughput test
Test throughput of submit and consume pair for rtio Signed-off-by: Tom Burdick <[email protected]>
1 parent e4b1032 commit fc32f1c

File tree

4 files changed

+105
-3
lines changed

4 files changed

+105
-3
lines changed

tests/subsys/rtio/rtio_api/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ CONFIG_ZTEST_NEW_API=y
33
CONFIG_LOG=y
44
CONFIG_RTIO=y
55
CONFIG_RTIO_SYS_MEM_BLOCKS=y
6+
CONFIG_TIMING_FUNCTIONS=y

tests/subsys/rtio/rtio_api/src/test_rtio_api.c

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
#include <zephyr/app_memory/mem_domain.h>
1414
#include <zephyr/sys/util_loops.h>
1515
#include <zephyr/sys/time_units.h>
16-
#include <zephyr/rtio/rtio_mpsc.h>
16+
#include <zephyr/timing/timing.h>
1717
#include <zephyr/rtio/rtio.h>
1818

1919
#include "rtio_iodev_test.h"
2020

2121
/* Repeat tests to ensure they are repeatable */
22-
#define TEST_REPEATS 2
22+
#define TEST_REPEATS 4
2323

2424
#define MEM_BLK_COUNT 4
2525
#define MEM_BLK_SIZE 16
@@ -182,7 +182,8 @@ void test_rtio_multiple_chains_(struct rtio *r)
182182
cqe = rtio_cqe_consume(r);
183183
}
184184

185-
TC_PRINT("consumed cqe %p, result, %d, userdata %lu\n", cqe, cqe-> result, (uintptr_t)cqe->userdata);
185+
TC_PRINT("consumed cqe %p, result, %d, userdata %lu\n", cqe,
186+
cqe->result, (uintptr_t)cqe->userdata);
186187

187188
zassert_not_null(cqe, "Expected a valid cqe");
188189
zassert_ok(cqe->result, "Result should be ok");
@@ -427,6 +428,44 @@ ZTEST(rtio_api, test_rtio_transaction)
427428
}
428429
}
429430

431+
#define THROUGHPUT_ITERS 100000
432+
RTIO_DEFINE(r_throughput, 4, 4);
433+
434+
void _test_rtio_throughput(struct rtio *r)
435+
{
436+
timing_t start_time, end_time;
437+
struct rtio_cqe *cqe;
438+
struct rtio_sqe *sqe;
439+
440+
timing_init();
441+
timing_start();
442+
443+
start_time = timing_counter_get();
444+
445+
for (uint32_t i = 0; i < THROUGHPUT_ITERS; i++) {
446+
sqe = rtio_sqe_acquire(r);
447+
rtio_sqe_prep_nop(sqe, NULL, NULL);
448+
rtio_submit(r, 0);
449+
cqe = rtio_cqe_consume(r);
450+
rtio_cqe_release(r, cqe);
451+
}
452+
453+
end_time = timing_counter_get();
454+
455+
uint64_t cycles = timing_cycles_get(&start_time, &end_time);
456+
uint64_t ns = timing_cycles_to_ns(cycles);
457+
458+
TC_PRINT("%llu ns for %d iterations, %llu ns per op\n",
459+
ns, THROUGHPUT_ITERS, ns/THROUGHPUT_ITERS);
460+
}
461+
462+
463+
ZTEST(rtio_api, test_rtio_throughput)
464+
{
465+
_test_rtio_throughput(&r_throughput);
466+
}
467+
468+
430469
static void *rtio_api_setup(void)
431470
{
432471
#ifdef CONFIG_USERSPACE

tests/subsys/rtio/rtio_api/src/test_rtio_mpsc.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <zephyr/ztest.h>
88
#include <zephyr/kernel.h>
99
#include <zephyr/sys/util_loops.h>
10+
#include <zephyr/timing/timing.h>
1011
#include <zephyr/rtio/rtio_spsc.h>
1112
#include <zephyr/rtio/rtio_mpsc.h>
1213

@@ -182,4 +183,32 @@ ZTEST(rtio_mpsc, test_mpsc_threaded)
182183
}
183184
}
184185

186+
#define THROUGHPUT_ITERS 100000
187+
188+
ZTEST(rtio_mpsc, test_mpsc_throughput)
189+
{
190+
struct rtio_mpsc_node node;
191+
timing_t start_time, end_time;
192+
193+
rtio_mpsc_init(&mpsc_q);
194+
timing_init();
195+
timing_start();
196+
197+
start_time = timing_counter_get();
198+
199+
for (int i = 0; i < THROUGHPUT_ITERS; i++) {
200+
rtio_mpsc_push(&mpsc_q, &node);
201+
202+
rtio_mpsc_pop(&mpsc_q);
203+
}
204+
205+
end_time = timing_counter_get();
206+
207+
uint64_t cycles = timing_cycles_get(&start_time, &end_time);
208+
uint64_t ns = timing_cycles_to_ns(cycles);
209+
210+
TC_PRINT("%llu ns for %d iterations, %llu ns per op\n", ns,
211+
THROUGHPUT_ITERS, ns/THROUGHPUT_ITERS);
212+
}
213+
185214
ZTEST_SUITE(rtio_mpsc, NULL, NULL, NULL, NULL, NULL);

tests/subsys/rtio/rtio_api/src/test_rtio_spsc.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include <zephyr/ztest.h>
8+
#include <zephyr/timing/timing.h>
89
#include <zephyr/rtio/rtio_spsc.h>
910
#include "rtio_api.h"
1011

@@ -215,4 +216,36 @@ ZTEST(rtio_spsc, test_spsc_threaded)
215216
k_thread_join(tinfo[0].tid, K_FOREVER);
216217
}
217218

219+
#define THROUGHPUT_ITERS 100000
220+
221+
ZTEST(rtio_spsc, test_spsc_throughput)
222+
{
223+
timing_t start_time, end_time;
224+
225+
timing_init();
226+
timing_start();
227+
228+
start_time = timing_counter_get();
229+
230+
uint32_t *x, *y;
231+
232+
for (int i = 0; i < THROUGHPUT_ITERS; i++) {
233+
x = rtio_spsc_acquire(&spsc);
234+
*x = i;
235+
rtio_spsc_produce(&spsc);
236+
237+
y = rtio_spsc_consume(&spsc);
238+
rtio_spsc_release(&spsc);
239+
}
240+
241+
end_time = timing_counter_get();
242+
243+
uint64_t cycles = timing_cycles_get(&start_time, &end_time);
244+
uint64_t ns = timing_cycles_to_ns(cycles);
245+
246+
TC_PRINT("%llu ns for %d iterations, %llu ns per op\n", ns,
247+
THROUGHPUT_ITERS, ns/THROUGHPUT_ITERS);
248+
}
249+
250+
218251
ZTEST_SUITE(rtio_spsc, NULL, NULL, NULL, NULL, NULL);

0 commit comments

Comments
 (0)