From 6d0e7c5eba49efc171e63ff2631722a5c7f95460 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Wed, 25 Sep 2024 21:00:16 +0300 Subject: technically speaking deadlock free, but starves --- tests/simple_grid/sim.c | 93 ++++++++++++++++++++++++++++------------------ tests/simple_grid/test.c | 11 ++++-- tests/simple_riscv64/sim.c | 6 ++- tests/simple_uart/sim.c | 7 +++- 4 files changed, 73 insertions(+), 44 deletions(-) (limited to 'tests') diff --git a/tests/simple_grid/sim.c b/tests/simple_grid/sim.c index f11be21..519599e 100644 --- a/tests/simple_grid/sim.c +++ b/tests/simple_grid/sim.c @@ -8,30 +8,33 @@ #include #include #include -#include #include -unsigned char test_grid[] = { - 0xb3, 0x67, 0xb5, 0x00, 0x63, 0x9a, 0x07, 0x0a, 0xb7, 0x17, 0x00, 0x00, - 0x23, 0xb0, 0x07, 0x00, 0x1b, 0x57, 0x35, 0x00, 0xb7, 0x27, 0x00, 0x00, - 0x93, 0x06, 0x80, 0x02, 0x13, 0x77, 0x77, 0x00, 0x23, 0x80, 0xd7, 0x00, - 0x13, 0x07, 0x07, 0x03, 0x93, 0x76, 0x75, 0x00, 0x23, 0x80, 0xe7, 0x00, - 0x13, 0x87, 0x06, 0x03, 0x23, 0x80, 0xe7, 0x00, 0x93, 0x06, 0xc0, 0x02, - 0x1b, 0xd7, 0x35, 0x00, 0x23, 0x80, 0xd7, 0x00, 0x13, 0x77, 0x77, 0x00, - 0x93, 0x06, 0x00, 0x02, 0x23, 0x80, 0xd7, 0x00, 0x13, 0x07, 0x07, 0x03, - 0x93, 0xf6, 0x75, 0x00, 0x23, 0x80, 0xe7, 0x00, 0x13, 0x87, 0x06, 0x03, - 0x23, 0x80, 0xe7, 0x00, 0x13, 0x07, 0x90, 0x02, 0x23, 0x80, 0xe7, 0x00, - 0x93, 0x06, 0xa0, 0x00, 0x23, 0x80, 0xd7, 0x00, 0x1b, 0x87, 0x15, 0x00, - 0x93, 0x06, 0xf0, 0x03, 0x93, 0x77, 0xf7, 0x0f, 0x63, 0x98, 0xd5, 0x00, - 0x1b, 0x05, 0x15, 0x00, 0x13, 0x75, 0xf5, 0x0f, 0x93, 0x07, 0x00, 0x00, - 0x13, 0x15, 0x85, 0x00, 0x33, 0x65, 0xf5, 0x00, 0xb7, 0x17, 0x00, 0x00, - 0x23, 0xb0, 0xa7, 0x00, 0xb7, 0x16, 0x00, 0x00, 0x37, 0x47, 0x00, 0x00, - 0x83, 0xb7, 0x06, 0x00, 0xe3, 0x9e, 0xe7, 0xfe, 0x73, 0x00, 0x10, 0x00, - 0x67, 0x80, 0x00, 0x00, 0x13, 0x17, 0x85, 0x00, 0x33, 0x67, 0xb7, 0x00, - 0xb7, 0x16, 0x00, 0x00, 0x83, 0xb7, 0x06, 0x00, 0xe3, 0x9e, 0xe7, 0xfe, - 0x6f, 0xf0, 0x5f, 0xf4 +unsigned char _tmp_test_bin[] = { + 0x1b, 0x86, 0x05, 0x00, 0x63, 0x18, 0x05, 0x00, 0x93, 0x07, 0x10, 0x00, + 0x1b, 0x86, 0x05, 0x00, 0x63, 0x88, 0xf5, 0x0c, 0x93, 0x16, 0x85, 0x00, + 0x37, 0x17, 0x00, 0x10, 0xb3, 0xe6, 0xb6, 0x00, 0x13, 0x17, 0x47, 0x01, + 0x83, 0x37, 0x07, 0x00, 0xe3, 0x9e, 0xd7, 0xfe, 0x1b, 0x57, 0x35, 0x00, + 0xb7, 0x17, 0x00, 0x00, 0x93, 0x06, 0x80, 0x02, 0x13, 0x77, 0x77, 0x00, + 0x23, 0x80, 0xd7, 0x00, 0x13, 0x07, 0x07, 0x03, 0x93, 0x76, 0x75, 0x00, + 0x23, 0x80, 0xe7, 0x00, 0x13, 0x87, 0x06, 0x03, 0x23, 0x80, 0xe7, 0x00, + 0x93, 0x06, 0xc0, 0x02, 0x1b, 0xd7, 0x35, 0x00, 0x23, 0x80, 0xd7, 0x00, + 0x13, 0x77, 0x77, 0x00, 0x93, 0x06, 0x00, 0x02, 0x23, 0x80, 0xd7, 0x00, + 0x13, 0x07, 0x07, 0x03, 0x93, 0xf6, 0x75, 0x00, 0x23, 0x80, 0xe7, 0x00, + 0x13, 0x87, 0x06, 0x03, 0x23, 0x80, 0xe7, 0x00, 0x13, 0x07, 0x90, 0x02, + 0x23, 0x80, 0xe7, 0x00, 0x13, 0x07, 0xa0, 0x00, 0x23, 0x80, 0xe7, 0x00, + 0x93, 0x07, 0xf0, 0x03, 0x63, 0x0c, 0xf6, 0x02, 0x9b, 0x85, 0x15, 0x00, + 0x93, 0x95, 0x05, 0x03, 0x93, 0xd5, 0x05, 0x03, 0x13, 0x15, 0x85, 0x00, + 0x37, 0x17, 0x00, 0x10, 0x33, 0x65, 0xb5, 0x00, 0x13, 0x17, 0x47, 0x01, + 0x23, 0x30, 0xa7, 0x00, 0xb7, 0x46, 0x00, 0x00, 0x83, 0x37, 0x07, 0x00, + 0xe3, 0x9e, 0xd7, 0xfe, 0x73, 0x00, 0x10, 0x00, 0x67, 0x80, 0x00, 0x00, + 0x1b, 0x05, 0x15, 0x00, 0x13, 0x15, 0x05, 0x03, 0x13, 0x55, 0x05, 0x03, + 0x93, 0x05, 0x00, 0x00, 0x6f, 0xf0, 0x9f, 0xfc, 0xb7, 0x17, 0x00, 0x10, + 0x93, 0x97, 0x47, 0x01, 0x23, 0xb0, 0x07, 0x00, 0x13, 0x07, 0x00, 0x03, + 0xb7, 0x17, 0x00, 0x00, 0x23, 0x80, 0xe7, 0x00, 0x13, 0x07, 0xa0, 0x00, + 0x23, 0x80, 0xe7, 0x00, 0x6f, 0xf0, 0xdf, 0xf2 }; -unsigned int test_grid_len = 208; +unsigned int _tmp_test_bin_len = 260; static struct component *get_grid(struct component **grid, int i, int j, uint8_t x, uint8_t y) { @@ -55,45 +58,61 @@ static stat build_grid(struct clock_domain *clk, uint8_t x, uint8_t y) struct component **grid = calloc(x * y, sizeof(struct component *)); assert(grid); - struct component **routers = calloc(x * y, sizeof(struct component *)); - assert(routers); + struct component **pes = calloc(x * y, sizeof(struct component *)); + assert(pes); for (size_t i = 0; i < x; ++i) for (size_t j = 0; j < y; ++j) { - struct component *imem = create_simple_mem(4096); - init_simple_mem(imem, 0, test_grid_len, test_grid); + struct component *node = create_grid_node(i, j); + clock_domain_add(clk, node); + grid[i * x + j] = node; + + if (i == 0 && j == 0) + continue; - struct component *dmem = create_simple_mem(4096); - struct component *router = create_node_router(0, 0, i, j); - node_router_add(router, dmem, 4096, 4096); + if (i == 1 && j == 1) + continue; + + struct component *imem = create_simple_mem(4096); + init_simple_mem(imem, 0, _tmp_test_bin_len, _tmp_test_bin); - uint64_t rcv = grid_addr(0, 0, i, j, 16384); - struct component *rv64 = create_simple_riscv64(rcv, 0, imem, router); + uint64_t rcv = grid_addr(i, j, 0); + struct component *rv64 = create_simple_riscv64(rcv, 0, imem, node); simple_riscv64_set_reg(rv64, 10, i); /* a0 */ simple_riscv64_set_reg(rv64, 11, j); /* a1 */ clock_domain_add(clk, rv64); + clock_domain_add(clk, imem); - routers[i * x + j] = router; - grid[i * x + j] = create_grid_node(0, 0, i, j); + pes[i * x + j] = rv64; } struct component *uart = create_simple_uart(); - node_router_add(routers[0], uart, 8192, 1); + clock_domain_add(clk, uart); + grid_node_connect(grid[0], NULL, grid[x], grid[1], NULL, uart); + + struct component *dmem = create_simple_mem(4096); + clock_domain_add(clk, dmem); + grid_node_connect(grid[x + 1], grid[1], grid[2 * x + 1], grid[x + 2], grid[x], dmem); for (int i = 0; i < x; ++i) for (int j = 0; j < y; ++j) { + if (i == 0 && j == 0) + continue; + + if (i == 1 && j == 1) + continue; + struct component *node = grid[i * x + j]; - struct component *lower = routers[i * x + j]; + struct component *lower = pes[i * x + j]; struct component *left = get_grid(grid, i - 1, j , x, y); struct component *right = get_grid(grid, i + 1, j , x, y); struct component *up = get_grid(grid, i , j + 1, x, y); struct component *down = get_grid(grid, i , j - 1, x, y); - grid_node_connect(node, left, right, up, down, lower, NULL); - node_router_ascend(lower, node); + grid_node_connect(node, left, right, up, down, lower); } - free(routers); + free(pes); free(grid); return OK; } diff --git a/tests/simple_grid/test.c b/tests/simple_grid/test.c index 782062d..07f1123 100644 --- a/tests/simple_grid/test.c +++ b/tests/simple_grid/test.c @@ -1,14 +1,17 @@ #define X 64 #define Y 64 -void _start(unsigned char x, unsigned char y) +void _start(unsigned short x, unsigned short y) { - volatile unsigned long *counter = (unsigned long *)4096; - volatile char *uart = (char *)8192; + volatile unsigned long *counter = (unsigned long *)((1ULL << 48) | (1ULL << 32)); + volatile char *uart = (char *)4096; /* very hacky, not recommended but good enough for testing */ - if (x == 0 && y == 0) + if (x == 0 && y == 1) { *counter = 0; + *uart = '0'; + *uart = '\n'; + } else while (*counter != ((x << 8) | y)) ; diff --git a/tests/simple_riscv64/sim.c b/tests/simple_riscv64/sim.c index ae3cad4..f92be96 100644 --- a/tests/simple_riscv64/sim.c +++ b/tests/simple_riscv64/sim.c @@ -17,17 +17,19 @@ unsigned int simple_sum_len = 36; int main() { - const size_t size = 100000; + const size_t size = 4096; struct component *imem = create_simple_mem(size); /* This works for simple memory, but feels kind of hacky */ init_simple_mem(imem, 0, simple_sum_len, simple_sum); struct component *dmem = create_simple_mem(size); - struct component *rv64 = create_simple_riscv64(0, imem, dmem); + struct component *rv64 = create_simple_riscv64(4096, 0, imem, dmem); struct clock_domain *clk = create_clock_domain(NS(1)); clock_domain_add(clk, rv64); + clock_domain_add(clk, imem); + clock_domain_add(clk, dmem); struct gran_root *root = create_root(); root_add_clock(root, clk); diff --git a/tests/simple_uart/sim.c b/tests/simple_uart/sim.c index 762b591..c0d1f82 100644 --- a/tests/simple_uart/sim.c +++ b/tests/simple_uart/sim.c @@ -31,10 +31,15 @@ int main() simple_bus_add(bus, dmem, 0, size); simple_bus_add(bus, uart, size, 1); - struct component *rv64 = create_simple_riscv64(0, imem, bus); + struct component *rv64 = create_simple_riscv64(8192, 0, imem, bus); + simple_bus_add(bus, rv64, 8192, 4096); struct clock_domain *clk = create_clock_domain(NS(1)); clock_domain_add(clk, rv64); + clock_domain_add(clk, dmem); + clock_domain_add(clk, imem); + clock_domain_add(clk, bus); + clock_domain_add(clk, uart); struct gran_root *root = create_root(); root_add_clock(root, clk); -- cgit v1.3