trace buffer fix
This commit is contained in:
+17
-14
@@ -88,6 +88,8 @@ THE SOFTWARE.
|
||||
(void)err; \
|
||||
return X;
|
||||
|
||||
#define onload_debug false
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Mark callback
|
||||
//
|
||||
@@ -470,7 +472,8 @@ void hsa_kernel_handler(::proxy::Tracker::entry_t* entry) {
|
||||
}
|
||||
fprintf(kernel_file_handle, "dispatch[%lu], gpu-id(%u), tid(%u), kernel-name(\"%s\"), time(%lu,%lu,%lu,%lu)\n",
|
||||
index,
|
||||
::util::HsaRsrcFactory::Instance().GetAgentInfo(entry->agent)->dev_index,
|
||||
//::util::HsaRsrcFactory::Instance().GetAgentInfo(entry->agent)->dev_index,
|
||||
entry->dev_index,
|
||||
entry->kernel.tid,
|
||||
entry->kernel.name,
|
||||
entry->dispatch,
|
||||
@@ -985,51 +988,51 @@ PUBLIC_API roctracer_status_t roctracer_set_properties(
|
||||
// HSA-runtime tool on-load method
|
||||
PUBLIC_API bool roctracer_load(HsaApiTable* table, uint64_t runtime_version, uint64_t failed_tool_count,
|
||||
const char* const* failed_tool_names) {
|
||||
// printf("LIB roctracer_load\n"); fflush(stdout);
|
||||
if (onload_debug) printf("LIB roctracer_load\n"); fflush(stdout);
|
||||
static bool is_loaded = false;
|
||||
if (is_loaded) return true;
|
||||
is_loaded = true;
|
||||
|
||||
// printf("LIB roctracer_load end\n"); fflush(stdout);
|
||||
if (onload_debug) printf("LIB roctracer_load end\n"); fflush(stdout);
|
||||
return true;
|
||||
}
|
||||
|
||||
PUBLIC_API void roctracer_unload(bool destruct) {
|
||||
// printf("LIB roctracer_unload\n"); fflush(stdout);
|
||||
if (onload_debug) printf("LIB roctracer_unload (%d)\n", (int)destruct); fflush(stdout);
|
||||
static bool is_unloaded = false;
|
||||
if (is_unloaded) return;
|
||||
is_unloaded = true;
|
||||
|
||||
if (destruct == false) roctracer::trace_buffer.Flush();
|
||||
//if (destruct == false) roctracer::trace_buffer.Flush();
|
||||
if ((roctracer::hsa_support::output_prefix != NULL) && (roctracer::kernel_file_handle != NULL)) fclose(roctracer::kernel_file_handle);
|
||||
// printf("LIB roctracer_unload end\n"); fflush(stdout);
|
||||
if (onload_debug) printf("LIB roctracer_unload (%d) end\n", (int)destruct); fflush(stdout);
|
||||
}
|
||||
|
||||
PUBLIC_API bool OnLoad(HsaApiTable* table, uint64_t runtime_version, uint64_t failed_tool_count,
|
||||
const char* const* failed_tool_names) {
|
||||
// printf("LIB OnLoad\n"); fflush(stdout);
|
||||
if (onload_debug) printf("LIB OnLoad\n"); fflush(stdout);
|
||||
const bool ret = roctracer_load(table, runtime_version, failed_tool_count, failed_tool_names);
|
||||
// printf("LIB OnLoad end\n"); fflush(stdout);
|
||||
if (onload_debug) printf("LIB OnLoad end\n"); fflush(stdout);
|
||||
return ret;
|
||||
}
|
||||
PUBLIC_API void OnUnload() {
|
||||
// printf("LIB OnUnload\n"); fflush(stdout);
|
||||
if (onload_debug) printf("LIB OnUnload\n"); fflush(stdout);
|
||||
roctracer_unload(false);
|
||||
// printf("LIB OnUnload end\n"); fflush(stdout);
|
||||
if (onload_debug) printf("LIB OnUnload end\n"); fflush(stdout);
|
||||
}
|
||||
|
||||
CONSTRUCTOR_API void constructor() {
|
||||
// printf("LIB constructor\n"); fflush(stdout);
|
||||
if (onload_debug) printf("LIB constructor\n"); fflush(stdout);
|
||||
roctracer::util::Logger::Create();
|
||||
// printf("LIB constructor end\n"); fflush(stdout);
|
||||
if (onload_debug) printf("LIB constructor end\n"); fflush(stdout);
|
||||
}
|
||||
|
||||
DESTRUCTOR_API void destructor() {
|
||||
// printf("LIB destructor\n"); fflush(stdout);
|
||||
if (onload_debug) printf("LIB destructor\n"); fflush(stdout);
|
||||
roctracer_unload(true);
|
||||
util::HsaRsrcFactory::Destroy();
|
||||
roctracer::util::Logger::Destroy();
|
||||
// printf("LIB destructor end\n"); fflush(stdout);
|
||||
if (onload_debug) printf("LIB destructor end\n"); fflush(stdout);
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
+12
-4
@@ -5,6 +5,7 @@
|
||||
#include <mutex>
|
||||
#include <pthread.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define PTHREAD_CALL(call) \
|
||||
do { \
|
||||
@@ -37,6 +38,7 @@ struct trace_entry_t {
|
||||
uint64_t end; // kernel end timestamp, ns
|
||||
uint64_t complete;
|
||||
hsa_agent_t agent;
|
||||
uint32_t dev_index;
|
||||
hsa_signal_t orig;
|
||||
hsa_signal_t signal;
|
||||
union {
|
||||
@@ -56,6 +58,7 @@ class TraceBuffer {
|
||||
typedef void (*callback_t)(Entry*);
|
||||
typedef TraceBuffer<Entry> Obj;
|
||||
typedef uint64_t pointer_t;
|
||||
typedef std::mutex mutex_t;
|
||||
|
||||
struct flush_prm_t {
|
||||
uint32_t type;
|
||||
@@ -87,17 +90,19 @@ class TraceBuffer {
|
||||
PTHREAD_CALL(pthread_join(work_thread_, &res));
|
||||
if (res != PTHREAD_CANCELED) abort_run("~TraceBuffer: consumer thread wasn't stopped correctly");
|
||||
|
||||
Flush();
|
||||
flush_buf();
|
||||
}
|
||||
|
||||
|
||||
Entry* GetEntry() {
|
||||
const pointer_t pointer = read_pointer_.fetch_add(1);
|
||||
if (pointer >= end_pointer_) wrap_buffer(pointer);
|
||||
return data_ + pointer;
|
||||
if (pointer >= end_pointer_) abort_run("pointer >= end_pointer_ after buffer wrap");
|
||||
return data_ + (pointer + size_ - end_pointer_);
|
||||
}
|
||||
|
||||
void Flush() {
|
||||
std::lock_guard<mutex_t> lck(mutex_);
|
||||
flush_buf();
|
||||
}
|
||||
|
||||
@@ -148,6 +153,7 @@ class TraceBuffer {
|
||||
}
|
||||
|
||||
void wrap_buffer(const pointer_t pointer) {
|
||||
std::lock_guard<mutex_t> lck(mutex_);
|
||||
PTHREAD_CALL(pthread_mutex_lock(&work_mutex_));
|
||||
if (pointer >= end_pointer_) {
|
||||
data_ = next_;
|
||||
@@ -170,8 +176,8 @@ class TraceBuffer {
|
||||
uint32_t size_;
|
||||
Entry* data_;
|
||||
Entry* next_;
|
||||
std::atomic<pointer_t> read_pointer_;
|
||||
pointer_t end_pointer_;
|
||||
volatile std::atomic<pointer_t> read_pointer_;
|
||||
volatile std::atomic<pointer_t> end_pointer_;
|
||||
std::list<Entry*> buf_list_;
|
||||
|
||||
flush_prm_t* flush_prm_arr_;
|
||||
@@ -181,6 +187,8 @@ class TraceBuffer {
|
||||
pthread_t work_thread_;
|
||||
pthread_mutex_t work_mutex_;
|
||||
pthread_cond_t work_cond_;
|
||||
|
||||
mutex_t mutex_;
|
||||
};
|
||||
} // namespace roctracer
|
||||
|
||||
|
||||
Reference in New Issue
Block a user