Commit b0158cc8 authored by Andy Ross's avatar Andy Ross Committed by Anas Nashif
Browse files

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: default avatarAndy Ross <andrew.j.ross@intel.com>
parent dba3555f
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -523,9 +523,6 @@ void z_thread_priority_set(struct k_thread *thread, int prio)
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 @@ void z_impl_k_yield(void)
			    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);
		}
	}