tracing: add lock_context and migrate synchronization primitives to unified tracing#7264
tracing: add lock_context and migrate synchronization primitives to unified tracing#7264v4xsh wants to merge 10 commits into
Conversation
Signed-off-by: v4xsh <vanshdobhal11@gmail.com>
Signed-off-by: v4xsh <vanshdobhal11@gmail.com>
Signed-off-by: v4xsh <vanshdobhal11@gmail.com>
Signed-off-by: v4xsh <vanshdobhal11@gmail.com>
Up to standards ✅🟢 Issues
|
|
Can one of the admins verify this patch? |
There was a problem hiding this comment.
Pull request overview
Introduces a hpx::tracing::lock_context abstraction that hides per-tracing-backend (Tracy / ITT / no-op) lock instrumentation behind a uniform interface, and migrates the synchronization primitives in libs/core/synchronization and libs/core/concurrency from raw hpx::tracy::lock_data members and per-call #if defined(HPX_HAVE_MODULE_TRACY) guards to that new abstraction. A new HPX_HAVE_TRACING macro unifies the previously split HPX_HAVE_ITTNOTIFY / HPX_HAVE_MODULE_TRACY constructor guards.
Changes:
- Add
hpx::tracing::lock_context(Tracy-backed; constexpr no-op in ITT/disabled builds) and theHPX_HAVE_TRACINGmacro inlibs/core/tracing. - Replace
hpx::tracy::lock_datamembers andHPX_HAVE_MODULE_TRACYguards inmutexand bothspinlocktypes withHPX_NO_UNIQUE_ADDRESS lock_context. - Add
hpx_tracingto the module dependency list ofsynchronizationandconcurrency.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| libs/core/tracing/include/hpx/tracing/tracing.hpp | Adds lock_context declarations for Tracy/ITT/disabled branches and defines HPX_HAVE_TRACING. |
| libs/core/tracing/src/tracing.cpp | Out-of-line implementations of lock_context delegating to hpx::tracy lock APIs. |
| libs/core/synchronization/include/hpx/synchronization/mutex.hpp | Replaces tracy member/guards with a HPX_NO_UNIQUE_ADDRESS lock_context; switches constructor guard to HPX_HAVE_TRACING. |
| libs/core/synchronization/src/mutex.cpp | Removes #if HPX_HAVE_MODULE_TRACY guards in lock/try_lock/unlock paths in favor of lock_context calls. |
| libs/core/synchronization/include/hpx/synchronization/spinlock.hpp | Same migration for hpx::spinlock. |
| libs/core/concurrency/include/hpx/concurrency/spinlock.hpp | Same migration for hpx::util::spinlock. |
| libs/core/synchronization/CMakeLists.txt | Adds hpx_tracing module dependency. |
| libs/core/concurrency/CMakeLists.txt | Adds hpx_tracing module dependency. |
Comments suppressed due to low confidence (1)
libs/core/tracing/include/hpx/tracing/tracing.hpp:108
- The tracy-branch
lock_contextdeletes only the copy operations, which implicitly deletes the move operations as well — but the codebase convention (see e.g.hpx::util::detail::lock_datainlibs/core/lock_registration/include/hpx/lock_registration/detail/register_locks.hpp:46-49) is to delete copy and move operations explicitly. Consider addinglock_context(lock_context&&) = delete;andlock_context& operator=(lock_context&&) = delete;for clarity and to make the intent explicit.
lock_context(lock_context const&) = delete;
lock_context& operator=(lock_context const&) = delete;
| #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 |
There was a problem hiding this comment.
In general, we should define the HPX_HAVE_TRACING macro in the CMake build system. There we know if any of the tooling backends are enabled.
| : owner_id_(threads::invalid_thread_id) | ||
| , context_(std::string("hpx::mutex") + description) |
| }; | ||
|
|
||
| //////////////////////////////////////////////////////////////////////////// | ||
| HPX_CXX_CORE_EXPORT struct HPX_CORE_EXPORT lock_context |
Signed-off-by: v4xsh <vanshdobhal11@gmail.com>
| } | ||
|
|
||
| explicit spinlock(char const* desc) noexcept | ||
| : context_(std::string("util::spinlock#") + desc) |
There was a problem hiding this comment.
Hmmm, unconditionally creating a string is not a good idea as it involves an allocation. Can we do something like:
| : context_(std::string("util::spinlock#") + desc) | |
| : context_("util::spinlock#", desc) |
and create the string(s) only if needed?
|
|
||
| explicit spinlock(char const* const desc) noexcept | ||
| : v_(false) | ||
| , context_(std::string("hpx::spinlock#") + desc) |
There was a problem hiding this comment.
Same here, let's avoid always creating strings.
| #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 |
There was a problem hiding this comment.
In general, we should define the HPX_HAVE_TRACING macro in the CMake build system. There we know if any of the tooling backends are enabled.
| #if defined(HPX_HAVE_MODULE_TRACY) | ||
| #include <hpx/modules/tracy.hpp> | ||
|
|
||
| #define HPX_HAVE_TRACING 1 |
There was a problem hiding this comment.
As said, let's have this defined in the build system.
Signed-off-by: v4xsh <vanshdobhal11@gmail.com>
Signed-off-by: v4xsh <vanshdobhal11@gmail.com>
Signed-off-by: v4xsh <vanshdobhal11@gmail.com>
|
@hkaiser addressed all three points — switched to the prefix/suffix constructor to avoid the allocation, moved HPX_HAVE_TRACING to CMake, and cleaned up the leftover ifdef in the mutex constructor. Let me know if anything else needs fixing! |
Signed-off-by: v4xsh <vanshdobhal11@gmail.com>
Signed-off-by: v4xsh <vanshdobhal11@gmail.com>
Proposed Changes
hpx::tracing::lock_contextto the unified tracing abstraction layer with four methods:before_lock(),after_lock(),after_try_lock(bool),after_unlock()— Tracy branch delegates tohpx::tracy::lock_prepare,lock_acquired,lock_released; ITT and no-op branches are inlineconstexprno-opshpx::tracy::lock_datamembers and all#if defined(HPX_HAVE_MODULE_TRACY)guards inlibs/core/synchronization/mutex.hpp,mutex.cpp, andspinlock.hppwithhpx::tracing::lock_contexthpx::tracy::lock_datamember and all#if defined(HPX_HAVE_MODULE_TRACY)guards inlibs/core/concurrency/spinlock.hppwithhpx::tracing::lock_contextHPX_NO_UNIQUE_ADDRESSonlock_contextmembers in all three call sites so non-Tracy builds have zero size overheadhpx_tracingtoMODULE_DEPENDENCIESinlibs/core/synchronization/CMakeLists.txtandlibs/core/concurrency/CMakeLists.txtHPX_HAVE_TRACINGcompile-time macro (1 when Tracy or ITT active, 0 otherwise) to unify the constructor guards previously split acrossHPX_HAVE_ITTNOTIFYandHPX_HAVE_MODULE_TRACYChecklist