Skip to content

Commit

Permalink
sched: replace sync pause with async pause for nxtask_terminate
Browse files Browse the repository at this point in the history
reason:
In the kernel, we are planning to remove all occurrences of up_cpu_pause as one of the steps to
simplify the implementation of critical sections. The goal is to enable spin_lock_irqsave to encapsulate critical sections,
thereby facilitating the replacement of critical sections(big lock) with smaller spin_lock_irqsave(small lock)

Change-Id: Ie016191c03931f471424bb0fdc3fa4b86d91af3f
  • Loading branch information
hujun260 committed Sep 29, 2024
1 parent 7cf5e7c commit 1767403
Show file tree
Hide file tree
Showing 23 changed files with 91 additions and 143 deletions.
6 changes: 0 additions & 6 deletions arch/arm/src/common/arm_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ void up_exit(int status)
{
struct tcb_s *tcb = this_task();

/* Make sure that we are in a critical section with local interrupts.
* The IRQ state will be restored when the next task is started.
*/

enter_critical_section();

/* Destroy the task at the head of the ready to run list. */

nxtask_exit();
Expand Down
6 changes: 0 additions & 6 deletions arch/arm64/src/common/arm64_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ void up_exit(int status)
struct tcb_s *tcb = this_task();
UNUSED(status);

/* Make sure that we are in a critical section with local interrupts.
* The IRQ state will be restored when the next task is started.
*/

enter_critical_section();

/* Destroy the task at the head of the ready to run list. */
#ifdef CONFIG_ARCH_FPU
arm64_destory_fpu(tcb);
Expand Down
6 changes: 0 additions & 6 deletions arch/avr/src/common/avr_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ void up_exit(int status)
{
struct tcb_s *tcb = this_task();

/* Make sure that we are in a critical section with local interrupts.
* The IRQ state will be restored when the next task is started.
*/

enter_critical_section();

/* Destroy the task at the head of the ready to run list. */

nxtask_exit();
Expand Down
6 changes: 0 additions & 6 deletions arch/hc/src/common/hc_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ void up_exit(int status)
{
struct tcb_s *tcb = this_task();

/* Make sure that we are in a critical section with local interrupts.
* The IRQ state will be restored when the next task is started.
*/

enter_critical_section();

/* Destroy the task at the head of the ready to run list. */

nxtask_exit();
Expand Down
6 changes: 0 additions & 6 deletions arch/mips/src/common/mips_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ void up_exit(int status)
{
struct tcb_s *tcb = this_task();

/* Make sure that we are in a critical section with local interrupts.
* The IRQ state will be restored when the next task is started.
*/

enter_critical_section();

/* Destroy the task at the head of the ready to run list. */

nxtask_exit();
Expand Down
6 changes: 0 additions & 6 deletions arch/misoc/src/lm32/lm32_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ void up_exit(int status)
{
struct tcb_s *tcb = this_task();

/* Make sure that we are in a critical section with local interrupts.
* The IRQ state will be restored when the next task is started.
*/

enter_critical_section();

/* Destroy the task at the head of the ready to run list. */

nxtask_exit();
Expand Down
6 changes: 0 additions & 6 deletions arch/misoc/src/minerva/minerva_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ void up_exit(int status)
{
struct tcb_s *tcb = this_task();

/* Make sure that we are in a critical section with local interrupts. The
* IRQ state will be restored when the next task is started.
*/

enter_critical_section();

/* Destroy the task at the head of the ready to run list. */

nxtask_exit();
Expand Down
6 changes: 0 additions & 6 deletions arch/or1k/src/common/or1k_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ void up_exit(int status)
{
struct tcb_s *tcb = this_task();

/* Make sure that we are in a critical section with local interrupts.
* The IRQ state will be restored when the next task is started.
*/

enter_critical_section();

/* Destroy the task at the head of the ready to run list. */

nxtask_exit();
Expand Down
6 changes: 0 additions & 6 deletions arch/renesas/src/common/renesas_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ void up_exit(int status)
{
struct tcb_s *tcb = this_task();

/* Make sure that we are in a critical section with local interrupts.
* The IRQ state will be restored when the next task is started.
*/

enter_critical_section();

/* Destroy the task at the head of the ready to run list. */

nxtask_exit();
Expand Down
6 changes: 0 additions & 6 deletions arch/risc-v/src/common/riscv_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ void up_exit(int status)
{
struct tcb_s *tcb = this_task();

/* Make sure that we are in a critical section with local interrupts.
* The IRQ state will be restored when the next task is started.
*/

enter_critical_section();

/* Destroy the task at the head of the ready to run list. */

nxtask_exit();
Expand Down
6 changes: 0 additions & 6 deletions arch/sim/src/sim/sim_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ void up_exit(int status)
{
struct tcb_s *tcb;

/* Make sure that we are in a critical section with local interrupts.
* The IRQ state will be restored when the next task is started.
*/

enter_critical_section();

/* Destroy the task at the head of the ready to run list. */

nxtask_exit();
Expand Down
6 changes: 0 additions & 6 deletions arch/sparc/src/common/sparc_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ void up_exit(int status)
{
struct tcb_s *tcb = this_task();

/* Make sure that we are in a critical section with local interrupts.
* The IRQ state will be restored when the next task is started.
*/

(void)enter_critical_section();

/* Update scheduler parameters */

nxsched_suspend_scheduler(tcb);
Expand Down
6 changes: 0 additions & 6 deletions arch/tricore/src/common/tricore_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ void up_exit(int status)
{
struct tcb_s *tcb = this_task();

/* Make sure that we are in a critical section with local interrupts.
* The IRQ state will be restored when the next task is started.
*/

enter_critical_section();

/* Destroy the task at the head of the ready to run list. */

nxtask_exit();
Expand Down
6 changes: 0 additions & 6 deletions arch/x86/src/common/x86_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ void up_exit(int status)
{
struct tcb_s *tcb = this_task();

/* Make sure that we are in a critical section with local interrupts.
* The IRQ state will be restored when the next task is started.
*/

enter_critical_section();

/* Destroy the task at the head of the ready to run list. */

nxtask_exit();
Expand Down
6 changes: 0 additions & 6 deletions arch/x86_64/src/common/x86_64_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ void up_exit(int status)
{
struct tcb_s *tcb;

/* Make sure that we are in a critical section with local interrupts.
* The IRQ state will be restored when the next task is started.
*/

enter_critical_section();

/* Destroy the task at the head of the ready to run list. */

nxtask_exit();
Expand Down
6 changes: 0 additions & 6 deletions arch/xtensa/src/common/xtensa_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ void up_exit(int status)
{
struct tcb_s *tcb = this_task();

/* Make sure that we are in a critical section with local interrupts.
* The IRQ state will be restored when the next task is started.
*/

enter_critical_section();

/* Destroy the task at the head of the ready to run list. */

nxtask_exit();
Expand Down
6 changes: 0 additions & 6 deletions arch/z16/src/common/z16_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ void up_exit(int status)
{
FAR struct tcb_s *tcb = this_task();

/* Make sure that we are in a critical section with local interrupts.
* The IRQ state will be restored when the next task is started.
*/

enter_critical_section();

/* Destroy the task at the head of the ready to run list. */

nxtask_exit();
Expand Down
6 changes: 0 additions & 6 deletions arch/z80/src/common/z80_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ void up_exit(int status)
{
FAR struct tcb_s *tcb = this_task();

/* Make sure that we are in a critical section with local interrupts.
* The IRQ state will be restored when the next task is started.
*/

enter_critical_section();

/* Destroy the task at the head of the ready to run list. */

nxtask_exit();
Expand Down
8 changes: 8 additions & 0 deletions sched/pthread/pthread_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ void nx_pthread_exit(FAR void *exit_value)
_exit(EXIT_FAILURE);
}

/* Make sure that we are in a critical section with local interrupts.
* The IRQ state will be restored when the next task is started.
*/

enter_critical_section();

/* Perform common task termination logic. This will get called again later
* through logic kicked off by up_exit().
*
Expand All @@ -103,6 +109,8 @@ void nx_pthread_exit(FAR void *exit_value)
* once, or does something very naughty.
*/

tcb->flags |= TCB_FLAG_EXIT_PROCESSING;

nxtask_exithook(tcb, status);

up_exit(EXIT_SUCCESS);
Expand Down
8 changes: 8 additions & 0 deletions sched/task/exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ void _exit(int status)

#endif

/* Make sure that we are in a critical section with local interrupts.
* The IRQ state will be restored when the next task is started.
*/

enter_critical_section();

/* Perform common task termination logic. This will get called again later
* through logic kicked off by up_exit().
*
Expand All @@ -85,6 +91,8 @@ void _exit(int status)
* once, or does something very naughty.
*/

tcb->flags |= TCB_FLAG_EXIT_PROCESSING;

nxtask_exithook(tcb, status);

up_exit(status);
Expand Down
12 changes: 2 additions & 10 deletions sched/task/task_exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,6 @@ int nxtask_exit(void)

rtcb->task_state = TSTATE_TASK_READYTORUN;

/* Move the TCB to the specified blocked task list and delete it. Calling
* nxtask_terminate with non-blocking true will suppress atexit() and
* on-exit() calls and will cause buffered I/O to fail to be flushed. The
* former is required _exit() behavior; the latter is optional _exit()
* behavior.
*/

nxsched_add_blocked(dtcb, TSTATE_TASK_INACTIVE);

#ifdef CONFIG_SMP
/* NOTE:
* During nxtask_terminate(), enter_critical_section() will be called
Expand All @@ -165,7 +156,8 @@ int nxtask_exit(void)
rtcb->irqcount++;
#endif

ret = nxtask_terminate(dtcb->pid);
dtcb->task_state = TSTATE_TASK_INACTIVE;
ret = nxsched_release_tcb(dtcb, dtcb->flags & TCB_FLAG_TTYPE_MASK);

#ifdef CONFIG_SMP
rtcb->irqcount--;
Expand Down
22 changes: 1 addition & 21 deletions sched/task/task_exithook.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,7 @@ void nxtask_exithook(FAR struct tcb_s *tcb, int status)
* called. If that bit is set, then just exit doing nothing more..
*/

if ((tcb->flags & TCB_FLAG_EXIT_PROCESSING) != 0)
{
return;
}
DEBUGASSERT((tcb->flags & TCB_FLAG_EXIT_PROCESSING) != 0);

nxsched_dumponexit();

Expand All @@ -442,12 +439,6 @@ void nxtask_exithook(FAR struct tcb_s *tcb, int status)

nxtask_recover(tcb);

/* NOTE: signal handling needs to be done in a criticl section */

#ifdef CONFIG_SMP
irqstate_t flags = enter_critical_section();
#endif

/* Send the SIGCHLD signal to the parent task group */

nxtask_signalparent(tcb, status);
Expand Down Expand Up @@ -476,15 +467,4 @@ void nxtask_exithook(FAR struct tcb_s *tcb, int status)
umm_memdump(&dump);
}
#endif

/* This function can be re-entered in certain cases. Set a flag
* bit in the TCB to not that we have already completed this exit
* processing.
*/

tcb->flags |= TCB_FLAG_EXIT_PROCESSING;

#ifdef CONFIG_SMP
leave_critical_section(flags);
#endif
}
Loading

0 comments on commit 1767403

Please sign in to comment.