aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2022-10-21 15:16:08 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2022-10-21 15:16:08 +0300
commit00d3ae26dfd7c91c0817e71d71636982680d0b28 (patch)
tree866908a7f5b4fbbfd4ee32f752a4b96f2c867c63
parent08619630e9c7b638354323b443937701811b11d4 (diff)
downloadkmi-00d3ae26dfd7c91c0817e71d71636982680d0b28.tar.gz
kmi-00d3ae26dfd7c91c0817e71d71636982680d0b28.zip
slight optimisation to cur_tcb on riscv
-rw-r--r--arch/riscv64/kernel/cpu.c17
-rw-r--r--common/tcb.c3
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()];
}