From owner-svn-src-all@freebsd.org Tue Jul 7 15:22:30 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 24BB7995BD2; Tue, 7 Jul 2015 15:22:30 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id EF1E111EF; Tue, 7 Jul 2015 15:22:29 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.70]) by repo.freebsd.org (8.14.9/8.14.9) with ESMTP id t67FMT6L046124; Tue, 7 Jul 2015 15:22:29 GMT (envelope-from pfg@FreeBSD.org) Received: (from pfg@localhost) by repo.freebsd.org (8.14.9/8.14.9/Submit) id t67FMTDP046123; Tue, 7 Jul 2015 15:22:29 GMT (envelope-from pfg@FreeBSD.org) Message-Id: <201507071522.t67FMTDP046123@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pfg set sender to pfg@FreeBSD.org using -f From: "Pedro F. Giffuni" Date: Tue, 7 Jul 2015 15:22:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r285243 - head/sys/kern X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Jul 2015 15:22:30 -0000 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;