Page MenuHomeFreeBSD

D57829.diff
No OneTemporary

D57829.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
@@ -493,7 +493,7 @@
tdq_runq_add(struct tdq *tdq, struct thread *td, int flags)
{
struct td_sched *ts;
- u_char pri, idx;
+ int pri, idx; /* Must stay ints, see below. */
TDQ_LOCK_ASSERT(tdq, MA_OWNED);
THREAD_LOCK_BLOCKED_ASSERT(td, MA_OWNED);
@@ -520,15 +520,30 @@
idx = (RQ_PRI_TO_QUEUE_IDX(pri) - RQ_TS_POL_MIN +
tdq->tdq_ts_off) % RQ_TS_POL_MODULO;
/*
- * We avoid enqueuing low priority threads in the queue
- * that we are still draining, effectively shortening
- * the runqueue by one queue.
+ * We avoid enqueuing low priority threads in the queues
+ * we still have to drain. This effectively shortens
+ * the runqueue by a few queues (see update of
+ * 'tdq_ts_deq_off' in sched_clock()).
+ *
+ * The expressions that include differences below are
+ * measuring the "distance" from the dequeue offset to
+ * either 'idx' or the insertion offset modulo
+ * RQ_TS_POL_MODULO. It is necessary that these
+ * computations are performed with an 'int' type (else
+ * we would have to be conditional on whether the first
+ * term is greater or lower than the second, in the
+ * second case correcting the result with UCHAR_MAX %
+ * RQ_TS_POL_MODULO). Finally, adding RQ_TS_POL_MODULO
+ * before taking the modulo is to ensure the dividend is
+ * positive (we want a positive result).
*/
if (tdq->tdq_ts_deq_off != tdq->tdq_ts_off &&
- idx == tdq->tdq_ts_deq_off)
- /* Ensure the dividend is positive. */
- idx = (idx - 1 + RQ_TS_POL_MODULO) %
- RQ_TS_POL_MODULO;
+ (idx - tdq->tdq_ts_deq_off + RQ_TS_POL_MODULO) %
+ RQ_TS_POL_MODULO < ((int)tdq->tdq_ts_off -
+ tdq->tdq_ts_deq_off + RQ_TS_POL_MODULO) %
+ RQ_TS_POL_MODULO)
+ idx = (tdq->tdq_ts_deq_off - 1 +
+ RQ_TS_POL_MODULO) % RQ_TS_POL_MODULO;
}
/* Absolute queue index. */
idx += RQ_TS_POL_MIN;

File Metadata

Mime Type
text/plain
Expires
Fri, Jun 26, 9:00 PM (14 h, 4 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34327133
Default Alt Text
D57829.diff (1 KB)

Event Timeline