diff options
| author | blta <[email protected]> | 2022-08-06 10:00:09 +0800 |
|---|---|---|
| committer | Man, Jianting (Meco) <[email protected]> | 2022-08-16 00:05:56 -0400 |
| commit | 7750358bed31c6eab5d25a89c7b2f256c87f932d (patch) | |
| tree | 67a5acee18b127b8d1080957bca4f00d81a7d3e6 | |
| parent | dd94198bd6acaaf03324774fe415df3ca379d1f5 (diff) | |
[kernel/schedule] fix the time slice issue
| -rw-r--r-- | src/scheduler.c | 44 |
1 files changed, 37 insertions, 7 deletions
diff --git a/src/scheduler.c b/src/scheduler.c index 0f4cbcf94d..8148c144a4 100644 --- a/src/scheduler.c +++ b/src/scheduler.c @@ -683,8 +683,19 @@ void rt_schedule_insert_thread(struct rt_thread *thread) #endif /* RT_THREAD_PRIORITY_MAX > 32 */ rt_thread_ready_priority_group |= thread->number_mask; - 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) != 0) + { + 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)); + } + cpu_mask = RT_CPU_MASK ^ (1 << cpu_id); rt_hw_ipi_send(RT_SCHEDULE_IPI, cpu_mask); } @@ -697,8 +708,18 @@ void rt_schedule_insert_thread(struct rt_thread *thread) #endif /* RT_THREAD_PRIORITY_MAX > 32 */ pcpu->priority_group |= thread->number_mask; - rt_list_insert_before(&(rt_cpu_index(bind_cpu)->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) != 0) + { + rt_list_insert_before(&(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]), + &(thread->tlist)); + } if (cpu_id != bind_cpu) { @@ -733,9 +754,18 @@ void rt_schedule_insert_thread(struct rt_thread *thread) /* READY thread, insert to ready queue */ thread->stat = RT_THREAD_READY | (thread->stat & ~RT_THREAD_STAT_MASK); - /* insert thread to ready list */ - 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) != 0) + { + 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)); + } RT_DEBUG_LOG(RT_DEBUG_SCHEDULER, ("insert thread[%.*s], the priority: %d\n", RT_NAME_MAX, thread->name, thread->current_priority)); |
