From 89c549da732bd0bf98f91b4fdf154c5a1203d435 Mon Sep 17 00:00:00 2001 From: v4xsh Date: Wed, 13 May 2026 22:05:08 +0530 Subject: [PATCH 01/15] tracing: add hpx::tracing::lock_context abstraction Signed-off-by: v4xsh --- .../tracing/include/hpx/tracing/tracing.hpp | 63 +++++++++++++++++++ libs/core/tracing/src/tracing.cpp | 38 +++++++++++ 2 files changed, 101 insertions(+) diff --git a/libs/core/tracing/include/hpx/tracing/tracing.hpp b/libs/core/tracing/include/hpx/tracing/tracing.hpp index e508917f862..067c3921db7 100644 --- a/libs/core/tracing/include/hpx/tracing/tracing.hpp +++ b/libs/core/tracing/include/hpx/tracing/tracing.hpp @@ -10,10 +10,13 @@ #include #include +#include #if defined(HPX_HAVE_MODULE_TRACY) #include +#define HPX_HAVE_TRACING 1 + namespace hpx::tracing { //////////////////////////////////////////////////////////////////////////// @@ -93,6 +96,26 @@ namespace hpx::tracing { hpx::tracy::fiber_suspend_region impl; }; + //////////////////////////////////////////////////////////////////////////// + HPX_CXX_CORE_EXPORT struct HPX_CORE_EXPORT lock_context + { + explicit lock_context(char const* name = nullptr) noexcept; + explicit lock_context(std::string const& name) noexcept; + + ~lock_context(); + + lock_context(lock_context const&) = delete; + lock_context& operator=(lock_context const&) = delete; + + bool before_lock() const noexcept; + void after_lock() const noexcept; + void after_try_lock(bool acquired) const noexcept; + void after_unlock() const noexcept; + + private: + hpx::tracy::lock_data impl; + }; + //////////////////////////////////////////////////////////////////////////// HPX_CXX_CORE_EXPORT HPX_CORE_EXPORT void set_thread_name( char const* name) noexcept; @@ -106,6 +129,8 @@ namespace hpx::tracing { #elif defined(HPX_HAVE_ITTNOTIFY) && HPX_HAVE_ITTNOTIFY != 0 #include +#define HPX_HAVE_TRACING 1 + namespace hpx::tracing { //////////////////////////////////////////////////////////////////////////// @@ -178,6 +203,24 @@ namespace hpx::tracing { constexpr explicit fiber_suspend_region(char const*) noexcept {} }; + //////////////////////////////////////////////////////////////////////////// + HPX_CXX_CORE_EXPORT struct [[maybe_unused]] lock_context + { + constexpr explicit lock_context(char const* = nullptr) noexcept {} + constexpr explicit lock_context(std::string const&) noexcept {} + + constexpr bool before_lock() const noexcept + { + return false; + } + + constexpr void after_lock() const noexcept {} + + constexpr void after_try_lock(bool) const noexcept {} + + constexpr void after_unlock() const noexcept {} + }; + //////////////////////////////////////////////////////////////////////////// HPX_CXX_CORE_EXPORT constexpr void set_thread_name(char const*) noexcept {} @@ -193,6 +236,8 @@ namespace hpx::tracing { #else +#define HPX_HAVE_TRACING 0 + namespace hpx::tracing { //////////////////////////////////////////////////////////////////////////// @@ -245,6 +290,24 @@ namespace hpx::tracing { constexpr explicit fiber_suspend_region(char const*) noexcept {} }; + //////////////////////////////////////////////////////////////////////////// + HPX_CXX_CORE_EXPORT struct [[maybe_unused]] lock_context + { + constexpr explicit lock_context(char const* = nullptr) noexcept {} + constexpr explicit lock_context(std::string const&) noexcept {} + + constexpr bool before_lock() const noexcept + { + return false; + } + + constexpr void after_lock() const noexcept {} + + constexpr void after_try_lock(bool) const noexcept {} + + constexpr void after_unlock() const noexcept {} + }; + //////////////////////////////////////////////////////////////////////////// HPX_CXX_CORE_EXPORT constexpr void set_thread_name(char const*) noexcept {} diff --git a/libs/core/tracing/src/tracing.cpp b/libs/core/tracing/src/tracing.cpp index ea15872ed6e..a41485f872b 100644 --- a/libs/core/tracing/src/tracing.cpp +++ b/libs/core/tracing/src/tracing.cpp @@ -77,6 +77,44 @@ namespace hpx::tracing { fiber_suspend_region::~fiber_suspend_region() = default; + //////////////////////////////////////////////////////////////////////////// + // lock_context + + lock_context::lock_context(char const* name) noexcept + : impl(hpx::tracy::create(name)) + { + } + + lock_context::lock_context(std::string const& name) noexcept + : impl(hpx::tracy::create(name)) + { + } + + lock_context::~lock_context() + { + hpx::tracy::destroy(impl); + } + + bool lock_context::before_lock() const noexcept + { + return hpx::tracy::lock_prepare(impl); + } + + void lock_context::after_lock() const noexcept + { + hpx::tracy::lock_acquired(impl); + } + + void lock_context::after_try_lock(bool acquired) const noexcept + { + hpx::tracy::lock_acquired(impl, acquired); + } + + void lock_context::after_unlock() const noexcept + { + hpx::tracy::lock_released(impl); + } + //////////////////////////////////////////////////////////////////////////// // set_thread_name From 3d64f78159e818fdd85e1d66b643b47036332948 Mon Sep 17 00:00:00 2001 From: v4xsh Date: Wed, 13 May 2026 22:05:08 +0530 Subject: [PATCH 02/15] synchronization: migrate mutex to hpx::tracing::lock_context Signed-off-by: v4xsh --- .../include/hpx/synchronization/mutex.hpp | 10 ++--- libs/core/synchronization/src/mutex.cpp | 39 +++++-------------- 2 files changed, 13 insertions(+), 36 deletions(-) diff --git a/libs/core/synchronization/include/hpx/synchronization/mutex.hpp b/libs/core/synchronization/include/hpx/synchronization/mutex.hpp index d83ec421cff..c22a687db8f 100644 --- a/libs/core/synchronization/include/hpx/synchronization/mutex.hpp +++ b/libs/core/synchronization/include/hpx/synchronization/mutex.hpp @@ -16,11 +16,9 @@ #include #include #include +#include #include #include -#if defined(HPX_HAVE_MODULE_TRACY) -#include -#endif namespace hpx::threads { @@ -89,7 +87,7 @@ namespace hpx { /// /// \param description description of the \a mutex. /// -#if HPX_HAVE_ITTNOTIFY != 0 || defined(HPX_HAVE_MODULE_TRACY) +#if HPX_HAVE_ITTNOTIFY != 0 || HPX_HAVE_TRACING != 0 HPX_CORE_EXPORT mutex(char const* const description = ""); #else HPX_HOST_DEVICE_CONSTEXPR mutex(char const* const = "") noexcept @@ -245,9 +243,7 @@ namespace hpx { mutable mutex_type mtx_; threads::thread_id_type owner_id_; hpx::lcos::local::detail::condition_variable cond_; -#if defined(HPX_HAVE_MODULE_TRACY) - hpx::tracy::lock_data context_; -#endif + HPX_NO_UNIQUE_ADDRESS hpx::tracing::lock_context context_; /// \endcond NOPROTECTED }; diff --git a/libs/core/synchronization/src/mutex.cpp b/libs/core/synchronization/src/mutex.cpp index 72ebbedc3e0..048d3fed854 100644 --- a/libs/core/synchronization/src/mutex.cpp +++ b/libs/core/synchronization/src/mutex.cpp @@ -12,12 +12,10 @@ #include #include #include +#include #include #include #include -#if defined(HPX_HAVE_MODULE_TRACY) -#include -#endif #include #include @@ -26,24 +24,19 @@ namespace hpx { /////////////////////////////////////////////////////////////////////////// -#if HPX_HAVE_ITTNOTIFY != 0 || defined(HPX_HAVE_MODULE_TRACY) +#if HPX_HAVE_ITTNOTIFY != 0 || HPX_HAVE_TRACING != 0 mutex::mutex(char const* const description) : owner_id_(threads::invalid_thread_id) + , context_(std::string("hpx::mutex") + description) { HPX_ITT_SYNC_CREATE(this, "hpx::mutex", description); -#if defined(HPX_HAVE_MODULE_TRACY) - context_ = hpx::tracy::create(std::string("hpx::mutex") + description); -#endif } #endif -#if HPX_HAVE_ITTNOTIFY != 0 || defined(HPX_HAVE_MODULE_TRACY) +#if HPX_HAVE_ITTNOTIFY != 0 || HPX_HAVE_TRACING != 0 mutex::~mutex() { HPX_ITT_SYNC_DESTROY(this); -#if defined(HPX_HAVE_MODULE_TRACY) - hpx::tracy::destroy(context_); -#endif } #else mutex::~mutex() = default; @@ -54,9 +47,7 @@ namespace hpx { HPX_ASSERT(threads::get_self_ptr() != nullptr); HPX_ITT_SYNC_PREPARE(this); -#if defined(HPX_HAVE_MODULE_TRACY) - bool const run_after = hpx::tracy::lock_prepare(context_); -#endif + bool const run_after = context_.before_lock(); { std::unique_lock l(mtx_); @@ -86,10 +77,8 @@ namespace hpx { } HPX_ITT_SYNC_ACQUIRED(this); -#if defined(HPX_HAVE_MODULE_TRACY) if (run_after) - hpx::tracy::lock_acquired(context_); -#endif + context_.after_lock(); } bool mutex::try_lock(char const* /* description */, error_code& /* ec */) @@ -97,9 +86,7 @@ namespace hpx { HPX_ASSERT(threads::get_self_ptr() != nullptr); HPX_ITT_SYNC_PREPARE(this); -#if defined(HPX_HAVE_MODULE_TRACY) - bool const run_after = hpx::tracy::lock_prepare(context_); -#endif + bool const run_after = context_.before_lock(); { std::unique_lock l(mtx_); @@ -107,10 +94,8 @@ namespace hpx { if (owner_id_ != threads::invalid_thread_id) { HPX_ITT_SYNC_CANCEL(this); -#if defined(HPX_HAVE_MODULE_TRACY) if (run_after) - hpx::tracy::lock_acquired(context_, false); -#endif + context_.after_try_lock(false); return false; } @@ -119,10 +104,8 @@ namespace hpx { } HPX_ITT_SYNC_ACQUIRED(this); -#if defined(HPX_HAVE_MODULE_TRACY) if (run_after) - hpx::tracy::lock_acquired(context_, true); -#endif + context_.after_try_lock(true); return true; } @@ -148,9 +131,7 @@ namespace hpx { owner_id_ = threads::invalid_thread_id; HPX_ITT_SYNC_RELEASED(this); -#if defined(HPX_HAVE_MODULE_TRACY) - hpx::tracy::lock_released(context_); -#endif + context_.after_unlock(); { [[maybe_unused]] util::ignore_while_checking il(&l); From 2d95111e86f57a9d1128d3b9b98df4fb7071570d Mon Sep 17 00:00:00 2001 From: v4xsh Date: Wed, 13 May 2026 22:05:08 +0530 Subject: [PATCH 03/15] synchronization: migrate spinlock to hpx::tracing::lock_context Signed-off-by: v4xsh --- libs/core/synchronization/CMakeLists.txt | 1 + .../include/hpx/synchronization/spinlock.hpp | 46 +++++-------------- 2 files changed, 12 insertions(+), 35 deletions(-) diff --git a/libs/core/synchronization/CMakeLists.txt b/libs/core/synchronization/CMakeLists.txt index cffec573e77..ba59e20229f 100644 --- a/libs/core/synchronization/CMakeLists.txt +++ b/libs/core/synchronization/CMakeLists.txt @@ -95,6 +95,7 @@ add_hpx_module( hpx_thread_support hpx_timing hpx_topology + hpx_tracing hpx_type_support ${additional_dependencies} CMAKE_SUBDIRS examples tests diff --git a/libs/core/synchronization/include/hpx/synchronization/spinlock.hpp b/libs/core/synchronization/include/hpx/synchronization/spinlock.hpp index ce1b4ec1244..8da46b56a4e 100644 --- a/libs/core/synchronization/include/hpx/synchronization/spinlock.hpp +++ b/libs/core/synchronization/include/hpx/synchronization/spinlock.hpp @@ -22,9 +22,7 @@ #include #include #include -#if defined(HPX_HAVE_MODULE_TRACY) -#include -#endif +#include #include #include @@ -50,37 +48,27 @@ namespace hpx { private: std::atomic v_; -#if defined(HPX_HAVE_MODULE_TRACY) - hpx::tracy::lock_data context_; -#endif + HPX_NO_UNIQUE_ADDRESS hpx::tracing::lock_context context_; public: -#if HPX_HAVE_ITTNOTIFY != 0 || defined(HPX_HAVE_MODULE_TRACY) +#if HPX_HAVE_TRACING != 0 spinlock() noexcept : v_(false) + , context_("hpx::spinlock") { HPX_ITT_SYNC_CREATE(this, "hpx::spinlock", nullptr); -#if defined(HPX_HAVE_MODULE_TRACY) - context_ = hpx::tracy::create("hpx::spinlock"); -#endif } explicit spinlock(char const* const desc) noexcept : v_(false) + , context_(std::string("hpx::spinlock#") + desc) { HPX_ITT_SYNC_CREATE(this, "hpx::spinlock", desc); -#if defined(HPX_HAVE_MODULE_TRACY) - context_ = - hpx::tracy::create(std::string("hpx::spinlock#") + desc); -#endif } ~spinlock() { HPX_ITT_SYNC_DESTROY(this); -#if defined(HPX_HAVE_MODULE_TRACY) - hpx::tracy::destroy(context_); -#endif } #else constexpr spinlock() noexcept @@ -99,9 +87,7 @@ namespace hpx { void lock() { HPX_ITT_SYNC_PREPARE(this); -#if defined(HPX_HAVE_MODULE_TRACY) - bool const run_after = hpx::tracy::lock_prepare(context_); -#endif + bool const run_after = context_.before_lock(); // Checking for the value in is_locked() ensures that // acquire_lock is only called when is_locked computes to false. @@ -132,10 +118,8 @@ namespace hpx { } HPX_ITT_SYNC_ACQUIRED(this); -#if defined(HPX_HAVE_MODULE_TRACY) if (run_after) - hpx::tracy::lock_acquired(context_); -#endif + context_.after_lock(); util::register_lock(this); } @@ -143,26 +127,20 @@ namespace hpx { noexcept(util::register_lock(std::declval()))) { HPX_ITT_SYNC_PREPARE(this); -#if defined(HPX_HAVE_MODULE_TRACY) - bool const run_after = hpx::tracy::lock_prepare(context_); -#endif + bool const run_after = context_.before_lock(); if (acquire_lock()) { HPX_ITT_SYNC_ACQUIRED(this); -#if defined(HPX_HAVE_MODULE_TRACY) if (run_after) - hpx::tracy::lock_acquired(context_, true); -#endif + context_.after_try_lock(true); util::register_lock(this); return true; } HPX_ITT_SYNC_CANCEL(this); -#if defined(HPX_HAVE_MODULE_TRACY) if (run_after) - hpx::tracy::lock_acquired(context_, false); -#endif + context_.after_try_lock(false); return false; } @@ -174,9 +152,7 @@ namespace hpx { relinquish_lock(); HPX_ITT_SYNC_RELEASED(this); -#if defined(HPX_HAVE_MODULE_TRACY) - hpx::tracy::lock_released(context_); -#endif + context_.after_unlock(); util::unregister_lock(this); } From 0e1b3463a09ad9a6a5fa6605c34770616b3cca77 Mon Sep 17 00:00:00 2001 From: v4xsh Date: Wed, 13 May 2026 22:05:08 +0530 Subject: [PATCH 04/15] concurrency: migrate spinlock to hpx::tracing::lock_context Signed-off-by: v4xsh --- libs/core/concurrency/CMakeLists.txt | 1 + .../include/hpx/concurrency/spinlock.hpp | 44 +++++-------------- 2 files changed, 11 insertions(+), 34 deletions(-) diff --git a/libs/core/concurrency/CMakeLists.txt b/libs/core/concurrency/CMakeLists.txt index bcaf6ca6b6b..630d7cbe478 100644 --- a/libs/core/concurrency/CMakeLists.txt +++ b/libs/core/concurrency/CMakeLists.txt @@ -76,6 +76,7 @@ add_hpx_module( hpx_itt_notify hpx_lock_registration hpx_thread_support + hpx_tracing hpx_type_support hpx_version ${additional_dependencies} diff --git a/libs/core/concurrency/include/hpx/concurrency/spinlock.hpp b/libs/core/concurrency/include/hpx/concurrency/spinlock.hpp index 5222e7d0f1e..a08270a99ca 100644 --- a/libs/core/concurrency/include/hpx/concurrency/spinlock.hpp +++ b/libs/core/concurrency/include/hpx/concurrency/spinlock.hpp @@ -12,9 +12,7 @@ #include #include #include -#if defined(HPX_HAVE_MODULE_TRACY) -#include -#endif +#include #include #include @@ -32,50 +30,36 @@ namespace hpx::util { private: hpx::util::detail::spinlock m; -#if defined(HPX_HAVE_MODULE_TRACY) - hpx::tracy::lock_data context_; -#endif + HPX_NO_UNIQUE_ADDRESS hpx::tracing::lock_context context_; public: spinlock() noexcept + : context_("hpx::spinlock") { HPX_ITT_SYNC_CREATE(this, "util::spinlock", nullptr); -#if defined(HPX_HAVE_MODULE_TRACY) - context_ = hpx::tracy::create("hpx::spinlock"); -#endif } explicit spinlock(char const* desc) noexcept + : context_(std::string("util::spinlock#") + desc) { HPX_ITT_SYNC_CREATE(this, "util::spinlock", desc); -#if defined(HPX_HAVE_MODULE_TRACY) - context_ = - hpx::tracy::create(std::string("util::spinlock#") + desc); -#endif } ~spinlock() { HPX_ITT_SYNC_DESTROY(this); -#if defined(HPX_HAVE_MODULE_TRACY) - hpx::tracy::destroy(context_); -#endif } void lock() noexcept( noexcept(util::register_lock(std::declval()))) { HPX_ITT_SYNC_PREPARE(this); -#if defined(HPX_HAVE_MODULE_TRACY) - bool const run_after = hpx::tracy::lock_prepare(context_); -#endif + bool const run_after = context_.before_lock(); m.lock(); HPX_ITT_SYNC_ACQUIRED(this); -#if defined(HPX_HAVE_MODULE_TRACY) if (run_after) - hpx::tracy::lock_acquired(context_); -#endif + context_.after_lock(); util::register_lock(this); } @@ -83,25 +67,19 @@ namespace hpx::util { noexcept(util::register_lock(std::declval()))) { HPX_ITT_SYNC_PREPARE(this); -#if defined(HPX_HAVE_MODULE_TRACY) - bool const run_after = hpx::tracy::lock_prepare(context_); -#endif + bool const run_after = context_.before_lock(); if (m.try_lock()) { HPX_ITT_SYNC_ACQUIRED(this); -#if defined(HPX_HAVE_MODULE_TRACY) if (run_after) - hpx::tracy::lock_acquired(context_, true); -#endif + context_.after_try_lock(true); util::register_lock(this); return true; } HPX_ITT_SYNC_CANCEL(this); -#if defined(HPX_HAVE_MODULE_TRACY) if (run_after) - hpx::tracy::lock_acquired(context_, false); -#endif + context_.after_try_lock(false); return false; } @@ -113,9 +91,7 @@ namespace hpx::util { m.unlock(); HPX_ITT_SYNC_RELEASED(this); -#if defined(HPX_HAVE_MODULE_TRACY) - hpx::tracy::lock_released(context_); -#endif + context_.after_unlock(); util::unregister_lock(this); } }; From b28c577311dd2ba02ee0954dbf8b80ed49b8cc26 Mon Sep 17 00:00:00 2001 From: v4xsh Date: Thu, 14 May 2026 00:19:49 +0530 Subject: [PATCH 05/15] tracing: add missing include Signed-off-by: v4xsh --- libs/core/tracing/src/tracing.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libs/core/tracing/src/tracing.cpp b/libs/core/tracing/src/tracing.cpp index a41485f872b..c5c244c8f83 100644 --- a/libs/core/tracing/src/tracing.cpp +++ b/libs/core/tracing/src/tracing.cpp @@ -8,6 +8,7 @@ #include #include +#include #if defined(HPX_HAVE_MODULE_TRACY) From 0cf0ec226e31fa4143bd7dcb3692a5e2f4b03746 Mon Sep 17 00:00:00 2001 From: v4xsh Date: Thu, 14 May 2026 13:20:58 +0530 Subject: [PATCH 06/15] tracing: define HPX_HAVE_TRACING in CMake Signed-off-by: v4xsh --- CMakeLists.txt | 2 ++ cmake/HPX_SetupAllocator.cmake | 1 + cmake/HPX_SetupApex.cmake | 1 + libs/core/tracy/cmake/HPX_SetupTracy.cmake | 2 ++ 4 files changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index d0468591978..06609b0c8d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1227,6 +1227,8 @@ endif() unset(_hpx_tracing_backends) unset(_hpx_tracing_backends_count) +hpx_add_config_cond_define(HPX_HAVE_TRACING 0) + if(HPX_WITH_NETWORKING) hpx_add_config_define(HPX_HAVE_NETWORKING) diff --git a/cmake/HPX_SetupAllocator.cmake b/cmake/HPX_SetupAllocator.cmake index 4770573eef5..bd5f86b13ac 100644 --- a/cmake/HPX_SetupAllocator.cmake +++ b/cmake/HPX_SetupAllocator.cmake @@ -142,6 +142,7 @@ if(NOT TARGET hpx_dependencies_allocator) endif() hpx_add_config_define(HPX_HAVE_ITTNOTIFY 1) + hpx_add_config_define(HPX_HAVE_TRACING 1) hpx_add_config_define(HPX_HAVE_THREAD_DESCRIPTION) endif() diff --git a/cmake/HPX_SetupApex.cmake b/cmake/HPX_SetupApex.cmake index 35852a5ca94..d7c454cbb63 100644 --- a/cmake/HPX_SetupApex.cmake +++ b/cmake/HPX_SetupApex.cmake @@ -127,5 +127,6 @@ if(HPX_WITH_APEX AND NOT TARGET APEX::apex) ) target_link_libraries(APEX::apex INTERFACE ITTNotify::ittnotify) hpx_add_config_define(HPX_HAVE_ITTNOTIFY 1) + hpx_add_config_define(HPX_HAVE_TRACING 1) endif() endif() diff --git a/libs/core/tracy/cmake/HPX_SetupTracy.cmake b/libs/core/tracy/cmake/HPX_SetupTracy.cmake index 70a087eedca..7c2ccef12b4 100644 --- a/libs/core/tracy/cmake/HPX_SetupTracy.cmake +++ b/libs/core/tracy/cmake/HPX_SetupTracy.cmake @@ -6,6 +6,8 @@ include(HPX_AddDefinitions) +hpx_add_config_define(HPX_HAVE_TRACING 1) + # compatibility with older CMake versions if(TRACY_ROOT AND NOT Tracy_ROOT) set(Tracy_ROOT From e461cc7491831244032ec02f6c781a47a2401fb4 Mon Sep 17 00:00:00 2001 From: v4xsh Date: Thu, 14 May 2026 13:21:01 +0530 Subject: [PATCH 07/15] tracing: drop std::string lock_context overload Signed-off-by: v4xsh --- libs/core/tracing/include/hpx/tracing/tracing.hpp | 13 +++---------- libs/core/tracing/src/tracing.cpp | 4 ++-- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/libs/core/tracing/include/hpx/tracing/tracing.hpp b/libs/core/tracing/include/hpx/tracing/tracing.hpp index 067c3921db7..ee51fc61907 100644 --- a/libs/core/tracing/include/hpx/tracing/tracing.hpp +++ b/libs/core/tracing/include/hpx/tracing/tracing.hpp @@ -10,13 +10,10 @@ #include #include -#include #if defined(HPX_HAVE_MODULE_TRACY) #include -#define HPX_HAVE_TRACING 1 - namespace hpx::tracing { //////////////////////////////////////////////////////////////////////////// @@ -100,7 +97,7 @@ namespace hpx::tracing { HPX_CXX_CORE_EXPORT struct HPX_CORE_EXPORT lock_context { explicit lock_context(char const* name = nullptr) noexcept; - explicit lock_context(std::string const& name) noexcept; + explicit lock_context(char const* prefix, char const* suffix) noexcept; ~lock_context(); @@ -129,8 +126,6 @@ namespace hpx::tracing { #elif defined(HPX_HAVE_ITTNOTIFY) && HPX_HAVE_ITTNOTIFY != 0 #include -#define HPX_HAVE_TRACING 1 - namespace hpx::tracing { //////////////////////////////////////////////////////////////////////////// @@ -207,7 +202,7 @@ namespace hpx::tracing { HPX_CXX_CORE_EXPORT struct [[maybe_unused]] lock_context { constexpr explicit lock_context(char const* = nullptr) noexcept {} - constexpr explicit lock_context(std::string const&) noexcept {} + constexpr explicit lock_context(char const*, char const*) noexcept {} constexpr bool before_lock() const noexcept { @@ -236,8 +231,6 @@ namespace hpx::tracing { #else -#define HPX_HAVE_TRACING 0 - namespace hpx::tracing { //////////////////////////////////////////////////////////////////////////// @@ -294,7 +287,7 @@ namespace hpx::tracing { HPX_CXX_CORE_EXPORT struct [[maybe_unused]] lock_context { constexpr explicit lock_context(char const* = nullptr) noexcept {} - constexpr explicit lock_context(std::string const&) noexcept {} + constexpr explicit lock_context(char const*, char const*) noexcept {} constexpr bool before_lock() const noexcept { diff --git a/libs/core/tracing/src/tracing.cpp b/libs/core/tracing/src/tracing.cpp index c5c244c8f83..4d10c41ff16 100644 --- a/libs/core/tracing/src/tracing.cpp +++ b/libs/core/tracing/src/tracing.cpp @@ -86,8 +86,8 @@ namespace hpx::tracing { { } - lock_context::lock_context(std::string const& name) noexcept - : impl(hpx::tracy::create(name)) + lock_context::lock_context(char const* prefix, char const* suffix) noexcept + : impl(hpx::tracy::create(std::string(prefix) + suffix)) { } From 4283ff80120a0972687a531c7f0fcb05c381593e Mon Sep 17 00:00:00 2001 From: v4xsh Date: Thu, 14 May 2026 13:21:03 +0530 Subject: [PATCH 08/15] tracing: use prefix/suffix lock_context ctor Signed-off-by: v4xsh --- libs/core/concurrency/include/hpx/concurrency/spinlock.hpp | 2 +- .../synchronization/include/hpx/synchronization/spinlock.hpp | 2 +- libs/core/synchronization/src/mutex.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libs/core/concurrency/include/hpx/concurrency/spinlock.hpp b/libs/core/concurrency/include/hpx/concurrency/spinlock.hpp index a08270a99ca..a4f05e26d2a 100644 --- a/libs/core/concurrency/include/hpx/concurrency/spinlock.hpp +++ b/libs/core/concurrency/include/hpx/concurrency/spinlock.hpp @@ -40,7 +40,7 @@ namespace hpx::util { } explicit spinlock(char const* desc) noexcept - : context_(std::string("util::spinlock#") + desc) + : context_("util::spinlock#", desc) { HPX_ITT_SYNC_CREATE(this, "util::spinlock", desc); } diff --git a/libs/core/synchronization/include/hpx/synchronization/spinlock.hpp b/libs/core/synchronization/include/hpx/synchronization/spinlock.hpp index 8da46b56a4e..848bfa3b423 100644 --- a/libs/core/synchronization/include/hpx/synchronization/spinlock.hpp +++ b/libs/core/synchronization/include/hpx/synchronization/spinlock.hpp @@ -61,7 +61,7 @@ namespace hpx { explicit spinlock(char const* const desc) noexcept : v_(false) - , context_(std::string("hpx::spinlock#") + desc) + , context_("hpx::spinlock#", desc) { HPX_ITT_SYNC_CREATE(this, "hpx::spinlock", desc); } diff --git a/libs/core/synchronization/src/mutex.cpp b/libs/core/synchronization/src/mutex.cpp index 048d3fed854..ae9dedfa556 100644 --- a/libs/core/synchronization/src/mutex.cpp +++ b/libs/core/synchronization/src/mutex.cpp @@ -27,7 +27,7 @@ namespace hpx { #if HPX_HAVE_ITTNOTIFY != 0 || HPX_HAVE_TRACING != 0 mutex::mutex(char const* const description) : owner_id_(threads::invalid_thread_id) - , context_(std::string("hpx::mutex") + description) + , context_("hpx::mutex", description) { HPX_ITT_SYNC_CREATE(this, "hpx::mutex", description); } From f1a842cd2127a9dd645295e852d359ee242135e3 Mon Sep 17 00:00:00 2001 From: v4xsh Date: Thu, 14 May 2026 13:39:21 +0530 Subject: [PATCH 09/15] Guard tracing backend by HPX_HAVE_TRACING Signed-off-by: v4xsh --- libs/core/tracing/include/hpx/tracing/tracing.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/core/tracing/include/hpx/tracing/tracing.hpp b/libs/core/tracing/include/hpx/tracing/tracing.hpp index ee51fc61907..a6c1b1698cf 100644 --- a/libs/core/tracing/include/hpx/tracing/tracing.hpp +++ b/libs/core/tracing/include/hpx/tracing/tracing.hpp @@ -11,7 +11,7 @@ #include -#if defined(HPX_HAVE_MODULE_TRACY) +#if HPX_HAVE_TRACING != 0 && defined(HPX_HAVE_MODULE_TRACY) #include namespace hpx::tracing { @@ -123,7 +123,8 @@ namespace hpx::tracing { } // namespace hpx::tracing -#elif defined(HPX_HAVE_ITTNOTIFY) && HPX_HAVE_ITTNOTIFY != 0 +#elif HPX_HAVE_TRACING != 0 && defined(HPX_HAVE_ITTNOTIFY) && \ + HPX_HAVE_ITTNOTIFY != 0 #include namespace hpx::tracing { From bdecc74e5951ec0ca597712a36d973ac1b57346f Mon Sep 17 00:00:00 2001 From: v4xsh Date: Thu, 14 May 2026 13:43:47 +0530 Subject: [PATCH 10/15] Format tracing guard update Signed-off-by: v4xsh --- libs/core/tracing/include/hpx/tracing/tracing.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/core/tracing/include/hpx/tracing/tracing.hpp b/libs/core/tracing/include/hpx/tracing/tracing.hpp index a6c1b1698cf..ab23db9e75a 100644 --- a/libs/core/tracing/include/hpx/tracing/tracing.hpp +++ b/libs/core/tracing/include/hpx/tracing/tracing.hpp @@ -123,7 +123,7 @@ namespace hpx::tracing { } // namespace hpx::tracing -#elif HPX_HAVE_TRACING != 0 && defined(HPX_HAVE_ITTNOTIFY) && \ +#elif HPX_HAVE_TRACING != 0 && defined(HPX_HAVE_ITTNOTIFY) && \ HPX_HAVE_ITTNOTIFY != 0 #include From d33a9f26925f96b681b0812ea3bced6c65b5eed0 Mon Sep 17 00:00:00 2001 From: v4xsh Date: Thu, 14 May 2026 13:58:06 +0530 Subject: [PATCH 11/15] threading_base: fix region_init_data guard to use HPX_HAVE_TRACING Signed-off-by: v4xsh --- libs/core/threading_base/src/thread_data.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/core/threading_base/src/thread_data.cpp b/libs/core/threading_base/src/thread_data.cpp index 030bb751e09..714825406a2 100644 --- a/libs/core/threading_base/src/thread_data.cpp +++ b/libs/core/threading_base/src/thread_data.cpp @@ -539,7 +539,7 @@ namespace hpx::threads { } #endif -#if defined(HPX_HAVE_MODULE_TRACY) +#if HPX_HAVE_TRACING != 0 && defined(HPX_HAVE_MODULE_TRACY) tracing::region_init_data get_region_init_data(thread_data const* thrdptr) { return {thrdptr->get_description().get_description(), @@ -552,7 +552,8 @@ namespace hpx::threads { return {thrdptr->get_description().get_description(), thrdptr->get_tracy_fiber_name(), thrdptr->is_stackless()}; } -#elif defined(HPX_HAVE_ITTNOTIFY) && HPX_HAVE_ITTNOTIFY != 0 +#elif HPX_HAVE_TRACING != 0 && defined(HPX_HAVE_ITTNOTIFY) && \ + HPX_HAVE_ITTNOTIFY != 0 tracing::region_init_data get_region_init_data(thread_data const* thrdptr) { threads::thread_description const desc = thrdptr->get_description(); From ecf8a0c572f9ea260203afab7e3db60a25bb7257 Mon Sep 17 00:00:00 2001 From: v4xsh Date: Thu, 14 May 2026 14:40:56 +0530 Subject: [PATCH 12/15] tracing: fix branch dispatch conditions in tracing.hpp Signed-off-by: v4xsh --- libs/core/tracing/include/hpx/tracing/tracing.hpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libs/core/tracing/include/hpx/tracing/tracing.hpp b/libs/core/tracing/include/hpx/tracing/tracing.hpp index ab23db9e75a..ee51fc61907 100644 --- a/libs/core/tracing/include/hpx/tracing/tracing.hpp +++ b/libs/core/tracing/include/hpx/tracing/tracing.hpp @@ -11,7 +11,7 @@ #include -#if HPX_HAVE_TRACING != 0 && defined(HPX_HAVE_MODULE_TRACY) +#if defined(HPX_HAVE_MODULE_TRACY) #include namespace hpx::tracing { @@ -123,8 +123,7 @@ namespace hpx::tracing { } // namespace hpx::tracing -#elif HPX_HAVE_TRACING != 0 && defined(HPX_HAVE_ITTNOTIFY) && \ - HPX_HAVE_ITTNOTIFY != 0 +#elif defined(HPX_HAVE_ITTNOTIFY) && HPX_HAVE_ITTNOTIFY != 0 #include namespace hpx::tracing { From 1439902080072a1a534a13aa74ddde751ad259c7 Mon Sep 17 00:00:00 2001 From: v4xsh Date: Thu, 14 May 2026 14:53:11 +0530 Subject: [PATCH 13/15] synchronization: fix constexpr constructor guard to match tracing backend dispatch Signed-off-by: v4xsh --- .../synchronization/include/hpx/synchronization/mutex.hpp | 3 ++- .../include/hpx/synchronization/spinlock.hpp | 3 ++- libs/core/synchronization/src/mutex.cpp | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/libs/core/synchronization/include/hpx/synchronization/mutex.hpp b/libs/core/synchronization/include/hpx/synchronization/mutex.hpp index c22a687db8f..aaddd4125cb 100644 --- a/libs/core/synchronization/include/hpx/synchronization/mutex.hpp +++ b/libs/core/synchronization/include/hpx/synchronization/mutex.hpp @@ -87,7 +87,8 @@ namespace hpx { /// /// \param description description of the \a mutex. /// -#if HPX_HAVE_ITTNOTIFY != 0 || HPX_HAVE_TRACING != 0 +#if defined(HPX_HAVE_MODULE_TRACY) || \ + (defined(HPX_HAVE_ITTNOTIFY) && HPX_HAVE_ITTNOTIFY != 0) HPX_CORE_EXPORT mutex(char const* const description = ""); #else HPX_HOST_DEVICE_CONSTEXPR mutex(char const* const = "") noexcept diff --git a/libs/core/synchronization/include/hpx/synchronization/spinlock.hpp b/libs/core/synchronization/include/hpx/synchronization/spinlock.hpp index 848bfa3b423..7c8ff7f39e7 100644 --- a/libs/core/synchronization/include/hpx/synchronization/spinlock.hpp +++ b/libs/core/synchronization/include/hpx/synchronization/spinlock.hpp @@ -51,7 +51,8 @@ namespace hpx { HPX_NO_UNIQUE_ADDRESS hpx::tracing::lock_context context_; public: -#if HPX_HAVE_TRACING != 0 +#if defined(HPX_HAVE_MODULE_TRACY) || \ + (defined(HPX_HAVE_ITTNOTIFY) && HPX_HAVE_ITTNOTIFY != 0) spinlock() noexcept : v_(false) , context_("hpx::spinlock") diff --git a/libs/core/synchronization/src/mutex.cpp b/libs/core/synchronization/src/mutex.cpp index ae9dedfa556..0a31d3d32da 100644 --- a/libs/core/synchronization/src/mutex.cpp +++ b/libs/core/synchronization/src/mutex.cpp @@ -24,7 +24,8 @@ namespace hpx { /////////////////////////////////////////////////////////////////////////// -#if HPX_HAVE_ITTNOTIFY != 0 || HPX_HAVE_TRACING != 0 +#if defined(HPX_HAVE_MODULE_TRACY) || \ + (defined(HPX_HAVE_ITTNOTIFY) && HPX_HAVE_ITTNOTIFY != 0) mutex::mutex(char const* const description) : owner_id_(threads::invalid_thread_id) , context_("hpx::mutex", description) @@ -33,7 +34,8 @@ namespace hpx { } #endif -#if HPX_HAVE_ITTNOTIFY != 0 || HPX_HAVE_TRACING != 0 +#if defined(HPX_HAVE_MODULE_TRACY) || \ + (defined(HPX_HAVE_ITTNOTIFY) && HPX_HAVE_ITTNOTIFY != 0) mutex::~mutex() { HPX_ITT_SYNC_DESTROY(this); From 50aa40153952c5d7c81fa4413a3ef359d5f3a801 Mon Sep 17 00:00:00 2001 From: v4xsh Date: Thu, 14 May 2026 15:51:27 +0530 Subject: [PATCH 14/15] threading_base: align tracing guards with header Signed-off-by: v4xsh --- libs/core/threading_base/src/thread_data.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libs/core/threading_base/src/thread_data.cpp b/libs/core/threading_base/src/thread_data.cpp index 714825406a2..030bb751e09 100644 --- a/libs/core/threading_base/src/thread_data.cpp +++ b/libs/core/threading_base/src/thread_data.cpp @@ -539,7 +539,7 @@ namespace hpx::threads { } #endif -#if HPX_HAVE_TRACING != 0 && defined(HPX_HAVE_MODULE_TRACY) +#if defined(HPX_HAVE_MODULE_TRACY) tracing::region_init_data get_region_init_data(thread_data const* thrdptr) { return {thrdptr->get_description().get_description(), @@ -552,8 +552,7 @@ namespace hpx::threads { return {thrdptr->get_description().get_description(), thrdptr->get_tracy_fiber_name(), thrdptr->is_stackless()}; } -#elif HPX_HAVE_TRACING != 0 && defined(HPX_HAVE_ITTNOTIFY) && \ - HPX_HAVE_ITTNOTIFY != 0 +#elif defined(HPX_HAVE_ITTNOTIFY) && HPX_HAVE_ITTNOTIFY != 0 tracing::region_init_data get_region_init_data(thread_data const* thrdptr) { threads::thread_description const desc = thrdptr->get_description(); From fdc270450fa54035a0ab88c3ac09be11cae73adb Mon Sep 17 00:00:00 2001 From: v4xsh Date: Thu, 14 May 2026 21:09:52 +0530 Subject: [PATCH 15/15] tracing: simplify HPX_HAVE_TRACING define Signed-off-by: v4xsh --- cmake/HPX_SetupAllocator.cmake | 2 +- libs/core/synchronization/src/mutex.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/HPX_SetupAllocator.cmake b/cmake/HPX_SetupAllocator.cmake index bd5f86b13ac..778453ab654 100644 --- a/cmake/HPX_SetupAllocator.cmake +++ b/cmake/HPX_SetupAllocator.cmake @@ -142,7 +142,7 @@ if(NOT TARGET hpx_dependencies_allocator) endif() hpx_add_config_define(HPX_HAVE_ITTNOTIFY 1) - hpx_add_config_define(HPX_HAVE_TRACING 1) + hpx_add_config_define(HPX_HAVE_TRACING) hpx_add_config_define(HPX_HAVE_THREAD_DESCRIPTION) endif() diff --git a/libs/core/synchronization/src/mutex.cpp b/libs/core/synchronization/src/mutex.cpp index 0a31d3d32da..0143bc55273 100644 --- a/libs/core/synchronization/src/mutex.cpp +++ b/libs/core/synchronization/src/mutex.cpp @@ -28,7 +28,7 @@ namespace hpx { (defined(HPX_HAVE_ITTNOTIFY) && HPX_HAVE_ITTNOTIFY != 0) mutex::mutex(char const* const description) : owner_id_(threads::invalid_thread_id) - , context_("hpx::mutex", description) + , context_("hpx::mutex#", description) { HPX_ITT_SYNC_CREATE(this, "hpx::mutex", description); }