arch: move [enter|leave]_critical_section

move [enter|leave]_critical_section to the same place for easy to understand
and call matching

Signed-off-by: hujun5 <hujun5@xiaomi.com>
This commit is contained in:
hujun5 2023-05-25 09:00:30 +08:00 committed by Alin Jerpelea
parent 5c9c518f7f
commit 68187b68af
18 changed files with 61 additions and 126 deletions

View File

@ -351,13 +351,6 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver)
#endif
}
/* Increment the IRQ lock count so that when the task is
* restarted, it will hold the IRQ spinlock.
*/
DEBUGASSERT(tcb->irqcount < INT16_MAX);
tcb->irqcount++;
/* NOTE: If the task runs on another CPU(cpu), adjusting
* global IRQ controls will be done in the pause handler
* on the CPU(cpu) by taking a critical section.
@ -403,13 +396,6 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver)
tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs +
XCPTCONTEXT_SIZE;
/* Increment the IRQ lock count so that when the task is restarted,
* it will hold the IRQ spinlock.
*/
DEBUGASSERT(tcb->irqcount < INT16_MAX);
tcb->irqcount++;
/* Then set up to vector to the trampoline with interrupts
* disabled. We must already be in privileged thread mode to be
* here.

View File

@ -63,6 +63,8 @@ void arm_sigdeliver(void)
*/
int16_t saved_irqcount;
enter_critical_section();
#endif
board_autoled_on(LED_SIGNAL);
@ -154,6 +156,10 @@ retry:
board_autoled_off(LED_SIGNAL);
#ifdef CONFIG_SMP
/* We need to keep the IRQ lock until task switching */
rtcb->irqcount++;
leave_critical_section((uint16_t)regs[REG_PRIMASK]);
rtcb->irqcount--;
#endif
arm_fullcontextrestore(regs);

View File

@ -349,13 +349,6 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver)
#endif
}
/* Increment the IRQ lock count so that when the task is
* restarted, it will hold the IRQ spinlock.
*/
DEBUGASSERT(tcb->irqcount < INT16_MAX);
tcb->irqcount++;
/* NOTE: If the task runs on another CPU(cpu), adjusting
* global IRQ controls will be done in the pause handler
* on the CPU(cpu) by taking a critical section.
@ -401,13 +394,6 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver)
tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs +
XCPTCONTEXT_SIZE;
/* Increment the IRQ lock count so that when the task is restarted,
* it will hold the IRQ spinlock.
*/
DEBUGASSERT(tcb->irqcount < INT16_MAX);
tcb->irqcount++;
/* Then set up to vector to the trampoline with interrupts
* disabled
*/

View File

@ -63,6 +63,8 @@ void arm_sigdeliver(void)
*/
int16_t saved_irqcount;
enter_critical_section();
#endif
board_autoled_on(LED_SIGNAL);
@ -152,6 +154,10 @@ retry:
board_autoled_off(LED_SIGNAL);
#ifdef CONFIG_SMP
/* We need to keep the IRQ lock until task switching */
rtcb->irqcount++;
leave_critical_section(regs[REG_CPSR]);
rtcb->irqcount--;
#endif
arm_fullcontextrestore(regs);

View File

@ -368,13 +368,6 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver)
#endif
}
/* Increment the IRQ lock count so that when the task is
* restarted, it will hold the IRQ spinlock.
*/
DEBUGASSERT(tcb->irqcount < INT16_MAX);
tcb->irqcount++;
/* NOTE: If the task runs on another CPU(cpu), adjusting
* global IRQ controls will be done in the pause handler
* on the CPU(cpu) by taking a critical section.
@ -420,13 +413,6 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver)
tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs +
XCPTCONTEXT_SIZE;
/* Increment the IRQ lock count so that when the task is restarted,
* it will hold the IRQ spinlock.
*/
DEBUGASSERT(tcb->irqcount < INT16_MAX);
tcb->irqcount++;
/* Then set up to vector to the trampoline with interrupts
* disabled. We must already be in privileged thread mode to be
* here.

View File

@ -63,6 +63,8 @@ void arm_sigdeliver(void)
*/
int16_t saved_irqcount;
enter_critical_section();
#endif
board_autoled_on(LED_SIGNAL);
@ -158,6 +160,14 @@ retry:
board_autoled_off(LED_SIGNAL);
#ifdef CONFIG_SMP
/* We need to keep the IRQ lock until task switching */
rtcb->irqcount++;
#ifdef CONFIG_ARMV7M_USEBASEPRI
leave_critical_section((uint8_t)regs[REG_BASEPRI]);
#else
leave_critical_section((uint16_t)regs[REG_PRIMASK]);
#endif
rtcb->irqcount--;
#endif
arm_fullcontextrestore(regs);

View File

@ -352,13 +352,6 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver)
#endif
}
/* Increment the IRQ lock count so that when the task is
* restarted, it will hold the IRQ spinlock.
*/
DEBUGASSERT(tcb->irqcount < INT16_MAX);
tcb->irqcount++;
/* NOTE: If the task runs on another CPU(cpu), adjusting
* global IRQ controls will be done in the pause handler
* on the CPU(cpu) by taking a critical section.
@ -404,13 +397,6 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver)
tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs +
XCPTCONTEXT_SIZE;
/* Increment the IRQ lock count so that when the task is restarted,
* it will hold the IRQ spinlock.
*/
DEBUGASSERT(tcb->irqcount < INT16_MAX);
tcb->irqcount++;
/* Then set up to vector to the trampoline with interrupts
* disabled
*/

View File

@ -63,6 +63,8 @@ void arm_sigdeliver(void)
*/
int16_t saved_irqcount;
enter_critical_section();
#endif
board_autoled_on(LED_SIGNAL);
@ -149,6 +151,10 @@ retry:
board_autoled_off(LED_SIGNAL);
#ifdef CONFIG_SMP
/* We need to keep the IRQ lock until task switching */
rtcb->irqcount++;
leave_critical_section(regs[REG_CPSR]);
rtcb->irqcount--;
#endif
arm_fullcontextrestore(regs);

View File

@ -368,13 +368,6 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver)
#endif
}
/* Increment the IRQ lock count so that when the task is
* restarted, it will hold the IRQ spinlock.
*/
DEBUGASSERT(tcb->irqcount < INT16_MAX);
tcb->irqcount++;
/* In an SMP configuration, the interrupt disable logic also
* involves spinlocks that are configured per the TCB irqcount
* field. This is logically equivalent to
@ -424,13 +417,6 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver)
tcb->xcp.regs[REG_SP] = (uint32_t)tcb->xcp.regs +
XCPTCONTEXT_SIZE;
/* Increment the IRQ lock count so that when the task is restarted,
* it will hold the IRQ spinlock.
*/
DEBUGASSERT(tcb->irqcount < INT16_MAX);
tcb->irqcount++;
/* Then set up to vector to the trampoline with interrupts
* disabled. We must already be in privileged thread mode to be
* here.

View File

@ -63,6 +63,8 @@ void arm_sigdeliver(void)
*/
int16_t saved_irqcount;
enter_critical_section();
#endif
board_autoled_on(LED_SIGNAL);
@ -158,6 +160,14 @@ retry:
board_autoled_off(LED_SIGNAL);
#ifdef CONFIG_SMP
/* We need to keep the IRQ lock until task switching */
rtcb->irqcount++;
#ifdef CONFIG_ARMV8M_USEBASEPRI
leave_critical_section((uint8_t)regs[REG_BASEPRI]);
#else
leave_critical_section((uint16_t)regs[REG_PRIMASK]);
#endif
rtcb->irqcount--;
#endif
arm_fullcontextrestore(regs);

View File

@ -310,13 +310,6 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver)
CURRENT_REGS = tcb->xcp.regs;
}
/* Increment the IRQ lock count so that when the task is
* restarted, it will hold the IRQ spinlock.
*/
DEBUGASSERT(tcb->irqcount < INT16_MAX);
tcb->irqcount++;
/* NOTE: If the task runs on another CPU(cpu), adjusting
* global IRQ controls will be done in the pause handler
* on the CPU(cpu) by taking a critical section.
@ -353,13 +346,6 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver)
/* create signal process context */
arm64_init_signal_process(tcb, NULL);
/* Increment the IRQ lock count so that when the task is restarted,
* it will hold the IRQ spinlock.
*/
DEBUGASSERT(tcb->irqcount < INT16_MAX);
tcb->irqcount++;
}
}
}

View File

@ -71,6 +71,7 @@ void arm64_sigdeliver(void)
struct regs_context *pctx =
(struct regs_context *)rtcb->xcp.saved_reg;
flags = (pctx->spsr & SPSR_DAIF_MASK);
enter_critical_section();
#endif
sinfo("rtcb=%p sigdeliver=%p sigpendactionq.head=%p\n",
@ -163,6 +164,10 @@ retry:
/* Then restore the correct state for this thread of execution. */
#ifdef CONFIG_SMP
/* We need to keep the IRQ lock until task switching */
rtcb->irqcount++;
leave_critical_section(flags);
rtcb->irqcount--;
#endif
arm64_fullcontextrestore(rtcb->xcp.regs);

View File

@ -359,13 +359,6 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver)
CURRENT_REGS[REG_INT_CTX] = int_ctx;
}
/* Increment the IRQ lock count so that when the task is
* restarted, it will hold the IRQ spinlock.
*/
DEBUGASSERT(tcb->irqcount < INT16_MAX);
tcb->irqcount++;
/* NOTE: If the task runs on another CPU(cpu), adjusting
* global IRQ controls will be done in the pause handler
* on the CPU(cpu) by taking a critical section.
@ -411,13 +404,6 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver)
tcb->xcp.regs[REG_SP] = (uintptr_t)tcb->xcp.regs +
XCPTCONTEXT_SIZE;
/* Increment the IRQ lock count so that when the task is restarted,
* it will hold the IRQ spinlock.
*/
DEBUGASSERT(tcb->irqcount < INT16_MAX);
tcb->irqcount++;
/* Then set up to vector to the trampoline with interrupts
* disabled. We must already be in privileged thread mode to be
* here.

View File

@ -64,6 +64,8 @@ void riscv_sigdeliver(void)
*/
int16_t saved_irqcount;
enter_critical_section();
#endif
board_autoled_on(LED_SIGNAL);
@ -153,6 +155,10 @@ retry:
board_autoled_off(LED_SIGNAL);
#ifdef CONFIG_SMP
/* We need to keep the IRQ lock until task switching */
rtcb->irqcount++;
leave_critical_section(regs[REG_INT_CTX]);
rtcb->irqcount--;
#endif
riscv_fullcontextrestore(regs);

View File

@ -297,13 +297,6 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver)
sparc_savestate(tcb->xcp.regs);
}
/* Increment the IRQ lock count so that when the task is
* restarted, it will hold the IRQ spinlock.
*/
DEBUGASSERT(tcb->irqcount < INT16_MAX);
tcb->irqcount++;
/* NOTE: If the task runs on another CPU(cpu), adjusting
* global IRQ controls will be done in the pause handler
* on the CPU(cpu) by taking a critical section.
@ -336,13 +329,6 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver)
tcb->xcp.saved_npc = CURRENT_REGS[REG_NPC];
tcb->xcp.saved_status = CURRENT_REGS[REG_PSR];
/* Increment the IRQ lock count so that when the task is restarted,
* it will hold the IRQ spinlock.
*/
DEBUGASSERT(tcb->irqcount < INT16_MAX);
tcb->irqcount++;
/* Then set up to vector to the trampoline with interrupts
* disabled. We must already be in privileged thread mode to be
* here.

View File

@ -72,6 +72,8 @@ void sparc_sigdeliver(void)
*/
int16_t saved_irqcount;
enter_critical_section();
#endif
board_autoled_on(LED_SIGNAL);
@ -203,6 +205,10 @@ retry:
board_autoled_off(LED_SIGNAL);
#ifdef CONFIG_SMP
/* We need to keep the IRQ lock until task switching */
rtcb->irqcount++;
leave_critical_section((regs[REG_PSR]));
rtcb->irqcount--;
#endif
sparc_fullcontextrestore(regs);

View File

@ -391,13 +391,6 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver)
#endif
}
/* Increment the IRQ lock count so that when the task is
* restarted, it will hold the IRQ spinlock.
*/
DEBUGASSERT(tcb->irqcount < INT16_MAX);
tcb->irqcount++;
/* NOTE: If the task runs on another CPU(cpu), adjusting
* global IRQ controls will be done in the pause handler
* on the CPU(cpu) by taking a critical section.
@ -442,13 +435,6 @@ void up_schedule_sigaction(struct tcb_s *tcb, sig_deliver_t sigdeliver)
tcb->xcp.regs[REG_A1] = (uint32_t)tcb->xcp.regs +
XCPTCONTEXT_SIZE;
/* Increment the IRQ lock count so that when the task is restarted,
* it will hold the IRQ spinlock.
*/
DEBUGASSERT(tcb->irqcount < INT16_MAX);
tcb->irqcount++;
/* Then set up to vector to the trampoline with interrupts
* disabled
*/

View File

@ -63,6 +63,8 @@ void xtensa_sig_deliver(void)
*/
int16_t saved_irqcount;
enter_critical_section();
#endif
board_autoled_on(LED_SIGNAL);
@ -151,6 +153,10 @@ retry:
board_autoled_off(LED_SIGNAL);
#ifdef CONFIG_SMP
/* We need to keep the IRQ lock until task switching */
rtcb->irqcount++;
leave_critical_section((regs[REG_PS]));
rtcb->irqcount--;
#endif
xtensa_context_restore(regs);