kernel/sched: Fix reschedule points in SMP
There were two related bugs when in SMP mode:
1. Underneath z_reschedule(), the code was inexplicably checking the
swap_ok flag on the current CPU to see if it was OK to preempt the
current thread, but reschedule is the DEFINITION of a schedule
point and we always want to swap, even if the current thread is
non-preemptible.
2. With similar symptoms: in k_yield() a previous fix correct the
queue handling for SMP, but it missed the case where a thread of
the SAME priority as _current was on the queue and would fail to
swap. Yielding must always add the current thread to the back of
the current priority.
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
diff --git a/kernel/sched.c b/kernel/sched.c
index a6929c3..b85e0c6 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -523,9 +523,6 @@
static inline int resched(u32_t key)
{
#ifdef CONFIG_SMP
- if (!_current_cpu->swap_ok) {
- return 0;
- }
_current_cpu->swap_ok = 0;
#endif
@@ -919,9 +916,9 @@
z_is_thread_queued(_current)) {
_priq_run_remove(&_kernel.ready_q.runq,
_current);
- _priq_run_add(&_kernel.ready_q.runq,
- _current);
}
+ _priq_run_add(&_kernel.ready_q.runq, _current);
+ z_mark_thread_as_queued(_current);
update_cache(1);
}
}