Generalized updates (#174)
- include/rocprofiler/agent.h
- move rocprofiler_dim3_t
- include/rocprofiler/buffer_tracing.h
- size fields
- update kernel dispatch record
- include/rocprofiler/callback_tracing.h
- remove rocprofiler_callback_tracing_code_object_unload_data_t
- remove rocprofiler_callback_tracing_code_object_register_host_kernel_symbol_data_t
- include/rocprofiler/fwd.h
- added ROCPROFILER_STATUS_ERROR_CONTEXT_CONFLICT
- remove ROCPROFILER_CALLBACK_TRACING_CODE_OBJECT_UNLOAD
- remove ROCPROFILER_CALLBACK_TRACING_CODE_OBJECT_DEVICE_KERNEL_SYMBOL_UNREGISTER
- add rocprofiler_kernel_id_t typedef
- add rocprofiler_dim3_t (moved from agent.h)
- lib/common/synchronized.hpp
- rlock/wlock return decltype(auto)
- separate prototype from definition
- lib/common/utility.{hpp,cpp}
- timestamp functions replicating HSA implementation(s)
- init_public_api_struct for setting size field and ensuring certain type traits
- simplified static_cleanup_wrapper
- separate prototype from definition in active_capacity_gate
- lib/rocprofiler/agent.cpp
- tweak get_rocprofiler_agent impl
- lib/rocprofiler/buffer.cpp
- fix buffer message log level
- lib/rocprofiler/context.cpp
- use new paradigm for getting active contexts
- lib/rocprofiler/internal_threading.hpp
- update to simplified static_cleanup_wrapper implementation
- lib/rocprofiler/registration.cpp
- fix deactivating contexts
- lib/rocprofiler/rocprofiler.cpp
- status string for context conflict
- lib/rocprofiler/context/context.*
- correlation_id struct
- new get_active_contexts paradigm
- lib/rocprofiler/counters/core.*
- rocprofiler_packet union
- tweak start/stop context to accept pointer instead of handle
- lib/rocprofiler/counters/dimensions.cpp
- update to new get_rocp_agent() return type
- lib/rocprofiler/hsa/hsa.*
- update to new get_active_contexts paradigm
- update to new correlation id implementation
- guard against hsa.def.cpp direct compilation
- lib/rocprofiler/hsa/queue_controller.*
- update to change in get_rocp_agent return type
- consistent aliases
- lookup function for getting queue pointer from hsa queue id
- lib/rocprofiler/hsa/queue.*
- rocprofiler_packet
- extend queue_info_session_t
- lib/rocprofiler/tests/registration.cpp
- improve diagnostic on perf check for rocprofiler_lib.callback_registration_lambda_with_result
This commit is contained in:
committed by
GitHub
parent
63775f241a
commit
55f2dabbb3
+164
-47
@@ -22,19 +22,37 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "lib/common/defines.hpp"
|
||||
|
||||
#include <glog/logging.h>
|
||||
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <unistd.h>
|
||||
#include <chrono>
|
||||
#include <condition_variable>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
#include <ratio>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
namespace rocprofiler
|
||||
{
|
||||
namespace common
|
||||
{
|
||||
clockid_t
|
||||
get_accurate_clock_id_impl();
|
||||
|
||||
uint64_t
|
||||
get_clock_freq_ns_impl(clockid_t _clk_id);
|
||||
|
||||
inline uint64_t
|
||||
get_tid()
|
||||
{
|
||||
@@ -43,11 +61,51 @@ get_tid()
|
||||
return _v;
|
||||
}
|
||||
|
||||
inline clockid_t
|
||||
get_accurate_clock_id()
|
||||
{
|
||||
static auto clk_id = get_accurate_clock_id_impl();
|
||||
return clk_id;
|
||||
}
|
||||
|
||||
inline uint64_t
|
||||
get_accurate_clock_freq_ns()
|
||||
{
|
||||
static auto clk_freq = get_clock_freq_ns_impl(get_accurate_clock_id());
|
||||
return clk_freq;
|
||||
}
|
||||
|
||||
inline uint64_t
|
||||
get_ticks(clockid_t clk_id_v) noexcept
|
||||
{
|
||||
constexpr auto nanosec = std::nano::den;
|
||||
auto&& ts = timespec{};
|
||||
auto ret = clock_gettime(clk_id_v, &ts);
|
||||
|
||||
if(ROCPROFILER_UNLIKELY(ret != 0))
|
||||
{
|
||||
auto _err = errno;
|
||||
LOG(FATAL) << "clock_gettime failed: " << strerror(_err);
|
||||
}
|
||||
|
||||
return (static_cast<uint64_t>(ts.tv_sec) * nanosec) + static_cast<uint64_t>(ts.tv_nsec);
|
||||
}
|
||||
|
||||
// this equates to HSA-runtime library implementation of os::ReadAccurateClock()
|
||||
inline uint64_t
|
||||
timestamp_ns()
|
||||
{
|
||||
// TODO(jrmadsen): this should be updated to the HSA method
|
||||
return std::chrono::steady_clock::now().time_since_epoch().count();
|
||||
return get_ticks(get_accurate_clock_id()) * get_accurate_clock_freq_ns();
|
||||
}
|
||||
|
||||
// this equates to HSA-runtime library implementation of os::ReadSystemClock()
|
||||
inline uint64_t
|
||||
system_timestamp_ns()
|
||||
{
|
||||
constexpr auto boottime_clk = CLOCK_BOOTTIME;
|
||||
static auto boottime_clk_freq = get_clock_freq_ns_impl(boottime_clk);
|
||||
|
||||
return get_ticks(boottime_clk) * boottime_clk_freq;
|
||||
}
|
||||
|
||||
std::vector<std::string>
|
||||
@@ -69,34 +127,85 @@ get_val(Container& map, const Key& key)
|
||||
return (pos != map.end() ? &pos->second : nullptr);
|
||||
}
|
||||
|
||||
template <typename Tp>
|
||||
constexpr void
|
||||
assert_public_api_struct_properties()
|
||||
{
|
||||
static_assert(std::is_class<Tp>::value, "this is not a public API struct");
|
||||
static_assert(std::is_standard_layout<Tp>::value,
|
||||
"public API struct should have a standard layout");
|
||||
static_assert(std::is_trivially_default_constructible<Tp>::value,
|
||||
"public API struct should be trivially default constructible");
|
||||
static_assert(std::is_trivially_copy_constructible<Tp>::value,
|
||||
"public API struct should be trivially copy constructible");
|
||||
static_assert(std::is_trivially_move_constructible<Tp>::value,
|
||||
"public API struct should be trivially move constructible");
|
||||
static_assert(std::is_trivially_copy_assignable<Tp>::value,
|
||||
"public API struct should be trivially move assignable");
|
||||
static_assert(std::is_trivially_move_assignable<Tp>::value,
|
||||
"public API struct should be trivially move assignable");
|
||||
static_assert(std::is_trivially_copyable<Tp>::value,
|
||||
"public API struct should be trivially move assignable");
|
||||
static_assert(std::is_trivial<Tp>::value, "public API struct should be trivial");
|
||||
static_assert(offsetof(Tp, size) == 0, "public API struct should have a size field first");
|
||||
static_assert(sizeof(std::declval<Tp>().size) == sizeof(uint64_t),
|
||||
"public API struct size field should be 64 bits");
|
||||
}
|
||||
|
||||
template <typename Tp>
|
||||
decltype(auto)
|
||||
init_public_api_struct(Tp&& val)
|
||||
{
|
||||
assert_public_api_struct_properties<Tp>();
|
||||
|
||||
::memset(&val, 0, sizeof(Tp));
|
||||
val.size = sizeof(Tp);
|
||||
return std::forward<Tp>(val);
|
||||
}
|
||||
|
||||
template <typename Tp>
|
||||
Tp&
|
||||
init_public_api_struct(Tp& val)
|
||||
{
|
||||
assert_public_api_struct_properties<Tp>();
|
||||
|
||||
::memset(&val, 0, sizeof(Tp));
|
||||
val.size = sizeof(Tp);
|
||||
return val;
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple wrapper that will call a function when the
|
||||
* wrapper is being destroyed. This is primarily useful
|
||||
* for static variables where we want to run some destruction
|
||||
* operations when the program exits.
|
||||
*/
|
||||
template <typename T, typename L>
|
||||
template <typename Tp>
|
||||
class static_cleanup_wrapper
|
||||
{
|
||||
public:
|
||||
static_cleanup_wrapper(T&& data, L&& destroy_func)
|
||||
: _data(std::move(data))
|
||||
, _destroy_func(destroy_func)
|
||||
using data_type = Tp;
|
||||
using functor_type = std::function<void(Tp&)>;
|
||||
|
||||
static_cleanup_wrapper(data_type&& data, functor_type&& destroy_func)
|
||||
: m_data(std::move(data))
|
||||
, m_destroy_func(std::move(destroy_func))
|
||||
{}
|
||||
|
||||
static_cleanup_wrapper(L&& destroy_func)
|
||||
: _destroy_func(destroy_func)
|
||||
static_cleanup_wrapper(functor_type&& destroy_func)
|
||||
: m_destroy_func(std::move(destroy_func))
|
||||
{}
|
||||
|
||||
~static_cleanup_wrapper() { _destroy_func(_data); }
|
||||
~static_cleanup_wrapper() { m_destroy_func(m_data); }
|
||||
|
||||
void destroy() { _destroy_func(_data); }
|
||||
void destroy() { m_destroy_func(m_data); }
|
||||
|
||||
T& get() { return _data; }
|
||||
data_type& get() { return m_data; }
|
||||
const data_type& get() const { return m_data; }
|
||||
|
||||
private:
|
||||
T _data;
|
||||
L _destroy_func;
|
||||
data_type m_data = {};
|
||||
functor_type m_destroy_func = {};
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -107,41 +216,10 @@ private:
|
||||
class active_capacity_gate
|
||||
{
|
||||
public:
|
||||
active_capacity_gate(size_t capacity)
|
||||
: _capacity(capacity)
|
||||
{}
|
||||
void add_active(size_t size)
|
||||
{
|
||||
if(size >= _capacity)
|
||||
{
|
||||
throw std::runtime_error("Size exceeds gate capacity");
|
||||
}
|
||||
active_capacity_gate(size_t capacity);
|
||||
|
||||
std::unique_lock lock(_m);
|
||||
if(_count + size < _capacity)
|
||||
{
|
||||
_count += size;
|
||||
return;
|
||||
}
|
||||
_waiters++;
|
||||
_cv.wait(lock, [&]() { return _count + size < _capacity; });
|
||||
_waiters--;
|
||||
_count += size;
|
||||
}
|
||||
|
||||
void remove_active(size_t size)
|
||||
{
|
||||
std::unique_lock lock(_m);
|
||||
if(_count > size)
|
||||
_count -= size;
|
||||
else
|
||||
_count = 0;
|
||||
|
||||
if(_waiters > 0)
|
||||
{
|
||||
_cv.notify_all();
|
||||
}
|
||||
}
|
||||
void add_active(size_t size);
|
||||
void remove_active(size_t size);
|
||||
|
||||
private:
|
||||
size_t _count{0};
|
||||
@@ -151,5 +229,44 @@ private:
|
||||
std::condition_variable _cv;
|
||||
};
|
||||
|
||||
inline active_capacity_gate::active_capacity_gate(size_t capacity)
|
||||
: _capacity(capacity)
|
||||
{}
|
||||
|
||||
inline void
|
||||
active_capacity_gate::add_active(size_t size)
|
||||
{
|
||||
if(size >= _capacity)
|
||||
{
|
||||
throw std::runtime_error("Size exceeds gate capacity");
|
||||
}
|
||||
|
||||
std::unique_lock lock(_m);
|
||||
if(_count + size < _capacity)
|
||||
{
|
||||
_count += size;
|
||||
return;
|
||||
}
|
||||
_waiters++;
|
||||
_cv.wait(lock, [&]() { return _count + size < _capacity; });
|
||||
_waiters--;
|
||||
_count += size;
|
||||
}
|
||||
|
||||
inline void
|
||||
active_capacity_gate::remove_active(size_t size)
|
||||
{
|
||||
std::unique_lock lock(_m);
|
||||
if(_count > size)
|
||||
_count -= size;
|
||||
else
|
||||
_count = 0;
|
||||
|
||||
if(_waiters > 0)
|
||||
{
|
||||
_cv.notify_all();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace common
|
||||
} // namespace rocprofiler
|
||||
|
||||
Reference in New Issue
Block a user