Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F144168453
D1981.id4018.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
D1981.id4018.diff
View Options
Index: sys/kern/sched_ule.c
===================================================================
--- sys/kern/sched_ule.c
+++ sys/kern/sched_ule.c
@@ -360,17 +360,18 @@
/*
* We need some randomness. Implement the classic Linear Congruential
* generator X_{n+1}=(aX_n+c) mod m. These values are optimized for
- * m = 2^32, a = 69069 and c = 5. This is signed so that we can get
- * both positive and negative values from it by shifting the value
- * right.
+ * m = 2^32, a = 69069 and c = 5. We only return the upper 16 bits
+ * of the random state (in the low bits of our answer) to return
+ * the maximum randomness.
*/
-static int sched_random()
+static uint32_t sched_random()
{
- int rnd, *rndptr;
- rndptr = DPCPU_PTR(randomval);
- rnd = *rndptr * 69069 + 5;
- *rndptr = rnd;
- return(rnd);
+ uint32_t *rndptr;
+
+ rndptr = DPCPU_PTR(randomval);
+ *rndptr = *rndptr * 69069 + 5;
+
+ return (*rndptr >> 16);
}
#endif
@@ -718,7 +719,7 @@
CPU_CLR(cpu, &cpumask);
tdq = TDQ_CPU(cpu);
load = tdq->tdq_load * 256;
- rnd = sched_random() >> 26; /* -32 to +31 */
+ rnd = sched_random() & 31;
if (match & CPU_SEARCH_LOWEST) {
if (cpu == low->cs_prefer)
load -= 64;
@@ -882,7 +883,7 @@
return;
balance_ticks = max(balance_interval / 2, 1) +
- ((sched_random() >> 16) % balance_interval);
+ (sched_random() % balance_interval);
tdq = TDQ_SELF();
TDQ_UNLOCK(tdq);
sched_balance_group(cpu_top);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Feb 6, 8:51 PM (20 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28450367
Default Alt Text
D1981.id4018.diff (1 KB)
Attached To
Mode
D1981: Make sched_random() return an unsigned number.
Attached
Detach File
Event Timeline
Log In to Comment