Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 28 Nov 2016 08:20:21 +0100
From:      Hans Petter Selasky <hps@selasky.org>
To:        Mateusz Guzik <mjguzik@gmail.com>, freebsd-arch@freebsd.org
Subject:   Re: __read_only in the kernel
Message-ID:  <90f7f729-8bd6-c3d9-648d-1d4fce0ac82c@selasky.org>
In-Reply-To: <20161127212503.GA23218@dft-labs.eu>
References:  <20161127212503.GA23218@dft-labs.eu>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?90f7f729-8bd6-c3d9-648d-1d4fce0ac82c>