From owner-svn-src-all@FreeBSD.ORG Sun Jun 13 14:30:06 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 64D3D106566C; Sun, 13 Jun 2010 14:30:06 +0000 (UTC) (envelope-from mdf356@gmail.com) Received: from mail-gx0-f182.google.com (mail-gx0-f182.google.com [209.85.161.182]) by mx1.freebsd.org (Postfix) with ESMTP id D469E8FC16; Sun, 13 Jun 2010 14:30:05 +0000 (UTC) Received: by gxk27 with SMTP id 27so688612gxk.13 for ; Sun, 13 Jun 2010 07:30:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:sender:received :in-reply-to:references:date:x-google-sender-auth:message-id:subject :from:to:cc:content-type:content-transfer-encoding; bh=g1mJ3wTOQCbU2sqbTmBDYgoDDtopHkCjBNZN9sa+k5c=; b=UHNPbP501htn4heVGDlP9vbyYwJdJsIB+dY2RV21dHKQpVZCHT1NrsO9a8zLIrL2RM 7jHJPb5IFusP3M9PHuiZN2YDcqacQ83jvZPT/IKFj2cl5i4x52hiMocfJddK+859FwuK TITP26Irc2v5FMvQ6evcjiTx4MYH6lzrpGr+c= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type :content-transfer-encoding; b=ep9V5BEWmo45k4j3KvfbH0octBKVTEvj0GJEfk1w52x6rpdzkX+7dfYQiCyKBS2og7 GCRxWBVh3HkWvOF2zxInpDWPVjItZtrKYypq4gH6Ofp+UoE+/nnoIKhXmFyKZuCaB4FK R1xalxK3mbgeAJkHtStwYe9T3vp2hJdMRRO4Y= MIME-Version: 1.0 Received: by 10.224.45.31 with SMTP id c31mr1459451qaf.223.1276437551509; Sun, 13 Jun 2010 06:59:11 -0700 (PDT) Sender: mdf356@gmail.com Received: by 10.224.28.79 with HTTP; Sun, 13 Jun 2010 06:59:11 -0700 (PDT) In-Reply-To: <20100613101025.GD1320@garage.freebsd.pl> References: <201006130239.o5D2du3m086332@svn.freebsd.org> <20100613101025.GD1320@garage.freebsd.pl> Date: Sun, 13 Jun 2010 13:59:11 +0000 X-Google-Sender-Auth: 7cKFxn_aOFZF4WfSmcgx1bm0HCg Message-ID: From: mdf@FreeBSD.org To: Pawel Jakub Dawidek Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: svn-src-head@freebsd.org, Lawrence Stewart , svn-src-all@freebsd.org, src-committers@freebsd.org 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 14:30:06 -0000 On Sun, Jun 13, 2010 at 10:10 AM, Pawel Jakub Dawidek wro= te: > 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: >> =A0 Add a utility macro to simplify calculating an aggregate sum from a = DPCPU >> =A0 counter variable. >> >> =A0 Sponsored by: =A0 =A0 =A0 FreeBSD Foundation >> =A0 Reviewed by: =A0 =A0 =A0 =A0jhb, rpaulo, rwatson (previous version o= f patch) >> =A0 MFC after: =A01 week >> >> Modified: >> =A0 head/sys/sys/pcpu.h >> >> Modified: head/sys/sys/pcpu.h >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D >> --- head/sys/sys/pcpu.h =A0 =A0 =A0 Sun Jun 13 01:27:29 2010 =A0 =A0 =A0= =A0(r209118) >> +++ head/sys/sys/pcpu.h =A0 =A0 =A0 Sun Jun 13 02:39:55 2010 =A0 =A0 =A0= =A0(r209119) >> @@ -106,6 +106,17 @@ extern uintptr_t dpcpu_off[]; >> =A0#define =A0 =A0 =A0DPCPU_ID_GET(i, n) =A0 =A0 =A0(*DPCPU_ID_PTR(i, n)= ) >> =A0#define =A0 =A0 =A0DPCPU_ID_SET(i, n, v) =A0 (*DPCPU_ID_PTR(i, n) =3D= v) >> >> +/* >> + * Utility macros. >> + */ >> +#define DPCPU_SUM(n, var, sum) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 \ >> +do { =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 \ >> + =A0 =A0 (sum) =3D 0; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0\ >> + =A0 =A0 u_int i; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0\ >> + =A0 =A0 CPU_FOREACH(i) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0\ >> + =A0 =A0 =A0 =A0 =A0 =A0 (sum) +=3D (DPCPU_ID_PTR(i, n))->var; =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 \ >> +} while (0) > > I'd suggest first swapping variable declaration and '(sum) =3D 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? - if not, could it be? -Wshadow found several nasty bugs in our code, and apart from a few spurious warnings it has been handy to have when building our filesystem. Thanks, matthew