[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] build: force compiler to use atomics when coverage is enabled
- To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
- From: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
- Date: Wed, 9 Jul 2025 20:12:42 +0000
- Accept-language: en-US
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LWQ+Nc0eVb7PoDdAkDe+FYuYwP1xDm6QLVuNAQHja3k=; b=ccFVVymmhfX0dJ9Zg8/0ljCYwlgaruou8QtBtL1tfun2ecUsYoCMq3lYXTpaoJqIg0IyfvRe36crzX4Zs3fFxkOGNNN0Pjb64EHv5Z7JXGUrUalJpaGdN3KBF7/BtE6AvjnmimOKFIbvNmSMki9gKhL64C8QWxMZ1t6L1a7ks6inxKvA/bZ/93iseouRuSlXgejrcT7aBlzssZGgNASWvnQlsCTTlznNb1EtJOPiMZ113/huc1J4PDpE7IdWBXwvvuCFXB+kqyVGXyw3HEgw2r7YFDuqMRpNQtFsGxIqdHwLCd4GQeqbXOtkLVketiZgbu0NDdQ7tZdt0EW49AhChA==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=fX11pI3RRXd4pH2Po2k+LS7QqXQb4cPLfU7r1tb0xKc2FjmOe6KEfWkPctXaftLzsi7kAHjBZKVb77UyxgvvCMjp2VJFrktAjXpPUOx5eZKuw/aMj6zBwbyFlmEuByWK8ZWH1U8W+AKWStbIgSIbyBDXz0pf0RZcC0tONCn/oycdi5yGmw4VB2EbkF/UKnC65Upe7GRpJ3DSre4TLg/LVzcbHXx9Tbtsix8vB/qKDvTQNyLf/6UW9YXvr15ULNjTEzqEo4qumbGDOYV/Gtb1cbdhelTq6jPr+ev1CjBrlP15nTJSpVi755ecCjrVxp5PaBdkKcMkv/dar+VZGgTpOA==
- Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=epam.com;
- Cc: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>
- Delivery-date: Wed, 09 Jul 2025 20:13:08 +0000
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
- Thread-index: AQHb8Q3T4onJ/fNwmk+3ZG7sC0Ohjw==
- Thread-topic: [PATCH] build: force compiler to use atomics when coverage is enabled
By default GCC uses "simple" coverage counter update
mechanism. It is perfectly fine for single-threaded (or single CPU in
our case) setups, but will cause race conditions on SMP systems.
For example, I observed that counters are going backwards when running
Xen inside QEMU.
GCC starting from version 7 and LLVM/Clang starting from version 11
support -fprofile-update=atomic option, which forces coverage counter
updates to be atomic, which resolves the issue. As Xen runs mostly on
SMP systems, force use this option if it is supported by a compiler.
Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@xxxxxxxx>
---
xen/Kconfig | 4 ++++
xen/Rules.mk | 4 ++++
2 files changed, 8 insertions(+)
diff --git a/xen/Kconfig b/xen/Kconfig
index 07c4accf88..3a6635ac74 100644
--- a/xen/Kconfig
+++ b/xen/Kconfig
@@ -55,6 +55,10 @@ config CC_HAS_ASM_GOTO_OUTPUT
config CC_HAS_MCDC
def_bool $(cc-option,-fcondition-coverage)
+# Compiler supports -fprofile-update=atomic for correct SMP handling
+config CC_HAS_ATOMIC_PROFILE
+ def_bool $(cc-option,-fprofile-update=atomic)
+
# Set code alignment.
#
# Allow setting on a boolean basis, and then convert such selection to an
diff --git a/xen/Rules.mk b/xen/Rules.mk
index da21850926..7219a3033f 100644
--- a/xen/Rules.mk
+++ b/xen/Rules.mk
@@ -141,6 +141,10 @@ else
cov-cflags-$(CONFIG_CONDITION_COVERAGE) += -fcondition-coverage
endif
+ifeq ($(CONFIG_CC_HAS_ATOMIC_PROFILE),y)
+ cov-cflags-$(CONFIG_COVERAGE) += -fprofile-update=atomic
+endif
+
# Reset cov-cflags-y in cases where an objects has another one as prerequisite
$(nocov-y) $(filter %.init.o, $(obj-y) $(obj-bin-y) $(extra-y)): \
cov-cflags-y :=
--
2.50.0
|