From owner-freebsd-hackers@FreeBSD.ORG Sun Jul 11 11:54:19 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E0D21106566B; Sun, 11 Jul 2010 11:54:19 +0000 (UTC) (envelope-from avg@freebsd.org) Received: from citadel.icyb.net.ua (citadel.icyb.net.ua [212.40.38.140]) by mx1.freebsd.org (Postfix) with ESMTP id 4B8FA8FC17; Sun, 11 Jul 2010 11:54:17 +0000 (UTC) Received: from porto.topspin.kiev.ua (porto-e.starpoint.kiev.ua [212.40.38.100]) by citadel.icyb.net.ua (8.8.8p3/ICyb-2.3exp) with ESMTP id OAA27168; Sun, 11 Jul 2010 14:54:15 +0300 (EEST) (envelope-from avg@freebsd.org) Received: from localhost.topspin.kiev.ua ([127.0.0.1]) by porto.topspin.kiev.ua with esmtp (Exim 4.34 (FreeBSD)) id 1OXv6t-000DmG-EE; Sun, 11 Jul 2010 14:54:15 +0300 Message-ID: <4C39B0E6.3090400@freebsd.org> Date: Sun, 11 Jul 2010 14:54:14 +0300 From: Andriy Gapon User-Agent: Thunderbird 2.0.0.24 (X11/20100603) MIME-Version: 1.0 To: "Bjoern A. Zeeb" , freebsd-hackers@freebsd.org References: <4C246CD0.3020606@freebsd.org> <20100702082754.S14969@maildrop.int.zabbadoz.net> <4C320E6E.4040007@freebsd.org> <20100705171155.K14969@maildrop.int.zabbadoz.net> <4C321409.2070500@freebsd.org> <4C343C68.8010302@freebsd.org> <4C36FB32.30901@freebsd.org> In-Reply-To: <4C36FB32.30901@freebsd.org> X-Enigmail-Version: 0.96.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: Jeff Roberson , Konstantin Belousov , Peter Wemm Subject: Re: elf obj load: skip zero-sized sections early X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 11 Jul 2010 11:54:20 -0000 on 09/07/2010 13:34 Andriy Gapon said the following: > Having thought and experimented more, I don't see why we need inline assembly at > all and why DPCPU_DEFINE can not simply be defined as follows: > > #define DPCPU_DEFINE(t, n) \ > t DPCPU_NAME(n) __section("set_pcpu") \ > __aligned(CACHE_LINE_SIZE) __used > More explanation for this proposal with additional technical details, demonstrations and conclusions. First, this is the patch that I had in mind (note the file name): http://people.freebsd.org/~avg/dpcpu/pcpu.bad.patch Some test code that exercises DPCPU_DEFINE macro in various (redundant) ways: http://people.freebsd.org/~avg/dpcpu/dpcpu.c GCC-generated assembly with current version of pcpu.h: http://people.freebsd.org/~avg/dpcpu/dpcpu.orig.s Note #APP block, this is what gets produced from the inline assembly. Also note that GCC-generated section directive has exactly the same parameters as the parameters we use in the inline assembly - "aw",@progbits. GCC-generated assembly with patched pcpu.h and its diff from the previous version: http://people.freebsd.org/~avg/dpcpu/dpcpu.bad.s http://people.freebsd.org/~avg/dpcpu/dpcpu.bad.diff Note the section definition is exactly the same as before - it has the same flags, its alignment is the same too (.align 128 vs .p2align 7). It's also obvious where I got confused with this patch (bz, thanks!) and why the patch is named "bad". Instead of defining alignment for the section the patch sets CACHE_LINE_SIZE alignment for each variable defined in that section. Which is a waste, not good, etc. So, while this patch is bad, it still demonstrated that the real reason for the inline assembly is defining sections alignment. But the assembly has nothing to do with "aw" vs "a", variable initialization, etc. Which was my main point. For completeness, here is a patch that simply drops the inline assembly and the comment about it, and GCC-generated assembly and its diff: http://people.freebsd.org/~avg/dpcpu/pcpu.new.patch http://people.freebsd.org/~avg/dpcpu/dpcpu.new.s http://people.freebsd.org/~avg/dpcpu/dpcpu.new.diff As was speculated above, the only thing really changed is section alignment (from 128 to 4). And to be continued... -- Andriy Gapon