From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7880) id 1B153385B519; Thu, 16 Feb 2023 16:28:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1B153385B519 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676564881; bh=WGDQEWRTrosrTBE7U8vfFGhIfRvHqdSELFCAPXUVDY8=; h=From:To:Subject:Date:From; b=OOyujSaaTjWUSV/3eKgpWXcvRuKXr07zdMirN6pty1i0Ch6/ayRcdtpmM1Irwd647 XxBbI3aTRTaoFPUBxUu5MZxr5nFY1QV4xrng3fdo3oS/C6SytjqHxpQ0lAMNvy6kdG YkLCyWy++U3w0lL7H+pVmbvNl3AXxIC9dzov/ysA= 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: e42112badf6a42e36cfd4634bfe1590e6206c38c X-Git-Newrev: 2ec0ddcc2d8a42904b3b41e67662584e5ae7008c Message-Id: <20230216162801.1B153385B519@sourceware.org> Date: Thu, 16 Feb 2023 16:28:01 +0000 (GMT) List-Id: https://gcc.gnu.org/g:2ec0ddcc2d8a42904b3b41e67662584e5ae7008c commit 2ec0ddcc2d8a42904b3b41e67662584e5ae7008c 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);