From owner-freebsd-arch@freebsd.org Mon Nov 28 07:20: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 D617BC58F1E for ; Mon, 28 Nov 2016 07:20:40 +0000 (UTC) (envelope-from hps@selasky.org) Received: from mail.turbocat.net (heidi.turbocat.net [88.198.202.214]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id A1BA41914 for ; Mon, 28 Nov 2016 07:20:40 +0000 (UTC) (envelope-from hps@selasky.org) Received: from hps2016.home.selasky.org (unknown [62.141.129.119]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.turbocat.net (Postfix) with ESMTPSA id B67EA1FE024; Mon, 28 Nov 2016 08:20:37 +0100 (CET) Subject: Re: __read_only in the kernel To: Mateusz Guzik , freebsd-arch@freebsd.org References: <20161127212503.GA23218@dft-labs.eu> From: Hans Petter Selasky Message-ID: <90f7f729-8bd6-c3d9-648d-1d4fce0ac82c@selasky.org> Date: Mon, 28 Nov 2016 08:20:21 +0100 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <20161127212503.GA23218@dft-labs.eu> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit 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: Mon, 28 Nov 2016 07:20:40 -0000 On 11/27/16 22:25, 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_ */ > Hi, You might needs to patch the linuxkpi /sys/compat/linuxkpi/ too, which also defines this macro. --HPS