From 5d00e21852d956fada51d45481a5549f9fbd5ed3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?kleines=20Filmr=C3=B6llchen?= Date: Fri, 30 Dec 2022 11:41:48 +0100 Subject: [PATCH] Kernel/aarch64: Implement wait_cycles as a pause loop The hand-written assembly does not compile under Clang due to register size mismatches. Using a loop is slower (~6 instructions on O2 as opposed to 2 with hand-written assembly), but using the pause instruction makes this more efficient even under TCG. --- Kernel/Arch/aarch64/ASM_wrapper.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Kernel/Arch/aarch64/ASM_wrapper.h b/Kernel/Arch/aarch64/ASM_wrapper.h index b4ac85f45d..9f879b2469 100644 --- a/Kernel/Arch/aarch64/ASM_wrapper.h +++ b/Kernel/Arch/aarch64/ASM_wrapper.h @@ -62,13 +62,10 @@ inline ExceptionLevel get_current_exception_level() inline void wait_cycles(int n) { - // This is probably too fast when caching and branch prediction is turned on. // FIXME: Make timer-based. - asm("mov x0, %[value]\n" - "0:\n" - " subs x0, x0, #1\n" - " bne 0b" ::[value] "r"(n) - : "x0"); + for (int volatile i = 0; i < n; i = i + 1) { + Processor::pause(); + } } inline void el1_vector_table_install(void* vector_table)