patacongo commented on code in PR #11226:
URL: https://github.com/apache/nuttx/pull/11226#discussion_r1399759336


##########
sched/sched/sched_removereadytorun.c:
##########
@@ -194,22 +194,15 @@ bool nxsched_remove_readytorun(FAR struct tcb_s *rtcb, 
bool merge)
        * next tcb in the assigned task list (nxttcb) or a TCB in the
        * g_readytorun list.  We can only select a task from that list if
        * the affinity mask includes the current CPU.
-       *
-       * If pre-emption is locked or another CPU is in a critical section,
-       * then use the 'nxttcb' which will probably be the IDLE thread.
-       * REVISIT: What if it is not the IDLE thread?
        */

Review Comment:
   The IDLE thread will be the one at the end of the list of assigned threads.  
Normally there are only two tasks in the assigned task list:  The current 
running task and the IDLE thread.
   
   But if the thread has been "assigned" to the CPU via one of the 
setaffinity() functions, then the next task will NEVER be the IDLE thread.  In 
that case, there would be three or more tasks in the assigned list:  The 
current running task , all tasks assigned to the CPU, and finally the IDLE 
thread.
   
   The safest and fastest way to find the the IDLE task is to use the tail 
pointer of the doubly linked task list.
   
   It looks like this works correctly, but is not the most efficient since you 
don't have to search for the IDLE thread:
   
          for (rtrtcb = (FAR struct tcb_s *)g_readytorun.head;
                rtrtcb != NULL && !CPU_ISSET(cpu, &rtrtcb->affinity) ;
                rtrtcb = rtrtcb->flink);
   
   



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