1
0
Fork 0
forked from nuttx/nuttx-update

arch: inline up_switch_context,in arm arm64

reason:
when a context switch occurs, up_switch_context is executed.
In order to reduce the time taken for context switching,
we inline the up_switch_context function.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
hujun5 2024-08-06 11:24:26 +08:00 committed by Xiang Xiao
parent e7c9e46eb2
commit 4c69bb8cc7
13 changed files with 35 additions and 164 deletions

View file

@ -32,6 +32,7 @@
#include <sys/types.h>
#ifndef __ASSEMBLY__
# include <stdbool.h>
# include <arch/syscall.h>
#endif
/****************************************************************************
@ -76,6 +77,17 @@
#ifndef __ASSEMBLY__
#ifndef up_switch_context
#define up_switch_context(tcb, rtcb) \
do { \
if (!up_interrupt_context()) \
{ \
sys_call2(SYS_switch_context, (uintptr_t)&rtcb->xcp.regs, \
(uintptr_t)tcb->xcp.regs); \
} \
} while (0)
#endif
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"

View file

@ -312,6 +312,14 @@ static inline_function bool up_interrupt_context(void)
return ret;
}
#define up_switch_context(tcb, rtcb) \
do { \
if (!up_interrupt_context()) \
{ \
tc32_switchcontext(&rtcb->xcp.regs, tcb->xcp.regs); \
} \
} while (0)
/****************************************************************************
* Public Function Prototypes
****************************************************************************/

View file

@ -38,7 +38,6 @@ set(SRCS
arm_releasestack.c
arm_registerdump.c
arm_stackframe.c
arm_switchcontext.c
arm_usestack.c
arm_fork.c
${ARCH_TOOLCHAIN_PATH}/fork.S)

View file

@ -24,7 +24,7 @@ CMN_CSRCS += arm_allocateheap.c arm_createstack.c arm_exit.c
CMN_CSRCS += arm_getintstack.c arm_initialize.c arm_lowputs.c
CMN_CSRCS += arm_modifyreg8.c arm_modifyreg16.c arm_modifyreg32.c
CMN_CSRCS += arm_nputs.c arm_releasestack.c arm_registerdump.c
CMN_CSRCS += arm_stackframe.c arm_switchcontext.c
CMN_CSRCS += arm_stackframe.c
CMN_CSRCS += arm_usestack.c arm_fork.c
ifneq ($(CONFIG_ALARM_ARCH),y)

View file

@ -153,14 +153,6 @@
extern void arm_fullcontextrestore(uint32_t *restoreregs);
#endif
#ifndef arm_switchcontext
# define arm_switchcontext(saveregs, restoreregs) \
sys_call2(SYS_switch_context, (uintptr_t)saveregs, (uintptr_t)restoreregs);
#else
extern void arm_switchcontext(uint32_t **saveregs,
uint32_t *restoreregs);
#endif
/* Redefine the linker symbols as armlink style */
#ifdef CONFIG_ARM_TOOLCHAIN_ARMCLANG

View file

@ -1,74 +0,0 @@
/****************************************************************************
* arch/arm/src/common/arm_switchcontext.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 <nuttx/config.h>
#include <sched.h>
#include <assert.h>
#include <debug.h>
#include <nuttx/arch.h>
#include <nuttx/sched.h>
#include "sched/sched.h"
#include "group/group.h"
#include "clock/clock.h"
#include "arm_internal.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: up_switch_context
*
* Description:
* A task is currently in the ready-to-run list but has been prepped
* to execute. Restore its context, and start execution.
*
* Input Parameters:
* tcb: Refers to the head task of the ready-to-run list
* which will be executed.
* rtcb: Refers to the running task which will be blocked.
*
****************************************************************************/
void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb)
{
/* Are we in an interrupt handler? */
if (!up_interrupt_context())
{
/* Switch context to the context of the task at the head of the
* ready to run list.
*/
arm_switchcontext(&rtcb->xcp.regs, tcb->xcp.regs);
/* arm_switchcontext forces a context switch to the task at the
* head of the ready-to-run list. It does not 'return' in the
* normal sense. When it does return, it is because the blocked
* task is again ready to run and has execution priority.
*/
}
}

View file

@ -66,4 +66,3 @@ ifeq ($(CONFIG_TLSR82_SOFT_FPU),y)
endif
CFLAGS += -Darm_fullcontextrestore=tc32_fullcontextrestore
CFLAGS += -Darm_switchcontext=tc32_switchcontext

View file

@ -34,6 +34,7 @@
#ifndef __ASSEMBLY__
# include <stdint.h>
# include <arch/syscall.h>
#endif
/* Include NuttX-specific IRQ definitions */
@ -423,6 +424,15 @@ static inline_function void up_set_current_regs(uint64_t *regs)
__asm__ volatile ("msr " "tpidr_el1" ", %0" : : "r" (regs));
}
#define up_switch_context(tcb, rtcb) \
do { \
if (!up_interrupt_context()) \
{ \
sys_call2(SYS_switch_context, (uintptr_t)&rtcb->xcp.regs, \
(uintptr_t)tcb->xcp.regs); \
} \
} while (0)
/****************************************************************************
* Name: up_interrupt_context
*

View file

@ -29,7 +29,7 @@ list(APPEND SRCS arm64_fork_func.S)
list(APPEND SRCS arm64_initialize.c arm64_initialstate.c arm64_boot.c)
list(APPEND SRCS arm64_nputs.c arm64_copystate.c arm64_createstack.c)
list(APPEND SRCS arm64_releasestack.c arm64_stackframe.c arm64_usestack.c)
list(APPEND SRCS arm64_exit.c arm64_fork.c arm64_switchcontext.c)
list(APPEND SRCS arm64_exit.c arm64_fork.c)
list(APPEND SRCS arm64_schedulesigaction.c arm64_sigdeliver.c)
list(APPEND SRCS arm64_getintstack.c arm64_registerdump.c)
list(APPEND SRCS arm64_perf.c arm64_tcbinfo.c)

View file

@ -41,7 +41,7 @@ CMN_ASRCS += arm64_fork_func.S
CMN_CSRCS = arm64_initialize.c arm64_initialstate.c arm64_boot.c
CMN_CSRCS += arm64_nputs.c arm64_copystate.c arm64_createstack.c
CMN_CSRCS += arm64_releasestack.c arm64_stackframe.c arm64_usestack.c
CMN_CSRCS += arm64_exit.c arm64_fork.c arm64_switchcontext.c
CMN_CSRCS += arm64_exit.c arm64_fork.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

View file

@ -119,9 +119,6 @@
} \
while (1)
#define arm64_switchcontext(saveregs, restoreregs) \
sys_call2(SYS_switch_context, (uintptr_t)saveregs, (uintptr_t)restoreregs)
/****************************************************************************
* Public Types
****************************************************************************/

View file

@ -1,74 +0,0 @@
/****************************************************************************
* arch/arm64/src/common/arm64_switchcontext.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 <nuttx/config.h>
#include <sched.h>
#include <assert.h>
#include <debug.h>
#include <nuttx/arch.h>
#include <nuttx/sched.h>
#include "sched/sched.h"
#include "group/group.h"
#include "clock/clock.h"
#include "arm64_internal.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: up_switch_context
*
* Description:
* A task is currently in the ready-to-run list but has been prepped
* to execute. Restore its context, and start execution.
*
* Input Parameters:
* tcb: Refers to the head task of the ready-to-run list
* which will be executed.
* rtcb: Refers to the running task which will be blocked.
*
****************************************************************************/
void up_switch_context(struct tcb_s *tcb, struct tcb_s *rtcb)
{
/* Are we in an interrupt handler? */
if (!up_interrupt_context())
{
/* Switch context to the context of the task at the head of the
* ready to run list.
*/
arm64_switchcontext(&rtcb->xcp.regs, tcb->xcp.regs);
/* arm_switchcontext forces a context switch to the task at the
* head of the ready-to-run list. It does not 'return' in the
* normal sense. When it does return, it is because the blocked
* task is again ready to run and has execution priority.
*/
}
}

View file

@ -439,7 +439,9 @@ void up_release_stack(FAR struct tcb_s *dtcb, uint8_t ttype);
*
****************************************************************************/
#ifndef up_switch_context
void up_switch_context(FAR struct tcb_s *tcb, FAR struct tcb_s *rtcb);
#endif
/****************************************************************************
* Name: up_exit