From owner-freebsd-hackers@FreeBSD.ORG Tue Mar 18 19:29:49 2014 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 164767F5; Tue, 18 Mar 2014 19:29:49 +0000 (UTC) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [IPv6:2001:470:1f11:75::1]) (using TLSv1 with cipher ADH-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id E31B01A2; Tue, 18 Mar 2014 19:29:48 +0000 (UTC) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id CD87FB941; Tue, 18 Mar 2014 15:29:47 -0400 (EDT) From: John Baldwin To: freebsd-hackers@freebsd.org Subject: Re: [PATCH] amd64/pcpu.h: Use Clang builtins for clarity when referencing thread's pcpu Date: Tue, 18 Mar 2014 14:52:13 -0400 User-Agent: KMail/1.13.5 (FreeBSD/8.4-CBSD-20130906; KDE/4.5.5; amd64; ; ) References: <1394821826-19412-1-git-send-email-conrad.meyer@isilon.com> In-Reply-To: <1394821826-19412-1-git-send-email-conrad.meyer@isilon.com> MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201403181452.13685.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Tue, 18 Mar 2014 15:29:47 -0400 (EDT) Cc: "Meyer, Conrad" , Bryan Drewery X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Mar 2014 19:29:49 -0000 On Friday, March 14, 2014 2:31:08 pm Meyer, Conrad wrote: > We can efficiently reference thread-local pcpu members via the %gs > register with Clang-annotated C code, in place of inline GNU assembly. > > Motivations: > - Use C in leiu of inline assembly for clarity > - Clang's static analyser may be better able to understand PCPU_* > macros using the C constructs rather than inline assembly > (unverified) > > Sponsored by: EMC/Isilon storage division > Signed-off-by: Conrad Meyer > Reviewed-by: Max Laier > --- > This is more of a "what do you think?" than a pull request. It seems like using > annotated C instead of asm is nice (in particular, Clang detects casts from > pointers typed with one segment to another, or unsegmented type). On the other > hand, this is code that doesn't change frequently, and we may still need to > support GCC for some time. So adding a second, parallel implementation just > doubles room for bugs. I think this is neat and wanted to look at doing this when I first noticed the address_space() attribute in the clang docs. > Open questions: > - How long is GCC intended to be supported as a compiler? That I don't know. > - How atomic does PCPU_INC() need to be? It looks like it updates cpu-local > counters; as long as it's a single asm instruction, should it be fine > w.r.t. interrupts? The existing implementation does NOT use the 'lock; ' prefix. I think a single instruction is fine. > diff --git a/sys/amd64/include/pcpu.h b/sys/amd64/include/pcpu.h > index fe898e9..68892fc 100644 > --- a/sys/amd64/include/pcpu.h > +++ b/sys/amd64/include/pcpu.h > +#define curthread __extension__ ({ \ > + *((volatile __pcpu_type(pc_curthread) __GS_RELATIVE *) \ > + __pcpu_offset(pc_curthread)); \ > +}) Would be nice to not lose the __pure2 attribute for curthread (you might need it to still be an inline function to keep that) -- John Baldwin