From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7880) id 3F11A385AC29; Thu, 23 Feb 2023 23:21:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3F11A385AC29 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677194512; bh=gS7C/xG8Nfug7yXEVuFPQS1khobT45a6b0NCKKLNC88=; h=From:To:Subject:Date:From; b=MpMa/qeLAQbk1O+4bd4wm05yi9ncuyjypRvUWccux2Xa6lzkgAEDW6lR12pTGD6NS Wq4jchXcbPx4z8WpyIAugpCt4tIxWHDtQ5YIHoUTjBat5QPOCnjcMmeXEtd3jLimI0 sELm94FP+B9ZXcTTfOvILYPAp0m2WOjLdbAX1qtI= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Ondrej Kubanek To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/kubaneko/heads/histogram)] added atomic counter X-Act-Checkin: gcc X-Git-Author: kubaneko X-Git-Refname: refs/users/kubaneko/heads/histogram X-Git-Oldrev: b4bad988926bdc89042cc9448e604558f556f7cf X-Git-Newrev: 8a387e2c25edb5c0a8df049f2a1ccf76e2c922f5 Message-Id: <20230223232152.3F11A385AC29@sourceware.org> Date: Thu, 23 Feb 2023 23:21:52 +0000 (GMT) List-Id: https://gcc.gnu.org/g:8a387e2c25edb5c0a8df049f2a1ccf76e2c922f5 commit 8a387e2c25edb5c0a8df049f2a1ccf76e2c922f5 Author: kubaneko Date: Tue Nov 1 14:46:59 2022 +0000 added atomic counter Diff: --- libgcc/Makefile.in | 3 ++- libgcc/libgcov-profiler.c | 32 ++++++++++++++++++++++++++++++++ libgcc/libgcov.h | 1 + 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/libgcc/Makefile.in b/libgcc/Makefile.in index 74e3602347a..b3847db58bd 100644 --- a/libgcc/Makefile.in +++ b/libgcc/Makefile.in @@ -907,7 +907,8 @@ LIBGCOV_PROFILER = _gcov_interval_profiler \ _gcov_ior_profiler_atomic \ _gcov_indirect_call_profiler_v4 \ _gcov_time_profiler \ - _gcov_histogram_profiler + _gcov_histogram_profiler \ + _gcov_histogram_profiler_atomic LIBGCOV_INTERFACE = _gcov_dump _gcov_fork \ _gcov_execl _gcov_execlp \ _gcov_execle _gcov_execv _gcov_execvp _gcov_execve _gcov_reset \ diff --git a/libgcc/libgcov-profiler.c b/libgcc/libgcov-profiler.c index b36584723d5..4b1a3b423e2 100644 --- a/libgcc/libgcov-profiler.c +++ b/libgcc/libgcov-profiler.c @@ -56,6 +56,38 @@ __gcov_histogram_profiler (gcov_type *counters, gcov_type value) #endif + +#if defined(L_gcov_histogram_profiler_atomic) && GCOV_SUPPORTS_ATOMIC + +/* + * If value is less then 8 we increment corresponding counter + * otherwise we take its logarithm and increment corresponding counter + */ + +void +__gcov_histogram_profiler_atomic (gcov_type *counters, gcov_type value) +{ + if (value>=0 && value<8){ + __atomic_fetch_add (&counters[value], 1, __ATOMIC_RELAXED); + }else{ + gcc_assert(value>0); + int pow2 = 3; + while (1 << pow2 <= value || 1 << pow2 > 1 << (pow2 + 1)){ + ++pow2; + } + // pow2 is first bigger power of 2 + // we increment closer power of 2 + if ((1<>1, then increases the corresponding counter in COUNTERS. If the VALUE is above or below diff --git a/libgcc/libgcov.h b/libgcc/libgcov.h index d3eac74b766..cd2f48c4d6d 100644 --- a/libgcc/libgcov.h +++ b/libgcc/libgcov.h @@ -318,6 +318,7 @@ 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_histogram_profiler (gcov_type *, gcov_type); +extern void __gcov_histogram_profiler_atomic (gcov_type *, gcov_type); extern void __gcov_pow2_profiler (gcov_type *, gcov_type); extern void __gcov_pow2_profiler_atomic (gcov_type *, gcov_type); extern void __gcov_topn_values_profiler (gcov_type *, gcov_type);