From owner-freebsd-arch@freebsd.org Mon Jan 16 12:46:59 2017 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 5054BCB1DD4 for ; Mon, 16 Jan 2017 12:46:59 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: from mail-wm0-x242.google.com (mail-wm0-x242.google.com [IPv6:2a00:1450:400c:c09::242]) (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 D87171A22 for ; Mon, 16 Jan 2017 12:46:58 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: by mail-wm0-x242.google.com with SMTP id d140so14176317wmd.2 for ; Mon, 16 Jan 2017 04:46:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=DD2pm5AQPY9ZhEckPsgq6aT+uS8FdmwMC44hO+Ks62g=; b=bGZZUkCnLcF2qFzGiAZJUMqHM+uZwxRH8t7WN5ngET46ozf/K5qxmePzJC+8j9R5Dp 7+9yFfvWrEkzE5eYBMMwwDdN3lPf/qZ+4yeTdfpJVPHZhKL3KjqXF7ZRQGXweiF6a0GL SXeS4kmKi9ESJwa1BwJF4kPA3+8YjUC8Rtx3Ri03jERRtOfMrAFoN0qokIEdL3yHIm5F mPuDuknW3bX51BqWQwBTe5KNuTVvW1TyQCIZKugxf21ViZi7fzy0byecSw8KbfomosQi hnwYMyXRJt2t3iWve4Dv/17FvQo20lnjgRsrPoTTXl7CJT5SBv9T21GgBRKfB15Dq+oH cfww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=DD2pm5AQPY9ZhEckPsgq6aT+uS8FdmwMC44hO+Ks62g=; b=UpaKTH9XAzvCGjCk9jdlHOpf1nwQ25wJ/cNIztqupRQ6NiX2eqrDJKvH5yOwXwwlR2 GnwDnoXJ6MmxZfcrkIWCsQjyfWoJxwlOLgj4RNnDHJ4BLBKbcvzqUN4D4OyMSWMFLeSB siNDzF4egsYe9eIFuCoUcAhIhnRonGXmf1MljPZUKyvkFeVTOopAuovLiu2U2FFKbEjD SMb/3YD8DbQOHk0cyG+52G1cg6r49nJKP2FKVz9KZ52tSRR6JUhOXG3d4APUfkVSJWpt 0euozGADP4ZCecu+D6OT/Lex/yhmze38sDfAZgsqBOg7DnGEg3zo2OTtiPs8yWrd/GX8 kU9A== X-Gm-Message-State: AIkVDXIWigSoLhxHlOfSFW+PxuRa45r9BhqNyczJYL6l8sBcX6JlTV1ioDPZiQhDV6xdtA== X-Received: by 10.223.162.206 with SMTP id t14mr27414205wra.42.1484570817380; Mon, 16 Jan 2017 04:46:57 -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 w79sm28633415wmw.0.2017.01.16.04.46.55 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 16 Jan 2017 04:46:56 -0800 (PST) Date: Mon, 16 Jan 2017 13:46:53 +0100 From: Mateusz Guzik To: Bruce Evans Cc: freebsd-arch@freebsd.org Subject: Re: __read_only in the kernel Message-ID: <20170116124653.GB30475@dft-labs.eu> References: <20161127212503.GA23218@dft-labs.eu> <20161130011033.GA20999@dft-labs.eu> <20161201070246.S1023@besplex.bde.org> <20161229114554.GA29676@dft-labs.eu> <20161229153138.GC29676@dft-labs.eu> <20170113130942.E1016@besplex.bde.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20170113130942.E1016@besplex.bde.org> 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: Mon, 16 Jan 2017 12:46:59 -0000 On Fri, Jan 13, 2017 at 01:10:33PM +1100, Bruce Evans wrote: > On Thu, 29 Dec 2016, Mateusz Guzik wrote: > >Scratch the previous patch. I extended it with __exclusive_cache_line > >(happy with ideas for a better name) - to be used for something which > >has to be alone in the cacheline, e.g. an atomic counter. > > > >diff --git a/sys/compat/linuxkpi/common/include/linux/compiler.h b/sys/compat/linuxkpi/common/include/linux/compiler.h > >index c780abc..c32f1fa 100644 > >--- a/sys/compat/linuxkpi/common/include/linux/compiler.h > >+++ b/sys/compat/linuxkpi/common/include/linux/compiler.h > >@@ -67,7 +67,6 @@ > >#define typeof(x) __typeof(x) > > > >#define uninitialized_var(x) x = x > >-#define __read_mostly __attribute__((__section__(".data.read_mostly"))) > >#define __always_unused __unused > >#define __must_check __result_use_check > > > >diff --git a/sys/conf/ldscript.amd64 b/sys/conf/ldscript.amd64 > >index 5d86b03..45685a4 100644 > >--- a/sys/conf/ldscript.amd64 > >+++ b/sys/conf/ldscript.amd64 > >@@ -150,6 +150,17 @@ SECTIONS > > *(.data .data.* .gnu.linkonce.d.*) > > KEEP (*(.gnu.linkonce.d.*personality*)) > > } > >+ . = ALIGN(64); > >+ .data.read_mostly : > >+ { > >+ *(.data.read_mostly) > >+ } > >+ . = ALIGN(64); > >+ .data.exclusive_cache_line : > >+ { > >+ *(.data.exclusive_cache_line) > >+ } > >+ . = ALIGN(64); > > .data1 : { *(.data1) } > > _edata = .; PROVIDE (edata = .); > > __bss_start = .; > > I don't really understand this. Is it still needed? I forget if you > need separate sections to keep things together for more than the > purpose of aligning them. I think objects aligned to the cache line > size or larger can live almost anywhere in the address space without > making much difference to cache effectiveness on most arches including > amd64. > Without the above, while variables are aligned, they can end up with unaligned ones added just after them in the same cacheline. > >diff --git a/sys/dev/drm2/drm_os_freebsd.h b/sys/dev/drm2/drm_os_freebsd.h > >index dc01c6a..11c9feb 100644 > >--- a/sys/dev/drm2/drm_os_freebsd.h > >+++ b/sys/dev/drm2/drm_os_freebsd.h > >@@ -80,7 +80,6 @@ typedef void irqreturn_t; > > > >#define __init > >#define __exit > >-#define __read_mostly > > > >#define BUILD_BUG_ON(x) CTASSERT(!(x)) > >#define BUILD_BUG_ON_NOT_POWER_OF_2(x) > >diff --git a/sys/sys/systm.h b/sys/sys/systm.h > >index a1ce9b4..719e063 100644 > >--- a/sys/sys/systm.h > >+++ b/sys/sys/systm.h > >@@ -445,4 +445,8 @@ extern void (*softdep_ast_cleanup)(void); > > > >void counted_warning(unsigned *counter, const char *msg); > > > >+#define __read_mostly __section(".data.read_mostly") > >+#define __exclusive_cache_line __aligned(CACHE_LINE_SIZE) \ > >+ __section(".data.exclusive_cache_line") > >+ > >#endif /* !_SYS_SYSTM_H_ */ > > systm.h is better for the kernel, but will we want this for userland? > imho userspace may have their own variants which should not interfere with. > systm.h is randomly ordered, and appending to it with the new definitions > inversely ordered improves its randomness. Similarly for style. Indentation > for multi-line #define's is more random now. > Where do you propose moving this? I'm completely indifferent with the location. Fixed the indentation below. diff --git a/sys/compat/linuxkpi/common/include/linux/compiler.h b/sys/compat/linuxkpi/common/include/linux/compiler.h index c780abc..c32f1fa 100644 --- a/sys/compat/linuxkpi/common/include/linux/compiler.h +++ b/sys/compat/linuxkpi/common/include/linux/compiler.h @@ -67,7 +67,6 @@ #define typeof(x) __typeof(x) #define uninitialized_var(x) x = x -#define __read_mostly __attribute__((__section__(".data.read_mostly"))) #define __always_unused __unused #define __must_check __result_use_check diff --git a/sys/conf/ldscript.amd64 b/sys/conf/ldscript.amd64 index 5d86b03..e64a957 100644 --- a/sys/conf/ldscript.amd64 +++ b/sys/conf/ldscript.amd64 @@ -145,6 +145,17 @@ SECTIONS .got : { *(.got) } . = DATA_SEGMENT_RELRO_END (24, .); .got.plt : { *(.got.plt) } + . = ALIGN(64); + .data.read_mostly : + { + *(.data.read_mostly) + } + . = ALIGN(64); + .data.exclusive_cache_line : + { + *(.data.exclusive_cache_line) + } + . = ALIGN(64); .data : { *(.data .data.* .gnu.linkonce.d.*) diff --git a/sys/dev/drm2/drm_os_freebsd.h b/sys/dev/drm2/drm_os_freebsd.h index dc01c6a..11c9feb 100644 --- a/sys/dev/drm2/drm_os_freebsd.h +++ b/sys/dev/drm2/drm_os_freebsd.h @@ -80,7 +80,6 @@ typedef void irqreturn_t; #define __init #define __exit -#define __read_mostly #define BUILD_BUG_ON(x) CTASSERT(!(x)) #define BUILD_BUG_ON_NOT_POWER_OF_2(x) diff --git a/sys/sys/systm.h b/sys/sys/systm.h index a1ce9b4..418998e 100644 --- a/sys/sys/systm.h +++ b/sys/sys/systm.h @@ -445,4 +445,8 @@ extern void (*softdep_ast_cleanup)(void); void counted_warning(unsigned *counter, const char *msg); +#define __read_mostly __section(".data.read_mostly") +#define __exclusive_cache_line __aligned(CACHE_LINE_SIZE) \ + __section(".data.exclusive_cache_line") + #endif /* !_SYS_SYSTM_H_ */ -- Mateusz Guzik