From 45ebdc5fc7f68034cdf3d2df9f3668f676678cc7 Mon Sep 17 00:00:00 2001 From: "Rule Timothy (CC/EMT2)" Date: Thu, 11 Apr 2024 08:34:48 +0200 Subject: [PATCH] Relocate the network benchmark. --- doc/design.md | 23 +++++++ {extra => tests}/benchmark/Taskfile.yaml | 4 +- .../benchmark/bench_net.c | 64 +++++++++++++++++++ {extra => tests}/benchmark/benchmark-gen.go | 0 .../benchmark/template/network_ct_body.tmpl | 0 .../benchmark/template/network_ct_front.tmpl | 0 6 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 doc/design.md rename {extra => tests}/benchmark/Taskfile.yaml (90%) rename extra/benchmark/bench_net_ct.c => tests/benchmark/bench_net.c (74%) rename {extra => tests}/benchmark/benchmark-gen.go (100%) rename {extra => tests}/benchmark/template/network_ct_body.tmpl (100%) rename {extra => tests}/benchmark/template/network_ct_front.tmpl (100%) diff --git a/doc/design.md b/doc/design.md new file mode 100644 index 0000000..5493652 --- /dev/null +++ b/doc/design.md @@ -0,0 +1,23 @@ + + + +signals [index count] + + double signal[] + uint64_t value[] // value (encoded, to be packed) + double factor[] // encoding factor + int64_t offset[] // encoding offset + uint64_t min[] // encoding min (or apply at signal) + uint64_t max[] // encoding max (or apply at signal) + uint64_t shift[] // packing shift + uint64_t mask[] // packing mask + uint8_t endian[] // packing algo + uint8_t type[] // type of value (uint8_t ... float, double, map) + hash map{value -> value ??} + +messages [index count] + + uint64_t offset[] // offset to signals + uint64_t count[] // count of signals (in this message) + uint8_t packed[] // packed message + uint8_t rx_update[] // indicate rx (or use checksum) diff --git a/extra/benchmark/Taskfile.yaml b/tests/benchmark/Taskfile.yaml similarity index 90% rename from extra/benchmark/Taskfile.yaml rename to tests/benchmark/Taskfile.yaml index 71945f9..ba50a7a 100644 --- a/extra/benchmark/Taskfile.yaml +++ b/tests/benchmark/Taskfile.yaml @@ -42,9 +42,9 @@ tasks: SIGNALCOUNT: '{{.SIGNALCOUNT | default 2}}' cmds: - docker run --rm -v $(pwd):/tmp -w /tmp {{.GCC_BUILDER_IMAGE}} - gcc -shared -o build/network_ct.so -Wall -fpic build/network_ct.c + gcc -shared -o build/network_ct.so -Wall -fpic -O3 -march=native build/network_ct.c - docker run --rm -v $(pwd):/tmp -w /tmp {{.GCC_BUILDER_IMAGE}} - gcc -o build/bench_net -Wall bench_net.c -ldl + gcc -o build/bench_net -Wall -O3 -march=native bench_net.c -ldl sources: - build/network_ct.c - bench_net.c diff --git a/extra/benchmark/bench_net_ct.c b/tests/benchmark/bench_net.c similarity index 74% rename from extra/benchmark/bench_net_ct.c rename to tests/benchmark/bench_net.c index fc38da7..094864b 100644 --- a/extra/benchmark/bench_net_ct.c +++ b/tests/benchmark/bench_net.c @@ -135,6 +135,69 @@ void run_bench_loop(double* signals, signal_t* st, int count, int steps) } +typedef struct vector_t { + int count; + + double* signal; + double* factor; + int64_t* offset; + + uint64_t* buffer; + uint64_t* pack; + + uint64_t* max; + uint64_t* min; + uint64_t* shift; + uint64_t* mask; +} vector_t; + +void _allocate_vectors(vector_t* v) +{ + v->signal = calloc(v->count, sizeof(double)); + v->factor = calloc(v->count, sizeof(double)); + v->offset = calloc(v->count, sizeof(int64_t)); + + v->buffer = calloc(v->count, sizeof(uint64_t)); + v->pack = calloc(v->count, sizeof(uint64_t)); + + v->max = calloc(v->count, sizeof(uint64_t)); + v->min = calloc(v->count, sizeof(uint64_t)); + v->shift = calloc(v->count, sizeof(uint64_t)); + v->mask = calloc(v->count, sizeof(uint64_t)); +} + +void run_bench_vector(double* signals, signal_t* st, int count, int steps) +{ + vector_t v = { .count = count }; + _allocate_vectors(&v); + struct timespec _ts = get_timespec_now(); + + for (int step = 0; step < steps; step++) { + for (int i = 0; i < count; i++) { + double original = v.signal[i]; + double value = original + 1; + value = value > 100 ? 0.0 : value; + value = value / 0.5; + v.buffer[i] = (uint64_t)((uint8_t)(value)); + v.pack[i] |= + (uint64_t)((uint8_t)((uint8_t)(st[i].buffer[0] << 1u) & 0x7eu)); + v.buffer[i] = + (uint64_t)((uint8_t)((uint8_t)(v.pack[i] & 0x7eu) >> 1u)); + if (v.buffer[i] <= 200u) { + value = v.buffer[i] * 0.5; + } else { + value = value + 1; + } + v.signal[i] = value; + } + } + + uint64_t time_ns = get_elapsedtime_ns(_ts); + printf("VECTOR: Time %.9f (steps=%d, signals=%d)\n", + ns_to_us_to_sec(time_ns), steps, count); +} + + int main(int argc, char** argv) { if (argc != 2) { @@ -175,6 +238,7 @@ int main(int argc, char** argv) printf(" run cantools based benchmark ...\n"); run_bench_ct(signals, signal_table, signalCount, steps); run_bench_loop(signals, signal_table, signalCount, steps); + run_bench_vector(signals, signal_table, signalCount, steps); exit(0); diff --git a/extra/benchmark/benchmark-gen.go b/tests/benchmark/benchmark-gen.go similarity index 100% rename from extra/benchmark/benchmark-gen.go rename to tests/benchmark/benchmark-gen.go diff --git a/extra/benchmark/template/network_ct_body.tmpl b/tests/benchmark/template/network_ct_body.tmpl similarity index 100% rename from extra/benchmark/template/network_ct_body.tmpl rename to tests/benchmark/template/network_ct_body.tmpl diff --git a/extra/benchmark/template/network_ct_front.tmpl b/tests/benchmark/template/network_ct_front.tmpl similarity index 100% rename from extra/benchmark/template/network_ct_front.tmpl rename to tests/benchmark/template/network_ct_front.tmpl