Module Name: src
Committed By: matt
Date: Sat Dec 3 01:44:04 UTC 2011
Modified Files:
src/sys/arch/mips/conf [matt-nb5-mips64]: kern.ldscript
src/sys/arch/mips/include [matt-nb5-mips64]: mips_param.h
src/sys/net [matt-nb5-mips64]: if_gre.h
src/sys/sys [matt-nb5-mips64]: cdefs_elf.h
Log Message:
Add __cacheline_aligned and __read_mostly from -HEAD.
To generate a diff of this commit:
cvs rdiff -u -r1.5.78.1 -r1.5.78.2 src/sys/arch/mips/conf/kern.ldscript
cvs rdiff -u -r1.23.78.7 -r1.23.78.8 src/sys/arch/mips/include/mips_param.h
cvs rdiff -u -r1.39 -r1.39.12.1 src/sys/net/if_gre.h
cvs rdiff -u -r1.30 -r1.30.12.1 src/sys/sys/cdefs_elf.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/mips/conf/kern.ldscript
diff -u src/sys/arch/mips/conf/kern.ldscript:1.5.78.1 src/sys/arch/mips/conf/kern.ldscript:1.5.78.2
--- src/sys/arch/mips/conf/kern.ldscript:1.5.78.1 Wed Dec 22 06:13:36 2010
+++ src/sys/arch/mips/conf/kern.ldscript Sat Dec 3 01:44:04 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: kern.ldscript,v 1.5.78.1 2010/12/22 06:13:36 matt Exp $ */
+/* $NetBSD: kern.ldscript,v 1.5.78.2 2011/12/03 01:44:04 matt Exp $ */
/* ldscript for NetBSD/mips kernels and LKMs */
OUTPUT_ARCH(mips)
@@ -30,6 +30,11 @@ SECTIONS
_fdata = . ;
*(.data)
CONSTRUCTORS
+ . = ALIGN(32); /* COHERENCY_UNIT */
+ *(.data.cacheline_aligned)
+ . = ALIGN(32); /* COHERENCY_UNIT */
+ *(.data.read_mostly)
+ . = ALIGN(32); /* COHERENCY_UNIT */
}
_gp = ALIGN(16) + 0x7ff0;
.lit8 : { *(.lit8) }
Index: src/sys/arch/mips/include/mips_param.h
diff -u src/sys/arch/mips/include/mips_param.h:1.23.78.7 src/sys/arch/mips/include/mips_param.h:1.23.78.8
--- src/sys/arch/mips/include/mips_param.h:1.23.78.7 Fri Dec 2 00:01:37 2011
+++ src/sys/arch/mips/include/mips_param.h Sat Dec 3 01:44:04 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: mips_param.h,v 1.23.78.7 2011/12/02 00:01:37 matt Exp $ */
+/* $NetBSD: mips_param.h,v 1.23.78.8 2011/12/03 01:44:04 matt Exp $ */
#ifdef _KERNEL
#include <machine/cpu.h>
@@ -54,6 +54,10 @@
#define MSGBUFSIZE NBPG /* default message buffer size */
#endif
+#ifndef COHERENCY_UNIT
+#define COHERENCY_UNIT 32 /* MIPS cachelines are usually 32 bytes */
+#endif
+
/*
* Round p (pointer or byte index) up to a correctly-aligned value for all
* data types (int, long, ...). The result is u_int and must be cast to
Index: src/sys/net/if_gre.h
diff -u src/sys/net/if_gre.h:1.39 src/sys/net/if_gre.h:1.39.12.1
--- src/sys/net/if_gre.h:1.39 Mon Sep 8 23:36:55 2008
+++ src/sys/net/if_gre.h Sat Dec 3 01:44:03 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: if_gre.h,v 1.39 2008/09/08 23:36:55 gmcgarry Exp $ */
+/* $NetBSD: if_gre.h,v 1.39.12.1 2011/12/03 01:44:03 matt Exp $ */
/*
* Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -63,12 +63,12 @@ enum gre_state {
, GRE_S_DIE
};
-#define __cacheline_aligned __aligned(CACHE_LINE_SIZE)
+#define __xcacheline_aligned __aligned(CACHE_LINE_SIZE)
struct gre_bufq {
volatile int bq_prodidx;
volatile int bq_considx;
- size_t bq_len __cacheline_aligned;
+ size_t bq_len __xcacheline_aligned;
size_t bq_lenmask;
volatile int bq_drops;
struct mbuf **bq_buf;
Index: src/sys/sys/cdefs_elf.h
diff -u src/sys/sys/cdefs_elf.h:1.30 src/sys/sys/cdefs_elf.h:1.30.12.1
--- src/sys/sys/cdefs_elf.h:1.30 Mon Jul 21 15:22:19 2008
+++ src/sys/sys/cdefs_elf.h Sat Dec 3 01:44:04 2011
@@ -1,4 +1,4 @@
-/* $NetBSD: cdefs_elf.h,v 1.30 2008/07/21 15:22:19 lukem Exp $ */
+/* $NetBSD: cdefs_elf.h,v 1.30.12.1 2011/12/03 01:44:04 matt Exp $ */
/*
* Copyright (c) 1995, 1996 Carnegie-Mellon University.
@@ -156,4 +156,42 @@
#define __link_set_count(set) \
(__link_set_end(set) - __link_set_start(set))
+#ifdef _KERNEL
+
+/*
+ * On multiprocessor systems we can gain an improvement in performance
+ * by being mindful of which cachelines data is placed in.
+ *
+ * __read_mostly:
+ *
+ * It makes sense to ensure that rarely modified data is not
+ * placed in the same cacheline as frequently modified data.
+ * To mitigate the phenomenon known as "false-sharing" we
+ * can annotate rarely modified variables with __read_mostly.
+ * All such variables are placed into the .data.read_mostly
+ * section in the kernel ELF.
+ *
+ * Prime candidates for __read_mostly annotation are variables
+ * which are hardly ever modified and which are used in code
+ * hot-paths, e.g. pmap_initialized.
+ *
+ * __cacheline_aligned:
+ *
+ * Some data structures (mainly locks) benefit from being aligned
+ * on a cacheline boundary, and having a cacheline to themselves.
+ * This way, the modification of other data items cannot adversely
+ * affect the lock and vice versa.
+ *
+ * Any variables annotated with __cacheline_aligned will be
+ * placed into the .data.cacheline_aligned ELF section.
+ */
+#define __read_mostly \
+ __attribute__((__section__(".data.read_mostly")))
+
+#define __cacheline_aligned \
+ __attribute__((__aligned__(COHERENCY_UNIT), \
+ __section__(".data.cacheline_aligned")))
+
+#endif /* _KERNEL */
+
#endif /* !_SYS_CDEFS_ELF_H_ */