-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
[release/9.0] [mono][mini] Interlocked.CompareExchange and Interlocked.Exchange intrinsics for small types and enums #106897
Conversation
also add mono_atomic_cas_u8 utility function
maybe we can't actually do a 1 or 2 byte move from RAX ?
fixup u16 win32 atomic
for the 16-bit addressing prefix
…t fail to allocate a table index and generate a warning. This shouldn't happen in prod anyway Implement cmpxchg atomics natively in jiterpreter Remove unnecessary jiterp cas helpers Do cmpxchg result fixups as needed Add runtime option for jiterpreter atomics Implement atomic exchanges in the jiterpreter
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.
approved. please get a code review. once ready we can merge
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.
Interp/jiterp look right.
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.
The arm and llvm changes look good.
@@ -1216,12 +1216,42 @@ typedef union { | |||
|
|||
#define amd64_prefix_size(inst,p,size) do { x86_prefix((inst), p); } while (0) | |||
#define amd64_rdtsc_size(inst,size) do { amd64_codegen_pre(inst); amd64_emit_rex ((inst),(size),0,0,0); x86_rdtsc(inst); amd64_codegen_post(inst); } while (0) | |||
// FIXME: wrong for size == 1 or 2 |
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.
those limitations do not concern current usage scenarios?
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.
Correct. These macros are not currently used for size 1 or 2
PR is green, reviewed and signed off. Ready to merge /cc @carlossanlop |
Backport of #106660 to release/9.0
/cc @lambdageek
Customer Impact
After the BCL started to use the new
Interlocked.Exchange<T>(...)
andInterlocked.CompareExchange<T>(...)
APIs withbool
andenum
types for certain internal lock-free data structures, Mono experienced a severe performance regression across multiple form factors because we did not implement intrinsics for types backed by 8-bit and 16-bit integers. As a result the slower IL fallbacks were used. See #105335Regression
This is a performance regression, not a correctness regression.
Testing
We have test coverage for these cases in the JIT and libraries testsuires.
Risk
Medium.
Additionally on WebAssembly we now always emit the atomic instructions in the jiterpreter. It is possible customers may deploy apps on older browser that do not implement those instructions. (Although all modern browsers support the opcodes even on non-shared memory). As a mitigation the jiterpreter includes a configuration flag to turn off JITing for traces that require the new opcodes.
It is possible that there are correctness criteria that are missed by our testsuites and we may JIT or incorrect code on some architectures. It is unlikely that we will AOT incorrect code as changes to LLVM codegen were minor. Possible customer workarounds in case of a JIT bug would be to produce AOT profiles that force AOT for the affected methods.
Fixes #105335
Fixes #93488