From 4ec249cc39b6b559ce8dc9273acb77ddb4ee4978 Mon Sep 17 00:00:00 2001 From: Kacper Nowak Date: Fri, 16 Jun 2023 01:28:22 +0000 Subject: [PATCH] fix(ocl): Fix callbacks for nested API calls Prevent from tracing nested API calls (case when similar call is invoked in tracing callback) in OCL. Signed-off-by: Kacper Nowak Related-To: NEO-7958 --- opencl/source/tracing/tracing_notify.h | 34 ++++++++++++++++---------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/opencl/source/tracing/tracing_notify.h b/opencl/source/tracing/tracing_notify.h index d340aaedf9..8a2c0d5f09 100644 --- a/opencl/source/tracing/tracing_notify.h +++ b/opencl/source/tracing/tracing_notify.h @@ -13,7 +13,6 @@ #include #include -#include namespace HostSideTracing { @@ -28,20 +27,29 @@ namespace HostSideTracing { #define TRACING_ZERO_CLIENT_COUNTER(state) ((state) & (HostSideTracing::TRACING_STATE_ENABLED_BIT | HostSideTracing::TRACING_STATE_LOCKED_BIT)) #define TRACING_GET_CLIENT_COUNTER(state) ((state) & (~(HostSideTracing::TRACING_STATE_ENABLED_BIT | HostSideTracing::TRACING_STATE_LOCKED_BIT))) -#define TRACING_ENTER(name, ...) \ - bool isHostSideTracingEnabled_##name = false; \ - HostSideTracing::name##Tracer tracer_##name; \ - if (TRACING_GET_ENABLED_BIT(HostSideTracing::tracingState.load(std::memory_order_acquire))) { \ - isHostSideTracingEnabled_##name = HostSideTracing::addTracingClient(); \ - if (isHostSideTracingEnabled_##name) { \ - tracer_##name.enter(__VA_ARGS__); \ - } \ +inline thread_local bool tracingInProgress = false; + +#define TRACING_ENTER(name, ...) \ + bool isHostSideTracingEnabled_##name = false; \ + bool currentlyTracedCall = false; \ + HostSideTracing::name##Tracer tracer_##name; \ + if ((false == HostSideTracing::tracingInProgress) && TRACING_GET_ENABLED_BIT(HostSideTracing::tracingState.load(std::memory_order_acquire))) { \ + HostSideTracing::tracingInProgress = true; \ + currentlyTracedCall = true; \ + isHostSideTracingEnabled_##name = HostSideTracing::addTracingClient(); \ + if (isHostSideTracingEnabled_##name) { \ + tracer_##name.enter(__VA_ARGS__); \ + } \ } -#define TRACING_EXIT(name, ...) \ - if (isHostSideTracingEnabled_##name) { \ - tracer_##name.exit(__VA_ARGS__); \ - HostSideTracing::removeTracingClient(); \ +#define TRACING_EXIT(name, ...) \ + if (currentlyTracedCall) { \ + if (isHostSideTracingEnabled_##name) { \ + tracer_##name.exit(__VA_ARGS__); \ + HostSideTracing::removeTracingClient(); \ + } \ + HostSideTracing::tracingInProgress = false; \ + currentlyTracedCall = false; \ } typedef enum _tracing_notify_state_t {