From owner-freebsd-arch@freebsd.org Sun Nov 27 21:25:08 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 344F6C59063 for ; Sun, 27 Nov 2016 21:25:08 +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 C00111FDA for ; Sun, 27 Nov 2016 21:25:07 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: by mail-wm0-x243.google.com with SMTP id g23so16027469wme.1 for ; Sun, 27 Nov 2016 13:25:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:subject:message-id:mime-version:content-disposition :user-agent; bh=XJKsiso1p/xbH9qVgMnHpIImzVjJOenSQyWxn6ztDyI=; b=spgnNM/Ss1uEhOMhBDi/Mcy9HW77fYTJI1TloBbp1HWmjkkWjC6WnoyDx2cDhucoLv pcJtq0JunKyU3LxYxkwjEkyJherOgbNfYW4bE9p2U6jph5cR4QB8DrReB+z4Ot9UBAwZ T9IAgYO0yGwi+x2Tn/OFJ7cM2DoJiv5si0An7f/ixhgphY5pb3jexVmMAOQBk0nx1A3L Wvp1xnRloNRH0QWg6wLaSgeLPw/iU4tDJTbtRUrQKPflpQEFHoIiITu4lu1uuKngtnIt sHRvW8b36vZ9gzqvth4zjXcdJqXHjtB1UnFxwJ8DX4DEFqXVVXpDjhq5vLJvbtlvmsu1 WTfg== 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:mime-version :content-disposition:user-agent; bh=XJKsiso1p/xbH9qVgMnHpIImzVjJOenSQyWxn6ztDyI=; b=QlPT05H0kTM1d2Ijv2RPquQwJrGvwuL675J/1bGLzsn6+uD5CYcGj5V7nj4C5U5g0z pqyY+rrGpZxDiIudzjjoGByWM8ofqgvtWFgoSV0OYucr4cko3/RQMDH+m4M5OMljsKM4 WvWwX1y1G4OSEf4Tcd8BI5TQkJJ/CQlXs3K4IhpO6mHpR9hXH8HbvHOQ/XSrW5sKv2+k y6hxqYVj0AgG4rUWLBoQK9RTrsq9xvdcokvB7eUJewgGv4j+eaQE6v7WOrR1jPQ3+p9V o5BFibezN87bMN7sbYzL6yNdM6yJfG0ZFn5pVePNAF3zFSpyOXkexfA6nZQogH+S/KXo zuVA== X-Gm-Message-State: AKaTC007z1cM0I3nTp1z5ttGVplR64mXDhurywaTe12QQS+DY9AtbYq06wGt2o31XynzeA== X-Received: by 10.28.21.21 with SMTP id 21mr15304863wmv.132.1480281906033; Sun, 27 Nov 2016 13:25:06 -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 yg1sm59021306wjb.12.2016.11.27.13.25.05 for (version=TLS1_2 cipher=AES128-SHA bits=128/128); Sun, 27 Nov 2016 13:25:05 -0800 (PST) Date: Sun, 27 Nov 2016 22:25:03 +0100 From: Mateusz Guzik To: freebsd-arch@freebsd.org Subject: __read_only in the kernel Message-ID: <20161127212503.GA23218@dft-labs.eu> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline 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: Sun, 27 Nov 2016 21:25:08 -0000 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