Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arch: inline up_switch_context,in arm arm64 #13644

Merged
merged 2 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use inline function?

Copy link
Contributor Author

@hujun260 hujun260 Sep 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we use inline, we need to see the definition of struct tcb_s, but irq.h can't include nuttx/sched.h

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) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's create a new patch to inline other arch too

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