From owner-freebsd-arch@freebsd.org Wed Nov 30 01:10:40 2016 Return-Path: Delivered-To: freebsd-arch@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 3C77EC5B851 for ; Wed, 30 Nov 2016 01:10:40 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: from mail-wm0-x243.google.com (mail-wm0-x243.google.com [IPv6:2a00:1450:400c:c09::243]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id C5F9D1158 for ; Wed, 30 Nov 2016 01:10:39 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: by mail-wm0-x243.google.com with SMTP id a20so27116260wme.2 for ; Tue, 29 Nov 2016 17:10:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=F3kuuEckqVQcGb92sOfp67b6Fhe8COZOmdGcEzKZnU8=; b=B3B4K+d8fmHiLZDCBAQpwfUXxWO2xQJ5cm9iWoq+X9BwO+cl00UPNa4JkcOZNx1OvT dam7YhRsoNAMRcwS/wSyC4PW6xx/7APxv+1v2vuLpMpacGHAS3yZCDN9wOFeWk5gVl9F +1V3yUa4ceo/1VOnoRTynSgysSFE2QlL0ebhc444FvrGtE7CVF4fdNzsMjM2YaPdxyoZ bfgYbFJU+lj5ZBHMWb0wMBo2eOcC1fqzH+Tmel2Vbu74nBDzX5jpo552WReOKJq9Swl9 dIfi2Dmh5L7Pz277LZeBiD2bpRQXTL/dTG0zCHR0U5uCyqAteqgUZzszTCuMtLgg0cil /vng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=F3kuuEckqVQcGb92sOfp67b6Fhe8COZOmdGcEzKZnU8=; b=GCYDaJ9pQpHGY0cqjAOuqk2kGF6MxmM1zJm9MLldjZxYk1CdzrodEA5fbi+EAAtRbI Sd0mivfbUfXSQ86IujLSycF3D7AIKW7WDI9hwBeNgaFbJLdmPZc1mJky1AU0xmtGfpFm joZ8HywifGixiP8tBFzHifN16x8kT7SNciycSG0FKPRRV6GTs4078vRhaMJKxkgSa5Bg f4qJ9tS7qXMDerVyNe461sauJMwr+OHX1TZNEmN9T1XG1BT09e4RnKE9Sj1B0o2Ci1Uq WC6wWQODhgq8LtLoMGK8Cnpi6btUYsXAGwN6Lz5Vxb4lupXecI2SncIg29ftpOB4J4Lr peeA== X-Gm-Message-State: AKaTC02JDRMAXv4fzXi/YID5qzyuxaMdG7B0f9N8Up/d4uiTnHA6/7O0fCWruRHOYnt0oA== X-Received: by 10.28.230.197 with SMTP id e66mr27674784wmi.12.1480468237440; Tue, 29 Nov 2016 17:10:37 -0800 (PST) Received: from dft-labs.eu (n1x0n-1-pt.tunnel.tserv5.lon1.ipv6.he.net. [2001:470:1f08:1f7::2]) by smtp.gmail.com with ESMTPSA id j1sm70422492wjm.26.2016.11.29.17.10.36 for (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 29 Nov 2016 17:10:36 -0800 (PST) Date: Wed, 30 Nov 2016 02:10:34 +0100 From: Mateusz Guzik To: freebsd-arch@freebsd.org Subject: Re: __read_only in the kernel Message-ID: <20161130011033.GA20999@dft-labs.eu> References: <20161127212503.GA23218@dft-labs.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20161127212503.GA23218@dft-labs.eu> User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Nov 2016 01:10:40 -0000 I officially threaten to commit this by Friday. __read_mostly-ification of certain vars will follow. stable/11 and stable/10 will get the #define __read_mostly bit for convenience, but the feature itself will likely get mfced to 11. On Sun, Nov 27, 2016 at 10:25:03PM +0100, Mateusz Guzik wrote: > One of the standard problems in mpsafe kernels is false sharing. > > The somewhat standard way of combating parts of it for frequently read > and rarely (if ever) modified variables is an annotation which puts > them in a dedicated part of the binary and the somewhat standard name > for a macro doing the work is __read_mostly. > > The FreeBSD kernel still does not have it and I think it's long overdue. > > Now, I don't know how to do it nicely in the linker script, in > particular I don't know how get the cache line size. > > For testing purposes I hacked up a crap version below and verified it > works fine. > > I hacked up the following crap version. Would be nice if someone with > ld-clue fixed that up. I don't care about the header either. > > I just want the macro. :) > > diff --git a/sys/amd64/include/param.h b/sys/amd64/include/param.h > index a619e395..ab66e79 100644 > --- a/sys/amd64/include/param.h > +++ b/sys/amd64/include/param.h > @@ -152,4 +152,6 @@ > #define INKERNEL(va) (((va) >= DMAP_MIN_ADDRESS && (va) < DMAP_MAX_ADDRESS) \ > || ((va) >= VM_MIN_KERNEL_ADDRESS && (va) < VM_MAX_KERNEL_ADDRESS)) > > +#define __read_mostly __attribute__((__section__(".data.read_mostly"))) > + > #endif /* !_AMD64_INCLUDE_PARAM_H_ */ > diff --git a/sys/conf/ldscript.amd64 b/sys/conf/ldscript.amd64 > index 5d86b03..ae98447 100644 > --- a/sys/conf/ldscript.amd64 > +++ b/sys/conf/ldscript.amd64 > @@ -151,6 +151,11 @@ SECTIONS > KEEP (*(.gnu.linkonce.d.*personality*)) > } > .data1 : { *(.data1) } > + .data_read_mostly : > + { > + *(.data.read_mostly) > + . = ALIGN(64); > + } > _edata = .; PROVIDE (edata = .); > __bss_start = .; > .bss : > diff --git a/sys/sys/param.h b/sys/sys/param.h > index cf38985..dcd9526 100644 > --- a/sys/sys/param.h > +++ b/sys/sys/param.h > @@ -360,4 +360,8 @@ __END_DECLS > */ > #define __PAST_END(array, offset) (((__typeof__(*(array)) *)(array))[offset]) > > +#ifndef __read_mostly > +#define __read_mostly > +#endif > + > #endif /* _SYS_PARAM_H_ */ > -- > Mateusz Guzik -- Mateusz Guzik