From ef2b77be011e2b4b415d1c5bb4901431d81dfaee Mon Sep 17 00:00:00 2001 From: Kimplul Date: Wed, 25 Sep 2024 23:13:20 +0300 Subject: somewhat working grid + Starvation is still an issue, but adding a slight bit of randomness seems to help a bit. Also, simulating massive systems like 64x64 is a bit too slow, so scale grid example down to 16x16. 256 cores is still a fair bit, but I might try to think of some optimization methods. I wonder at what point threading becomes faster than just running on a single core? + Test now also sets processor nodes to sleep to avoid starvation issue, seems like an opportunity for a DoS attack if someone can get enough cores to bombard a single node with enough traffic. The riscv64 processor has an initial control interface, very messy code, should probably come up with a more elegant way to deal with sleep/wakeups --- tests/simple_grid/test.c | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'tests/simple_grid/test.c') diff --git a/tests/simple_grid/test.c b/tests/simple_grid/test.c index 07f1123..2891a6e 100644 --- a/tests/simple_grid/test.c +++ b/tests/simple_grid/test.c @@ -1,23 +1,21 @@ -#define X 64 -#define Y 64 +#define X 16 +#define Y 16 void _start(unsigned short x, unsigned short y) { - volatile unsigned long *counter = (unsigned long *)((1ULL << 48) | (1ULL << 32)); + volatile unsigned long *control = (unsigned long *)(((unsigned long)x << 32) | ((unsigned long)y << 48) + 128); volatile char *uart = (char *)4096; /* very hacky, not recommended but good enough for testing */ - if (x == 0 && y == 1) { - *counter = 0; + if (x == 0 && y == 2) { *uart = '0'; *uart = '\n'; } else - while (*counter != ((x << 8) | y)) - ; + *control = 0; /* go to sleep */ *uart = '('; - /* [0 - 63] as two octal numbers */ + /* [0 - 16] as two octal numbers */ *uart = ((x >> 3) & 0x7) + '0'; *uart = ((x >> 0) & 0x7) + '0'; @@ -30,17 +28,17 @@ void _start(unsigned short x, unsigned short y) *uart = ')'; *uart = '\n'; - if (y == 63) { + if (x == 15 && y == 15) + asm ("ebreak\n"); + + if (y == 15) { x++; y = 0; } else y++; - *counter = (x << 8) | y; - - while (*counter != (64 << 8)) - ; - - asm ("ebreak\n"); + volatile unsigned long *next = (unsigned long *)(((unsigned long)x << 32) | ((unsigned long)y << 48) + 128); + *next = 1; /* wake next core */ + *control = 0; /* go to sleep again */ } -- cgit v1.3