Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
#include <hpx/thread_pools/detail/scheduling_counters.hpp>
#include <hpx/thread_pools/detail/scheduling_log.hpp>

#if defined(HPX_HAVE_ITTNOTIFY) && HPX_HAVE_ITTNOTIFY != 0 && \
!defined(HPX_HAVE_APEX)
#include <hpx/modules/itt_notify.hpp>
#endif

#include <atomic>
#include <cstddef>
#include <cstdint>
Expand Down Expand Up @@ -87,16 +82,7 @@ namespace hpx::threads::detail {
scheduling_counters& counters, scheduling_callbacks& params)
{
std::atomic<hpx::state>& this_state = scheduler.get_state(num_thread);

#if defined(HPX_HAVE_ITTNOTIFY) && HPX_HAVE_ITTNOTIFY != 0 && \
!defined(HPX_HAVE_APEX)
util::itt::stack_context ctx; // helper for itt support
util::itt::thread_domain const thread_domain;
util::itt::id threadid(thread_domain, &scheduler);
util::itt::string_handle const task_id("task_id");
util::itt::string_handle const task_phase("task_phase");
// util::itt::frame_context fctx(thread_domain);
#endif
hpx::tracing::itt_loop_context itt_ctx;
Comment thread
hkaiser marked this conversation as resolved.
Outdated

std::int64_t& idle_loop_count = counters.idle_loop_count_;
std::int64_t& busy_loop_count = counters.busy_loop_count_;
Expand Down Expand Up @@ -217,18 +203,9 @@ namespace hpx::threads::detail {
is_active = false;
});

#if defined(HPX_HAVE_ITTNOTIFY) && HPX_HAVE_ITTNOTIFY != 0 && \
!defined(HPX_HAVE_APEX)
util::itt::caller_context cctx(
ctx, !thrdptr->is_stackless());
// util::itt::undo_frame_context undoframe(fctx);
util::itt::task task =
thrdptr->get_description().get_task_itt(
thread_domain);
task.add_metadata(task_id, thrdptr);
task.add_metadata(
task_phase, thrdptr->get_thread_phase());
#endif
hpx::tracing::itt_task_region itt_task(itt_ctx,
threads::get_thread_region_init_data(
thrdptr));
Comment thread
hkaiser marked this conversation as resolved.
Outdated
hpx::tracing::region rctx(
Comment thread
hkaiser marked this conversation as resolved.
Outdated
threads::get_region_init_data(thrdptr),
num_thread);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,18 @@ namespace hpx::threads {
return {};
}
#endif

#if defined(HPX_HAVE_ITTNOTIFY) && HPX_HAVE_ITTNOTIFY != 0 && \
!defined(HPX_HAVE_APEX)
HPX_CXX_CORE_EXPORT HPX_CORE_EXPORT tracing::thread_region_init_data
get_thread_region_init_data(thread_data const* thrdptr);
#else
HPX_CXX_CORE_EXPORT constexpr tracing::thread_region_init_data
get_thread_region_init_data(thread_data const*) noexcept
{
return {};
}
#endif
} // namespace hpx::threads

#include <hpx/config/warnings_suffix.hpp>
Expand Down
17 changes: 17 additions & 0 deletions libs/core/threading_base/src/thread_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,4 +556,21 @@ namespace hpx::threads {
}
#endif

#if defined(HPX_HAVE_ITTNOTIFY) && HPX_HAVE_ITTNOTIFY != 0 && \
!defined(HPX_HAVE_APEX)
tracing::thread_region_init_data get_thread_region_init_data(
thread_data const* thrdptr)
{
threads::thread_description const desc = thrdptr->get_description();
if (desc.kind() == threads::thread_description::data_type::description)
{
return {desc.get_description(), thrdptr->get_thread_phase(),
thrdptr, thrdptr->is_stackless(), 0, false,
desc.get_description_itt().handle_};
Comment thread
hkaiser marked this conversation as resolved.
}
return {"address", thrdptr->get_thread_phase(), thrdptr,
thrdptr->is_stackless(), desc.get_address(), true, nullptr};
}
#endif

} // namespace hpx::threads
3 changes: 3 additions & 0 deletions libs/core/tracing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ set(tracing_module_dependencies hpx_config)
if(HPX_TRACY_WITH_TRACY)
list(APPEND tracing_module_dependencies hpx_tracy)
endif()
if(HPX_WITH_ITTNOTIFY)
list(APPEND tracing_module_dependencies hpx_itt_notify)
endif()

include(HPX_AddModule)
add_hpx_module(
Expand Down
145 changes: 145 additions & 0 deletions libs/core/tracing/include/hpx/tracing/tracing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@
#include <hpx/config.hpp>

#include <cstddef>
#include <memory>

namespace hpx::tracing {

////////////////////////////////////////////////////////////////////////////
HPX_CXX_CORE_EXPORT struct thread_region_init_data
{
char const* name = nullptr;
std::size_t thread_phase = 0;
void const* thread_ptr = nullptr;
bool is_stackless = false;
std::size_t address = 0;
bool is_address_type = false;
void* itt_string_handle = nullptr;
};

} // namespace hpx::tracing

#if defined(HPX_HAVE_MODULE_TRACY)
#include <hpx/modules/tracy.hpp>
Expand Down Expand Up @@ -81,12 +98,115 @@ namespace hpx::tracing {
hpx::tracy::fiber_suspend_region impl;
};

////////////////////////////////////////////////////////////////////////////
HPX_CXX_CORE_EXPORT struct HPX_CORE_EXPORT [[maybe_unused]] itt_loop_context
{
constexpr explicit itt_loop_context() noexcept {}

~itt_loop_context() = default;

itt_loop_context(itt_loop_context const&) = delete;
itt_loop_context& operator=(itt_loop_context const&) = delete;
};

////////////////////////////////////////////////////////////////////////////
HPX_CXX_CORE_EXPORT struct HPX_CORE_EXPORT [[maybe_unused]] itt_task_region
{
constexpr explicit itt_task_region(
itt_loop_context&, thread_region_init_data const&) noexcept
{
}

~itt_task_region() = default;

itt_task_region(itt_task_region const&) = delete;
itt_task_region& operator=(itt_task_region const&) = delete;
};

////////////////////////////////////////////////////////////////////////////
HPX_CXX_CORE_EXPORT HPX_CORE_EXPORT void set_thread_name(
char const* name) noexcept;

} // namespace hpx::tracing

#elif defined(HPX_HAVE_ITTNOTIFY) && HPX_HAVE_ITTNOTIFY != 0 && \
!defined(HPX_HAVE_APEX)

namespace hpx::tracing {

////////////////////////////////////////////////////////////////////////////
HPX_CXX_CORE_EXPORT struct region_init_data
{
};

HPX_CXX_CORE_EXPORT struct [[maybe_unused]] region
{
constexpr explicit region(region_init_data const&, std::size_t) noexcept
{
}
};

////////////////////////////////////////////////////////////////////////////
HPX_CXX_CORE_EXPORT struct [[maybe_unused]] mark_event
{
constexpr explicit mark_event(char const*) noexcept {}
};

////////////////////////////////////////////////////////////////////////////
HPX_CXX_CORE_EXPORT struct fiber_region_init_data
{
};

HPX_CXX_CORE_EXPORT struct [[maybe_unused]] fiber_region
{
constexpr explicit fiber_region(
fiber_region_init_data const&, std::size_t) noexcept
{
}
};

////////////////////////////////////////////////////////////////////////////
HPX_CXX_CORE_EXPORT struct [[maybe_unused]] fiber_suspend_region
{
constexpr explicit fiber_suspend_region(char const*) noexcept {}
};

////////////////////////////////////////////////////////////////////////////
HPX_CXX_CORE_EXPORT struct HPX_CORE_EXPORT itt_loop_context
{
explicit itt_loop_context();
~itt_loop_context();

itt_loop_context(itt_loop_context const&) = delete;
itt_loop_context& operator=(itt_loop_context const&) = delete;

private:
struct impl;
std::unique_ptr<impl> impl_;

friend struct itt_task_region;
};

////////////////////////////////////////////////////////////////////////////
HPX_CXX_CORE_EXPORT struct HPX_CORE_EXPORT itt_task_region
{
explicit itt_task_region(
itt_loop_context& ctx, thread_region_init_data const& data);
~itt_task_region();

itt_task_region(itt_task_region const&) = delete;
itt_task_region& operator=(itt_task_region const&) = delete;

private:
struct impl;
std::unique_ptr<impl> impl_;
};
Comment thread
hkaiser marked this conversation as resolved.
Outdated

////////////////////////////////////////////////////////////////////////////
HPX_CXX_CORE_EXPORT constexpr void set_thread_name(char const*) noexcept {}

} // namespace hpx::tracing

#else

namespace hpx::tracing {
Expand Down Expand Up @@ -128,6 +248,31 @@ namespace hpx::tracing {
constexpr explicit fiber_suspend_region(char const*) noexcept {}
};

////////////////////////////////////////////////////////////////////////////
HPX_CXX_CORE_EXPORT struct [[maybe_unused]] itt_loop_context
{
constexpr explicit itt_loop_context() noexcept {}

~itt_loop_context() = default;

itt_loop_context(itt_loop_context const&) = delete;
itt_loop_context& operator=(itt_loop_context const&) = delete;
};

////////////////////////////////////////////////////////////////////////////
HPX_CXX_CORE_EXPORT struct [[maybe_unused]] itt_task_region
{
constexpr explicit itt_task_region(
itt_loop_context&, thread_region_init_data const&) noexcept
{
}

~itt_task_region() = default;

itt_task_region(itt_task_region const&) = delete;
itt_task_region& operator=(itt_task_region const&) = delete;
};

////////////////////////////////////////////////////////////////////////////
HPX_CXX_CORE_EXPORT constexpr void set_thread_name(char const*) noexcept {}

Expand Down
72 changes: 72 additions & 0 deletions libs/core/tracing/src/tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <hpx/tracing/tracing.hpp>

#include <cstddef>
#include <memory>

#if defined(HPX_HAVE_MODULE_TRACY)

Expand Down Expand Up @@ -88,3 +89,74 @@ namespace hpx::tracing {
} // namespace hpx::tracing

#endif

#if !defined(HPX_HAVE_MODULE_TRACY) && defined(HPX_HAVE_ITTNOTIFY) && \
HPX_HAVE_ITTNOTIFY != 0 && !defined(HPX_HAVE_APEX)
#include <hpx/modules/itt_notify.hpp>

namespace hpx::tracing {

struct itt_loop_context::impl
{
util::itt::stack_context stack_ctx;
util::itt::thread_domain thread_domain;
util::itt::string_handle task_id;
util::itt::string_handle task_phase;

impl()
: task_id("task_id")
, task_phase("task_phase")
{
}
};

itt_loop_context::itt_loop_context()
: impl_(std::make_unique<impl>())
{
}

itt_loop_context::~itt_loop_context() = default;

struct itt_task_region::impl
{
util::itt::caller_context cctx;
util::itt::task task;

static util::itt::task make_task(
itt_loop_context::impl& ctx, thread_region_init_data const& data)
{
if (data.is_address_type)
{
return util::itt::task(ctx.thread_domain,
util::itt::string_handle("address"), data.address);
}
if (data.itt_string_handle != nullptr)
{
return util::itt::task(ctx.thread_domain,
util::itt::string_handle(static_cast<___itt_string_handle*>(
data.itt_string_handle)));
}
return util::itt::task(
ctx.thread_domain, util::itt::string_handle(data.name));
}

impl(itt_loop_context::impl& ctx, thread_region_init_data const& data)
: cctx(ctx.stack_ctx, !data.is_stackless)
, task(make_task(ctx, data))
{
task.add_metadata(ctx.task_id, data.thread_ptr);
task.add_metadata(ctx.task_phase, data.thread_phase);
}
};

itt_task_region::itt_task_region(
itt_loop_context& ctx, thread_region_init_data const& data)
: impl_(std::make_unique<impl>(*ctx.impl_, data))
{
}

Comment thread
hkaiser marked this conversation as resolved.
Outdated
itt_task_region::~itt_task_region() = default;

} // namespace hpx::tracing

#endif
Loading