From b69cbc0caa8eb7bc262515b115a493b59aa010f6 Mon Sep 17 00:00:00 2001 From: Rob Clark Date: Tue, 9 Aug 2022 09:28:57 -0700 Subject: [PATCH] egl: atrace support Perfetto is showing mutex contention on disp->Mutex when multiple threads are making egl calls on their own current context. This makes it easier to see what is contending with what. Signed-off-by: Rob Clark Acked-by: Eric Engestrom Part-of: --- src/egl/main/eglapi.c | 2 ++ src/egl/main/eglcurrent.c | 1 + src/util/log.h | 48 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c index eb3adf19e14..ba40407e55d 100644 --- a/src/egl/main/eglapi.c +++ b/src/egl/main/eglapi.c @@ -95,6 +95,7 @@ #include #include "c11/threads.h" #include "util/debug.h" +#include "util/log.h" #include "util/macros.h" #include "egldefines.h" @@ -282,6 +283,7 @@ _eglSetFuncName(const char *funcName, _EGLDisplay *disp, EGLenum objectType, _EG #define _EGL_FUNC_START(disp, objectType, object, ret) \ do { \ + MESA_TRACE_FUNC(); \ if (!_eglSetFuncName(__func__, disp, objectType, (_EGLResource *) object)) { \ if (disp) \ _eglUnlockDisplay(disp); \ diff --git a/src/egl/main/eglcurrent.c b/src/egl/main/eglcurrent.c index 75267e8a784..17f9ccc43bb 100644 --- a/src/egl/main/eglcurrent.c +++ b/src/egl/main/eglcurrent.c @@ -30,6 +30,7 @@ #include #include #include + #include "c11/threads.h" #include "util/u_thread.h" #include "util/u_string.h" diff --git a/src/util/log.h b/src/util/log.h index d9e965a2bf6..047d196d366 100644 --- a/src/util/log.h +++ b/src/util/log.h @@ -110,4 +110,52 @@ __mesa_log_use_args(UNUSED const char *format, ...) { } } #endif +/* NOTE: for now disable atrace for C++ to workaround a ndk bug with ordering + * between stdatomic.h and atomic.h. See: + * + * https://github.com/android/ndk/issues/1178 + */ +#if defined(ANDROID) && !defined(__cplusplus) + +#include + +#define MESA_TRACE_BEGIN(name) atrace_begin(ATRACE_TAG_GRAPHICS, name) +#define MESA_TRACE_END() atrace_end(ATRACE_TAG_GRAPHICS) + +#else + +/* XXX we would like to use perfetto, but it lacks a C header */ +#define MESA_TRACE_BEGIN(name) +#define MESA_TRACE_END() + +#endif /* ANDROID */ + +#if __has_attribute(cleanup) && __has_attribute(unused) + +#define MESA_TRACE_SCOPE(name) \ + int _mesa_trace_scope_##__LINE__ \ + __attribute__((cleanup(mesa_trace_scope_end), unused)) = \ + mesa_trace_scope_begin(name) + +static inline int +mesa_trace_scope_begin(const char *name) +{ + MESA_TRACE_BEGIN(name); + return 0; +} + +static inline void +mesa_trace_scope_end(int *scope) +{ + MESA_TRACE_END(); +} + +#else + +#define MESA_TRACE_SCOPE(name) + +#endif /* __has_attribute(cleanup) && __has_attribute(unused) */ + +#define MESA_TRACE_FUNC() MESA_TRACE_SCOPE(__func__) + #endif /* MESA_LOG_H */