Date: Tue, 7 Jul 2015 15:22:29 +0000 (UTC) From: "Pedro F. Giffuni" <pfg@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r285243 - head/sys/kern Message-ID: <201507071522.t67FMTDP046123@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: pfg Date: Tue Jul 7 15:22:29 2015 New Revision: 285243 URL: https://svnweb.freebsd.org/changeset/base/285243 Log: 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. Modified: head/sys/kern/sched_ule.c Modified: head/sys/kern/sched_ule.c ============================================================================== --- head/sys/kern/sched_ule.c Tue Jul 7 13:17:02 2015 (r285242) +++ head/sys/kern/sched_ule.c Tue Jul 7 15:22:29 2015 (r285243) @@ -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 th } #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;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201507071522.t67FMTDP046123>