summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorChia-I Wu <olvaffe@gmail.com>2022-08-29 17:25:15 -0700
committerMarge Bot <emma+marge@anholt.net>2022-09-02 19:46:50 +0000
commit4d747d5690bc47acda27bc0e75069fa7f3790857 (patch)
tree28f239ca88ce097de3b6631301a02d307680336f /src/util
parent18d7cb4abbd65b6eb1091d902245271dc49cd8ed (diff)
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>
Diffstat (limited to 'src/util')
-rw-r--r--src/util/perf/u_trace.c11
-rw-r--r--src/util/perf/u_trace.h5
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