Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 4 Dec 2012 05:28:20 +0000 (UTC)
From:      Alfred Perlstein <alfred@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r243853 - head/sys/kern
Message-ID:  <201212040528.qB45SKND065393@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: alfred
Date: Tue Dec  4 05:28:20 2012
New Revision: 243853
URL: http://svnweb.freebsd.org/changeset/base/243853

Log:
  replace bit shifting loop with 1<<fls(n), improve comments.
  
  Reviewed by: davide

Modified:
  head/sys/kern/kern_timeout.c

Modified: head/sys/kern/kern_timeout.c
==============================================================================
--- head/sys/kern/kern_timeout.c	Tue Dec  4 04:37:42 2012	(r243852)
+++ head/sys/kern/kern_timeout.c	Tue Dec  4 05:28:20 2012	(r243853)
@@ -84,7 +84,7 @@ SYSCTL_INT(_debug, OID_AUTO, to_avg_mpca
  * TODO:
  *	allocate more timeout table slots when table overflows.
  */
-int callwheelsize, callwheelbits, callwheelmask;
+int callwheelsize, callwheelmask;
 
 /*
  * The callout cpu migration entity represents informations necessary for
@@ -218,12 +218,10 @@ kern_timeout_callwheel_alloc(caddr_t v)
 	timeout_cpu = PCPU_GET(cpuid);
 	cc = CC_CPU(timeout_cpu);
 	/*
-	 * Calculate callout wheel size
+	 * Calculate callout wheel size, should be next power of two higher
+	 * than 'ncallout'.
 	 */
-	for (callwheelsize = 1, callwheelbits = 0;
-	     callwheelsize < ncallout;
-	     callwheelsize <<= 1, ++callwheelbits)
-		;
+	callwheelsize = 1 << fls(ncallout);
 	callwheelmask = callwheelsize - 1;
 
 	cc->cc_callout = (struct callout *)v;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201212040528.qB45SKND065393>