Module: Mesa
Branch: main
Commit: 4d747d5690bc47acda27bc0e75069fa7f3790857
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=4d747d5690bc47acda27bc0e75069fa7f3790857

Author: Chia-I Wu <[email protected]>
Date:   Mon Aug 29 17:25:15 2022 -0700

util/perf: simplify u_trace_instrument

When ut_perfetto_enabled changes, update _u_trace_instrument as well.
This allows u_trace_instrument to check just a single variable.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18309>

---

 src/util/perf/u_trace.c | 11 +++++++----
 src/util/perf/u_trace.h |  5 +++--
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/util/perf/u_trace.c b/src/util/perf/u_trace.c
index 2bd80d98e95..4e565314fd9 100644
--- a/src/util/perf/u_trace.c
+++ b/src/util/perf/u_trace.c
@@ -38,7 +38,7 @@
 #define TIMESTAMP_BUF_SIZE 0x1000
 #define TRACES_PER_CHUNK   (TIMESTAMP_BUF_SIZE / sizeof(uint64_t))
 
-bool _u_trace_instrument;
+int _u_trace_instrument;
 
 #ifdef HAVE_PERFETTO
 int ut_perfetto_enabled;
@@ -369,7 +369,8 @@ get_tracefile(void)
          tracefile = stdout;
       }
 
-      _u_trace_instrument = tracefile || debug_get_option_trace_instrument();
+      if (tracefile || debug_get_option_trace_instrument())
+         p_atomic_inc(&_u_trace_instrument);
 
       firsttime = false;
    }
@@ -465,14 +466,16 @@ u_trace_perfetto_start(void)
 {
    list_for_each_entry (struct u_trace_context, utctx, &ctx_list, node)
       queue_init(utctx);
-   ut_perfetto_enabled++;
+   if (p_atomic_inc_return(&ut_perfetto_enabled) == 1)
+      p_atomic_inc(&_u_trace_instrument);
 }
 
 void
 u_trace_perfetto_stop(void)
 {
    assert(ut_perfetto_enabled > 0);
-   ut_perfetto_enabled--;
+   if (p_atomic_dec_return(&ut_perfetto_enabled) == 0)
+      p_atomic_dec(&_u_trace_instrument);
 }
 #endif
 
diff --git a/src/util/perf/u_trace.h b/src/util/perf/u_trace.h
index fcee7499891..9d3acfc8745 100644
--- a/src/util/perf/u_trace.h
+++ b/src/util/perf/u_trace.h
@@ -28,6 +28,7 @@
 #include <stdint.h>
 #include <stdio.h>
 
+#include "util/u_atomic.h"
 #include "util/u_queue.h"
 
 #ifdef __cplusplus
@@ -286,8 +287,8 @@ void u_trace_perfetto_stop(void);
 static inline bool
 u_trace_instrument(void)
 {
-   extern bool _u_trace_instrument;
-   return _u_trace_instrument || ut_perfetto_enabled;
+   extern int _u_trace_instrument;
+   return p_atomic_read_relaxed(&_u_trace_instrument);
 }
 
 static inline bool

Reply via email to