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.
This commit is contained in:
Pedro F. Giffuni 2015-07-07 15:22:29 +00:00
parent c886a05c13
commit 9129dd59be
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=285243

View File

@ -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;