Skip to content

Commit

Permalink
armv7-a/armv7-r/armv8-r: percpu reg store this_task
Browse files Browse the repository at this point in the history
This is continue work of apache#13726

We can utilize percpu storage to hold information about the
current running task. If we intend to implement this feature, we would
need to define two macros that help us manage this percpu information
effectively.

up_this_task: This macro is designed to read the contents of the percpu
register to retrieve information about the current
running task.This allows us to quickly access
task-specific data without having to disable interrupts,
access global variables and obtain the current cpu index.

up_update_task: This macro is responsible for updating the contents of
the percpu register.It is typically called during
initialization or when a context switch occurs to ensure
that the percpu register reflects the information of the
newly running task.

Signed-off-by: hujun5 <[email protected]>
  • Loading branch information
hujun260 authored and xiaoxiang781216 committed Dec 6, 2024
1 parent 344968b commit 1e49cb4
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 21 deletions.
2 changes: 2 additions & 0 deletions arch/arm/include/armv7-a/cp15.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,6 @@
value; \
}) \

#define CP15_MODIFY(v,m,a) CP15_SET(a, ((CP15_GET(a) & ~(m)) | ((uintptr_t)(v) & (m))))

#endif /* __ARCH_ARM_SRC_ARMV7_A_CP15_H */
12 changes: 5 additions & 7 deletions arch/arm/include/armv7-a/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,18 +472,16 @@ static inline_function uint32_t up_getsp(void)
return sp;
}

noinstrument_function
static inline_function bool up_interrupt_context(void)
{
return (bool)CP15_GET(TPIDRPRW);
}

noinstrument_function
static inline_function void up_set_interrupt_context(bool flag)
{
CP15_SET(TPIDRPRW, flag);
CP15_MODIFY(flag, 1ul, TPIDRPRW);
}

#define up_this_task() ((struct tcb_s *)(CP15_GET(TPIDRPRW) & ~1ul))
#define up_update_task(t) CP15_MODIFY(t, ~1ul, TPIDRPRW)
#define up_interrupt_context() (CP15_GET(TPIDRPRW) & 1)

/****************************************************************************
* Public Data
****************************************************************************/
Expand Down
2 changes: 2 additions & 0 deletions arch/arm/include/armv7-r/cp15.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,6 @@
value; \
}) \

#define CP15_MODIFY(v,m,a) CP15_SET(a, ((CP15_GET(a) & ~(m)) | ((uintptr_t)(v) & (m))))

#endif /* __ARCH_ARM_SRC_ARMV7_R_CP15_H */
12 changes: 5 additions & 7 deletions arch/arm/include/armv7-r/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -467,18 +467,16 @@ static inline_function uint32_t up_getsp(void)
return sp;
}

noinstrument_function
static inline_function bool up_interrupt_context(void)
{
return (bool)CP15_GET(TPIDRPRW);
}

noinstrument_function
static inline_function void up_set_interrupt_context(bool flag)
{
CP15_SET(TPIDRPRW, flag);
CP15_MODIFY(flag, 1ul, TPIDRPRW);
}

#define up_this_task() ((struct tcb_s *)(CP15_GET(TPIDRPRW) & ~1ul))
#define up_update_task(t) CP15_MODIFY(t, ~1ul, TPIDRPRW)
#define up_interrupt_context() (CP15_GET(TPIDRPRW) & 1)

/****************************************************************************
* Public Data
****************************************************************************/
Expand Down
2 changes: 2 additions & 0 deletions arch/arm/include/armv8-r/cp15.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,6 @@
_value; \
}) \

#define CP15_MODIFY(v,m,a) CP15_SET(a, ((CP15_GET(a) & ~(m)) | ((uintptr_t)(v) & (m))))

#endif /* __ARCH_ARM_SRC_ARMV8_R_CP15_H */
12 changes: 5 additions & 7 deletions arch/arm/include/armv8-r/irq.h
Original file line number Diff line number Diff line change
Expand Up @@ -467,18 +467,16 @@ static inline_function uint32_t up_getsp(void)
return sp;
}

noinstrument_function
static inline_function bool up_interrupt_context(void)
{
return (bool)CP15_GET(TPIDRPRW);
}

noinstrument_function
static inline_function void up_set_interrupt_context(bool flag)
{
CP15_SET(TPIDRPRW, flag);
CP15_MODIFY(flag, 1ul, TPIDRPRW);
}

#define up_this_task() ((struct tcb_s *)(CP15_GET(TPIDRPRW) & ~1ul))
#define up_update_task(t) CP15_MODIFY(t, ~1ul, TPIDRPRW)
#define up_interrupt_context() (CP15_GET(TPIDRPRW) & 1)

/****************************************************************************
* Public Data
****************************************************************************/
Expand Down
9 changes: 9 additions & 0 deletions arch/arm/src/armv7-a/arm_scu.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <stdint.h>

#include <arch/irq.h>
#include <sched/sched.h>

#include "arm_internal.h"
#include "cp15_cacheops.h"
Expand Down Expand Up @@ -57,6 +58,14 @@ void arm_enable_smp(int cpu)
{
uint32_t regval;

/* We need to confirm that current_task has been initialized. */

while (!current_task(this_cpu()));

/* Init idle task to percpu reg */

up_update_task(current_task(cpu));

/* Handle actions unique to CPU0 which comes up first */

if (cpu == 0)
Expand Down
9 changes: 9 additions & 0 deletions arch/arm/src/armv7-r/arm_scu.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <stdint.h>

#include <arch/irq.h>
#include <sched/sched.h>

#include "arm_internal.h"
#include "cp15_cacheops.h"
Expand Down Expand Up @@ -57,6 +58,14 @@ void arm_enable_smp(int cpu)
{
uint32_t regval;

/* We need to confirm that current_task has been initialized. */

while (!current_task(this_cpu()));

/* Init idle task to percpu reg */

up_update_task(current_task(cpu));

/* Handle actions unique to CPU0 which comes up first */

if (cpu == 0)
Expand Down

0 comments on commit 1e49cb4

Please sign in to comment.