patacongo opened a new issue #3875:
URL: https://github.com/apache/incubator-nuttx/issues/3875
There are a few places in the code where there is a check if PID == 0 to
determine if a thread is an IDLE thread. This is wrong. These checks were all
corrected a few years back but we have grown several new bad checks.
Determining if a task is the IDLE thread by checking if pid == 0 is wrong
because it is not true in the SMP case where there are multiple IDLE tasks, one
for each CPU and the PID if these IDLE threads is not zero in all cases. Each
IDLE thask has a unique PID.
In most places, a foolproof check is that tcb->flink == NULL which is true
in all cases AFTER initialization when the TCB is placed in the ready-to-run
list (single CPU mode) or in the assigned tasks list(s) (SMP mode). That IDLE
task is always at the end of these lists and, hence, always has flink == NULL.
That rule, however, probably may apply early in initialization before the the
newly created IDLE task has been made ready to run ready-to-run.
IDLE threads could also be distinguished by having priority == 0 as well.
We might need to add a TDB_FLAG_IDLE_TASK flag to handle this case.
Here are a few possible cases and relevant comments that I found. Not all
of the checks for pid == 0 may be checks for the IDLE task. Many APIs accept
pid == 0 to mean the current PID:
arch/arm/src/arm/arm_initialstate.c: if (tcb->pid == 0)
arch/arm/src/armv6-m/arm_initialstate.c: if (tcb->pid == 0)
arch/arm/src/armv7-a/arm_initialstate.c: if (tcb->pid == 0)
arch/arm/src/armv7-m/arm_initialstate.c: if (tcb->pid == 0)
arch/arm/src/armv7-r/arm_initialstate.c: if (tcb->pid == 0)
arch/arm/src/armv8-m/arm_initialstate.c: if (tcb->pid == 0)
arch/avr/src/avr/up_initialstate.c: if (tcb->pid == 0)
arch/avr/src/avr32/up_initialstate.c: if (tcb->pid == 0)
arch/hc/src/m9s12/m9s12_initialstate.c: if (tcb->pid == 0)
arch/mips/src/mips32/mips_initialstate.c: if (tcb->pid == 0)
arch/misoc/src/lm32/lm32_initialstate.c: if (tcb->pid == 0)
arch/misoc/src/minerva/minerva_initialstate.c: if (tcb->pid == 0)
arch/or1k/src/common/up_initialstate.c: if (tcb->pid == 0)
arch/renesas/src/m16c/m16c_initialstate.c: if (tcb->pid == 0)
arch/renesas/src/rx65n/rx65n_initialstate.c: if (tcb->pid == 0)
arch/renesas/src/sh1/sh1_initialstate.c: if (tcb->pid == 0)
arch/risc-v/src/esp32c3/esp32c3_wifi_adapter.c: if (pid ==
0)
arch/risc-v/src/rv32im/riscv_initialstate.c: if (tcb->pid == 0)
arch/risc-v/src/rv64gc/riscv_initialstate.c: if (tcb->pid == 0)
arch/sim/src/sim/up_initialstate.c: if (tcb->pid == 0)
arch/x86/src/i486/up_initialstate.c: if (tcb->pid == 0)
arch/x86_64/src/intel64/up_initialstate.c: if (tcb->pid == 0)
arch/xtensa/src/common/xtensa_initialstate.c: if (tcb->pid == 0)
arch/xtensa/src/esp32/esp32_spiram.c: if (pid == 0 || pid == 1)
arch/xtensa/src/esp32/esp32_wifi_adapter.c: if (pid == 0)
arch/z80/src/z180/z180_initialstate.c: if (tcb->pid == 0)
arch/z80/src/z80/z80_initialstate.c: if (tcb->pid == 0)
include/nuttx/clock.h: * pid - The task ID of the thread of interest.
pid == 0 is IDLE thread.
sched/pthread/pthread_cancel.c: /* pid == 0 is the IDLE task (in a
single CPU configuration). Callers
sched/sched/sched_cpuload.c: * pid - The task ID of the thread of
interest. pid == 0 is the IDLE
sched/task/task_getpid.c: * pid == 0 must be running, and
sched/task/task_getppid.c: * pid == 0 must be running, and
sched/task/task_gettid.c: * pid == 0 must be running, and
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]