patacongo edited a comment on issue #2935:
URL: 
https://github.com/apache/incubator-nuttx/issues/2935#issuecomment-803175480


   I believe that I understand the problem.  It is complex to explain.
   
   * The scheduler makes decisions based on transitions from from running to 
suspended states.  In this case, both thread 1 and thread 2 are started at the 
same time.
   * Thread 2 does not run initially because it is blocked by thread 1 which 
has higher HI priority.  The scheduler does not get any indication of this and, 
for all it knows, thread 2 is happily running.
   * There is special logic to detect this case when either the budget interval 
expires or when thread 2 is suspended.  In this case, thread 2's budget 
interval will expire without ever running.  The case that thread 2 never ran is 
handled by checking to see if thread 2 is still suspended at the end of the 
budget interval.  In this case, I believe that thread 2 is running at the time 
its budget interval expires due to a race condition, so the scheduler makes a 
bad decision:
   * When the budget intervals are the same for both thread 1 and thread 2, I 
suspect that thread 1 is processed first:  It drops its priority causing thread 
2 to run because it has the higher LO priority.
   * So when thread 2 is processed, it is already running and appears to the 
scheduler that it has always been running.  So its budget interval is ended, 
its priority is dropped, and it is receives no high priority budget interval.
   
   That is consistent with the condition we see that causes the failure (i.e., 
with both budget intervals the same) and with the counting that we see in 
collected data (no high priority counts).
   
   A solution would require additional state information to detect the case 
that thread 2 was not initially running.  There is already a 
sporadic->suspended that is set to true when the thread is started.  However, 
it is reset to false when thread 2 resumes (actually runs for the first time) 
so that information is lost.


-- 
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:
us...@infra.apache.org


Reply via email to