From 2ebdb61620995a67b110526dfd1e0b6c3d5f6b11 Mon Sep 17 00:00:00 2001 From: Bowgo Tsai Date: Thu, 15 Jul 2021 09:46:53 +0000 Subject: [PATCH] Revert "bionic_systrace: moving global static variables" This reverts commit 1e1c7845aab0542306f61d8e8c880aca096ea336. Reason for revert: makes property get/set non-reentrant Bug: 193050299 Test: build and boot a device Change-Id: If59e3dc25684a3c2b1d3ff74f995311afe6c6e89 Merged-In: If59e3dc25684a3c2b1d3ff74f995311afe6c6e89 (cherry picked from commit 3ec21f527acbaefb5f7a114125bc7a93baa780c7) --- libc/bionic/bionic_systrace.cpp | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/libc/bionic/bionic_systrace.cpp b/libc/bionic/bionic_systrace.cpp index 0de51c50a..06f450514 100644 --- a/libc/bionic/bionic_systrace.cpp +++ b/libc/bionic/bionic_systrace.cpp @@ -31,29 +31,33 @@ #define WRITE_OFFSET 32 static Lock g_lock; +static uint64_t g_tags; +static int g_trace_marker_fd = -1; + +static CachedProperty& GetTagsProp() { + static CachedProperty cached_property(kTraceTagsProp); + return cached_property; +} bool should_trace(const uint64_t enable_tags) { - static uint64_t tags_val; - static CachedProperty tags_prop(kTraceTagsProp); g_lock.lock(); - if (tags_prop.DidChange()) { - tags_val = strtoull(tags_prop.Get(), nullptr, 0); + if (GetTagsProp().DidChange()) { + g_tags = strtoull(GetTagsProp().Get(), nullptr, 0); } g_lock.unlock(); - return tags_val & enable_tags; + return g_tags & enable_tags; } int get_trace_marker_fd() { - static int opened_trace_marker_fd = -1; g_lock.lock(); - if (opened_trace_marker_fd == -1) { - opened_trace_marker_fd = open("/sys/kernel/tracing/trace_marker", O_CLOEXEC | O_WRONLY); - if (opened_trace_marker_fd == -1) { - opened_trace_marker_fd = open("/sys/kernel/debug/tracing/trace_marker", O_CLOEXEC | O_WRONLY); + if (g_trace_marker_fd == -1) { + g_trace_marker_fd = open("/sys/kernel/tracing/trace_marker", O_CLOEXEC | O_WRONLY); + if (g_trace_marker_fd == -1) { + g_trace_marker_fd = open("/sys/kernel/debug/tracing/trace_marker", O_CLOEXEC | O_WRONLY); } } g_lock.unlock(); - return opened_trace_marker_fd; + return g_trace_marker_fd; } // event could be 'B' for begin or 'E' for end.