Skip to content

[kernel][src] fix: patch for the time slice scheduler #6645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 47 additions & 23 deletions src/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,6 @@ void rt_schedule(void)
{
rt_schedule_insert_thread(current_thread);
}
current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK;
}
to_thread->oncpu = cpu_id;
if (to_thread != current_thread)
Expand Down Expand Up @@ -455,7 +454,6 @@ void rt_schedule(void)
{
need_insert_from_thread = 1;
}
rt_current_thread->stat &= ~RT_THREAD_STAT_YIELD_MASK;
}

if (to_thread != rt_current_thread)
Expand Down Expand Up @@ -669,9 +667,6 @@ void rt_schedule_insert_thread(struct rt_thread *thread)
goto __exit;
}

/* READY thread, insert to ready queue */
thread->stat = RT_THREAD_READY | (thread->stat & ~RT_THREAD_STAT_MASK);

cpu_id = rt_hw_cpu_id();
bind_cpu = thread->bind_cpu ;

Expand All @@ -683,16 +678,24 @@ void rt_schedule_insert_thread(struct rt_thread *thread)
#endif /* RT_THREAD_PRIORITY_MAX > 32 */
rt_thread_ready_priority_group |= thread->number_mask;

/* there is no time slices left(YIELD), inserting thread before ready list*/
if((thread->stat & RT_THREAD_STAT_YIELD_MASK) != 0)
if((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_RUNNING)
{
/* there is no time slices left(YIELD), inserting thread before ready list*/
if((thread->stat & RT_THREAD_STAT_YIELD_MASK) == RT_THREAD_STAT_YIELD)
{
rt_list_insert_before(&(rt_thread_priority_table[thread->current_priority]),
&(thread->tlist));
}
/* there are some time slices left, inserting thread after ready list to schedule it firstly at next time*/
else
{
rt_list_insert_after(&(rt_thread_priority_table[thread->current_priority]),
&(thread->tlist));
}
}
/* there are some time slices left, inserting thread after ready list to schedule it firstly at next time*/
else
{
rt_list_insert_after(&(rt_thread_priority_table[thread->current_priority]),
rt_list_insert_before(&(rt_thread_priority_table[thread->current_priority]),
&(thread->tlist));
}

Expand All @@ -708,13 +711,21 @@ void rt_schedule_insert_thread(struct rt_thread *thread)
#endif /* RT_THREAD_PRIORITY_MAX > 32 */
pcpu->priority_group |= thread->number_mask;

/* there is no time slices left(YIELD), inserting thread before ready list*/
if((thread->stat & RT_THREAD_STAT_YIELD_MASK) != 0)
if((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_RUNNING)
{
/* there is no time slices left(YIELD), inserting thread before ready list*/
if((thread->stat & RT_THREAD_STAT_YIELD_MASK) == RT_THREAD_STAT_YIELD)
{
rt_list_insert_before(&(rt_cpu_index(bind_cpu)->priority_table[thread->current_priority]),
&(thread->tlist));
&(thread->tlist));
}
/* there are some time slices left, inserting thread after ready list to schedule it firstly at next time*/
else
{
rt_list_insert_after(&(rt_cpu_index(bind_cpu)->priority_table[thread->current_priority]),
&(thread->tlist));
}
}
/* there are some time slices left, inserting thread after ready list to schedule it firstly at next time*/
else
{
rt_list_insert_after(&(rt_cpu_index(bind_cpu)->priority_table[thread->current_priority]),
Expand All @@ -727,7 +738,10 @@ void rt_schedule_insert_thread(struct rt_thread *thread)
rt_hw_ipi_send(RT_SCHEDULE_IPI, cpu_mask);
}
}

/* clear YIELD status*/
thread->stat &= ~RT_THREAD_STAT_YIELD_MASK;
/* READY thread, insert to ready queue */
thread->stat = RT_THREAD_READY | (thread->stat & ~RT_THREAD_STAT_MASK);
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("insert thread[%.*s], the priority: %d\n",
RT_NAME_MAX, thread->name, thread->current_priority));

Expand All @@ -752,21 +766,31 @@ void rt_schedule_insert_thread(struct rt_thread *thread)
goto __exit;
}

/* READY thread, insert to ready queue */
thread->stat = RT_THREAD_READY | (thread->stat & ~RT_THREAD_STAT_MASK);
/* there is no time slices left(YIELD), inserting thread before ready list*/
if((thread->stat & RT_THREAD_STAT_YIELD_MASK) != 0)
if((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_RUNNING)
{
rt_list_insert_before(&(rt_thread_priority_table[thread->current_priority]),
&(thread->tlist));
/* there is no time slices left(YIELD), inserting thread before ready list*/
if((thread->stat & RT_THREAD_STAT_YIELD_MASK) == RT_THREAD_STAT_YIELD)
{
rt_list_insert_before(&(rt_thread_priority_table[thread->current_priority]),
&(thread->tlist));
}
/* there are some time slices left, inserting thread after ready list to schedule it firstly at next time*/
else
{
rt_list_insert_after(&(rt_thread_priority_table[thread->current_priority]),
&(thread->tlist));
}
}
/* there are some time slices left, inserting thread after ready list to schedule it firstly at next time*/
else
{
rt_list_insert_after(&(rt_thread_priority_table[thread->current_priority]),
rt_list_insert_before(&(rt_thread_priority_table[thread->current_priority]),
&(thread->tlist));
}

}
/* clear YIELD status*/
thread->stat &= ~RT_THREAD_STAT_YIELD_MASK;
/* READY thread, insert to ready queue */
thread->stat = RT_THREAD_READY | (thread->stat & ~RT_THREAD_STAT_MASK);
RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("insert thread[%.*s], the priority: %d\n",
RT_NAME_MAX, thread->name, thread->current_priority));

Expand Down