From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7880) id 4ED5D3858C54; Tue, 22 Nov 2022 13:13:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4ED5D3858C54 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669122820; bh=gKdWtCs5/aowNh8YtErJhgL0er0gYuzkvAVFTFnAxZo=; h=From:To:Subject:Date:From; b=N6oaIkT33Yge7Gj/CgnsfymJcT8P49mTBlPvvlgmmxyykt8SQpbUiyHQo8AqUCQK+ SadAHv7ZUmu3I86XUNxmUotIqxKloC+07I/W0Yfn3cAM1NTJBO0u4IkYJgbtF+oa8R TyEUPmZpopsahjoEvyGoMWhzczBY8zNKxJ4jM2Eo= 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: 1cfbfa54233de23c87bfa0d9cd1228a00958566c X-Git-Newrev: 6d710a27d95879ade1841a8ace7854cdfd1ad5ac Message-Id: <20221122131340.4ED5D3858C54@sourceware.org> Date: Tue, 22 Nov 2022 13:13:40 +0000 (GMT) List-Id: https://gcc.gnu.org/g:6d710a27d95879ade1841a8ace7854cdfd1ad5ac commit 6d710a27d95879ade1841a8ace7854cdfd1ad5ac 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 db430e0b6af..52c0c250b0c 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 eb944158a3c..f150d75fee1 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 c01b5afe04b..b32f50ddec3 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);