From f8288b8177da2151ef6e479ec504252dd5c88669 Mon Sep 17 00:00:00 2001 From: hujun5 Date: Mon, 11 Dec 2023 21:02:36 +0800 Subject: [PATCH] arm64: optimise for arm64_switchcontext We can save execution time by inline arm64_fullcontextrestore and arm64_switchcontext test: We can use qemu for testing. compiling make distclean -j20; ./tools/configure.sh -l qemu-armv8a:nsh_smp ;make -j20 running qemu-system-aarch64 -cpu cortex-a53 -smp 4 -nographic -machine virt,virtualization=on,gic-version=3 -net none -chardev stdio,id=con,mux=on -serial chardev:con -mon chardev=con,mode=readline -kernel ./nuttx Signed-off-by: hujun5 --- arch/arm64/src/common/Make.defs | 2 +- arch/arm64/src/common/arm64_internal.h | 18 ++++-- arch/arm64/src/common/arm64_task_sched.c | 81 ------------------------ 3 files changed, 14 insertions(+), 87 deletions(-) delete mode 100644 arch/arm64/src/common/arm64_task_sched.c diff --git a/arch/arm64/src/common/Make.defs b/arch/arm64/src/common/Make.defs index 4bb12ec7eb457..00cb0b7099664 100644 --- a/arch/arm64/src/common/Make.defs +++ b/arch/arm64/src/common/Make.defs @@ -45,7 +45,7 @@ endif CMN_CSRCS = arm64_initialize.c arm64_initialstate.c arm64_boot.c CMN_CSRCS += arm64_nputs.c arm64_idle.c arm64_copystate.c arm64_createstack.c CMN_CSRCS += arm64_releasestack.c arm64_stackframe.c arm64_usestack.c -CMN_CSRCS += arm64_task_sched.c arm64_exit.c arm64_fork.c arm64_switchcontext.c +CMN_CSRCS += arm64_exit.c arm64_fork.c arm64_switchcontext.c CMN_CSRCS += arm64_schedulesigaction.c arm64_sigdeliver.c CMN_CSRCS += arm64_getintstack.c arm64_registerdump.c CMN_CSRCS += arm64_perf.c arm64_tcbinfo.c diff --git a/arch/arm64/src/common/arm64_internal.h b/arch/arm64/src/common/arm64_internal.h index 8d82fa0837fdb..b05ff81044a6a 100644 --- a/arch/arm64/src/common/arm64_internal.h +++ b/arch/arm64/src/common/arm64_internal.h @@ -32,6 +32,7 @@ # include # include # include +# include #endif #include "arm64_arch.h" @@ -116,6 +117,18 @@ # define SMP_STACK_WORDS (SMP_STACK_SIZE >> 2) #endif +/* Context switching */ + +#define arm64_fullcontextrestore(restoreregs) \ + do \ + { \ + sys_call1(SYS_restore_context, (uintptr_t)restoreregs); \ + } \ + while (1) + +#define arm64_switchcontext(saveregs, restoreregs) \ + sys_call2(SYS_switch_context, (uintptr_t)saveregs, (uintptr_t)restoreregs) + /**************************************************************************** * Public Types ****************************************************************************/ @@ -267,11 +280,6 @@ int arm64_psci_init(const char *method); void __start(void); void arm64_secondary_start(void); -/* Context switching */ - -void arm64_fullcontextrestore(uint64_t *restoreregs) noreturn_function; -void arm64_switchcontext(uint64_t **saveregs, uint64_t *restoreregs); - /* Signal handling **********************************************************/ void arm64_sigdeliver(void); diff --git a/arch/arm64/src/common/arm64_task_sched.c b/arch/arm64/src/common/arm64_task_sched.c deleted file mode 100644 index 69f27df8c1a8f..0000000000000 --- a/arch/arm64/src/common/arm64_task_sched.c +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** - * arch/arm64/src/common/arm64_task_sched.c - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. The - * ASF licenses this file to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the - * License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "sched/sched.h" -#include "group/group.h" -#include "arm64_internal.h" -#include "arm64_fatal.h" - -#ifdef CONFIG_ARCH_FPU -#include "arm64_fpu.h" -#endif - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: arm64_fullcontextrestore - * - * Description: - * Restore the current thread context. Full prototype is: - * - * void arm64_fullcontextrestore(uint64_t *restoreregs) noreturn_function; - * - * Returned Value: - * None - * - ****************************************************************************/ - -void arm64_fullcontextrestore(uint64_t *restoreregs) -{ - sys_call1(SYS_restore_context, (uintptr_t)restoreregs); - - __builtin_unreachable(); -} - -/**************************************************************************** - * Name: arm64_switchcontext - * - * Description: - * Save the current thread context and restore the specified context. - * - * Returned Value: - * None - * - ****************************************************************************/ - -void arm64_switchcontext(uint64_t **saveregs, uint64_t *restoreregs) -{ - sys_call2(SYS_switch_context, (uintptr_t)saveregs, (uintptr_t)restoreregs); -}