Skip to content

Commit

Permalink
Disable some TSan instrumentation for performance
Browse files Browse the repository at this point in the history
The functions that we un-instrumentation are called often but should not
contain data races with user code.

Co-authored-by: Fabrice Buoro <[email protected]>
  • Loading branch information
OlivierNicole and fabbing committed Mar 3, 2023
1 parent 506aa62 commit 10187d2
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions runtime/caml/mlvalues.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)))

Expand Down
2 changes: 2 additions & 0 deletions runtime/interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions runtime/minor_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions runtime/shared_heap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ,
Expand Down
1 change: 1 addition & 0 deletions runtime/str.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 10187d2

Please sign in to comment.