From 9129dd59be397d8345052ec7fcb478f814e5b66d Mon Sep 17 00:00:00 2001 From: "Pedro F. Giffuni" Date: Tue, 7 Jul 2015 15:22:29 +0000 Subject: [PATCH] Relocate sched_random() within the SMP section. Place sched_random nearer to where it's first used: moving the code nearer to where it is used makes the code easier to read and we can reduce the initial "#ifdef SMP" island. Reword a little the comment and clean some whitespaces while here. --- sys/kern/sched_ule.c | 38 ++++++++++++++++++-------------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/sys/kern/sched_ule.c b/sys/kern/sched_ule.c index 17371e7fe258..47278527c2c4 100644 --- a/sys/kern/sched_ule.c +++ b/sys/kern/sched_ule.c @@ -356,26 +356,6 @@ SDT_PROBE_DEFINE(sched, , , remain__cpu); SDT_PROBE_DEFINE2(sched, , , surrender, "struct thread *", "struct proc *"); -#ifdef SMP -/* - * 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. We only return the upper 16 bits - * of the random state (in the low bits of our answer) to return - * the maximum randomness. - */ -static uint32_t -sched_random(void) -{ - uint32_t *rndptr; - - rndptr = DPCPU_PTR(randomval); - *rndptr = *rndptr * 69069 + 5; - - return (*rndptr >> 16); -} -#endif - /* * Print the threads waiting on a run-queue. */ @@ -625,6 +605,24 @@ tdq_setlowpri(struct tdq *tdq, struct thread *ctd) } #ifdef SMP +/* + * We need some randomness. Implement a 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. We only return the upper 16 bits + * of the random state (in the low bits of our answer) to keep + * the maximum randomness. + */ +static uint32_t +sched_random(void) +{ + uint32_t *rndptr; + + rndptr = DPCPU_PTR(randomval); + *rndptr = *rndptr * 69069 + 5; + + return (*rndptr >> 16); +} + struct cpu_search { cpuset_t cs_mask; u_int cs_prefer;