Skip to content

Commit 1fad0f1

Browse files
xianglycxiaoxiang781216
authored andcommitted
arch/x86_64: this_task is stored in the CPU private data
By default in SMP, obtaining this_task requires disabling interrupts, obtaining the current CPU index, accessing a global variable, and re-enabling interrupts. Storing this_task in percpu makes retrieval faster. Signed-off-by: liwenxiang1 <liwenxiang1@xiaomi.com>
1 parent 6485093 commit 1fad0f1

File tree

4 files changed

+28
-27
lines changed

4 files changed

+28
-27
lines changed

arch/x86_64/include/irq.h

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,9 @@ struct intel64_cpu_s
7272

7373
bool interrupt_context;
7474

75-
/* current_regs holds a references to the current interrupt level
76-
* register storage structure. If is non-NULL only during interrupt
77-
* processing. Access to current_regs must be through
78-
* up_current_regs() and up_set_current_regs() functions
79-
*/
75+
/* Current task */
8076

81-
uint64_t *current_regs;
77+
struct tcb_s *this_task;
8278

8379
#ifdef CONFIG_LIB_SYSCALL
8480
/* Current user RSP for syscall */
@@ -143,22 +139,6 @@ static inline_function int up_cpu_index(void)
143139
* Inline functions
144140
****************************************************************************/
145141

146-
static inline_function uint64_t *up_current_regs(void)
147-
{
148-
uint64_t *regs;
149-
__asm__ volatile("movq %%gs:(%c1), %0"
150-
: "=r" (regs)
151-
: "i" (offsetof(struct intel64_cpu_s, current_regs)));
152-
return regs;
153-
}
154-
155-
static inline_function void up_set_current_regs(uint64_t *regs)
156-
{
157-
__asm__ volatile("movq %0, %%gs:(%c1)"
158-
:: "r" (regs), "i" (offsetof(struct intel64_cpu_s,
159-
current_regs)));
160-
}
161-
162142
static inline_function bool up_interrupt_context(void)
163143
{
164144
bool flag;
@@ -177,12 +157,30 @@ static inline_function void up_set_interrupt_context(bool flag)
177157
interrupt_context)));
178158
}
179159

160+
/****************************************************************************
161+
* Schedule acceleration macros
162+
****************************************************************************/
163+
164+
#define up_this_task() \
165+
({ \
166+
struct tcb_s *this_task; \
167+
__asm__ volatile("movq %%gs:(%c1), %0" \
168+
: "=r" (this_task) \
169+
: "i" (offsetof(struct intel64_cpu_s, this_task))); \
170+
this_task; \
171+
})
172+
173+
#define up_update_task(t) \
174+
__asm__ volatile("movq %0, %%gs:(%c1)" \
175+
:: "r" ((struct tcb_s *)t), \
176+
"i" (offsetof(struct intel64_cpu_s, this_task)))
177+
180178
/****************************************************************************
181179
* Name: up_getusrpc
182180
****************************************************************************/
183181

184182
#define up_getusrpc(regs) \
185-
(((uint64_t *)((regs) ? (regs) : up_current_regs()))[REG_RIP])
183+
(((uint64_t *)((regs) ? (regs) : running_regs()))[REG_RIP])
186184

187185
#undef EXTERN
188186
#ifdef __cplusplus

arch/x86_64/src/intel64/intel64_backtrace_fp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ int up_backtrace(struct tcb_s *tcb,
145145
{
146146
ret += backtrace(rtcb->stack_base_ptr,
147147
rtcb->stack_base_ptr + rtcb->adj_stack_size,
148-
(void *)up_current_regs()[REG_RBP],
149-
(void *)up_current_regs()[REG_RIP],
148+
(void *)running_regs()[REG_RBP],
149+
(void *)running_regs()[REG_RIP],
150150
&buffer[ret], size - ret, &skip);
151151
}
152152
}

arch/x86_64/src/intel64/intel64_cpustart.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ void x86_64_ap_boot(void)
148148

149149
x86_64_cpu_priv_set(cpu);
150150

151-
tcb = this_task();
151+
tcb = current_task(cpu);
152152
UNUSED(tcb);
153153

154154
/* Configure interrupts */
@@ -192,6 +192,8 @@ void x86_64_ap_boot(void)
192192
__revoke_low_memory();
193193
}
194194

195+
up_update_task(tcb);
196+
195197
/* Then transfer control to the IDLE task */
196198

197199
nx_idle_trampoline();

arch/x86_64/src/intel64/intel64_regdump.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <debug.h>
3131
#include <nuttx/irq.h>
3232

33+
#include "sched/sched.h"
3334
#include "x86_64_internal.h"
3435

3536
/****************************************************************************
@@ -113,7 +114,7 @@ void backtrace(uint64_t rbp)
113114

114115
void up_dump_register(void *dumpregs)
115116
{
116-
volatile uint64_t *regs = dumpregs ? dumpregs : up_current_regs();
117+
volatile uint64_t *regs = dumpregs ? dumpregs : running_regs();
117118
uint64_t mxcsr;
118119
uint64_t cr2;
119120

0 commit comments

Comments
 (0)