diff --git a/ze/btx_zeinterval_callbacks.cpp b/ze/btx_zeinterval_callbacks.cpp index 2bbd7993..29cd6a4b 100644 --- a/ze/btx_zeinterval_callbacks.cpp +++ b/ze/btx_zeinterval_callbacks.cpp @@ -1,4 +1,5 @@ #include "xprof_utils.hpp" +#include #include #include #include @@ -6,7 +7,6 @@ #include #include #include -#include std::string strip_event_class_name(const char *str) { std::string temp(str); @@ -354,7 +354,7 @@ static void eventMemory2ptr_callbacks(void *btx_handle, void *usr_data, auto *data = static_cast(usr_data); const hp_t hp{hostname, vpid}; std::stringstream name; - name << strip_event_class_name(event_class_name) << " (" + name << strip_event_class_name(event_class_name) << "(" << memory_location(data, hp, (uintptr_t)srcptr) << "2" << memory_location(data, hp, (uintptr_t)dstptr) << ")"; std::string metadata = ""; @@ -364,8 +364,8 @@ static void eventMemory2ptr_callbacks(void *btx_handle, void *usr_data, hCommandList, name.str(), metadata, device, ts}; // Should we check Error ? Send with Error? - btx_push_message_lttng_traffic(btx_handle, hostname, vpid, vtid, - ts, BACKEND_ZE, name.str().c_str(), size); + btx_push_message_lttng_traffic(btx_handle, hostname, vpid, vtid, ts, + BACKEND_ZE, name.str().c_str(), size); } static void eventMemory1ptr_callbacks(void *btx_handle, void *usr_data, @@ -388,21 +388,21 @@ static void eventMemory1ptr_callbacks(void *btx_handle, void *usr_data, hCommandList, name.str(), metadata, device, ts}; // Should we check Error ? Send with Error? - btx_push_message_lttng_traffic(btx_handle, hostname, vpid, vtid, - ts, BACKEND_ZE, name.str().c_str(), size); + btx_push_message_lttng_traffic(btx_handle, hostname, vpid, vtid, ts, + BACKEND_ZE, name.str().c_str(), size); } static void memory_but_no_event_callbacks(void *btx_handle, void *usr_data, - int64_t ts, const char *event_class_name, - const char *hostname, int64_t vpid, - uint64_t vtid, - size_t size) { + int64_t ts, + const char *event_class_name, + const char *hostname, int64_t vpid, + uint64_t vtid, size_t size) { - btx_push_message_lttng_traffic(btx_handle, hostname, vpid, vtid, - ts, BACKEND_ZE, strip_event_class_name(event_class_name).c_str(), size); + btx_push_message_lttng_traffic( + btx_handle, hostname, vpid, vtid, ts, BACKEND_ZE, + strip_event_class_name(event_class_name).c_str(), size); } - static void launchCommandEntry_Rest_callbacks( void *btx_handle, void *usr_data, int64_t ts, const char *event_class_name, const char *hostname, int64_t vpid, uint64_t vtid, @@ -495,16 +495,17 @@ static void memFree_exit_callback(void *btx_handle, void *usr_data, int64_t ts, /* * Timestamp Shift - */ + */ static void property_device_timer_callback(void *btx_handle, void *usr_data, - int64_t ts, const char *hostname, - int64_t vpid, uint64_t vtid, - ze_device_handle_t hDevice, - uint64_t hostTimestamp, - uint64_t deviceTimestamp) { - auto *data = static_cast(usr_data); - data->device_timestamps_pair_ref[ {hostname, vpid, (thapi_device_id) hDevice} ] = {ts, deviceTimestamp}; + int64_t ts, const char *hostname, + int64_t vpid, uint64_t vtid, + ze_device_handle_t hDevice, + uint64_t hostTimestamp, + uint64_t deviceTimestamp) { + auto *data = static_cast(usr_data); + data->device_timestamps_pair_ref[{hostname, vpid, (thapi_device_id)hDevice}] = + {ts, deviceTimestamp}; } /* @@ -539,8 +540,8 @@ static void event_profiling_callback(void *btx_handle, void *usr_data, const hp_event_t hpe{hostname, vpid, hEvent}; // Maybe we should check if not present - data->event_payload[hpe] = {vtid, commandName, metadata, - device, lltngMin, clockLttngDevice}; + data->event_payload[hpe] = {vtid, commandName, metadata, device, + lltngMin, clockLttngDevice, false}; } static void event_profiling_result_callback( @@ -557,9 +558,17 @@ static void event_profiling_result_callback( ((status != ZE_RESULT_SUCCESS) || (timestampStatus != ZE_RESULT_SUCCESS)); const auto &[vtid_submision, commandName, metadata, device, lltngMin, - clockLttngDevice] = + clockLttngDevice, to_ignore] = data->event_payload[{hostname, vpid, hEvent}]; + // The duration of an event created from an event pool that was created using + // ZE_EVENT_POOL_FLAG_KERNEL_TIMESTAMP or + // ZE_EVENT_POOL_FLAG_KERNEL_MAPPED_TIMESTAMP flags is undefined. + // However, for consistency and orthogonality the event will report correctly + // as signaled when used by other event API functionality. + if (to_ignore) + return; + // No device information. No convertion to ns, to looping uint64_t delta = globalEnd - globalStart; uint64_t start = lltngMin; @@ -588,45 +597,89 @@ static void event_profiling_result_callback( metadata.c_str()); } -/* - * Sampling +static void zeEventDestroy_entry_callback(void *btx_handle, void *usr_data, + int64_t ts, const char *hostname, + int64_t vpid, uint64_t vtid, + ze_event_handle_t hEvent) { + + auto *data = static_cast(usr_data); + push_entry(data, {hostname, vpid, vtid}, hEvent); +} + +static void zeEventDestroy_exit_callback(void *btx_handle, void *usr_data, + int64_t ts, const char *hostname, + int64_t vpid, uint64_t vtid, + ze_result_t zeResult) { + + if (zeResult != ZE_RESULT_SUCCESS) + return; + + auto *data = static_cast(usr_data); + auto hEvent = pop_entry(data, {hostname, vpid, vtid}); + data->event_payload.erase({hostname, vpid, hEvent}); +} + +static void zeToIgnore_entry_callback(void *btx_handle, void *usr_data, + int64_t ts, const char *event_class_name, + const char *hostname, int64_t vpid, + uint64_t vtid, ze_event_handle_t hEvent) { + + auto *data = static_cast(usr_data); + push_entry(data, {hostname, vpid, vtid}, hEvent); +} + +static void zeToIgnore_exit_callback(void *btx_handle, void *usr_data, + int64_t ts, const char *event_class_name, + const char *hostname, int64_t vpid, + uint64_t vtid, ze_result_t zeResult) { + + if (zeResult != ZE_RESULT_SUCCESS) + return; + + auto *data = static_cast(usr_data); + auto hEvent = pop_entry(data, {hostname, vpid, vtid}); + auto &payload = data->event_payload[{hostname, vpid, hEvent}]; + std::get(payload) = true; +} + +/* + * Sampling */ -static void -lttng_ust_ze_sampling_gpu_energy_callback(void *btx_handle, void *usr_data, int64_t ts, const char *hostname, - int64_t vpid, uint64_t vtid, - ze_device_handle_t hDevice, uint32_t domain, uint64_t energy, uint64_t sampling_ts) { +static void lttng_ust_ze_sampling_gpu_energy_callback( + void *btx_handle, void *usr_data, int64_t ts, const char *hostname, + int64_t vpid, uint64_t vtid, ze_device_handle_t hDevice, uint32_t domain, + uint64_t energy, uint64_t sampling_ts) { - btx_push_message_lttng_power(btx_handle, hostname, 0, 0, - ts, BACKEND_ZE, (uint64_t) hDevice, domain, energy); + btx_push_message_lttng_power(btx_handle, hostname, 0, 0, ts, BACKEND_ZE, + (uint64_t)hDevice, domain, energy); } -static void -lttng_ust_ze_sampling_gpu_frequency_callback(void *btx_handle, void *usr_data, int64_t ts, const char *hostname, - int64_t vpid, uint64_t vtid, - ze_device_handle_t hDevice, uint32_t domain, uint64_t frequency) { +static void lttng_ust_ze_sampling_gpu_frequency_callback( + void *btx_handle, void *usr_data, int64_t ts, const char *hostname, + int64_t vpid, uint64_t vtid, ze_device_handle_t hDevice, uint32_t domain, + uint64_t frequency) { - btx_push_message_lttng_frequency(btx_handle, hostname, 0, 0, - ts, BACKEND_ZE, (uint64_t) hDevice, domain, frequency); + btx_push_message_lttng_frequency(btx_handle, hostname, 0, 0, ts, BACKEND_ZE, + (uint64_t)hDevice, domain, frequency); } -static void -lttng_ust_ze_sampling_computeEngine_callback(void *btx_handle, void *usr_data, int64_t ts, const char *hostname, - int64_t vpid, uint64_t vtid, - ze_device_handle_t hDevice, uint32_t subDevice, +static void lttng_ust_ze_sampling_computeEngine_callback( + void *btx_handle, void *usr_data, int64_t ts, const char *hostname, + int64_t vpid, uint64_t vtid, ze_device_handle_t hDevice, uint32_t subDevice, uint64_t activeTime, uint64_t sampling_ts) { - btx_push_message_lttng_computeEU(btx_handle, hostname, 0, 0, - ts, BACKEND_ZE, (uint64_t) hDevice, subDevice, activeTime); + btx_push_message_lttng_computeEU(btx_handle, hostname, 0, 0, ts, BACKEND_ZE, + (uint64_t)hDevice, subDevice, activeTime); } -static void -lttng_ust_ze_sampling_copyEngine_callback(void *btx_handle, void *usr_data, int64_t ts, const char *hostname, - int64_t vpid, uint64_t vtid, - ze_device_handle_t hDevice, uint32_t subDevice, uint64_t activeTime, uint64_t sampling_ts) { +static void lttng_ust_ze_sampling_copyEngine_callback( + void *btx_handle, void *usr_data, int64_t ts, const char *hostname, + int64_t vpid, uint64_t vtid, ze_device_handle_t hDevice, uint32_t subDevice, + uint64_t activeTime, uint64_t sampling_ts) { - btx_push_message_lttng_copyEU(btx_handle, hostname, 0, 0, - ts, BACKEND_ZE, (uint64_t) hDevice, subDevice, activeTime); + btx_push_message_lttng_copyEU(btx_handle, hostname, 0, 0, ts, BACKEND_ZE, + (uint64_t)hDevice, subDevice, activeTime); } /* @@ -670,8 +723,8 @@ void btx_register_usr_callbacks(void *btx_handle) { btx_handle, &property_kernel_callback); /* Drift */ - btx_register_callbacks_lttng_ust_ze_properties_device_timer(btx_handle, - &property_device_timer_callback); + btx_register_callbacks_lttng_ust_ze_properties_device_timer( + btx_handle, &property_device_timer_callback); /* Profiling Command (everything who signal an event on completion) */ btx_register_callbacks_launchKernelEntry_group_present( @@ -684,9 +737,9 @@ void btx_register_usr_callbacks(void *btx_handle) { &eventMemory1ptr_callbacks); btx_register_callbacks_launchCommandEntry_Rest( btx_handle, &launchCommandEntry_Rest_callbacks); - - btx_register_callbacks_memory_but_no_event( - btx_handle, &memory_but_no_event_callbacks); + + btx_register_callbacks_memory_but_no_event(btx_handle, + &memory_but_no_event_callbacks); /* Remove Memory */ btx_register_callbacks_memFree_entry(btx_handle, &memFree_entry_callback); @@ -702,14 +755,22 @@ void btx_register_usr_callbacks(void *btx_handle) { btx_register_callbacks_lttng_ust_ze_profiling_event_profiling_results( btx_handle, &event_profiling_result_callback); + btx_register_callbacks_lttng_ust_ze_zeEventDestroy_entry( + btx_handle, &zeEventDestroy_entry_callback); + btx_register_callbacks_lttng_ust_ze_zeEventDestroy_exit( + btx_handle, &zeEventDestroy_exit_callback); + + btx_register_callbacks_zeToIgnore_entry(btx_handle, + &zeToIgnore_entry_callback); + btx_register_callbacks_zeToIgnore_exit(btx_handle, &zeToIgnore_exit_callback); + /* Sampling */ btx_register_callbacks_lttng_ust_ze_sampling_gpu_energy( - btx_handle, <tng_ust_ze_sampling_gpu_energy_callback); + btx_handle, <tng_ust_ze_sampling_gpu_energy_callback); btx_register_callbacks_lttng_ust_ze_sampling_gpu_frequency( - btx_handle, <tng_ust_ze_sampling_gpu_frequency_callback); + btx_handle, <tng_ust_ze_sampling_gpu_frequency_callback); btx_register_callbacks_lttng_ust_ze_sampling_computeEngine( - btx_handle, <tng_ust_ze_sampling_computeEngine_callback); + btx_handle, <tng_ust_ze_sampling_computeEngine_callback); btx_register_callbacks_lttng_ust_ze_sampling_copyEngine( - btx_handle, <tng_ust_ze_sampling_copyEngine_callback); - + btx_handle, <tng_ust_ze_sampling_copyEngine_callback); } diff --git a/ze/btx_zeinterval_callbacks.hpp b/ze/btx_zeinterval_callbacks.hpp index 4824606c..ee24fda2 100644 --- a/ze/btx_zeinterval_callbacks.hpp +++ b/ze/btx_zeinterval_callbacks.hpp @@ -16,6 +16,7 @@ typedef std::tuple hp_module_t; typedef std::map memory_interval_t; typedef std::tuple clock_lttng_device_t; +typedef bool to_ignore_t; struct data_s { /* Host */ @@ -49,7 +50,8 @@ struct data_s { device_timestamps_pair_ref; std::unordered_map< hp_event_t, std::tuple> + thapi_device_id, uint64_t, clock_lttng_device_t, + to_ignore_t>> event_payload; }; typedef struct data_s data_t; diff --git a/ze/btx_zematching_model.yaml b/ze/btx_zematching_model.yaml index 1ea5d880..22d139b1 100644 --- a/ze/btx_zematching_model.yaml +++ b/ze/btx_zematching_model.yaml @@ -134,6 +134,21 @@ - :name: ^hCommandList$ :field_class: :cast_type: ze_command_list_handle_t +# To ignore. Either mean nothing or instaneous + - :set_id: zeToIgnore_entry + :name: "zeCommandListAppendSignalEvent|zeEventHostSignal" + :domain: entries + :payload_field_class: + :type: structure + :members: + - :name: ^hEvent$ + - :set_id: zeToIgnore_exit + :name: "zeCommandListAppendSignalEvent|zeEventHostSignal" + :domain: exits + :payload_field_class: + :type: structure + :members: + - :name: ^zeResult$ #Free memory - :set_id: memFree_entry :domain: entries