evolution124 opened a new issue, #19680:
URL: https://github.com/apache/nuttx/issues/19680

   ### Description / Steps to reproduce the issue
   
   on latest nuttx, configure with nsh64 & smp & and CONFIG_SMP_NCPU is 2.
   The issue is after adjust task's affinity, the task may became an orphan 
task which will never be scheduled to run any more.
   
   ### 1. The setup are like bellow:
   1.1) M is main task
   1.2) T0, T1 are task0 and task1
   2.3) C0, C1 are CPU0 and CPU1
   
   ### 2. The issue produced as bellow.
   2.1) main task create two task, t0 and t1. 
       **M task** 
           **-> pthread_create(t0, t0_task_entry ....)**
           **-> pthread_create(t1, t1_task_entry ....)**
   
   2.2) sometimes, t0 and t1 may scheduled to CPU1
        **t0 running on CPU1**
                **-> t0  set affinity to CPU0 (by sched_setaffinity)**
        **t1 is pending on CPU1 because t0 is running.**
   
   2.3)  schedule tick came, t0 goto g_readytorun
           **t0 switching out to g_readytorun tasklist(the affinity is CPU0, 
not CPU1, so in SMP goto g_readylist)**
           **t1 switching in, set t1's affinity to CPU1 (by sched_setaffinity)**
   
   2.4) because prevsiously all the tasks are created on CPU1, so CPU0 only 
have idle task, which do not have TCB_FLAG_SCHED_RR  flag, then t0 in 
g_readytorun task list became an orphan task(no schedule running). Code as 
bellow.
   
   ```
   //./nuttxspace/nuttx/sched/sched/sched_processtick.c
   
   static inline void nxsched_cpu_scheduler(int cpu)
   {
     FAR struct tcb_s *rtcb = current_task(cpu);
     ...
     //idle task won't branch to run nxsched_process_roundrobin(...)
     if ((rtcb->flags & TCB_FLAG_POLICY_MASK) == TCB_FLAG_SCHED_RR) 
       {
           //this will not be called because the rtcb is idle task which does 
not have TCB_FLAG_SCHED_RR flag.
           **nxsched_process_roundrobin(rtcb, 1, false);
       }
   ```
           
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   ### On which OS does this issue occur?
   
   [OS: Linux]
   
   ### What is the version of your OS?
   
   Ubuntu 22.04.4 LTS
   
   ### NuttX Version
   
   375462322eeb6d2da57e6dff84c747a56bfa2eef (origin/master)
   
   ### Issue Architecture
   
   [Arch: risc-v]
   
   ### Issue Area
   
   [Area: OS Components], [Area: Kernel]
   
   ### Host information
   
   qemu to run the rv64
   qemu-system-riscv64 --version
   QEMU emulator version 10.0.0
   Copyright (c) 2003-2025 Fabrice Bellard and the QEMU Project developers
   
   ### Verification
   
   - [x] I have verified before submitting the report.


-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to