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::loop_context trace_ctx;

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,19 +203,7 @@ 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::region rctx(
hpx::tracing::region rctx(trace_ctx,
threads::get_region_init_data(thrdptr),
num_thread);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,9 @@ namespace hpx::threads {
return static_cast<thread_data*>(tid.get());
}

#if defined(HPX_HAVE_MODULE_TRACY)
#if defined(HPX_HAVE_MODULE_TRACY) || \
(defined(HPX_HAVE_ITTNOTIFY) && HPX_HAVE_ITTNOTIFY != 0 && \
!defined(HPX_HAVE_APEX))
Comment thread
hkaiser marked this conversation as resolved.
Outdated
HPX_CXX_CORE_EXPORT HPX_CORE_EXPORT tracing::region_init_data
get_region_init_data(thread_data const* thrdptr);

Expand Down
20 changes: 20 additions & 0 deletions libs/core/threading_base/src/thread_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,26 @@ 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 && \
!defined(HPX_HAVE_APEX)
tracing::region_init_data get_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};
}

tracing::fiber_region_init_data get_fiber_region_init_data(
Comment thread
hkaiser marked this conversation as resolved.
Outdated
thread_data const*)
{
return {};
}
#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
112 changes: 109 additions & 3 deletions libs/core/tracing/include/hpx/tracing/tracing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,22 @@ namespace hpx::tracing {
bool is_stackless = false;
};

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

~loop_context() = default;

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

////////////////////////////////////////////////////////////////////////////
HPX_CXX_CORE_EXPORT struct HPX_CORE_EXPORT region
{
explicit region(
region_init_data const& init_data, std::size_t num_thread) noexcept;
explicit region(loop_context&, region_init_data const& init_data,
std::size_t num_thread) noexcept;

~region();

Expand Down Expand Up @@ -87,6 +99,87 @@ namespace hpx::tracing {

} // namespace hpx::tracing

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

namespace hpx::tracing {

////////////////////////////////////////////////////////////////////////////
HPX_CXX_CORE_EXPORT struct 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;
};

////////////////////////////////////////////////////////////////////////////
HPX_CXX_CORE_EXPORT struct HPX_CORE_EXPORT loop_context
{
explicit loop_context() noexcept;
~loop_context();

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

util::itt::stack_context stack_ctx;
util::itt::thread_domain thread_domain;
util::itt::string_handle task_id;
util::itt::string_handle task_phase;
};

////////////////////////////////////////////////////////////////////////////
HPX_CXX_CORE_EXPORT struct HPX_CORE_EXPORT region
{
explicit region(
loop_context& ctx, region_init_data const& data, std::size_t);
~region();

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

private:
static util::itt::task make_task(
loop_context& ctx, region_init_data const& data);

util::itt::caller_context cctx;
util::itt::task task;
};

////////////////////////////////////////////////////////////////////////////
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 constexpr void set_thread_name(char const*) noexcept {}

} // namespace hpx::tracing

#else

namespace hpx::tracing {
Expand All @@ -96,9 +189,22 @@ namespace hpx::tracing {
{
};

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

~loop_context() = default;

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

////////////////////////////////////////////////////////////////////////////
HPX_CXX_CORE_EXPORT struct [[maybe_unused]] region
{
constexpr explicit region(region_init_data const&, std::size_t) noexcept
constexpr explicit region(
loop_context&, region_init_data const&, std::size_t) noexcept
{
}
};
Expand Down
53 changes: 51 additions & 2 deletions libs/core/tracing/src/tracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ namespace hpx::tracing {
data.name, num_thread, data.thread_phase, enabled);
}

region::region(
region_init_data const& data, std::size_t const num_thread) noexcept
region::region(loop_context&, region_init_data const& data,
std::size_t const num_thread) noexcept
: impl(create_tracy_region(data, num_thread))
{
}
Expand Down Expand Up @@ -87,4 +87,53 @@ namespace hpx::tracing {

} // namespace hpx::tracing

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

namespace hpx::tracing {

////////////////////////////////////////////////////////////////////////////
// loop_context

loop_context::loop_context() noexcept
: task_id("task_id")
, task_phase("task_phase")
{
}

loop_context::~loop_context() = default;

////////////////////////////////////////////////////////////////////////////
// region

util::itt::task region::make_task(
loop_context& ctx, 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));
}

region::region(loop_context& ctx, region_init_data const& data, std::size_t)
: 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);
}

region::~region() = default;

} // namespace hpx::tracing

#endif
Loading