Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F165594164
D57829.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D57829.diff
View Options
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
@@ -484,6 +484,17 @@
return (0);
}
+static inline int
+normalize_ts_off(int offset)
+{
+ /*
+ * Adding RQ_TS_POL_MODULO before taking the modulo is to ensure the
+ * dividend is positive (we want a positive result).
+ */
+ MPASS(offset >= -RQ_TS_POL_MODULO);
+ return ((offset + RQ_TS_POL_MODULO) % RQ_TS_POL_MODULO);
+}
+
/*
* Add a thread to the actual run-queue. Keeps transferable counts up to
* date with what is actually on the run-queue. Selects the correct
@@ -517,18 +528,34 @@
/* Current queue from which processes are being run. */
idx = tdq->tdq_ts_deq_off;
else {
- idx = (RQ_PRI_TO_QUEUE_IDX(pri) - RQ_TS_POL_MIN +
- tdq->tdq_ts_off) % RQ_TS_POL_MODULO;
+ idx = normalize_ts_off(
+ /* Offset corresponding to priority. */
+ RQ_PRI_TO_QUEUE_IDX(pri) - RQ_TS_POL_MIN +
+ /* Insertion offset. */
+ tdq->tdq_ts_off);
/*
- * 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. Thanks to the arithmetic operators
+ * always performing the usual arithmetic conversions,
+ * all operands are promoted to integers, which is
+ * necessary to accomodate corner cases (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).
*/
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;
+ normalize_ts_off(idx - tdq->tdq_ts_deq_off) <
+ normalize_ts_off(tdq->tdq_ts_off -
+ tdq->tdq_ts_deq_off))
+ idx = normalize_ts_off(tdq->tdq_ts_deq_off - 1);
}
/* Absolute queue index. */
idx += RQ_TS_POL_MIN;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Aug 9, 6:30 PM (20 h, 36 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34630673
Default Alt Text
D57829.diff (2 KB)
Attached To
Mode
D57829: sched_ule: Fix selecting lowest priority thread early in corner case
Attached
Detach File
Event Timeline
Log In to Comment