Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Introduce membar_datadep_consumer.



details:   https://anonhg.NetBSD.org/src/rev/83f1d092637b
branches:  trunk
changeset: 335481:83f1d092637b
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Thu Jan 08 22:27:17 2015 +0000

description:
Introduce membar_datadep_consumer.

Discussed briefly on tech-kern without objection:

https://mail-index.netbsd.org/tech-kern/2014/11/20/msg018054.html
https://mail-index.netbsd.org/tech-kern/2015/01/07/msg018326.html

diffstat:

 common/lib/libc/arch/alpha/atomic/membar_ops.S |   4 +-
 lib/libc/atomic/membar_ops.3                   |  44 ++++++++++++++++++++++++-
 sys/arch/alpha/include/types.h                 |   3 +-
 sys/sys/atomic.h                               |   8 ++++-
 4 files changed, 54 insertions(+), 5 deletions(-)

diffs (130 lines):

diff -r fada0f2e4409 -r 83f1d092637b common/lib/libc/arch/alpha/atomic/membar_ops.S
--- a/common/lib/libc/arch/alpha/atomic/membar_ops.S    Thu Jan 08 22:03:42 2015 +0000
+++ b/common/lib/libc/arch/alpha/atomic/membar_ops.S    Thu Jan 08 22:27:17 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: membar_ops.S,v 1.6 2008/05/25 15:56:11 chs Exp $       */
+/*     $NetBSD: membar_ops.S,v 1.7 2015/01/08 22:27:17 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2006, 2007 The NetBSD Foundation, Inc.
@@ -87,3 +87,5 @@
 STRONG_ALIAS(_membar_exit,_membar_sync)
 ATOMIC_OP_ALIAS(membar_consumer,_membar_sync)
 STRONG_ALIAS(_membar_consumer,_membar_sync)
+ATOMIC_OP_ALIAS(membar_datadep_consumer,_membar_sync)
+STRONG_ALIAS(_membar_datadep_consumer,_membar_sync)
diff -r fada0f2e4409 -r 83f1d092637b lib/libc/atomic/membar_ops.3
--- a/lib/libc/atomic/membar_ops.3      Thu Jan 08 22:03:42 2015 +0000
+++ b/lib/libc/atomic/membar_ops.3      Thu Jan 08 22:27:17 2015 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: membar_ops.3,v 1.3 2011/04/28 11:56:26 wiz Exp $
+.\"    $NetBSD: membar_ops.3,v 1.4 2015/01/08 22:27:17 riastradh Exp $
 .\"
 .\" Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
 .\" All rights reserved.
@@ -27,7 +27,7 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd February 11, 2007
+.Dd November 20, 2014
 .Dt MEMBAR_OPS 3
 .Os
 .Sh NAME
@@ -52,6 +52,8 @@
 .Ft void
 .Fn membar_consumer "void"
 .Ft void
+.Fn membar_datadep_consumer "void"
+.Ft void
 .Fn membar_sync "void"
 .Sh DESCRIPTION
 The
@@ -83,6 +85,40 @@
 .It Fn membar_consumer
 All loads preceding the memory barrier will complete before any loads
 after the memory barrier complete.
+.It Fn membar_datadep_consumer
+Same as
+.Fn membar_consumer ,
+but limited to loads of addresses dependent on prior loads, or
+.Sq data-dependent
+loads:
+.Bd -literal -offset indent
+int **pp, *p, v;
+
+p = *pp;
+membar_datadep_consumer();
+v = *p;
+consume(v);
+.Ed
+.Pp
+Does not guarantee ordering of loads in branches, or
+.Sq control-dependent
+loads -- you must use
+.Fn membar_consumer
+instead:
+.Bd -literal -offset indent
+int *ok, *p, v;
+
+if (*ok) {
+       membar_consumer();
+       v = *p;
+       consume(v);
+}
+.Ed
+.Pp
+Most CPUs do not reorder data-dependent loads (i.e., most CPUs
+guarantee that cached values are not stale in that case), so
+.Fn membar_datadep_consumer
+is a no-op on those CPUs.
 .It Fn membar_sync
 All loads and stores preceding the memory barrier will complete and
 reach global visibility before any loads and stores after the memory
@@ -95,3 +131,7 @@
 .Nm membar_ops
 functions first appeared in
 .Nx 5.0 .
+The data-dependent load barrier,
+.Fn membar_datadep_consumer ,
+first appeared in
+.Nx 7.0 .
diff -r fada0f2e4409 -r 83f1d092637b sys/arch/alpha/include/types.h
--- a/sys/arch/alpha/include/types.h    Thu Jan 08 22:03:42 2015 +0000
+++ b/sys/arch/alpha/include/types.h    Thu Jan 08 22:27:17 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: types.h,v 1.49 2012/01/25 18:09:13 matt Exp $ */
+/* $NetBSD: types.h,v 1.50 2015/01/08 22:27:17 riastradh Exp $ */
 
 /*-
  * Copyright (c) 1990, 1993
@@ -70,6 +70,7 @@
 
 #define        __HAVE_NEW_STYLE_BUS_H
 #define        __HAVE_ATOMIC_OPERATIONS
+#define        __HAVE_MEMBAR_DATADEP_CONSUMER
 #define        __HAVE_CPU_COUNTER
 #define        __HAVE_SYSCALL_INTERN
 #define        __HAVE_MINIMAL_EMUL
diff -r fada0f2e4409 -r 83f1d092637b sys/sys/atomic.h
--- a/sys/sys/atomic.h  Thu Jan 08 22:03:42 2015 +0000
+++ b/sys/sys/atomic.h  Thu Jan 08 22:27:17 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: atomic.h,v 1.12 2014/02/21 15:52:53 martin Exp $       */
+/*     $NetBSD: atomic.h,v 1.13 2015/01/08 22:27:18 riastradh Exp $    */
 
 /*-
  * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc.
@@ -156,6 +156,12 @@
 void           membar_consumer(void);
 void           membar_sync(void);
 
+#ifdef __HAVE_MEMBAR_DATADEP_CONSUMER
+void           membar_datadep_consumer(void);
+#else
+#define        membar_datadep_consumer()       ((void)0)
+#endif
+
 __END_DECLS
 
 #endif /* ! _SYS_ATOMIC_H_ */



Home | Main Index | Thread Index | Old Index