mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 23:40:19 +08:00
nuttx/sched: remove nxsched_remove_readytorun from up_block_task
It takes about 10 cycles to obtain the task list according to the task status. In most cases, we know the task status, so we can directly add the task from the specified task list to reduce time consuming.
This commit is contained in:
committed by
Masayuki Ishikawa
parent
e54b602208
commit
08f7152d9f
@@ -45,112 +45,71 @@
|
||||
* 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 most be
|
||||
* stopped, its context saved and moved into one of the
|
||||
* waiting task lists. It it was the task at the head
|
||||
* of the ready-to-run list, then a context to the new
|
||||
* ready to run task must be performed.
|
||||
* task_state: Specifies which waiting task list should be
|
||||
* 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)
|
||||
if (CURRENT_REGS)
|
||||
{
|
||||
switch_needed |= nxsched_merge_pending();
|
||||
/* Yes, then we have to do things differently.
|
||||
* Just copy the CURRENT_REGS into the OLD rtcb.
|
||||
*/
|
||||
|
||||
up_savestate(rtcb->xcp.regs);
|
||||
|
||||
/* Restore the exception context of the rtcb at the (new) head
|
||||
* of the ready-to-run task list.
|
||||
*/
|
||||
|
||||
rtcb = this_task();
|
||||
|
||||
/* Reset scheduler parameters */
|
||||
|
||||
nxsched_resume_scheduler(rtcb);
|
||||
|
||||
/* Then switch contexts. Any necessary address environment
|
||||
* changes will be made when the interrupt returns.
|
||||
*/
|
||||
|
||||
up_restorestate(rtcb->xcp.regs);
|
||||
}
|
||||
|
||||
/* Now, perform the context switch if one is needed */
|
||||
/* No, then we will need to perform the user context switch */
|
||||
|
||||
if (switch_needed)
|
||||
else
|
||||
{
|
||||
/* Update scheduler parameters */
|
||||
/* Get the context of the task at the head of the ready to
|
||||
* run list.
|
||||
*/
|
||||
|
||||
nxsched_suspend_scheduler(rtcb);
|
||||
struct tcb_s *nexttcb = this_task();
|
||||
|
||||
/* Are we in an interrupt handler? */
|
||||
/* Reset scheduler parameters */
|
||||
|
||||
if (CURRENT_REGS)
|
||||
{
|
||||
/* Yes, then we have to do things differently.
|
||||
* Just copy the CURRENT_REGS into the OLD rtcb.
|
||||
*/
|
||||
nxsched_resume_scheduler(nexttcb);
|
||||
|
||||
up_savestate(rtcb->xcp.regs);
|
||||
/* Then switch contexts */
|
||||
|
||||
/* Restore the exception context of the rtcb at the (new) head
|
||||
* of the ready-to-run task list.
|
||||
*/
|
||||
up_switchcontext(rtcb->xcp.regs, nexttcb->xcp.regs);
|
||||
|
||||
rtcb = this_task();
|
||||
|
||||
/* Reset scheduler parameters */
|
||||
|
||||
nxsched_resume_scheduler(rtcb);
|
||||
|
||||
/* Then switch contexts. Any necessary address environment
|
||||
* changes will be made when the interrupt returns.
|
||||
*/
|
||||
|
||||
up_restorestate(rtcb->xcp.regs);
|
||||
}
|
||||
|
||||
/* No, then we will need to perform the user context switch */
|
||||
|
||||
else
|
||||
{
|
||||
/* Get the context of the task at the head of the ready to
|
||||
* run list.
|
||||
*/
|
||||
|
||||
struct tcb_s *nexttcb = this_task();
|
||||
|
||||
/* Reset scheduler parameters */
|
||||
|
||||
nxsched_resume_scheduler(nexttcb);
|
||||
|
||||
/* Then switch contexts */
|
||||
|
||||
up_switchcontext(rtcb->xcp.regs, nexttcb->xcp.regs);
|
||||
|
||||
/* up_switchcontext forces a context switch to the task at the
|
||||
* head of the ready-to-run list. It does not 'return' in the
|
||||
* normal sense. When it does return, it is because the blocked
|
||||
* task is again ready to run and has execution priority.
|
||||
*/
|
||||
}
|
||||
/* up_switchcontext forces a context switch to the task at the
|
||||
* head of the ready-to-run list. It does not 'return' in the
|
||||
* normal sense. When it does return, it is because the blocked
|
||||
* task is again ready to run and has execution priority.
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +88,7 @@ void up_reprioritize_rtr(struct tcb_s *tcb, uint8_t priority)
|
||||
* remove the head of the ready to run list.
|
||||
*/
|
||||
|
||||
switch_needed = nxsched_remove_readytorun(tcb);
|
||||
switch_needed = nxsched_remove_readytorun(tcb, false);
|
||||
|
||||
/* Setup up the new task priority */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user