Skip to content

Commit

Permalink
Relocate the network benchmark.
Browse files Browse the repository at this point in the history
  • Loading branch information
timrulebosch committed Apr 29, 2024
1 parent cff79ae commit 45ebdc5
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 2 deletions.
23 changes: 23 additions & 0 deletions doc/design.md
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 64 additions & 0 deletions extra/benchmark/bench_net_ct.c → tests/benchmark/bench_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
File renamed without changes.

0 comments on commit 45ebdc5

Please sign in to comment.