From 131af4eec38752a27e6e56579fbf76178e022ec1 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Thu, 1 Dec 2022 02:05:19 +0200 Subject: start looking into memory handling + Now 10M alloc/frees succeed, which totals more memory than the virtual machine has, so no too obvious leaks are occuring. For future debugging speed, changed 10M to 1M. + Also quick fix to rpcs, stacks are now assigned. Not entirely sure why they worked before this, but good that I found it. --- arch/riscv64/conf/init | Bin 2720 -> 5088 bytes arch/riscv64/conf/init.c | 31 ++++++++++++++++++++++++++++++- arch/riscv64/conf/initrd | Bin 3072 -> 5632 bytes arch/riscv64/kernel/proc.c | 7 +++++++ 4 files changed, 37 insertions(+), 1 deletion(-) (limited to 'arch/riscv64') diff --git a/arch/riscv64/conf/init b/arch/riscv64/conf/init index eba8186..0d99b80 100755 Binary files a/arch/riscv64/conf/init and b/arch/riscv64/conf/init differ diff --git a/arch/riscv64/conf/init.c b/arch/riscv64/conf/init.c index de9814e..4cd4cea 100644 --- a/arch/riscv64/conf/init.c +++ b/arch/riscv64/conf/init.c @@ -18,6 +18,7 @@ */ #include +#include #include "../../../include/apos/syscalls.h" struct sys_ret { @@ -184,6 +185,27 @@ static void sys_poweroff(long type) ecall(r); } +static void *sys_req_mem(size_t count) +{ + struct sys_ret r = {.a0 = SYS_REQ_MEM, .a1 = count, + .a2 = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 4)}; + r = ecall(r); + + if (r.a0) + print_value("sys_req_mem() failed with error ", r.a0); + + return (void *)r.a1; +} + +static void sys_free_mem(void *p) +{ + struct sys_ret r = {.a0 = SYS_FREE_MEM, .a1 = (long)p}; + r = ecall(r); + + if (r.a0) + print_value("sys_free_mem() failed with error ", r.a0); +} + void callback(long status, long tid, long d0, long d1, long d2, long d3) { (void)status; @@ -244,12 +266,19 @@ void _start() csr_read(CSR_TIME, i); start = i; n = 0; while (i < start + second) { - sys_ipc_req(1, d0, d1, d2, d3); + sys_ipc_req(1, n, d1, d2, d3); csr_read(CSR_TIME, i); n++; } print_value("IPC requests per second", n); + puts("Doing memory allocations...\n"); + for (i = 0; i < 1000000; ++i) { + char *p = sys_req_mem(10); + *p = 'c'; + sys_free_mem(p); + } + sys_poweroff(0); } diff --git a/arch/riscv64/conf/initrd b/arch/riscv64/conf/initrd index 905bbfe..8d36a5a 100644 Binary files a/arch/riscv64/conf/initrd and b/arch/riscv64/conf/initrd differ diff --git a/arch/riscv64/kernel/proc.c b/arch/riscv64/kernel/proc.c index 0f19789..d58b41b 100644 --- a/arch/riscv64/kernel/proc.c +++ b/arch/riscv64/kernel/proc.c @@ -63,6 +63,13 @@ void set_thread(struct tcb *t) r->tp = (long)t->thread_storage; } +void set_stack(struct tcb *t, vm_t s) +{ + /** @todo also set frame pointer on architectures that need it? */ + struct riscv_regs *r = (struct riscv_regs *)(t->regs) - 1; + r->sp = s; +} + vm_t get_stack(struct tcb *t) { struct riscv_regs *r = (struct riscv_regs *)(t->regs) - 1; -- cgit v1.3