-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Atomically order specsigflags, specptr, and invoke #47832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
0aba553 to
3d37f33
Compare
3d37f33 to
51fe491
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (reviewed in-person)
Should we also make this a little more accurate (requiring forward progress of each iteration):
diff --git a/src/gf.c b/src/gf.c
index df50b42216..b8223efb7c 100644
--- a/src/gf.c
+++ b/src/gf.c
@@ -2199,10 +2199,11 @@ jl_value_t *jl_fptr_const_return(jl_value_t *f, jl_value_t **args, uint32_t narg
jl_value_t *jl_fptr_args(jl_value_t *f, jl_value_t **args, uint32_t nargs, jl_code_instance_t *m)
{
+ jl_fptr_args_t invoke = jl_atomic_load_relaxed(&m->specptr.fptr1);
while (1) {
- jl_fptr_args_t invoke = jl_atomic_load_relaxed(&m->specptr.fptr1);
if (invoke)
return invoke(f, args, nargs);
+ invoke = jl_atomic_load_acquire(&m->specptr.fptr1);
}
}|
@maleadt does GPUCompiler use any of codeinst->( |
No, we never use what's been compiled by the JIT, but use aotcompile directly. |
|
bump? Looks like this needs a rebase |
670bf11 to
d6b7fd6
Compare
9ccd54c to
41fb231
Compare
Co-authored-by: Jameson Nash <[email protected]> Co-authored-by: Dilum Aluthge <[email protected]> (cherry picked from commit 6412a56)
Co-authored-by: Jameson Nash <[email protected]> Co-authored-by: Dilum Aluthge <[email protected]> (cherry picked from commit 6412a56)
Co-authored-by: Jameson Nash <[email protected]> Co-authored-by: Dilum Aluthge <[email protected]> (cherry picked from commit 6412a56)
Co-authored-by: Jameson Nash <[email protected]> Co-authored-by: Dilum Aluthge <[email protected]> (cherry picked from commit 6412a56)
These atomics depend on the following rules:
On the write side:
On the read side:
The reasoning behind this set of changes is that we want to support multiple threads setting specptr/invokeptr/specsig to potentially different values, and we don't want to end up in a situation where the codeinst transitions from being valid to be called to invalid to be called. This motivates the once-set restrictions. However, we also want to support potential future upgrading of invokeptr/specptr (e.g. to transition from interpreted to compiled, or compiled at low optimization to compiled at high optimization), which motivates being able to override specptr and invokeptr as long as those values are equivalently callable.
Invokeptr must be reloaded after checking for 0b10 in specsigflags due to the case of the original load returning an invokeptr that does not rely on specptr (for interpretation), but then another thread sets specptr. In this case, we want to grab the updated invokeptr which we know is definitely written after specsigflags & 0b10 is set.