diff mbox

[v2,0/5] Convert Sparc to atomic optabs

Message ID 4ED65C50.3050701@redhat.com
State New
Headers show

Commit Message

Richard Henderson Nov. 30, 2011, 4:39 p.m. UTC
On 11/28/2011 10:12 AM, Richard Henderson wrote:
> Richard Henderson (5):
>   sparc: Convert to mem_thread_fence.
>   sparc: Convert to atomic_load/store.
>   sparc: Convert to atomic_compare_and_swap.
>   sparc: Convert to atomic_exchange.
>   sparc: Add -mmemory-model command-line option.
> 
>  gcc/config/sparc/constraints.md |    5 +-
>  gcc/config/sparc/predicates.md  |   13 ++
>  gcc/config/sparc/sparc-opts.h   |   10 ++
>  gcc/config/sparc/sparc-protos.h |    4 +-
>  gcc/config/sparc/sparc.c        |  149 ++++++++++++++++++++++-
>  gcc/config/sparc/sparc.md       |    1 +
>  gcc/config/sparc/sparc.opt      |   22 ++++
>  gcc/config/sparc/sync.md        |  258 +++++++++++++++++++++++++--------------
>  gcc/doc/invoke.texi             |   74 ++++++++---
>  9 files changed, 420 insertions(+), 116 deletions(-)

I've committed this sequence to mainline after re-testing on sparc64-linux.

As a follow-up, I have a patch to change the default memory model to TSO for all versions of both Linux and Solaris.  This leaves the memory model set to the most relaxed for the cpu when targeting other OSs, and I suppose in particular RTEMS.

I guess my only question is: has TSO always been the default for Solaris?  I seem to recall Dave saying that Linux used to be RMO, but so long ago that surely no one is using new software on it...

Please give me a yea or nay on the assumptions above.


r~
commit 8d403cd6a943589c708728ef9c3d472d5f810e44
Author: Richard Henderson <rth@redhat.com>
Date:   Wed Nov 30 08:32:34 2011 -0800

    sparc: Default memory model to TSO for Linux and Solaris.

Comments

David Miller Nov. 30, 2011, 5:44 p.m. UTC | #1
From: Richard Henderson <rth@redhat.com>
Date: Wed, 30 Nov 2011 08:39:44 -0800

> I've committed this sequence to mainline after re-testing on
> sparc64-linux.

I've got a regstrap running on Niagara-3, sorry for taking so long :-/

> As a follow-up, I have a patch to change the default memory model to
> TSO for all versions of both Linux and Solaris.  This leaves the
> memory model set to the most relaxed for the cpu when targeting
> other OSs, and I suppose in particular RTEMS.
> 
> I guess my only question is: has TSO always been the default for
> Solaris?  I seem to recall Dave saying that Linux used to be RMO,
> but so long ago that surely no one is using new software on it...

Linux originally did RMO but I killed that several years ago, no
new chips are implementing RMO and this means all the necessary
membar instructions are nothing but pure overhead.

Solaris always ran userspace in TSO as far as I remember.

Your change will leave FreeBSD and NetBSD with the RMO setting, and
both of them run userland in TSO as well.

BTW, Linux has a "memory_ordering" system call where you can change
the PSTATE_MM setting to whatever memory model you like.  I suppose
Solaris has something similar.

So one thing to consider doing is, if there is some doubt, to set
it explicitly to TSO in some crt code.
Richard Henderson Nov. 30, 2011, 6:40 p.m. UTC | #2
On 11/30/2011 09:44 AM, David Miller wrote:
> Linux originally did RMO but I killed that several years ago, no
> new chips are implementing RMO and this means all the necessary
> membar instructions are nothing but pure overhead.

Well, you've now got the option for -mmemory-model=sc to omit every last one.

> Solaris always ran userspace in TSO as far as I remember.

Ok.

> Your change will leave FreeBSD and NetBSD with the RMO setting, and
> both of them run userland in TSO as well.

Eh.  It'll be easy enough for a bsd maintainer to update if they like.

> BTW, Linux has a "memory_ordering" system call where you can change
> the PSTATE_MM setting to whatever memory model you like.  I suppose
> Solaris has something similar.

Interesting, but...

> So one thing to consider doing is, if there is some doubt, to set
> it explicitly to TSO in some crt code.

... easier to keep the RMO/PSO default in that case.


r~
David Miller Nov. 30, 2011, 8:33 p.m. UTC | #3
From: Richard Henderson <rth@redhat.com>
Date: Wed, 30 Nov 2011 10:40:36 -0800

> On 11/30/2011 09:44 AM, David Miller wrote:
>> So one thing to consider doing is, if there is some doubt, to set
>> it explicitly to TSO in some crt code.
> 
> ... easier to keep the RMO/PSO default in that case.

I'd rather you use a default of TSO on Linux.
Richard Henderson Nov. 30, 2011, 9:12 p.m. UTC | #4
On 11/30/2011 12:33 PM, David Miller wrote:
> From: Richard Henderson <rth@redhat.com>
> Date: Wed, 30 Nov 2011 10:40:36 -0800
> 
>> On 11/30/2011 09:44 AM, David Miller wrote:
>>> So one thing to consider doing is, if there is some doubt, to set
>>> it explicitly to TSO in some crt code.
>>
>> ... easier to keep the RMO/PSO default in that case.
> 
> I'd rather you use a default of TSO on Linux.

Of course I'm switching Linux, as the patch says.  What I mean is,
I'm going to leave the cpu default for the other operating systems,
rather than try to play with crt files.


r~
David Miller Nov. 30, 2011, 9:15 p.m. UTC | #5
From: Richard Henderson <rth@redhat.com>
Date: Wed, 30 Nov 2011 13:12:35 -0800

> On 11/30/2011 12:33 PM, David Miller wrote:
>> From: Richard Henderson <rth@redhat.com>
>> Date: Wed, 30 Nov 2011 10:40:36 -0800
>> 
>>> On 11/30/2011 09:44 AM, David Miller wrote:
>>>> So one thing to consider doing is, if there is some doubt, to set
>>>> it explicitly to TSO in some crt code.
>>>
>>> ... easier to keep the RMO/PSO default in that case.
>> 
>> I'd rather you use a default of TSO on Linux.
> 
> Of course I'm switching Linux, as the patch says.  What I mean is,
> I'm going to leave the cpu default for the other operating systems,
> rather than try to play with crt files.

Ok, that makes sense, thanks.
diff mbox

Patch

diff --git a/gcc/config.gcc b/gcc/config.gcc
index a477289..d0f7b28 100644
--- a/gcc/config.gcc
+++ b/gcc/config.gcc
@@ -2357,7 +2357,7 @@  sparc-*-rtems*)
 	tmake_file="sparc/t-sparc sparc/t-elf t-rtems"
 	;;
 sparc-*-linux*)
-	tm_file="${tm_file} dbxelf.h elfos.h sparc/sysv4.h gnu-user.h linux.h glibc-stdint.h"
+	tm_file="${tm_file} dbxelf.h elfos.h sparc/sysv4.h gnu-user.h linux.h glibc-stdint.h sparc/tso.h"
 	extra_options="${extra_options} sparc/long-double-switch.opt"
 	case ${target} in
 	    *-leon-*)
@@ -2384,7 +2384,7 @@  sparc-*-netbsdelf*)
 	tmake_file="${tmake_file} sparc/t-sparc"
 	;;
 sparc*-*-solaris2*)
-	tm_file="sparc/biarch64.h ${tm_file} ${sol2_tm_file} sol2-bi.h"
+	tm_file="sparc/biarch64.h ${tm_file} ${sol2_tm_file} sol2-bi.h sparc/tso.h"
 	case ${target} in
 	    sparc64-*-* | sparcv9-*-*)
 		tm_file="sparc/default-64.h ${tm_file}"
@@ -2410,7 +2410,7 @@  sparc64-*-rtems*)
 	tmake_file="${tmake_file} sparc/t-sparc t-rtems"
 	;;
 sparc64-*-linux*)
-	tm_file="sparc/biarch64.h ${tm_file} dbxelf.h elfos.h sparc/sysv4.h gnu-user.h linux.h glibc-stdint.h sparc/default-64.h sparc/linux64.h"
+	tm_file="sparc/biarch64.h ${tm_file} dbxelf.h elfos.h sparc/sysv4.h gnu-user.h linux.h glibc-stdint.h sparc/default-64.h sparc/linux64.h sparc/tso.h"
 	extra_options="${extra_options} sparc/long-double-switch.opt"
 	tmake_file="${tmake_file} sparc/t-sparc sparc/t-linux64"
 	;;
diff --git a/gcc/config/sparc/sparc.c b/gcc/config/sparc/sparc.c
index 713db26..20efb00 100644
--- a/gcc/config/sparc/sparc.c
+++ b/gcc/config/sparc/sparc.c
@@ -1162,8 +1162,12 @@  sparc_option_override (void)
 
   if (sparc_memory_model == SMM_DEFAULT)
     {
+      /* Choose the memory model for the operating system.  */
+      enum sparc_memory_model_type os_default = SUBTARGET_DEFAULT_MEMORY_MODEL;
+      if (os_default != SMM_DEFAULT)
+	sparc_memory_model = os_default;
       /* Choose the most relaxed model for the processor.  */
-      if (TARGET_V9)
+      else if (TARGET_V9)
 	sparc_memory_model = SMM_RMO;
       else if (TARGET_V8)
 	sparc_memory_model = SMM_PSO;
diff --git a/gcc/config/sparc/sparc.h b/gcc/config/sparc/sparc.h
index 32f8c10..bb6b079 100644
--- a/gcc/config/sparc/sparc.h
+++ b/gcc/config/sparc/sparc.h
@@ -1755,3 +1755,8 @@  extern int sparc_indent_opcode;
 #define MASK_DEBUG_ALL			MASK_DEBUG_OPTIONS
 
 #define TARGET_DEBUG_OPTIONS		(sparc_debug & MASK_DEBUG_OPTIONS)
+
+/* By default, use the weakest memory model for the cpu.  */
+#ifndef SUBTARGET_DEFAULT_MEMORY_MODEL
+#define SUBTARGET_DEFAULT_MEMORY_MODEL	SMM_DEFAULT
+#endif
diff --git a/gcc/config/sparc/tso.h b/gcc/config/sparc/tso.h
new file mode 100644
index 0000000..c81ea4d
--- /dev/null
+++ b/gcc/config/sparc/tso.h
@@ -0,0 +1,23 @@ 
+/* Include fragment for Sparc TSO operating systems.
+   Copyright (C) 2011 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3, or (at your option)
+any later version.
+
+GCC is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GCC; see the file COPYING3.  If not see
+<http://www.gnu.org/licenses/>.  */
+
+
+/* This operating system sets PSTATE.MM to the TSO memory model.  */
+#undef SUBTARGET_DEFAULT_MEMORY_MODEL
+#define SUBTARGET_DEFAULT_MEMORY_MODEL	SMM_TSO