From 10187d2372d3cf26bf0d886a4a88e536d8fd13d2 Mon Sep 17 00:00:00 2001 From: Olivier Nicole Date: Thu, 2 Mar 2023 14:22:59 +0100 Subject: [PATCH] Disable some TSan instrumentation for performance The functions that we un-instrumentation are called often but should not contain data races with user code. Co-authored-by: Fabrice Buoro --- runtime/caml/mlvalues.h | 7 +++++-- runtime/interp.c | 2 ++ runtime/minor_gc.c | 2 ++ runtime/shared_heap.c | 1 + runtime/str.c | 1 + 5 files changed, 11 insertions(+), 2 deletions(-) diff --git a/runtime/caml/mlvalues.h b/runtime/caml/mlvalues.h index 8332d1fe7f..448232680f 100644 --- a/runtime/caml/mlvalues.h +++ b/runtime/caml/mlvalues.h @@ -193,8 +193,11 @@ where 0 <= R <= 31 is HEADER_RESERVED_BITS, set with the #endif #define Hp_atomic_val(val) ((atomic_uintnat *)(val) - 1) -#define Hd_val(val) ((header_t) \ - (atomic_load_explicit(Hp_atomic_val(val), memory_order_relaxed))) +CAMLno_user_tsan /* Disable TSan instrumentation for performance. */ +Caml_inline header_t Hd_val(value val) +{ + return atomic_load_explicit(Hp_atomic_val(val), memory_order_relaxed); +} #define Color_val(val) (Color_hd (Hd_val (val))) diff --git a/runtime/interp.c b/runtime/interp.c index d206d87822..5f47101d3c 100644 --- a/runtime/interp.c +++ b/runtime/interp.c @@ -244,6 +244,8 @@ static value raise_unhandled_effect; /* The interpreter itself */ +CAMLno_user_tsan /* No need to TSan-instrument this (and pay a slowdown) + function as TSan is not supported for bytecode. */ value caml_interprete(code_t prog, asize_t prog_size) { #ifdef PC_REG diff --git a/runtime/minor_gc.c b/runtime/minor_gc.c index d063f9f518..8bfe6dd70e 100644 --- a/runtime/minor_gc.c +++ b/runtime/minor_gc.c @@ -171,6 +171,7 @@ static void spin_on_header(value v) { } } +CAMLno_user_tsan /* Disable TSan instrumentation for performance. */ Caml_inline header_t get_header_val(value v) { header_t hd = atomic_load_explicit(Hp_atomic_val(v), memory_order_acquire); if (!Is_update_in_progress(hd)) @@ -381,6 +382,7 @@ static void oldify_one (void* st_v, value v, volatile value *p) Note that [oldify_one] itself is called by oldify_mopup, so we have to be careful to remove the first entry from the list before oldifying its fields. */ +CAMLno_user_tsan /* Disable TSan instrumentation for performance. */ static void oldify_mopup (struct oldify_state* st, int do_ephemerons) { value v, new_v, f; diff --git a/runtime/shared_heap.c b/runtime/shared_heap.c index 5e6568dc55..b7ae0b66d3 100644 --- a/runtime/shared_heap.c +++ b/runtime/shared_heap.c @@ -256,6 +256,7 @@ Caml_inline void pool_initialize(pool* r, } /* Allocating an object from a pool */ +CAMLno_user_tsan /* Disable TSan instrumentation for performance. */ static intnat pool_sweep(struct caml_heap_state* local, pool**, sizeclass sz , diff --git a/runtime/str.c b/runtime/str.c index 32ca54c7a5..fc9cee585e 100644 --- a/runtime/str.c +++ b/runtime/str.c @@ -268,6 +268,7 @@ CAMLprim value caml_bytes_set64(value str, value index, value newval) return Val_unit; } +CAMLno_user_tsan /* Disable TSan instrumentation for performance. */ CAMLprim value caml_string_equal(value s1, value s2) { mlsize_t sz1, sz2;