Skip to content

Commit 537eafb

Browse files
committed
Change all the atomic operations to _relaxed
1 parent 619dec8 commit 537eafb

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

src/aotcompile.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ void *jl_create_native(jl_array_t *methods, const jl_cgparams_t cgparams, int _p
286286
JL_GC_PUSH1(&src);
287287
JL_LOCK(&codegen_lock);
288288
uint64_t compiler_start_time = 0;
289-
uint8_t measure_compile_time_enabled = jl_atomic_load(&jl_measure_compile_time_enabled);
289+
uint8_t measure_compile_time_enabled = jl_atomic_load_relaxed(&jl_measure_compile_time_enabled);
290290
if (measure_compile_time_enabled)
291291
compiler_start_time = jl_hrtime();
292292

@@ -416,7 +416,7 @@ void *jl_create_native(jl_array_t *methods, const jl_cgparams_t cgparams, int _p
416416

417417
data->M = std::move(clone);
418418
if (measure_compile_time_enabled)
419-
jl_atomic_fetch_add(&jl_cumulative_compile_time, (jl_hrtime() - compiler_start_time));
419+
jl_atomic_fetch_add_relaxed(&jl_cumulative_compile_time, (jl_hrtime() - compiler_start_time));
420420
if (policy == CompilationPolicy::ImagingMode)
421421
imaging_mode = 0;
422422
JL_UNLOCK(&codegen_lock); // Might GC
@@ -916,7 +916,7 @@ void *jl_get_llvmf_defn(jl_method_instance_t *mi, size_t world, char getwrapper,
916916
jl_llvm_functions_t decls;
917917
JL_LOCK(&codegen_lock);
918918
uint64_t compiler_start_time = 0;
919-
uint8_t measure_compile_time_enabled = jl_atomic_load(&jl_measure_compile_time_enabled);
919+
uint8_t measure_compile_time_enabled = jl_atomic_load_relaxed(&jl_measure_compile_time_enabled);
920920
if (measure_compile_time_enabled)
921921
compiler_start_time = jl_hrtime();
922922
std::tie(m, decls) = jl_emit_code(mi, src, jlrettype, output);
@@ -943,7 +943,7 @@ void *jl_get_llvmf_defn(jl_method_instance_t *mi, size_t world, char getwrapper,
943943
}
944944
JL_GC_POP();
945945
if (measure_compile_time_enabled)
946-
jl_atomic_fetch_add(&jl_cumulative_compile_time, (jl_hrtime() - compiler_start_time));
946+
jl_atomic_fetch_add_relaxed(&jl_cumulative_compile_time, (jl_hrtime() - compiler_start_time));
947947
JL_UNLOCK(&codegen_lock); // Might GC
948948
if (F)
949949
return F;

src/gf.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3165,7 +3165,7 @@ static uint8_t inference_is_measuring_compile_time = 0;
31653165
JL_DLLEXPORT void jl_typeinf_begin(void)
31663166
{
31673167
JL_LOCK(&typeinf_lock);
3168-
if (jl_atomic_load(&jl_measure_compile_time_enabled)) {
3168+
if (jl_atomic_load_relaxed(&jl_measure_compile_time_enabled)) {
31693169
inference_start_time = jl_hrtime();
31703170
inference_is_measuring_compile_time = 1;
31713171
}
@@ -3174,7 +3174,7 @@ JL_DLLEXPORT void jl_typeinf_begin(void)
31743174
JL_DLLEXPORT void jl_typeinf_end(void)
31753175
{
31763176
if (typeinf_lock.count == 1 && inference_is_measuring_compile_time) {
3177-
jl_atomic_fetch_add(&jl_cumulative_compile_time, (jl_hrtime() - inference_start_time));
3177+
jl_atomic_fetch_add_relaxed(&jl_cumulative_compile_time, (jl_hrtime() - inference_start_time));
31783178
inference_is_measuring_compile_time = 0;
31793179
}
31803180
JL_UNLOCK(&typeinf_lock);

src/jitlayers.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ uint64_t jl_cumulative_compile_time_ns_before()
8080
{
8181
// Increment the flag to allow reentrant callers to `@time`.
8282
jl_atomic_fetch_add(&jl_measure_compile_time_enabled, 1);
83-
return jl_atomic_load(&jl_cumulative_compile_time);
83+
return jl_atomic_load_relaxed(&jl_cumulative_compile_time);
8484
}
8585
extern "C" JL_DLLEXPORT
8686
uint64_t jl_cumulative_compile_time_ns_after()
8787
{
8888
// Decrement the flag when done measuring, allowing other callers to continue measuring.
8989
jl_atomic_fetch_add(&jl_measure_compile_time_enabled, -1);
90-
return jl_atomic_load(&jl_cumulative_compile_time);
90+
return jl_atomic_load_relaxed(&jl_cumulative_compile_time);
9191
}
9292

9393
// this generates llvm code for the lambda info
@@ -233,7 +233,7 @@ int jl_compile_extern_c(void *llvmmod, void *p, void *sysimg, jl_value_t *declrt
233233
{
234234
JL_LOCK(&codegen_lock);
235235
uint64_t compiler_start_time = 0;
236-
uint8_t measure_compile_time_enabled = jl_atomic_load(&jl_measure_compile_time_enabled);
236+
uint8_t measure_compile_time_enabled = jl_atomic_load_relaxed(&jl_measure_compile_time_enabled);
237237
if (measure_compile_time_enabled)
238238
compiler_start_time = jl_hrtime();
239239
jl_codegen_params_t params;
@@ -259,7 +259,7 @@ int jl_compile_extern_c(void *llvmmod, void *p, void *sysimg, jl_value_t *declrt
259259
jl_add_to_ee(std::unique_ptr<Module>(into));
260260
}
261261
if (codegen_lock.count == 1 && measure_compile_time_enabled)
262-
jl_atomic_fetch_add(&jl_cumulative_compile_time, (jl_hrtime() - compiler_start_time));
262+
jl_atomic_fetch_add_relaxed(&jl_cumulative_compile_time, (jl_hrtime() - compiler_start_time));
263263
JL_UNLOCK(&codegen_lock);
264264
return success;
265265
}
@@ -315,7 +315,7 @@ jl_code_instance_t *jl_generate_fptr(jl_method_instance_t *mi JL_PROPAGATES_ROOT
315315
{
316316
JL_LOCK(&codegen_lock); // also disables finalizers, to prevent any unexpected recursion
317317
uint64_t compiler_start_time = 0;
318-
uint8_t measure_compile_time_enabled = jl_atomic_load(&jl_measure_compile_time_enabled);
318+
uint8_t measure_compile_time_enabled = jl_atomic_load_relaxed(&jl_measure_compile_time_enabled);
319319
if (measure_compile_time_enabled)
320320
compiler_start_time = jl_hrtime();
321321
// if we don't have any decls already, try to generate it now
@@ -355,7 +355,7 @@ jl_code_instance_t *jl_generate_fptr(jl_method_instance_t *mi JL_PROPAGATES_ROOT
355355
codeinst = NULL;
356356
}
357357
if (codegen_lock.count == 1 && measure_compile_time_enabled)
358-
jl_atomic_fetch_add(&jl_cumulative_compile_time, (jl_hrtime() - compiler_start_time));
358+
jl_atomic_fetch_add_relaxed(&jl_cumulative_compile_time, (jl_hrtime() - compiler_start_time));
359359
JL_UNLOCK(&codegen_lock);
360360
JL_GC_POP();
361361
return codeinst;
@@ -369,7 +369,7 @@ void jl_generate_fptr_for_unspecialized(jl_code_instance_t *unspec)
369369
}
370370
JL_LOCK(&codegen_lock);
371371
uint64_t compiler_start_time = 0;
372-
uint8_t measure_compile_time_enabled = jl_atomic_load(&jl_measure_compile_time_enabled);
372+
uint8_t measure_compile_time_enabled = jl_atomic_load_relaxed(&jl_measure_compile_time_enabled);
373373
if (measure_compile_time_enabled)
374374
compiler_start_time = jl_hrtime();
375375
if (unspec->invoke == NULL) {
@@ -399,7 +399,7 @@ void jl_generate_fptr_for_unspecialized(jl_code_instance_t *unspec)
399399
JL_GC_POP();
400400
}
401401
if (codegen_lock.count == 1 && measure_compile_time_enabled)
402-
jl_atomic_fetch_add(&jl_cumulative_compile_time, (jl_hrtime() - compiler_start_time));
402+
jl_atomic_fetch_add_relaxed(&jl_cumulative_compile_time, (jl_hrtime() - compiler_start_time));
403403
JL_UNLOCK(&codegen_lock); // Might GC
404404
}
405405

@@ -422,7 +422,7 @@ jl_value_t *jl_dump_method_asm(jl_method_instance_t *mi, size_t world,
422422
// so create an exception here so we can print pretty our lies
423423
JL_LOCK(&codegen_lock); // also disables finalizers, to prevent any unexpected recursion
424424
uint64_t compiler_start_time = 0;
425-
uint8_t measure_compile_time_enabled = jl_atomic_load(&jl_measure_compile_time_enabled);
425+
uint8_t measure_compile_time_enabled = jl_atomic_load_relaxed(&jl_measure_compile_time_enabled);
426426
if (measure_compile_time_enabled)
427427
compiler_start_time = jl_hrtime();
428428
specfptr = (uintptr_t)codeinst->specptr.fptr;
@@ -449,7 +449,7 @@ jl_value_t *jl_dump_method_asm(jl_method_instance_t *mi, size_t world,
449449
JL_GC_POP();
450450
}
451451
if (measure_compile_time_enabled)
452-
jl_atomic_fetch_add(&jl_cumulative_compile_time, (jl_hrtime() - compiler_start_time));
452+
jl_atomic_fetch_add_relaxed(&jl_cumulative_compile_time, (jl_hrtime() - compiler_start_time));
453453
JL_UNLOCK(&codegen_lock);
454454
}
455455
if (specfptr != 0)

src/task.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ static void JL_NORETURN throw_internal(jl_task_t *ct, jl_value_t *exception JL_M
564564
// We blindly disable compilation time tracking here, for all running Tasks, even though
565565
// it may cause some incorrect measurements. This is a known bug, and is being tracked
566566
// here: https://github.com/JuliaLang/julia/pull/39138
567-
jl_atomic_store_release(&jl_measure_compile_time_enabled, 0);
567+
jl_atomic_store_relaxed(&jl_measure_compile_time_enabled, 0);
568568
JL_GC_PUSH1(&exception);
569569
jl_gc_unsafe_enter(ptls);
570570
if (exception) {

0 commit comments

Comments
 (0)