mirror of
https://github.com/apache/nuttx.git
synced 2026-09-27 18:58:27 +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
@@ -43,103 +43,62 @@
|
||||
* 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));
|
||||
/* TODO */
|
||||
|
||||
/* sinfo("Blocking TCB=%p\n", tcb); */
|
||||
|
||||
/* 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();
|
||||
ASSERT(false);
|
||||
}
|
||||
|
||||
/* Now, perform the context switch if one is needed */
|
||||
/* Copy the exception context into the TCB at the (old) head of the
|
||||
* ready-to-run Task list. if setjmp returns a non-zero
|
||||
* value, then this is really the previously running task restarting!
|
||||
*/
|
||||
|
||||
if (switch_needed)
|
||||
else if (!setjmp(rtcb->xcp.regs))
|
||||
{
|
||||
/* Update scheduler parameters */
|
||||
|
||||
nxsched_suspend_scheduler(rtcb);
|
||||
|
||||
/* TODO */
|
||||
|
||||
if (CURRENT_REGS)
|
||||
{
|
||||
ASSERT(false);
|
||||
}
|
||||
|
||||
/* Copy the exception context into the TCB at the (old) head of the
|
||||
* ready-to-run Task list. if setjmp returns a non-zero
|
||||
* value, then this is really the previously running task restarting!
|
||||
/* Restore the exception context of the rtcb at the (new) head
|
||||
* of the ready-to-run task list.
|
||||
*/
|
||||
|
||||
else if (!setjmp(rtcb->xcp.regs))
|
||||
{
|
||||
/* Restore the exception context of the rtcb at the (new) head
|
||||
* of the ready-to-run task list.
|
||||
*/
|
||||
rtcb = this_task();
|
||||
sinfo("New Active Task TCB=%p\n", rtcb);
|
||||
|
||||
rtcb = this_task();
|
||||
sinfo("New Active Task TCB=%p\n", rtcb);
|
||||
/* Reset scheduler parameters */
|
||||
|
||||
/* Reset scheduler parameters */
|
||||
nxsched_resume_scheduler(rtcb);
|
||||
|
||||
nxsched_resume_scheduler(rtcb);
|
||||
/* Restore the cpu lock */
|
||||
|
||||
/* Restore the cpu lock */
|
||||
restore_critical_section();
|
||||
|
||||
restore_critical_section();
|
||||
/* Then switch contexts */
|
||||
|
||||
/* Then switch contexts */
|
||||
longjmp(rtcb->xcp.regs, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The way that we handle signals in the simulation is kind of
|
||||
* a kludge. This would be unsafe in a truly multi-threaded,
|
||||
* interrupt driven environment.
|
||||
*/
|
||||
|
||||
longjmp(rtcb->xcp.regs, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* The way that we handle signals in the simulation is kind of
|
||||
* a kludge. This would be unsafe in a truly multi-threaded,
|
||||
* interrupt driven environment.
|
||||
*/
|
||||
|
||||
sim_sigdeliver();
|
||||
}
|
||||
sim_sigdeliver();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +87,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