Page MenuHomeFreeBSD

D61448.1794544728.diff
No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None

D61448.1794544728.diff

diff --git a/sys/kern/sched_ule.c b/sys/kern/sched_ule.c
--- a/sys/kern/sched_ule.c
+++ b/sys/kern/sched_ule.c
@@ -1090,13 +1090,8 @@
if (td == NULL)
return (-1);
- /*
- * Although the run queue is locked the thread may be
- * blocked. We can not set the lock until it is unblocked.
- */
- thread_lock_block_wait(td);
- sched_rem(td);
THREAD_LOCKPTR_ASSERT(td, TDQ_LOCKPTR(from));
+ sched_rem(td);
td->td_lock = TDQ_LOCKPTR(to);
td_get_sched(td)->ts_cpu = cpu;
return (tdq_add(to, td, SRQ_YIELDING));
@@ -1266,8 +1261,8 @@
}
struct runq_steal_pred_data {
- struct thread *td;
- int cpu;
+ int cpu; /* Destination CPU. */
+ struct thread *td; /* Output. */
};
static bool
@@ -1277,7 +1272,17 @@
struct thread *td;
TAILQ_FOREACH(td, q, td_runq) {
- if (THREAD_CAN_MIGRATE(td) && THREAD_CAN_SCHED(td, d->cpu)) {
+ if (THREAD_CAN_MIGRATE(td) && THREAD_CAN_SCHED(td, d->cpu) &&
+ /*
+ * Because both the source and destination runqueues are
+ * locked while stealing, and waiting for the blocked lock
+ * cannot be done while the source is locked (deadlock
+ * possible with sched_switch()), we skip threads that
+ * are still blocked.
+ */
+ td->td_lock != &blocked_lock) {
+ THREAD_LOCKPTR_ASSERT(td,
+ TDQ_LOCKPTR(TDQ_CPU(td_get_sched(td)->ts_cpu)));
d->td = td;
return (true);
}
@@ -2885,13 +2890,16 @@
int lowpri;
TDQ_LOCK_ASSERT(tdq, MA_OWNED);
- THREAD_LOCK_BLOCKED_ASSERT(td, MA_OWNED);
+ THREAD_LOCKPTR_BLOCKED_ASSERT(td, TDQ_LOCKPTR(tdq));
KASSERT((td->td_inhibitors == 0),
- ("sched_add: trying to run inhibited thread"));
+ ("%s: trying to run inhibited thread", __func__));
KASSERT((TD_CAN_RUN(td) || TD_IS_RUNNING(td)),
- ("sched_add: bad thread state"));
+ ("%s: bad thread state", __func__));
KASSERT(td->td_flags & TDF_INMEM,
- ("sched_add: thread swapped out"));
+ ("%s: thread swapped out", __func__));
+ KASSERT(td_get_sched(td)->ts_cpu == TDQ_ID(tdq),
+ ("%s: Inconsistent 'ts_cpu' (%d) and 'tdq_id' (%d)", __func__,
+ td_get_sched(td)->ts_cpu, TDQ_ID(tdq)));
lowpri = tdq->tdq_lowpri;
if (td->td_priority < lowpri)

File Metadata

Mime Type
text/plain
Expires
Fri, Nov 13, 4:38 AM (21 h, 16 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
41685355
Default Alt Text
D61448.1794544728.diff (2 KB)

Event Timeline