public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Martin Liška" <mliska@suse.cz>
To: Jakub Jelinek <jakub@redhat.com>
Cc: David Edelsohn <dje.gcc@gmail.com>,
	Nathan Sidwell <nathan@acm.org>,
	GCC Patches <gcc-patches@gcc.gnu.org>, Jan Hubicka <jh@suse.cz>,
	Andreas Schwab <schwab@suse.de>,
	Richard Biener <richard.guenther@gmail.com>
Subject: Re: [PATCH] Detect whether target can use -fprofile-update=atomic
Date: Tue, 06 Sep 2016 13:15:00 -0000	[thread overview]
Message-ID: <c28437fa-224d-ae27-89fd-9e3086e26c81@suse.cz> (raw)
In-Reply-To: <20160906125136.GG14857@tucnak.redhat.com>

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

On 09/06/2016 02:51 PM, Jakub Jelinek wrote:
> On Tue, Sep 06, 2016 at 02:45:32PM +0200, Martin Liška wrote:
>> --- a/gcc/tree-profile.c
>> +++ b/gcc/tree-profile.c
>> @@ -528,6 +528,13 @@ gimple_gen_ior_profiler (histogram_value value, unsigned tag, unsigned base)
>>    gsi_insert_before (&gsi, call, GSI_NEW_STMT);
>>  }
>>  
>> +#ifndef HAVE_sync_compare_and_swapsi
>> +#define HAVE_sync_compare_and_swapsi 0
>> +#endif
>> +#ifndef HAVE_atomic_compare_and_swapsi
>> +#define HAVE_atomic_compare_and_swapsi 0
>> +#endif
>> +
>>  /* Profile all functions in the callgraph.  */
>>  
>>  static unsigned int
>> @@ -535,6 +542,16 @@ tree_profiling (void)
>>  {
>>    struct cgraph_node *node;
>>  
>> +  /* Verify whether we can utilize atomic update operations.  */
>> +  if (flag_profile_update == PROFILE_UPDATE_ATOMIC
>> +      && !HAVE_sync_compare_and_swapsi
>> +      && !HAVE_atomic_compare_and_swapsi)
> 
> This isn't in sync with:
> 
>> +/* Detect whether target can support atomic update of profilers.  */
>> +#if LONG_LONG_TYPE_SIZE <= 32 && __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
>> +#define GCOV_SUPPORTS_ATOMIC 1
>> +#else
>> +#if LONG_LONG_TYPE_SIZE > 32 && __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
>> +#define GCOV_SUPPORTS_ATOMIC 1
>> +#else
>> +#define GCOV_SUPPORTS_ATOMIC 0
>> +#endif
>> +#endif
> 
> this.  Either you implement the poor man's 64-bit atomics with 32-bit cas
> and adjust the latter, or the former needs to look at the target's gcov type
> (long long always?) and depending on its size either test the HAVE_*si or
> HAVE_*di macros.
> 
> 	Jakub
> 

Ok, thanks, this should be the proper patch, where I distinguish sizeof(gcov_type) and
use appropriate GAVE_*{s,d}i macros.

Ready for trunk?
Thanks,
Martin

[-- Attachment #2: 0001-PATCH-Detect-whether-target-can-use-fprofile-update-.patch --]
[-- Type: text/x-patch, Size: 6027 bytes --]

From 41bef1e975042071c973c3cb733a0e0d9a59fec6 Mon Sep 17 00:00:00 2001
From: marxin <mliska@suse.cz>
Date: Tue, 6 Sep 2016 14:35:52 +0200
Subject: [PATCH] [PATCH] Detect whether target can use -fprofile-update=atomic

libgcc/ChangeLog:

2016-09-06  Martin Liska  <mliska@suse.cz>

	* libgcov-profiler.c: Use __GCC_HAVE_SYNC_COMPARE_AND_SWAP_{4,8} to
	conditionaly enable/disable *_atomic functions.

gcc/ChangeLog:

2016-09-06  Martin Liska  <mliska@suse.cz>

	* tree-profile.c (tree_profiling): Detect whether target can use
	-fprofile-update=atomic.

gcc/testsuite/ChangeLog:

2016-09-06  Martin Liska  <mliska@suse.cz>

	* gcc.dg/profile-update-warning.c: New test.
---
 gcc/testsuite/gcc.dg/profile-update-warning.c |  7 ++++++
 gcc/tree-profile.c                            | 35 +++++++++++++++++++++++++++
 libgcc/libgcov-profiler.c                     | 24 ++++++++++++++----
 3 files changed, 61 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/profile-update-warning.c

diff --git a/gcc/testsuite/gcc.dg/profile-update-warning.c b/gcc/testsuite/gcc.dg/profile-update-warning.c
new file mode 100644
index 0000000..0614fad
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/profile-update-warning.c
@@ -0,0 +1,7 @@
+/* { dg-do compile { target { i?86-*-* x86_64-*-* } } } */
+/* { dg-options "-fprofile-update=atomic -fprofile-generate -march=i386 -m32" } */
+
+int main(int argc, char *argv[])
+{
+  return 0;
+} /* { dg-warning "target does not support atomic profile update, single mode is selected" } */
diff --git a/gcc/tree-profile.c b/gcc/tree-profile.c
index 622869e..a3e6dca 100644
--- a/gcc/tree-profile.c
+++ b/gcc/tree-profile.c
@@ -528,6 +528,20 @@ gimple_gen_ior_profiler (histogram_value value, unsigned tag, unsigned base)
   gsi_insert_before (&gsi, call, GSI_NEW_STMT);
 }
 
+#ifndef HAVE_sync_compare_and_swapsi
+#define HAVE_sync_compare_and_swapsi 0
+#endif
+#ifndef HAVE_atomic_compare_and_swapsi
+#define HAVE_atomic_compare_and_swapsi 0
+#endif
+
+#ifndef HAVE_sync_compare_and_swapdi
+#define HAVE_sync_compare_and_swapdi 0
+#endif
+#ifndef HAVE_atomic_compare_and_swapdi
+#define HAVE_atomic_compare_and_swapdi 0
+#endif
+
 /* Profile all functions in the callgraph.  */
 
 static unsigned int
@@ -535,6 +549,27 @@ tree_profiling (void)
 {
   struct cgraph_node *node;
 
+  /* Verify whether we can utilize atomic update operations.  */
+  if (flag_profile_update == PROFILE_UPDATE_ATOMIC)
+    {
+      bool can_support = false;
+      if (sizeof (gcov_type) == 4)
+	can_support
+	  = HAVE_sync_compare_and_swapsi || HAVE_atomic_compare_and_swapsi;
+      else if (sizeof (gcov_type) == 8)
+	can_support
+	  = HAVE_sync_compare_and_swapdi || HAVE_atomic_compare_and_swapdi;
+      else
+	gcc_unreachable ();
+
+      if (!can_support)
+      {
+	warning (0, "target does not support atomic profile update, "
+		 "single mode is selected");
+	flag_profile_update = PROFILE_UPDATE_SINGLE;
+      }
+    }
+
   /* This is a small-ipa pass that gets called only once, from
      cgraphunit.c:ipa_passes().  */
   gcc_assert (symtab->state == IPA_SSA);
diff --git a/libgcc/libgcov-profiler.c b/libgcc/libgcov-profiler.c
index 70a821d..887041f 100644
--- a/libgcc/libgcov-profiler.c
+++ b/libgcc/libgcov-profiler.c
@@ -24,8 +24,20 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
 #include "libgcov.h"
+#include "auto-target.h"
 #if !defined(inhibit_libc)
 
+/* Detect whether target can support atomic update of profilers.  */
+#if LONG_LONG_TYPE_SIZE <= 32 && __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4
+#define GCOV_SUPPORTS_ATOMIC 1
+#else
+#if LONG_LONG_TYPE_SIZE > 32 && __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8
+#define GCOV_SUPPORTS_ATOMIC 1
+#else
+#define GCOV_SUPPORTS_ATOMIC 0
+#endif
+#endif
+
 #ifdef L_gcov_interval_profiler
 /* If VALUE is in interval <START, START + STEPS - 1>, then increases the
    corresponding counter in COUNTERS.  If the VALUE is above or below
@@ -46,7 +58,7 @@ __gcov_interval_profiler (gcov_type *counters, gcov_type value,
 }
 #endif
 
-#ifdef L_gcov_interval_profiler_atomic
+#if defined(L_gcov_interval_profiler_atomic) && GCOV_SUPPORTS_ATOMIC
 /* If VALUE is in interval <START, START + STEPS - 1>, then increases the
    corresponding counter in COUNTERS.  If the VALUE is above or below
    the interval, COUNTERS[STEPS] or COUNTERS[STEPS + 1] is increased
@@ -80,7 +92,7 @@ __gcov_pow2_profiler (gcov_type *counters, gcov_type value)
 }
 #endif
 
-#ifdef L_gcov_pow2_profiler_atomic
+#if defined(L_gcov_pow2_profiler_atomic) && GCOV_SUPPORTS_ATOMIC
 /* If VALUE is a power of two, COUNTERS[1] is incremented.  Otherwise
    COUNTERS[0] is incremented.  Function is thread-safe.  */
 
@@ -134,7 +146,7 @@ __gcov_one_value_profiler (gcov_type *counters, gcov_type value)
 }
 #endif
 
-#ifdef L_gcov_one_value_profiler_atomic
+#if defined(L_gcov_one_value_profiler_atomic) && GCOV_SUPPORTS_ATOMIC
 
 /* Update one value profilers (COUNTERS) for a given VALUE.
 
@@ -342,6 +354,7 @@ __gcov_time_profiler (gcov_type* counters)
     counters[0] = ++function_counter;
 }
 
+#if GCOV_SUPPORTS_ATOMIC
 /* Sets corresponding COUNTERS if there is no value.
    Function is thread-safe.  */
 
@@ -352,6 +365,7 @@ __gcov_time_profiler_atomic (gcov_type* counters)
     counters[0] = __atomic_add_fetch (&function_counter, 1, MEMMODEL_RELAXED);
 }
 #endif
+#endif
 
 
 #ifdef L_gcov_average_profiler
@@ -366,7 +380,7 @@ __gcov_average_profiler (gcov_type *counters, gcov_type value)
 }
 #endif
 
-#ifdef L_gcov_average_profiler_atomic
+#if defined(L_gcov_average_profiler_atomic) && GCOV_SUPPORTS_ATOMIC
 /* Increase corresponding COUNTER by VALUE.  FIXME: Perhaps we want
    to saturate up.  Function is thread-safe.  */
 
@@ -388,7 +402,7 @@ __gcov_ior_profiler (gcov_type *counters, gcov_type value)
 }
 #endif
 
-#ifdef L_gcov_ior_profiler_atomic
+#if defined(L_gcov_ior_profiler_atomic) && GCOV_SUPPORTS_ATOMIC
 /* Bitwise-OR VALUE into COUNTER.  Function is thread-safe.  */
 
 void
-- 
2.9.2


  reply	other threads:[~2016-09-06 13:13 UTC|newest]

Thread overview: 95+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-01  8:50 [PATCH 0/4] Various GCOV/PGO improvements marxin
2016-08-01  8:49 ` [PATCH 3/4] Fix typo in gcov.texi marxin
2016-08-01  8:50 ` [PATCH 2/4] Remove __gcov_indirect_call_profiler marxin
2016-08-01  8:50 ` [PATCH 1/4] Cherry-pick fprofile-generate-atomic from google/gcc-4_9 branch marxin
2016-08-01 12:22   ` Nathan Sidwell
2016-08-01 13:29     ` Martin Liška
2016-08-04 14:48       ` Nathan Sidwell
2016-08-04 15:34         ` Martin Liška
2016-08-04 16:43           ` Nathan Sidwell
2016-08-04 17:03             ` Nathan Sidwell
2016-08-05  8:55               ` Martin Liška
2016-08-05 12:38                 ` Nathan Sidwell
2016-08-05 12:48                   ` Martin Liška
2016-08-05 13:14                     ` Nathan Sidwell
2016-08-05 13:43                       ` Martin Liška
2016-08-08 13:59                         ` [PATCH 5/N] Add new *_atomic counter update function, (-fprofile-update=atomic) Martin Liška
2016-08-08 15:24                           ` Nathan Sidwell
2016-08-08 16:51                             ` Martin Liška
2016-08-08 17:03                               ` Martin Liška
2016-08-09 12:36                                 ` Nathan Sidwell
2016-08-08 16:56                             ` [PATCH] Fix POW2 histogram Martin Liška
2016-08-09  8:41                               ` [PATCH 2/N] Fix usage of " Martin Liška
2016-08-09 12:37                                 ` Nathan Sidwell
2016-08-09 12:34                               ` [PATCH] Fix " Nathan Sidwell
2016-08-09 11:24                         ` [PATCH] Set -fprofile-update=atomic when -pthread is present Martin Liška
2016-08-09 12:40                           ` Nathan Sidwell
2016-08-09 19:04                           ` Andi Kleen
2016-08-12 13:31                             ` Martin Liška
2016-08-18  3:16                               ` Jeff Law
2016-08-18 11:02                                 ` Nathan Sidwell
2016-08-18 15:51                                 ` Andi Kleen
2016-08-18 15:53                                   ` Jeff Law
2016-10-03 12:13                                     ` Martin Liška
2016-10-03 12:26                                       ` Nathan Sidwell
2016-10-03 16:46                                         ` Jeff Law
2016-10-03 17:52                                           ` Andi Kleen
2016-10-04 12:05                                         ` Martin Liška
2016-10-05 17:54                                           ` Jeff Law
2016-10-13 15:34                                           ` [PATCH] Introduce -fprofile-update=maybe-atomic Martin Liška
2016-10-31  9:13                                             ` Martin Liška
2016-11-10 13:19                                               ` Martin Liška
2016-11-10 15:43                                                 ` Nathan Sidwell
2016-11-10 15:55                                                   ` David Edelsohn
2016-11-10 16:18                                                     ` Nathan Sidwell
2016-11-10 15:58                                                   ` Martin Liška
2016-11-10 16:17                                                     ` David Edelsohn
2016-11-10 16:24                                                       ` Martin Liška
2016-11-10 17:31                                                         ` Nathan Sidwell
2016-11-11 10:48                                                           ` Martin Liška
2016-11-11 15:11                                                             ` Nathan Sidwell
2016-11-10 16:14                                                   ` Nathan Sidwell
2016-11-10 16:16                                                     ` David Edelsohn
2016-08-18 15:54                                   ` [PATCH] Set -fprofile-update=atomic when -pthread is present Jakub Jelinek
2016-08-18 16:06                                     ` Richard Biener
2016-09-07 11:41                                       ` Martin Liška
     [not found]                                         ` <CAFiYyc0UaSzXhZmyG9QRkHGT4JFowxBfE2yb-NvXE=hR1xafdA@mail.gmail.com>
2016-09-15 10:18                                           ` [RFC] Speed-up -fprofile-update=atomic Martin Liška
2016-10-04  9:45                                             ` Richard Biener
2016-10-12 13:53                                               ` Martin Liška
2016-10-13  9:43                                                 ` Richard Biener
2016-10-17 11:47                                                   ` Martin Liška
     [not found]                                                     ` <CAFiYyc3eDT4g926PPZuktz5fEW=k-PibAcxhigx4GBcxoXNJFQ@mail.gmail.com>
2016-10-24 12:09                                                       ` Martin Liška
     [not found]                                                         ` <CAFiYyc1tSdTdqqkHcMp+dgE43+8tHL6kY8E07TCHoZBeUT-ggQ@mail.gmail.com>
2016-10-25 14:32                                                           ` Martin Liška
2016-10-26  9:29                                                             ` Richard Biener
2016-10-26  9:32                                                               ` Richard Biener
2016-08-18 16:04                                   ` [PATCH] Set -fprofile-update=atomic when -pthread is present Richard Biener
2016-08-10 12:57                         ` [PATCH 1/4] Cherry-pick fprofile-generate-atomic from google/gcc-4_9 branch Nathan Sidwell
2016-08-13 12:14                         ` [BUILDROBOT] avr broken (was: [PATCH 1/4] Cherry-pick fprofile-generate-atomic from google/gcc-4_9 branch) Jan-Benedict Glaw
     [not found]                           ` <4455937b-eba7-fe66-fe1a-3172567dd1e4@suse.cz>
2016-08-16 13:36                             ` [BUILDROBOT] avr broken Nathan Sidwell
     [not found]                               ` <617e8799-b7db-fefd-b3a3-842e9a7decfd@suse.cz>
2016-08-16 14:31                                 ` Nathan Sidwell
2016-08-16 17:05                                   ` Jan-Benedict Glaw
2016-08-16 18:26                                     ` Nathan Sidwell
2016-08-17  7:21                                       ` Denis Chertykov
2016-08-17  7:22                                         ` Martin Liška
2016-08-17  8:11                                       ` Jan-Benedict Glaw
2016-08-16 12:56                         ` [PATCH] Detect whether target can use -fprofile-update=atomic Martin Liška
2016-08-16 14:31                           ` Nathan Sidwell
2016-09-06 10:57                             ` Martin Liška
2016-09-06 11:17                               ` David Edelsohn
2016-09-06 12:15                                 ` Nathan Sidwell
2016-09-06 12:39                                   ` Jakub Jelinek
2016-09-06 12:43                                     ` David Edelsohn
2016-09-06 12:41                                   ` David Edelsohn
2016-09-06 12:51                                     ` Martin Liška
2016-09-06 13:13                                       ` Jakub Jelinek
2016-09-06 13:15                                         ` Martin Liška [this message]
2016-09-06 13:45                                           ` Jakub Jelinek
2016-09-06 13:50                                             ` Martin Liška
2016-09-06 14:06                                               ` Jakub Jelinek
2016-09-07  7:52                                               ` Christophe Lyon
2016-09-07  9:35                                                 ` Martin Liška
2016-09-07 16:06                                                   ` Christophe Lyon
2016-09-12 20:20                                                   ` Jeff Law
2016-09-29  8:31                                               ` Rainer Orth
2016-08-01  8:50 ` [PATCH 4/4] Add tests for __gcov_dump and __gcov_reset marxin
2016-08-01 12:11 ` [PATCH 0/4] Various GCOV/PGO improvements Nathan Sidwell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c28437fa-224d-ae27-89fd-9e3086e26c81@suse.cz \
    --to=mliska@suse.cz \
    --cc=dje.gcc@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=jh@suse.cz \
    --cc=nathan@acm.org \
    --cc=richard.guenther@gmail.com \
    --cc=schwab@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).