Skip to content

Commit

Permalink
xtensa: g_current_regs is only used to determine if we are in irq,
Browse files Browse the repository at this point in the history
with other functionalities removed.

reason:
by doing this we can reduce context switch time,
When we exit from an interrupt handler, we directly use tcb->xcp.regs

before
text    data     bss     dec     hex filename
178368     876  130604  309848   4ba58 nuttx
after
text    data     bss     dec     hex filename
178120     876  130212  309208   4b7d8 nuttx

szie change -248

Signed-off-by: hujun5 <[email protected]>
  • Loading branch information
hujun260 committed Sep 27, 2024
1 parent 981fd0c commit 7ebe788
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 354 deletions.
7 changes: 0 additions & 7 deletions arch/xtensa/src/common/xtensa.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,6 @@
#define IDLETHREAD_STACKSIZE ((CONFIG_IDLETHREAD_STACKSIZE + 15) & ~15)
#define IDLETHREAD_STACKWORDS (IDLETHREAD_STACKSIZE >> 2)

/* In the Xtensa model, the state is saved in stack,
* only a reference stored in TCB.
*/

#define xtensa_savestate(regs) ((regs) = up_current_regs())
#define xtensa_restorestate(regs) up_set_current_regs(regs)

/* Context switching via system calls ***************************************/

#define xtensa_context_restore(regs)\
Expand Down
12 changes: 2 additions & 10 deletions arch/xtensa/src/common/xtensa_cpupause.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,7 @@ int up_cpu_paused_save(void)
sched_note_cpu_paused(tcb);
#endif

/* Save the current context at current_regs into the TCB at the head
* of the assigned task list for this CPU.
*/

xtensa_savestate(tcb->xcp.regs);
UNUSED(tcb);

return OK;
}
Expand Down Expand Up @@ -186,11 +182,7 @@ int up_cpu_paused_restore(void)

nxsched_resume_scheduler(tcb);

/* Then switch contexts. Any necessary address environment changes
* will be made when the interrupt returns.
*/

xtensa_restorestate(tcb->xcp.regs);
UNUSED(tcb);

return OK;
}
Expand Down
22 changes: 13 additions & 9 deletions arch/xtensa/src/common/xtensa_irqdispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@

uint32_t *xtensa_irq_dispatch(int irq, uint32_t *regs)
{
struct tcb_s *tcb = this_task();

#ifdef CONFIG_SUPPRESS_INTERRUPTS
board_autoled_on(LED_INIRQ);
PANIC();
Expand All @@ -62,15 +64,23 @@ uint32_t *xtensa_irq_dispatch(int irq, uint32_t *regs)

up_set_current_regs(regs);

if (irq != XTENSA_IRQ_SWINT)
{
/* we are not trigger by syscall */

tcb->xcp.regs = regs;
}

/* Deliver the IRQ */

irq_dispatch(irq, regs);
tcb = this_task();

/* Check for a context switch. If a context switch occurred, then
* current_regs will have a different value than it did on entry.
*/

if (regs != up_current_regs())
if (regs != tcb->xcp.regs)
{
#ifdef CONFIG_ARCH_ADDRENV
/* Make sure that the address environment for the previously
Expand All @@ -92,14 +102,8 @@ uint32_t *xtensa_irq_dispatch(int irq, uint32_t *regs)
* crashes.
*/

g_running_tasks[this_cpu()] = this_task();
}

/* Restore the cpu lock */

if (regs != up_current_regs())
{
regs = up_current_regs();
g_running_tasks[this_cpu()] = tcb;
regs = tcb->xcp.regs;
}

/* Set current_regs to NULL to indicate that we are no longer in an
Expand Down
Loading

0 comments on commit 7ebe788

Please sign in to comment.