ZhengweiZhu commented on issue #2983:
URL: https://github.com/apache/brpc/issues/2983#issuecomment-3388228204

   > > Jumping precedes tracing, from the tracer's perspective the current 
implementation set m->traced = true first, then find its status 
TASK_STATUS_JUMPING and block at WaitForJumping(m). When the bthread is about 
to jumping to run, it finds it is traced so block at WaitForTracing(m).
   > 
   > In this scenario, bthread first locks and sets status to 
TASK_STATUS_JUMPING. At this time, tracing=false, so WaitForTracing() will not 
be called.
   > 
   > 
[brpc/src/bthread/task_tracer.cpp](https://github.com/apache/brpc/blob/4eeb5e260af165291f95f30f0fa64f9ff67ba192/src/bthread/task_tracer.cpp#L139-L163)
   > 
   > Lines 139 to 163 in 
[4eeb5e2](/apache/brpc/commit/4eeb5e260af165291f95f30f0fa64f9ff67ba192)
   > 
   >      bool tracing; 
   >      { 
   >          BAIDU_SCOPED_LOCK(m->version_lock); 
   >          if (TASK_STATUS_UNKNOWN == m->status && TASK_STATUS_JUMPING == s) 
{ 
   >              // Do not update status for jumping when bthread is ending. 
   >              return; 
   >          } 
   >   
   >          tracing = m->traced; 
   >          // bthread is scheduled for the first time. 
   >          if (TASK_STATUS_READY == s || NULL == m->stack) { 
   >              m->status = TASK_STATUS_FIRST_READY; 
   >          } else { 
   >              m->status = s; 
   >          } 
   >          if (TASK_STATUS_CREATED == s) { 
   >              m->worker_tid = pthread_t{}; 
   >          } 
   >      } 
   >   
   >      // Make sure bthread does not jump stack when it is being traced. 
   >      if (tracing && TASK_STATUS_JUMPING == s) { 
   >          WaitForTracing(m); 
   >      } 
   >  }
   
   
   To clarify this, assume the bthread to be traced is A. The status of A is 
TASK_STATUS_JUMPING when A is jumping from OR jumping to, which relates to 
cur_meta and next_meta in sched_to. 
https://github.com/apache/brpc/blob/4eeb5e260af165291f95f30f0fa64f9ff67ba192/src/bthread/task_group.cpp#L754-L756
   The timeline is: 
   t1: the first time as traced is false so 
g->_control->_task_tracer.set_status(TASK_STATUS_JUMPING, cur_meta) succeeds
   t2: the tracer starts to trace bthread A (which is in TASK_STATUS_JUMPING) 
and set A->traced to true and blocks at WaitForJumping
   t3: the A is jumping to and 
g->_control->_task_tracer.set_status(TASK_STATUS_JUMPING, next_meta) blocks at 
WaitForTracing as its traced is already set to true by tracer and its status is 
always TASK_STATUS_JUMPING.
   


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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to