[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2] 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, 16 Jul 2025 21:23:14 +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=+xvue2va1E2ikO8sg/D+isPczYwxJTxTgxdL8O1ZEYw=; b=yjiK/IX6nYU7w4nUhX1DYQmvJ0Q2p09c+sb8Uzhqfyz4miCxj4BG72nr9CShnV/6Bd3AV5DM8d5C5F7mTtNrm0wWj6EJj2SzprNjzDfhrpBwWA7/CorqnYfqnHcTWdTYxZHhW/9MLOlusM/XpMOI682O9z+c7pi+PsxzKRvwG1qjp2i/8KwujFBtlmTE/4P3Ir86happHLY9/7lHcyNZSVUWtf8KjwqJtE4IcLFIG+aQ5nqyR6EGCkZapPTBV13bZuxoX2kJzPw3lRIL7DvFzZ05Tuk7QE5Brv0fy644VWFZphgvxk3XlWfpbW/uWsVg21m/JC19YZwSgaGblUNfDQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Cdscno4x45EzaIb9fj8qOxaHLiB5HKkDPukCY4bGeOmMHaoInFcCR322NgiXqrRNHx+lC4OV+FlXHQl6Cl2f/xQqFOmcNzCkTExUDyzKOmA7izxq2e1LeeBiUaLq6wIy7WGMjFh7WJ1okLOEoadSqhZ0vG01XWnFbaNCUugLmtYarO7jz5VEQcsBk1f81mjJaK6IbU3RbkG/Od3PAfK82pQ/JTomoIlb1P1BaxRmYRYaFob9RMRFJgNmkT1rr5McvJ9NaIJkckL3NlejW7uxlovm5IePvYeALoLT9dDtu0Uu4Z/ZWcIPu6LXOliNPg/d7VsG7dwedY3QOjPIJJFZbQ==
  • 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, 16 Jul 2025 21:51:53 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHb9pfXTSTU5wd70UKxH4Py9cX5aQ==
  • Thread-topic: [PATCH v2] 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>

---

Changes in v2:

 - Use $(cc-option-add) instead of a Kconfig variable
---
 xen/Rules.mk | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/xen/Rules.mk b/xen/Rules.mk
index da21850926..24f447b957 100644
--- a/xen/Rules.mk
+++ b/xen/Rules.mk
@@ -141,6 +141,9 @@ else
     cov-cflags-$(CONFIG_CONDITION_COVERAGE) += -fcondition-coverage
 endif
 
+# Ensure that profile/coverage data is updated atomically
+$(call cc-option-add,cov-cflags-$(CONFIG_COVERAGE),CC,-fprofile-update=atomic)
+
 # 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



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.