sched/sched: address performance concerns for sched_lock in non-SMP case
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
This commit is contained in:
parent
e3ca288087
commit
7911a25774
@ -236,17 +236,12 @@ int sched_lock(void)
|
||||
|
||||
if (rtcb != NULL && !up_interrupt_context())
|
||||
{
|
||||
FAR struct tcb_s *ptcb;
|
||||
irqstate_t flags;
|
||||
|
||||
/* Catch attempts to increment the lockcount beyond the range of the
|
||||
* integer type.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(rtcb->lockcount < MAX_LOCK_COUNT);
|
||||
|
||||
flags = enter_critical_section();
|
||||
|
||||
/* A counter is used to support locking. This allows nested lock
|
||||
* operations on this thread (on any CPU)
|
||||
*/
|
||||
@ -269,22 +264,6 @@ int sched_lock(void)
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Move any tasks in the ready-to-run list to the pending task list
|
||||
* where they will not be available to run until the scheduler is
|
||||
* unlocked and nxsched_merge_pending() is called. So ready-to-run
|
||||
* will consist only from the currently runnig task and the idle task.
|
||||
*/
|
||||
|
||||
for (ptcb = rtcb->flink; ptcb && ptcb->flink; ptcb = rtcb->flink)
|
||||
{
|
||||
dq_rem((FAR dq_entry_t *)ptcb, &g_readytorun);
|
||||
|
||||
nxsched_add_prioritized(ptcb, &g_pendingtasks);
|
||||
ptcb->task_state = TSTATE_TASK_PENDING;
|
||||
}
|
||||
|
||||
leave_critical_section(flags);
|
||||
}
|
||||
|
||||
return OK;
|
||||
|
@ -142,6 +142,35 @@ static inline void nxsched_running_setpriority(FAR struct tcb_s *tcb,
|
||||
{
|
||||
FAR struct tcb_s *rtcb = this_task();
|
||||
|
||||
if (rtcb->lockcount > 0)
|
||||
{
|
||||
/* Move all tasks with the higher priority from the ready-to-run
|
||||
* list to the pending list.
|
||||
*/
|
||||
|
||||
do
|
||||
{
|
||||
bool check = nxsched_remove_readytorun(nxttcb, false);
|
||||
DEBUGASSERT(check == false);
|
||||
UNUSED(check);
|
||||
|
||||
nxsched_add_prioritized(nxttcb, &g_pendingtasks);
|
||||
nxttcb->task_state = TSTATE_TASK_PENDING;
|
||||
|
||||
#ifdef CONFIG_SMP
|
||||
nxttcb = nxsched_nexttcb(tcb);
|
||||
#else
|
||||
nxttcb = tcb->flink;
|
||||
#endif
|
||||
}
|
||||
while (sched_priority < nxttcb->sched_priority);
|
||||
|
||||
/* Change the task priority */
|
||||
|
||||
tcb->sched_priority = (uint8_t)sched_priority;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* A context switch will occur. */
|
||||
|
||||
if (nxsched_reprioritize_rtr(tcb, sched_priority))
|
||||
@ -149,6 +178,7 @@ static inline void nxsched_running_setpriority(FAR struct tcb_s *tcb,
|
||||
up_switch_context(this_task(), rtcb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Otherwise, we can just change priority since it has no effect */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user