aboutsummaryrefslogtreecommitdiff
path: root/tests/simple_grid/test.c
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2024-09-25 23:13:20 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2024-09-25 23:15:10 +0300
commitef2b77be011e2b4b415d1c5bb4901431d81dfaee (patch)
treea724518db2d00b35a73e0a0e62009fd2083ef89e /tests/simple_grid/test.c
parent6d0e7c5eba49efc171e63ff2631722a5c7f95460 (diff)
downloadgran-ef2b77be011e2b4b415d1c5bb4901431d81dfaee.tar.gz
gran-ef2b77be011e2b4b415d1c5bb4901431d81dfaee.zip
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
Diffstat (limited to 'tests/simple_grid/test.c')
-rw-r--r--tests/simple_grid/test.c28
1 files changed, 13 insertions, 15 deletions
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 */
}