diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2022-10-21 17:43:31 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2022-10-21 17:43:31 +0300 |
| commit | ec989bbe7d9bb7a844eeddeceaeb7bb7e4d5dab6 (patch) | |
| tree | 51221980ad2d4c8701e1a6e762a47495dec289de /common | |
| parent | a06dbb8a63d825ebb1ad65372ce1ce1f572891bc (diff) | |
| download | kmi-ec989bbe7d9bb7a844eeddeceaeb7bb7e4d5dab6.tar.gz kmi-ec989bbe7d9bb7a844eeddeceaeb7bb7e4d5dab6.zip | |
initial implementation of swap
+ Slightly unsure if it should be a syscall, or if assign would be
enough. Also, which thread should run in a fork/spawn? For now, old
thread, though this might increase latency. Or add swap flag to these
calls?
Diffstat (limited to 'common')
| -rw-r--r-- | common/proc.c | 2 | ||||
| -rw-r--r-- | common/tcb.c | 4 | ||||
| -rw-r--r-- | common/uapi/proc.c | 15 |
3 files changed, 15 insertions, 6 deletions
diff --git a/common/proc.c b/common/proc.c index 6a3bedf..946078b 100644 --- a/common/proc.c +++ b/common/proc.c @@ -37,9 +37,7 @@ stat_t init_proc(void *fdt) return ERR_OOMEM; /* set current tcb */ - cpu_assign(t); use_tcb(t); - use_vmem(t->proc.vmem); /* allocate stacks after ELF file to make sure nothing of importance * clashes */ diff --git a/common/tcb.c b/common/tcb.c index f618cd6..42e634d 100644 --- a/common/tcb.c +++ b/common/tcb.c @@ -305,9 +305,13 @@ struct tcb *cur_proc() void use_tcb(struct tcb *t) { + cpu_assign(t); + id_t cpu = cpu_id(); t->cpu_id = cpu; cpu_tcb[cpu] = t; + + use_vmem(t->proc.vmem); } struct tcb *get_tcb(id_t tid) diff --git a/common/uapi/proc.c b/common/uapi/proc.c index a668246..a9a3dce 100644 --- a/common/uapi/proc.c +++ b/common/uapi/proc.c @@ -12,6 +12,8 @@ #include <apos/bits.h> #include <apos/mem_regions.h> +#include <arch/proc.h> + /** * Create syscall handler. * @@ -122,10 +124,15 @@ SYSCALL_DEFINE1(kill)(sys_arg_t tid) * @return \ref OK and 0. */ SYSCALL_DEFINE1(swap)(sys_arg_t tid){ - /** \todo switch to process */ - /** \todo should switch return the registers of the new thread that would - * be used for message passing? */ - return (struct sys_ret){ OK, 0, 0, 0, 0, 0 }; + struct tcb *t = get_tcb(tid); + if (!t) + /** @todo add error sys_ret macro? */ + return (struct sys_ret){ERR_INVAL, 0, 0, 0, 0, 0}; + + /* switch over to new thread */ + use_tcb(t); + + return get_args(t); } /** |
