diff options
| -rw-r--r-- | arch/riscv64/kernel/cpu.c | 17 | ||||
| -rw-r--r-- | common/tcb.c | 3 |
2 files changed, 12 insertions, 8 deletions
diff --git a/arch/riscv64/kernel/cpu.c b/arch/riscv64/kernel/cpu.c index 38cf262..4273d02 100644 --- a/arch/riscv64/kernel/cpu.c +++ b/arch/riscv64/kernel/cpu.c @@ -16,12 +16,15 @@ void cpu_assign(struct tcb *t) id_t cpu_id() { - /* yes, slightly weird situation where cur_tcb() call cpu_id() which - * gets the current tcb and returns the cpu id in the tcb, so that that - * id can be used to get the tcb we want. I might try to work out - * something slightly smarter, although this is likely not going to have - * basically any kind of importance for perfomance. */ - struct tcb *t; - __asm__ volatile ("mv %0, tp\n" : "=r" (t) ::); + struct tcb *t = cur_tcb(); return t->cpu_id; } + +/* override cur_tcb() in common/tcb.c since on risc-v this is apparently the + * optimal strategy. */ +/* @todo should this be the default for all arches? */ +struct tcb *cur_tcb() +{ + register struct tcb *t __asm__ ("tp"); + return t; +} diff --git a/common/tcb.c b/common/tcb.c index 94abef7..8ff86ab 100644 --- a/common/tcb.c +++ b/common/tcb.c @@ -291,7 +291,8 @@ DEFINE_ATTACH(attach_proc, proc); DEFINE_DETACH(detach_rpc, rpc); DEFINE_DETACH(detach_proc, proc); -struct tcb *cur_tcb() +/* weak to allow optimisation on risc-v, but provide fallback for future */ +__weak struct tcb *cur_tcb() { return cpu_tcb[cpu_id()]; } |
