diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2022-12-01 02:05:19 +0200 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2022-12-01 02:05:19 +0200 |
| commit | 131af4eec38752a27e6e56579fbf76178e022ec1 (patch) | |
| tree | 1940634f69a44395fc6945b25c5cbc8b68bba876 /arch | |
| parent | e25f1e7a8f8f2320546ad4950464713d85b47785 (diff) | |
| download | kmi-131af4eec38752a27e6e56579fbf76178e022ec1.tar.gz kmi-131af4eec38752a27e6e56579fbf76178e022ec1.zip | |
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.
Diffstat (limited to 'arch')
| -rwxr-xr-x | arch/riscv64/conf/init | bin | 2720 -> 5088 bytes | |||
| -rw-r--r-- | arch/riscv64/conf/init.c | 31 | ||||
| -rw-r--r-- | arch/riscv64/conf/initrd | bin | 3072 -> 5632 bytes | |||
| -rw-r--r-- | arch/riscv64/kernel/proc.c | 7 |
4 files changed, 37 insertions, 1 deletions
diff --git a/arch/riscv64/conf/init b/arch/riscv64/conf/init Binary files differindex eba8186..0d99b80 100755 --- a/arch/riscv64/conf/init +++ b/arch/riscv64/conf/init 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 <stdint.h> +#include <stddef.h> #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 Binary files differindex 905bbfe..8d36a5a 100644 --- a/arch/riscv64/conf/initrd +++ b/arch/riscv64/conf/initrd 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; |
