From owner-svn-src-all@FreeBSD.ORG Sun Jun 13 18:48:03 2010 Return-Path: Delivered-To: svn-src-all@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E3C58106564A; Sun, 13 Jun 2010 18:48:02 +0000 (UTC) (envelope-from rdivacky@vlk.vlakno.cz) Received: from vlakno.cz (lev.vlakno.cz [77.93.215.190]) by mx1.freebsd.org (Postfix) with ESMTP id 9313B8FC1B; Sun, 13 Jun 2010 18:48:01 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by vlakno.cz (Postfix) with ESMTP id E02E09CB0C1; Sun, 13 Jun 2010 20:44:11 +0200 (CEST) X-Virus-Scanned: amavisd-new at vlakno.cz Received: from vlakno.cz ([127.0.0.1]) by localhost (lev.vlakno.cz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id FXCMJNEAaZ0s; Sun, 13 Jun 2010 20:44:09 +0200 (CEST) Received: from vlk.vlakno.cz (localhost [127.0.0.1]) by vlakno.cz (Postfix) with ESMTP id BEDA19CB102; Sun, 13 Jun 2010 20:44:09 +0200 (CEST) Received: (from rdivacky@localhost) by vlk.vlakno.cz (8.14.3/8.14.3/Submit) id o5DIi9LW052147; Sun, 13 Jun 2010 20:44:09 +0200 (CEST) (envelope-from rdivacky) Date: Sun, 13 Jun 2010 20:44:09 +0200 From: Roman Divacky To: mdf@FreeBSD.org Message-ID: <20100613184409.GA51992@freebsd.org> References: <201006130239.o5D2du3m086332@svn.freebsd.org> <20100613101025.GD1320@garage.freebsd.pl> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i Cc: svn-src-head@FreeBSD.org, Lawrence Stewart , svn-src-all@FreeBSD.org, src-committers@FreeBSD.org, Pawel Jakub Dawidek Subject: Re: svn commit: r209119 - head/sys/sys X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 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: Sun, 13 Jun 2010 18:48:03 -0000 On Sun, Jun 13, 2010 at 01:59:11PM +0000, mdf@FreeBSD.org wrote: > On Sun, Jun 13, 2010 at 10:10 AM, Pawel Jakub Dawidek wrote: > > On Sun, Jun 13, 2010 at 02:39:55AM +0000, Lawrence Stewart wrote: > >> Author: lstewart > >> Date: Sun Jun 13 02:39:55 2010 > >> New Revision: 209119 > >> URL: http://svn.freebsd.org/changeset/base/209119 > >> > >> Log: > >> ? Add a utility macro to simplify calculating an aggregate sum from a DPCPU > >> ? counter variable. > >> > >> ? Sponsored by: ? ? ? FreeBSD Foundation > >> ? Reviewed by: ? ? ? ?jhb, rpaulo, rwatson (previous version of patch) > >> ? MFC after: ?1 week > >> > >> Modified: > >> ? head/sys/sys/pcpu.h > >> > >> Modified: head/sys/sys/pcpu.h > >> ============================================================================== > >> --- head/sys/sys/pcpu.h ? ? ? Sun Jun 13 01:27:29 2010 ? ? ? ?(r209118) > >> +++ head/sys/sys/pcpu.h ? ? ? Sun Jun 13 02:39:55 2010 ? ? ? ?(r209119) > >> @@ -106,6 +106,17 @@ extern uintptr_t dpcpu_off[]; > >> ?#define ? ? ?DPCPU_ID_GET(i, n) ? ? ?(*DPCPU_ID_PTR(i, n)) > >> ?#define ? ? ?DPCPU_ID_SET(i, n, v) ? (*DPCPU_ID_PTR(i, n) = v) > >> > >> +/* > >> + * Utility macros. > >> + */ > >> +#define DPCPU_SUM(n, var, sum) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? \ > >> +do { ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? \ > >> + ? ? (sum) = 0; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?\ > >> + ? ? u_int i; ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?\ > >> + ? ? CPU_FOREACH(i) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?\ > >> + ? ? ? ? ? ? (sum) += (DPCPU_ID_PTR(i, n))->var; ? ? ? ? ? ? ? ? ? ? \ > >> +} while (0) > > > > I'd suggest first swapping variable declaration and '(sum) = 0;'. > > Also using 'i' as a counter in macro can easly lead to name collision. > > If you need to do it, I'd suggest '_i' or something. > > Maybe it would be better to make it an inline function rather than macro? > > (Relevant but almost a thread hijack): > > At Isilon we've run into a lot of problems with variable declarations > in macros, especially with -Wshadow turned on. We ended up > backporting __COUNTER__ from later versions of gcc and then using it > to make unique variable names. > > - is the backport (or a fresh implementation) something that could be > done within the scope of the GPL license? > - is it something FreeBSD would be interested in? > - is __COUNTER__ supported by clang? __COUNTER__ is supported by clang