xiaoxiang781216 commented on code in PR #7599: URL: https://github.com/apache/incubator-nuttx/pull/7599#discussion_r1026183408
########## arch/xtensa/src/common/xtensa_blocktask.c: ########## @@ -45,108 +45,69 @@ * Name: up_block_task * * Description: - * The currently executing task at the head of the ready to run list must - * be stopped. Save its context and move it to the inactive list - * specified by task_state. + * The currently executing task has already removed from ready-to-run list. + * Save its context and switch to the next running task at the head of the + * ready-to-run list. * * Input Parameters: - * tcb: Refers to a task in the ready-to-run list (normally the task at - * the head of the list). It must be stopped, its context saved and - * moved into one of the waiting task lists. If it was the task at the - * head of the ready-to-run list, then a context switch to the new - * ready to run task must be performed. - * task_state: Specifies which waiting task list should hold the blocked - * task TCB. + * rtcb: Reference to the running task which is different to the + * task (next running task) at the head of the list. * ****************************************************************************/ -void up_block_task(struct tcb_s *tcb, tstate_t task_state) +void up_block_task(struct tcb_s *rtcb) { - struct tcb_s *rtcb = this_task(); - bool switch_needed; + /* Update scheduler parameters */ - /* Verify that the context switch can be performed */ + nxsched_suspend_scheduler(rtcb); - DEBUGASSERT((tcb->task_state >= FIRST_READY_TO_RUN_STATE) && - (tcb->task_state <= LAST_READY_TO_RUN_STATE)); + /* Are we in an interrupt handler? */ - /* Remove the tcb task from the ready-to-run list. If we are blocking the - * task at the head of the task list (the most likely case), then a - * context switch to the next ready-to-run task is needed. In this case, - * it should also be true that rtcb == tcb. - */ - - switch_needed = nxsched_remove_readytorun(tcb); - - /* Add the task to the specified blocked task list */ - - nxsched_add_blocked(tcb, (tstate_t)task_state); - - /* If there are any pending tasks, then add them to the ready-to-run - * task list now - */ - - if (g_pendingtasks.head) - { - switch_needed |= nxsched_merge_pending(); - } - - /* Now, perform the context switch if one is needed */ - - if (switch_needed) + if (CURRENT_REGS) { - /* Update scheduler parameters */ - - nxsched_suspend_scheduler(rtcb); - - /* Are we in an interrupt handler? */ + /* Yes, then we have to do things differently. + * Just copy the CURRENT_REGS into the OLD rtcb. + */ - if (CURRENT_REGS) - { - /* Yes, then we have to do things differently. - * Just copy the CURRENT_REGS into the OLD rtcb. - */ + xtensa_savestate(rtcb->xcp.regs); - xtensa_savestate(rtcb->xcp.regs); + /* Restore the exception context of the rtcb at the (new) head + * of the ready-to-run task list. + */ - /* Restore the exception context of the rtcb at the (new) head - * of the ready-to-run task list. - */ + rtcb = this_task(); - rtcb = this_task(); + /* Reset scheduler parameters */ - /* Reset scheduler parameters */ + nxsched_resume_scheduler(rtcb); - nxsched_resume_scheduler(rtcb); + /* Then switch contexts. Any necessary address environment + * changes will be made when the interrupt returns. + */ - /* Then switch contexts. Any necessary address environment - * changes will be made when the interrupt returns. - */ - - xtensa_restorestate(rtcb->xcp.regs); - } + xtensa_restorestate(rtcb->xcp.regs); + } - /* No, then we will need to perform the user context switch */ + /* No, then we will need to perform the user context switch */ - else - { - struct tcb_s *nexttcb = this_task(); + else + { + struct tcb_s *nexttcb = this_task(); - /* Switch context to the context of the task at the head of the - * ready to run list. - */ + /* Switch context to the context of the task at the head of the + * ready to run list. + */ - nxsched_resume_scheduler(nexttcb); + nxsched_resume_scheduler(nexttcb); Review Comment: I guess xtensa doesn't support kernel mode yet. And the origin code doens't invoke group_addrenv, it's better to not add group_addrenv in this patch. -- 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: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org