Skip to content

Commit ec09828

Browse files
authored
Merge pull request #21712 from elenaf9/benchmark_udp/fix-rtt-record-buffer
benchmark_udp: improve rtt record buffering
2 parents cd461dc + 1ce1834 commit ec09828

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

sys/test_utils/benchmark_udp/benchmark_udp.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
#define ENABLE_DEBUG 0
2828
#include "debug.h"
2929

30+
#ifndef RECORD_CACHE_SIZE
31+
# define RECORD_CACHE_SIZE (4)
32+
#endif
33+
3034
static sock_udp_t sock;
3135
static uint32_t delay_us = US_PER_SEC;
3236
static uint16_t payload_size = 32;
@@ -43,34 +47,26 @@ static sema_inv_t thread_sync;
4347
struct {
4448
uint32_t seq_no;
4549
uint32_t time_tx_us;
46-
} record_tx[4];
50+
} record_tx[RECORD_CACHE_SIZE];
4751

4852
static uint32_t _get_rtt(uint32_t seq_num, uint32_t prev)
4953
{
50-
for (unsigned i = 0; i < ARRAY_SIZE(record_tx); ++i) {
51-
if (record_tx[i].seq_no == seq_num) {
52-
return xtimer_now_usec() - record_tx[i].time_tx_us;
53-
}
54+
uint32_t idx = seq_num % RECORD_CACHE_SIZE;
55+
56+
if (record_tx[idx].seq_no == seq_num) {
57+
return xtimer_now_usec() - record_tx[idx].time_tx_us;
5458
}
5559

5660
return prev;
5761
}
5862

59-
static void _put_rtt(uint32_t seq_num) {
60-
uint8_t oldest = 0;
61-
uint32_t oldest_diff = 0;
63+
static void _put_rtt(uint32_t seq_num)
64+
{
6265
uint32_t now = xtimer_now_usec();
66+
uint32_t idx = seq_num % RECORD_CACHE_SIZE;
6367

64-
for (unsigned i = 0; i < ARRAY_SIZE(record_tx); ++i) {
65-
uint32_t diff = now - record_tx[i].time_tx_us;
66-
if (diff > oldest_diff) {
67-
oldest_diff = diff;
68-
oldest = i;
69-
}
70-
}
71-
72-
record_tx[oldest].seq_no = seq_num;
73-
record_tx[oldest].time_tx_us = now;
68+
record_tx[idx].seq_no = seq_num;
69+
record_tx[idx].time_tx_us = now;
7470
}
7571

7672
static void *_listen_thread(void *ctx)

0 commit comments

Comments
 (0)