aboutsummaryrefslogtreecommitdiff
path: root/libgcc
diff options
context:
space:
mode:
authorMartin Liska <mliska@suse.cz>2016-08-10 15:14:56 +0200
committerMartin Liska <marxin@gcc.gnu.org>2016-08-10 13:14:56 +0000
commita266236e856aec790b1757064eccff876fad4703 (patch)
tree4e0657ae5a14e0c48b2bae73db433a086900d985 /libgcc
parent22063dbc90d0eb8a7cc7939e0941899f90b403db (diff)
downloadgcc-a266236e856aec790b1757064eccff876fad4703.zip
gcc-a266236e856aec790b1757064eccff876fad4703.tar.gz
gcc-a266236e856aec790b1757064eccff876fad4703.tar.bz2
Add new *_atomic counter update function
PR gcov-profile/58306 * Makefile.in: New functions (modules) are added. * libgcov-profiler.c (__gcov_interval_profiler_atomic): New function. (__gcov_pow2_profiler_atomic): New function. (__gcov_one_value_profiler_body): New argument is instroduced. (__gcov_one_value_profiler): Call with the new argument. (__gcov_one_value_profiler_atomic): Likewise. (__gcov_indirect_call_profiler_v2): Likewise. (__gcov_time_profiler_atomic): New function. (__gcov_average_profiler_atomic): Likewise. (__gcov_ior_profiler_atomic): Likewise. * libgcov.h: Declare the aforementioned functions. PR gcov-profile/58306 * gcc.dg/tree-prof/val-profiler-threads-1.c: New test. PR gcov-profile/58306 * tree-profile.c (gimple_init_edge_profiler): Create conditionally atomic variants of profile update functions. From-SVN: r239324
Diffstat (limited to 'libgcc')
-rw-r--r--libgcc/ChangeLog16
-rw-r--r--libgcc/Makefile.in14
-rw-r--r--libgcc/libgcov-profiler.c103
-rw-r--r--libgcc/libgcov.h7
4 files changed, 132 insertions, 8 deletions
diff --git a/libgcc/ChangeLog b/libgcc/ChangeLog
index 866d14a..49186fa 100644
--- a/libgcc/ChangeLog
+++ b/libgcc/ChangeLog
@@ -1,3 +1,19 @@
+2016-08-10 Martin Liska <mliska@suse.cz>
+
+ PR gcov-profile/58306
+ * Makefile.in: New functions (modules) are added.
+ * libgcov-profiler.c (__gcov_interval_profiler_atomic): New
+ function.
+ (__gcov_pow2_profiler_atomic): New function.
+ (__gcov_one_value_profiler_body): New argument is instroduced.
+ (__gcov_one_value_profiler): Call with the new argument.
+ (__gcov_one_value_profiler_atomic): Likewise.
+ (__gcov_indirect_call_profiler_v2): Likewise.
+ (__gcov_time_profiler_atomic): New function.
+ (__gcov_average_profiler_atomic): Likewise.
+ (__gcov_ior_profiler_atomic): Likewise.
+ * libgcov.h: Declare the aforementioned functions.
+
2016-08-09 Martin Liska <mliska@suse.cz>
* libgcov-util.c: Fix typo and GNU coding style.
diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in
index efaf7f7..ba37c65 100644
--- a/libgcc/Makefile.in
+++ b/libgcc/Makefile.in
@@ -858,10 +858,18 @@ include $(iterator)
LIBGCOV_MERGE = _gcov_merge_add _gcov_merge_single _gcov_merge_delta \
_gcov_merge_ior _gcov_merge_time_profile _gcov_merge_icall_topn
-LIBGCOV_PROFILER = _gcov_interval_profiler _gcov_pow2_profiler \
+LIBGCOV_PROFILER = _gcov_interval_profiler \
+ _gcov_interval_profiler_atomic \
+ _gcov_pow2_profiler \
+ _gcov_pow2_profiler_atomic \
_gcov_one_value_profiler \
- _gcov_average_profiler _gcov_ior_profiler \
- _gcov_indirect_call_profiler_v2 _gcov_time_profiler \
+ _gcov_one_value_profiler_atomic \
+ _gcov_average_profiler \
+ _gcov_average_profiler_atomic \
+ _gcov_ior_profiler \
+ _gcov_ior_profiler_atomic \
+ _gcov_indirect_call_profiler_v2 \
+ _gcov_time_profiler \
_gcov_indirect_call_topn_profiler
LIBGCOV_INTERFACE = _gcov_dump _gcov_flush _gcov_fork \
_gcov_execl _gcov_execlp \
diff --git a/libgcc/libgcov-profiler.c b/libgcc/libgcov-profiler.c
index a99d93b..70a821d 100644
--- a/libgcc/libgcov-profiler.c
+++ b/libgcc/libgcov-profiler.c
@@ -46,6 +46,26 @@ __gcov_interval_profiler (gcov_type *counters, gcov_type value,
}
#endif
+#ifdef L_gcov_interval_profiler_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
+ instead. Function is thread-safe. */
+
+void
+__gcov_interval_profiler_atomic (gcov_type *counters, gcov_type value,
+ int start, unsigned steps)
+{
+ gcov_type delta = value - start;
+ if (delta < 0)
+ __atomic_fetch_add (&counters[steps + 1], 1, MEMMODEL_RELAXED);
+ else if (delta >= steps)
+ __atomic_fetch_add (&counters[steps], 1, MEMMODEL_RELAXED);
+ else
+ __atomic_fetch_add (&counters[delta], 1, MEMMODEL_RELAXED);
+}
+#endif
+
#ifdef L_gcov_pow2_profiler
/* If VALUE is a power of two, COUNTERS[1] is incremented. Otherwise
COUNTERS[0] is incremented. */
@@ -60,6 +80,21 @@ __gcov_pow2_profiler (gcov_type *counters, gcov_type value)
}
#endif
+#ifdef L_gcov_pow2_profiler_atomic
+/* If VALUE is a power of two, COUNTERS[1] is incremented. Otherwise
+ COUNTERS[0] is incremented. Function is thread-safe. */
+
+void
+__gcov_pow2_profiler_atomic (gcov_type *counters, gcov_type value)
+{
+ if (value == 0 || (value & (value - 1)))
+ __atomic_fetch_add (&counters[0], 1, MEMMODEL_RELAXED);
+ else
+ __atomic_fetch_add (&counters[1], 1, MEMMODEL_RELAXED);
+}
+#endif
+
+
/* Tries to determine the most common value among its inputs. Checks if the
value stored in COUNTERS[0] matches VALUE. If this is the case, COUNTERS[1]
is incremented. If this is not the case and COUNTERS[1] is not zero,
@@ -68,10 +103,12 @@ __gcov_pow2_profiler (gcov_type *counters, gcov_type value)
function is called more than 50% of the time with one value, this value
will be in COUNTERS[0] in the end.
- In any case, COUNTERS[2] is incremented. */
+ In any case, COUNTERS[2] is incremented. If USE_ATOMIC is set to 1,
+ COUNTERS[2] is updated with an atomic instruction. */
static inline void
-__gcov_one_value_profiler_body (gcov_type *counters, gcov_type value)
+__gcov_one_value_profiler_body (gcov_type *counters, gcov_type value,
+ int use_atomic)
{
if (value == counters[0])
counters[1]++;
@@ -82,14 +119,36 @@ __gcov_one_value_profiler_body (gcov_type *counters, gcov_type value)
}
else
counters[1]--;
- counters[2]++;
+
+ if (use_atomic)
+ __atomic_fetch_add (&counters[2], 1, MEMMODEL_RELAXED);
+ else
+ counters[2]++;
}
#ifdef L_gcov_one_value_profiler
void
__gcov_one_value_profiler (gcov_type *counters, gcov_type value)
{
- __gcov_one_value_profiler_body (counters, value);
+ __gcov_one_value_profiler_body (counters, value, 0);
+}
+#endif
+
+#ifdef L_gcov_one_value_profiler_atomic
+
+/* Update one value profilers (COUNTERS) for a given VALUE.
+
+ CAVEAT: Following function is not thread-safe, only total number
+ of executions (COUNTERS[2]) is update with an atomic instruction.
+ Problem is that one cannot atomically update two counters
+ (COUNTERS[0] and COUNTERS[1]), for more information please read
+ following email thread:
+ https://gcc.gnu.org/ml/gcc-patches/2016-08/msg00024.html. */
+
+void
+__gcov_one_value_profiler_atomic (gcov_type *counters, gcov_type value)
+{
+ __gcov_one_value_profiler_body (counters, value, 1);
}
#endif
@@ -265,7 +324,7 @@ __gcov_indirect_call_profiler_v2 (gcov_type value, void* cur_func)
if (cur_func == __gcov_indirect_call_callee
|| (__LIBGCC_VTABLE_USES_DESCRIPTORS__ && __gcov_indirect_call_callee
&& *(void **) cur_func == *(void **) __gcov_indirect_call_callee))
- __gcov_one_value_profiler_body (__gcov_indirect_call_counters, value);
+ __gcov_one_value_profiler_body (__gcov_indirect_call_counters, value, 0);
}
#endif
@@ -282,8 +341,19 @@ __gcov_time_profiler (gcov_type* counters)
if (!counters[0])
counters[0] = ++function_counter;
}
+
+/* Sets corresponding COUNTERS if there is no value.
+ Function is thread-safe. */
+
+void
+__gcov_time_profiler_atomic (gcov_type* counters)
+{
+ if (!counters[0])
+ counters[0] = __atomic_add_fetch (&function_counter, 1, MEMMODEL_RELAXED);
+}
#endif
+
#ifdef L_gcov_average_profiler
/* Increase corresponding COUNTER by VALUE. FIXME: Perhaps we want
to saturate up. */
@@ -296,6 +366,18 @@ __gcov_average_profiler (gcov_type *counters, gcov_type value)
}
#endif
+#ifdef L_gcov_average_profiler_atomic
+/* Increase corresponding COUNTER by VALUE. FIXME: Perhaps we want
+ to saturate up. Function is thread-safe. */
+
+void
+__gcov_average_profiler_atomic (gcov_type *counters, gcov_type value)
+{
+ __atomic_fetch_add (&counters[0], value, MEMMODEL_RELAXED);
+ __atomic_fetch_add (&counters[1], 1, MEMMODEL_RELAXED);
+}
+#endif
+
#ifdef L_gcov_ior_profiler
/* Bitwise-OR VALUE into COUNTER. */
@@ -306,4 +388,15 @@ __gcov_ior_profiler (gcov_type *counters, gcov_type value)
}
#endif
+#ifdef L_gcov_ior_profiler_atomic
+/* Bitwise-OR VALUE into COUNTER. Function is thread-safe. */
+
+void
+__gcov_ior_profiler_atomic (gcov_type *counters, gcov_type value)
+{
+ __atomic_fetch_or (&counters[0], value, MEMMODEL_RELAXED);
+}
+#endif
+
+
#endif /* inhibit_libc */
diff --git a/libgcc/libgcov.h b/libgcc/libgcov.h
index 80f13e2..25147de 100644
--- a/libgcc/libgcov.h
+++ b/libgcc/libgcov.h
@@ -268,12 +268,19 @@ extern void __gcov_merge_icall_topn (gcov_type *, unsigned) ATTRIBUTE_HIDDEN;
/* The profiler functions. */
extern void __gcov_interval_profiler (gcov_type *, gcov_type, int, unsigned);
+extern void __gcov_interval_profiler_atomic (gcov_type *, gcov_type, int,
+ unsigned);
extern void __gcov_pow2_profiler (gcov_type *, gcov_type);
+extern void __gcov_pow2_profiler_atomic (gcov_type *, gcov_type);
extern void __gcov_one_value_profiler (gcov_type *, gcov_type);
+extern void __gcov_one_value_profiler_atomic (gcov_type *, gcov_type);
extern void __gcov_indirect_call_profiler_v2 (gcov_type, void *);
extern void __gcov_time_profiler (gcov_type *);
+extern void __gcov_time_profiler_atomic (gcov_type *);
extern void __gcov_average_profiler (gcov_type *, gcov_type);
+extern void __gcov_average_profiler_atomic (gcov_type *, gcov_type);
extern void __gcov_ior_profiler (gcov_type *, gcov_type);
+extern void __gcov_ior_profiler_atomic (gcov_type *, gcov_type);
extern void __gcov_indirect_call_topn_profiler (gcov_type, void *);
extern void gcov_sort_n_vals (gcov_type *, int);