From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id C02AE3858403 for ; Fri, 4 Nov 2022 08:27:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C02AE3858403 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embedded-brains.de Received: from sslproxy03.your-server.de ([88.198.220.132]) by dedi548.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1oqs37-000Ftl-5m for gcc@gcc.gnu.org; Fri, 04 Nov 2022 09:27:36 +0100 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy03.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oqs36-000DSc-Oa for gcc@gcc.gnu.org; Fri, 04 Nov 2022 09:27:36 +0100 Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 7520B48017C for ; Fri, 4 Nov 2022 09:27:36 +0100 (CET) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id Ey97NVh-4J2T for ; Fri, 4 Nov 2022 09:27:36 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 1AFD7480185 for ; Fri, 4 Nov 2022 09:27:36 +0100 (CET) X-Virus-Scanned: amavisd-new at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id AbCTh4FD8OeC for ; Fri, 4 Nov 2022 09:27:36 +0100 (CET) Received: from [10.10.171.6] (unknown [10.10.171.6]) by mail.embedded-brains.de (Postfix) with ESMTPSA id D620148017C for ; Fri, 4 Nov 2022 09:27:35 +0100 (CET) Message-ID: <13ec35ee-19b2-536c-42d9-28efcd01df5b@embedded-brains.de> Date: Fri, 4 Nov 2022 09:27:34 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 To: GCC Development Content-Language: en-US From: Sebastian Huber Subject: -fprofile-update=atomic vs. 32-bit architectures Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-Authenticated-Sender: smtp-embedded@poldinet.de X-Virus-Scanned: Clear (ClamAV 0.103.7/26709/Thu Nov 3 08:56:21 2022) X-Spam-Status: No, score=-5.3 required=5.0 tests=BAYES_00,KAM_DMARC_STATUS,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Hello, even recent 32-bit architectures such as RISC-V do not support 64-bit=20 atomic operations. Using -fprofile-update=3Datomic for the 32-bit RISC-V= =20 RV32GC ISA yields: warning: target does not support atomic profile update, single mode is=20 selected For multi-threaded applications it is quite important to use atomic=20 counter increments to get valid coverage data. I think this fall back is=20 not really good. Maybe we should consider using this approach from Jakub=20 Jelinek for 32-bit architectures lacking 64-bit atomic operations: if (__atomic_add_fetch_4 ((unsigned int *) &val, 1, __ATOMIC_RELAXED)=20 =3D=3D 0) __atomic_fetch_add_4 (((unsigned int *) &val) + 1, 1,=20 __ATOMIC_RELAXED); https://patchwork.ozlabs.org/project/gcc/patch/19c4a81d-6ecd-8c6e-b641-e2= 57c1959baf@suse.cz/#1447334 Last year I added the TARGET_GCOV_TYPE_SIZE target hook to optionally=20 reduce the gcov type size to 32 bits. I am not really sure if this was a=20 good idea. Longer running executables may observe counter overflows=20 leading to invalid coverage data. If someone wants atomic updates, then=20 the updates should be atomic even if this means to use a library=20 implementation (libatomic). What about the following approach if -fprofile-update=3Datomic is given: 1. Use 64-bit atomics if available. 2. Use if (__atomic_add_fetch_4 ((unsigned int *) &val, 1, __ATOMIC_RELAXED)=20 =3D=3D 0) __atomic_fetch_add_4 (((unsigned int *) &val) + 1, 1,=20 __ATOMIC_RELAXED); if 32-bit atomics are available. 3. Else use a library call (libatomic). --=20 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=C3=BCnchen Registernummer: HRB 157899 Vertretungsberechtigte Gesch=C3=A4ftsf=C3=BChrer: Peter Rasmussen, Thomas= D=C3=B6rfler Unsere Datenschutzerkl=C3=A4rung finden Sie hier: https://embedded-brains.de/datenschutzerklaerung/