Skip to content

Commit

Permalink
arch: inline up_switch_context,in arm arm64
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
hujun260 committed Sep 27, 2024
1 parent 3e459c0 commit d9f0e30
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 164 deletions.
12 changes: 12 additions & 0 deletions arch/arm/include/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <sys/types.h>
#ifndef __ASSEMBLY__
# include <stdbool.h>
# include <arch/syscall.h>
#endif

/****************************************************************************
Expand Down Expand Up @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions arch/arm/include/tlsr82/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
****************************************************************************/
Expand Down
1 change: 0 additions & 1 deletion arch/arm/src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion arch/arm/src/common/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 0 additions & 8 deletions arch/arm/src/common/arm_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
74 changes: 0 additions & 74 deletions arch/arm/src/common/arm_switchcontext.c

This file was deleted.

1 change: 0 additions & 1 deletion arch/arm/src/tlsr82/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,3 @@ ifeq ($(CONFIG_TLSR82_SOFT_FPU),y)
endif

CFLAGS += -Darm_fullcontextrestore=tc32_fullcontextrestore
CFLAGS += -Darm_switchcontext=tc32_switchcontext
10 changes: 10 additions & 0 deletions arch/arm64/include/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#ifndef __ASSEMBLY__
# include <stdint.h>
# include <arch/syscall.h>
#endif

/* Include NuttX-specific IRQ definitions */
Expand Down Expand Up @@ -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
*
Expand Down
2 changes: 1 addition & 1 deletion arch/arm64/src/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion arch/arm64/src/common/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions arch/arm64/src/common/arm64_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@
} \
while (1)

#define arm64_switchcontext(saveregs, restoreregs) \
sys_call2(SYS_switch_context, (uintptr_t)saveregs, (uintptr_t)restoreregs)

/****************************************************************************
* Public Types
****************************************************************************/
Expand Down
74 changes: 0 additions & 74 deletions arch/arm64/src/common/arm64_switchcontext.c

This file was deleted.

2 changes: 2 additions & 0 deletions include/nuttx/arch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d9f0e30

Please sign in to comment.