public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][libstc++v3]Add new dg-require-thread-fence directive.
@ 2015-04-21 14:32 Renlin Li
  2015-04-22 10:19 ` Jonathan Wakely
  0 siblings, 1 reply; 6+ messages in thread
From: Renlin Li @ 2015-04-21 14:32 UTC (permalink / raw)
  To: gcc-patches, libstdc++; +Cc: Richard.Earnshaw, Ramana.Radhakrishnan

[-- Attachment #1: Type: text/plain, Size: 1404 bytes --]

Hi all,

This patch defines a new dg-require-thread-fence directive. And three 
test cases are updated to use it.

The new directive are used to check whether the target support thread 
fence either by the target back-end or external library function call. A 
thread fence is required to expand atomic load/store.

There is a case that a call to some external __sync_synchronize will be 
emitted, and it's not implemented. You will get linking errors like 
this: undefined reference to `__sync_synchronize`. Test cases which are 
gated by this directive will be skipped if no thread fence is available. 
For example the three test cases updated here. They fail on 
arm-none-eabi target where __sync_synchronize() isn't implemented and 
target cpu has no memory_barrier.

___sync_synchronize () is used to check whether thread-fence is 
available. In GCC sync_synchronize is expanded as 
expand_mem_thread_fence (MEMMODEL_SEQ_CST).

Okay to commit?


libstdc++-v3/ChangeLog:

2015-04-21  Renlin Li  <renlin.li@arm.com>

     * testsuite/lib/dg-options.exp (dg-require-thread-fence): New.
     * testsuite/lib/libstdc++.exp (check_v3_target_thread_fence): New.
     * testsuite/29_atomics/atomic_flag/clear/1.cc: Use it.
     * testsuite/29_atomics/atomic_flag/test_and_set/explicit.cc: Likewise.
     * testsuite/29_atomics/atomic_flag/test_and_set/implicit.cc: Likewise.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: fence-new.diff --]
[-- Type: text/x-patch; name=fence-new.diff, Size: 4179 bytes --]

diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_flag/clear/1.cc b/libstdc++-v3/testsuite/29_atomics/atomic_flag/clear/1.cc
index 0a4219c..a6e2299 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic_flag/clear/1.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_flag/clear/1.cc
@@ -1,4 +1,5 @@
 // { dg-options "-std=gnu++11" }
+// { dg-require-thread-fence "" }
 
 // Copyright (C) 2009-2015 Free Software Foundation, Inc.
 //
diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/explicit.cc b/libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/explicit.cc
index 2ff740b..0655be4 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/explicit.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/explicit.cc
@@ -1,4 +1,5 @@
 // { dg-options "-std=gnu++11" }
+// { dg-require-thread-fence "" }
 
 // Copyright (C) 2008-2015 Free Software Foundation, Inc.
 //
diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/implicit.cc b/libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/implicit.cc
index 6ac20c0..a867da2 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/implicit.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/implicit.cc
@@ -1,4 +1,5 @@
 // { dg-options "-std=gnu++11" }
+// { dg-require-thread-fence "" }
 
 // Copyright (C) 2008-2015 Free Software Foundation, Inc.
 //
diff --git a/libstdc++-v3/testsuite/lib/dg-options.exp b/libstdc++-v3/testsuite/lib/dg-options.exp
index 38c8206..56ca896 100644
--- a/libstdc++-v3/testsuite/lib/dg-options.exp
+++ b/libstdc++-v3/testsuite/lib/dg-options.exp
@@ -115,6 +115,15 @@ proc dg-require-cmath { args } {
     return
 }
 
+proc dg-require-thread-fence { args } {
+    if { ![ check_v3_target_thread_fence ] } {
+	upvar dg-do-what dg-do-what
+	set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
+	return
+    }
+    return
+}
+
 proc dg-require-atomic-builtins { args } {
     if { ![ check_v3_target_atomic_builtins ] } {
 	upvar dg-do-what dg-do-what
diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp
index b2f7d00..9e395e2 100644
--- a/libstdc++-v3/testsuite/lib/libstdc++.exp
+++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
@@ -1221,6 +1221,62 @@ proc check_v3_target_cmath { } {
     return $et_c99_math
 }
 
+proc check_v3_target_thread_fence { } {
+    global cxxflags
+    global DEFAULT_CXXFLAGS
+    global et_thread_fence
+
+    global tool
+
+    if { ![info exists et_thread_fence_target_name] } {
+	set et_thread_fence_target_name ""
+    }
+
+    # If the target has changed since we set the cached value, clear it.
+    set current_target [current_target_name]
+    if { $current_target != $et_thread_fence_target_name } {
+	verbose "check_v3_target_thread_fence: `$et_thread_fence_target_name'" 2
+	set et_thread_fence_target_name $current_target
+	if [info exists et_thread_fence] {
+	    verbose "check_v3_target_thread_fence: removing cached result" 2
+	    unset et_thread_fence
+	}
+    }
+
+    if [info exists et_thread_fence] {
+	verbose "check_v3_target_thread_fence: using cached result" 2
+    } else {
+	set et_thread_fence 0
+
+	# Set up and preprocess a C++11 test program that depends
+	# on the thread fence to be available.
+	set src thread_fence[pid].cc
+
+	set f [open $src "w"]
+	puts $f "int main() {"
+	puts $f "__sync_synchronize ();"
+	puts $f "return 0;"
+	puts $f "}"
+	close $f
+
+	set cxxflags_saved $cxxflags
+	set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror -std=gnu++11"
+
+	set lines [v3_target_compile $src /dev/null executable ""]
+	set cxxflags $cxxflags_saved
+	file delete $src
+
+	if [string match "" $lines] {
+	    # No error message, linking succeeded.
+	    set et_thread_fence 1
+	} else {
+	    verbose "check_v3_target_thread_fence: compilation failed" 2
+	}
+    }
+    verbose "check_v3_target_thread_fence: $et_thread_fence" 2
+    return $et_thread_fence
+}
+
 proc check_v3_target_atomic_builtins { } {
     global cxxflags
     global DEFAULT_CXXFLAGS

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][libstc++v3]Add new dg-require-thread-fence directive.
  2015-04-21 14:32 [PATCH][libstc++v3]Add new dg-require-thread-fence directive Renlin Li
@ 2015-04-22 10:19 ` Jonathan Wakely
  2015-04-22 11:43   ` Renlin Li
  0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Wakely @ 2015-04-22 10:19 UTC (permalink / raw)
  To: Renlin Li; +Cc: gcc-patches, libstdc++, Richard.Earnshaw, Ramana.Radhakrishnan

On 21/04/15 15:29 +0100, Renlin Li wrote:
>Hi all,
>
>This patch defines a new dg-require-thread-fence directive. And three 
>test cases are updated to use it.
>
>The new directive are used to check whether the target support thread 
>fence either by the target back-end or external library function call. 
>A thread fence is required to expand atomic load/store.
>
>There is a case that a call to some external __sync_synchronize will 
>be emitted, and it's not implemented. You will get linking errors like 
>this: undefined reference to `__sync_synchronize`. Test cases which 
>are gated by this directive will be skipped if no thread fence is 
>available. For example the three test cases updated here. They fail on 
>arm-none-eabi target where __sync_synchronize() isn't implemented and 
>target cpu has no memory_barrier.
>
>___sync_synchronize () is used to check whether thread-fence is 
>available. In GCC sync_synchronize is expanded as 
>expand_mem_thread_fence (MEMMODEL_SEQ_CST).

I don't like making the directive depend directly on the legacy
__sync_synchronize function, because that function is not required on
most targets, AFAICT it's only needed for ARM and MIPS.

Could you make the directive check
__atomic_thread_fence(__ATOMIC_SEQ_CST) instead? I think that will
still expand to __sync_synchronize() for ARM, so should still test the
same thing, but that way we aren't adding a dependency on
__sync_synchronize for all targets.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][libstc++v3]Add new dg-require-thread-fence directive.
  2015-04-22 10:19 ` Jonathan Wakely
@ 2015-04-22 11:43   ` Renlin Li
  2015-04-22 12:59     ` Jonathan Wakely
  0 siblings, 1 reply; 6+ messages in thread
From: Renlin Li @ 2015-04-22 11:43 UTC (permalink / raw)
  To: Jonathan Wakely
  Cc: gcc-patches, libstdc++, Richard Earnshaw, Ramana Radhakrishnan

[-- Attachment #1: Type: text/plain, Size: 1734 bytes --]

Hi Jonathan,

Thank you for the suggestion. I have just attached the updated the 
patch. It works as before.
Is this Okay to commit?

Regards,
Renlin Li

On 22/04/15 11:19, Jonathan Wakely wrote:
> On 21/04/15 15:29 +0100, Renlin Li wrote:
>> Hi all,
>>
>> This patch defines a new dg-require-thread-fence directive. And three
>> test cases are updated to use it.
>>
>> The new directive are used to check whether the target support thread
>> fence either by the target back-end or external library function call.
>> A thread fence is required to expand atomic load/store.
>>
>> There is a case that a call to some external __sync_synchronize will
>> be emitted, and it's not implemented. You will get linking errors like
>> this: undefined reference to `__sync_synchronize`. Test cases which
>> are gated by this directive will be skipped if no thread fence is
>> available. For example the three test cases updated here. They fail on
>> arm-none-eabi target where __sync_synchronize() isn't implemented and
>> target cpu has no memory_barrier.
>>
>> ___sync_synchronize () is used to check whether thread-fence is
>> available. In GCC sync_synchronize is expanded as
>> expand_mem_thread_fence (MEMMODEL_SEQ_CST).
> I don't like making the directive depend directly on the legacy
> __sync_synchronize function, because that function is not required on
> most targets, AFAICT it's only needed for ARM and MIPS.
>
> Could you make the directive check
> __atomic_thread_fence(__ATOMIC_SEQ_CST) instead? I think that will
> still expand to __sync_synchronize() for ARM, so should still test the
> same thing, but that way we aren't adding a dependency on
> __sync_synchronize for all targets.
>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: fence-new.diff --]
[-- Type: text/x-patch; name=fence-new.diff, Size: 4198 bytes --]

diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_flag/clear/1.cc b/libstdc++-v3/testsuite/29_atomics/atomic_flag/clear/1.cc
index 0a4219c..a6e2299 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic_flag/clear/1.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_flag/clear/1.cc
@@ -1,4 +1,5 @@
 // { dg-options "-std=gnu++11" }
+// { dg-require-thread-fence "" }
 
 // Copyright (C) 2009-2015 Free Software Foundation, Inc.
 //
diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/explicit.cc b/libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/explicit.cc
index 2ff740b..0655be4 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/explicit.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/explicit.cc
@@ -1,4 +1,5 @@
 // { dg-options "-std=gnu++11" }
+// { dg-require-thread-fence "" }
 
 // Copyright (C) 2008-2015 Free Software Foundation, Inc.
 //
diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/implicit.cc b/libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/implicit.cc
index 6ac20c0..a867da2 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/implicit.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_flag/test_and_set/implicit.cc
@@ -1,4 +1,5 @@
 // { dg-options "-std=gnu++11" }
+// { dg-require-thread-fence "" }
 
 // Copyright (C) 2008-2015 Free Software Foundation, Inc.
 //
diff --git a/libstdc++-v3/testsuite/lib/dg-options.exp b/libstdc++-v3/testsuite/lib/dg-options.exp
index 38c8206..56ca896 100644
--- a/libstdc++-v3/testsuite/lib/dg-options.exp
+++ b/libstdc++-v3/testsuite/lib/dg-options.exp
@@ -115,6 +115,15 @@ proc dg-require-cmath { args } {
     return
 }
 
+proc dg-require-thread-fence { args } {
+    if { ![ check_v3_target_thread_fence ] } {
+	upvar dg-do-what dg-do-what
+	set dg-do-what [list [lindex ${dg-do-what} 0] "N" "P"]
+	return
+    }
+    return
+}
+
 proc dg-require-atomic-builtins { args } {
     if { ![ check_v3_target_atomic_builtins ] } {
 	upvar dg-do-what dg-do-what
diff --git a/libstdc++-v3/testsuite/lib/libstdc++.exp b/libstdc++-v3/testsuite/lib/libstdc++.exp
index b2f7d00..9e395e2 100644
--- a/libstdc++-v3/testsuite/lib/libstdc++.exp
+++ b/libstdc++-v3/testsuite/lib/libstdc++.exp
@@ -1221,6 +1221,62 @@ proc check_v3_target_cmath { } {
     return $et_c99_math
 }
 
+proc check_v3_target_thread_fence { } {
+    global cxxflags
+    global DEFAULT_CXXFLAGS
+    global et_thread_fence
+
+    global tool
+
+    if { ![info exists et_thread_fence_target_name] } {
+	set et_thread_fence_target_name ""
+    }
+
+    # If the target has changed since we set the cached value, clear it.
+    set current_target [current_target_name]
+    if { $current_target != $et_thread_fence_target_name } {
+	verbose "check_v3_target_thread_fence: `$et_thread_fence_target_name'" 2
+	set et_thread_fence_target_name $current_target
+	if [info exists et_thread_fence] {
+	    verbose "check_v3_target_thread_fence: removing cached result" 2
+	    unset et_thread_fence
+	}
+    }
+
+    if [info exists et_thread_fence] {
+	verbose "check_v3_target_thread_fence: using cached result" 2
+    } else {
+	set et_thread_fence 0
+
+	# Set up and preprocess a C++11 test program that depends
+	# on the thread fence to be available.
+	set src thread_fence[pid].cc
+
+	set f [open $src "w"]
+	puts $f "int main() {"
+	puts $f "__atomic_thread_fence (__ATOMIC_SEQ_CST);"
+	puts $f "return 0;"
+	puts $f "}"
+	close $f
+
+	set cxxflags_saved $cxxflags
+	set cxxflags "$cxxflags $DEFAULT_CXXFLAGS -Werror -std=gnu++11"
+
+	set lines [v3_target_compile $src /dev/null executable ""]
+	set cxxflags $cxxflags_saved
+	file delete $src
+
+	if [string match "" $lines] {
+	    # No error message, linking succeeded.
+	    set et_thread_fence 1
+	} else {
+	    verbose "check_v3_target_thread_fence: compilation failed" 2
+	}
+    }
+    verbose "check_v3_target_thread_fence: $et_thread_fence" 2
+    return $et_thread_fence
+}
+
 proc check_v3_target_atomic_builtins { } {
     global cxxflags
     global DEFAULT_CXXFLAGS

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][libstc++v3]Add new dg-require-thread-fence directive.
  2015-04-22 11:43   ` Renlin Li
@ 2015-04-22 12:59     ` Jonathan Wakely
  2015-05-06  8:27       ` Renlin Li
  0 siblings, 1 reply; 6+ messages in thread
From: Jonathan Wakely @ 2015-04-22 12:59 UTC (permalink / raw)
  To: Renlin Li
  Cc: Jonathan Wakely, gcc-patches, libstdc++,
	Richard Earnshaw, Ramana Radhakrishnan

On 22 April 2015 at 12:25, Renlin Li wrote:
> Hi Jonathan,
>
> Thank you for the suggestion. I have just attached the updated the patch. It
> works as before.
> Is this Okay to commit?

OK, thanks.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][libstc++v3]Add new dg-require-thread-fence directive.
  2015-04-22 12:59     ` Jonathan Wakely
@ 2015-05-06  8:27       ` Renlin Li
  2015-05-06 15:43         ` Jonathan Wakely
  0 siblings, 1 reply; 6+ messages in thread
From: Renlin Li @ 2015-05-06  8:27 UTC (permalink / raw)
  To: Jonathan Wakely
  Cc: Jonathan Wakely, gcc-patches, libstdc++, Ramana Radhakrishnan

Hi Jonathan,

On 22/04/15 13:58, Jonathan Wakely wrote:
> On 22 April 2015 at 12:25, Renlin Li wrote:
>> Hi Jonathan,
>>
>> Thank you for the suggestion. I have just attached the updated the patch. It
>> works as before.
>> Is this Okay to commit?
> OK, thanks.
>

Is it Okay for me to backport this patch to branch 5.0 and 4.9?

Regards,
Renlin Li

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH][libstc++v3]Add new dg-require-thread-fence directive.
  2015-05-06  8:27       ` Renlin Li
@ 2015-05-06 15:43         ` Jonathan Wakely
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Wakely @ 2015-05-06 15:43 UTC (permalink / raw)
  To: Renlin Li; +Cc: Jonathan Wakely, gcc-patches, libstdc++, Ramana Radhakrishnan

On 6 May 2015 at 09:27, Renlin Li wrote:
> Hi Jonathan,
>
>
> On 22/04/15 13:58, Jonathan Wakely wrote:
>>
>> On 22 April 2015 at 12:25, Renlin Li wrote:
>>>
>>> Hi Jonathan,
>>>
>>> Thank you for the suggestion. I have just attached the updated the patch.
>>> It
>>> works as before.
>>> Is this Okay to commit?
>>
>> OK, thanks.
>>
>
> Is it Okay for me to backport this patch to branch 5.0 and 4.9?

Yes, OK.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-05-06 15:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-21 14:32 [PATCH][libstc++v3]Add new dg-require-thread-fence directive Renlin Li
2015-04-22 10:19 ` Jonathan Wakely
2015-04-22 11:43   ` Renlin Li
2015-04-22 12:59     ` Jonathan Wakely
2015-05-06  8:27       ` Renlin Li
2015-05-06 15:43         ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).