public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Sebastian Huber <sebastian.huber@embedded-brains.de>
To: GCC Development <gcc@gcc.gnu.org>
Subject: -fprofile-update=atomic vs. 32-bit architectures
Date: Fri, 4 Nov 2022 09:27:34 +0100	[thread overview]
Message-ID: <13ec35ee-19b2-536c-42d9-28efcd01df5b@embedded-brains.de> (raw)

Hello,

even recent 32-bit architectures such as RISC-V do not support 64-bit 
atomic operations.  Using -fprofile-update=atomic for the 32-bit RISC-V 
RV32GC ISA yields:

warning: target does not support atomic profile update, single mode is 
selected

For multi-threaded applications it is quite important to use atomic 
counter increments to get valid coverage data. I think this fall back is 
not really good. Maybe we should consider using this approach from Jakub 
Jelinek for 32-bit architectures lacking 64-bit atomic operations:

   if (__atomic_add_fetch_4 ((unsigned int *) &val, 1, __ATOMIC_RELAXED) 
== 0)
     __atomic_fetch_add_4 (((unsigned int *) &val) + 1, 1, 
__ATOMIC_RELAXED);

https://patchwork.ozlabs.org/project/gcc/patch/19c4a81d-6ecd-8c6e-b641-e257c1959baf@suse.cz/#1447334

Last year I added the TARGET_GCOV_TYPE_SIZE target hook to optionally 
reduce the gcov type size to 32 bits. I am not really sure if this was a 
good idea. Longer running executables may observe counter overflows 
leading to invalid coverage data. If someone wants atomic updates, then 
the updates should be atomic even if this means to use a library 
implementation (libatomic).

What about the following approach if -fprofile-update=atomic is given:

1. Use 64-bit atomics if available.

2. Use

   if (__atomic_add_fetch_4 ((unsigned int *) &val, 1, __ATOMIC_RELAXED) 
== 0)
     __atomic_fetch_add_4 (((unsigned int *) &val) + 1, 1, 
__ATOMIC_RELAXED);

if 32-bit atomics are available.

3. Else use a library call (libatomic).

-- 
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.huber@embedded-brains.de
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/

             reply	other threads:[~2022-11-04  8:27 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-04  8:27 Sebastian Huber [this message]
2022-11-04  9:53 ` Gabriel Paubert
2022-11-04 10:02   ` Sebastian Huber
2022-11-05 11:18 ` Richard Biener
2022-11-08  6:22   ` Sebastian Huber
2022-11-08 10:25     ` Richard Biener
2022-11-08 12:00       ` Sebastian Huber
2022-11-08 13:52         ` Richard Biener
2022-12-05  7:26       ` Sebastian Huber
2022-12-05  7:44         ` Richard Biener
2022-12-06 13:11           ` Sebastian Huber
2022-12-06 16:08             ` Richard Biener
2022-12-07  8:51               ` Sebastian Huber
2022-12-07  9:09                 ` Richard Biener
2022-12-07  9:24                   ` Sebastian Huber
2022-12-07 11:49                     ` Richard Biener
2022-12-07  9:55 ` Sebastian Huber

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=13ec35ee-19b2-536c-42d9-28efcd01df5b@embedded-brains.de \
    --to=sebastian.huber@embedded-brains.de \
    --cc=gcc@gcc.gnu.org \
    /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).