Skip to content
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

Implement Atomics Behavior #23

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft

Implement Atomics Behavior #23

wants to merge 7 commits into from

Conversation

TYKUHN2
Copy link

@TYKUHN2 TYKUHN2 commented Dec 27, 2024

Implemented full atomics behavior (minus RL/AC) for potential future multicore support.

Zalrsc was implemented by emulating bus snooping with a notify function. When multicore is implemented, the notify mechanism will have to be improved.

Zaamo was implemented using Java features including VarHandle and Unsafe. Unsafe only has support for word and double word. Some devices were omitted (throws MemoryAccessException) due to being out of scope. VirtIO is currently omitted because I am unfamiliar and am not sure if implementing it makes sense.

Direct test for ByteBufferMemory atomic support added with aggressive data racing to verify functionality. No new tests specific to the Zaamo instructions added. I have made tests for Zalrsc that verify they work, but I have not committed them. Existing Zalrsc tests fail, but when recompiled from source they succeed.

Zawrs and Zacas were never defined within the emulator so I haven't implemented them.

FENCE, FENCE.I and RL/AC flags for A instructions are not implemented (NOPs) because, realistically, the emulator's overhead will prevent the spatial/temporal locality that necessitates such features.

Tasks:

  • Implement Zalrsc
  • Implement Zaamo
  • Add test for Zalrsc
  • Add test for Zaamo
  • Add support for main memory atomic operations
  • Add device support for atomic operations (if desired)
  • Implement Zawrs (if desired)
  • Implement Zacas (if desired)
  • Review code style, comments, etc.

Properly implemented Zalrsc pending testing.
RL/AC flags are still missing, I'll have to read how to implement them.
The notify is before the store, which could cause spurious failures if the store fails, but spec permits that :)
Fixed notify not triggering if TLB is missed due to split TLB.
Required adding new method to MemoryMappedDevice interface, but denying Zaamo with MemoryAccessViolation is acceptable.
Devices where Compare and Set is possible (and easy) to implement have gotten implementations.
Implemented a new test case for ByteBufferMemory to test storeCAS reference implementation (used elsewhere) works.
After reconsideration, emulation code is *very* unlikely to be short enough for the host to reorder emulated operations.
Theoretically, it could be reordered, but emulation framework will likely more than fully occupy and reordering system.
For the same reason, FENCE (FENCE.I is different) can remain NO-OP.
Turns out the byteBufferViewVarHandle does not support direct byte buffers.
Replaced with an Unsafe call for slightly reduced (but should still be sufficient) functionality.
Only Word and DoubleWord instructions exist so the RISC-V code shouldn't see a difference.
Fixed alignment testing errors in Zalrsc
Fixed incorrect implementation for AMOSWAP.W
Fixed missing sign extension for LR.W
Fixed bounds check for storeCAS and notify.
Added quick return in notify if nothing is in reservation set (mostly for debugging reasons.)
Fixed storex using virtual address notification using a notify in both storex and storeSlow.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant