[go: up one dir, main page]

RISC-V: New state allocation and initialisation mechanism

Part of RV-568

Stacked MRs

What

Introduce a new allocation and initialisation mechanism. Switch to this new mechanism in the test and PVM stepper in addition to the "NodePVM" state machine.

The remainder of the code base is migrated in RISC-V: Prefer `new` over `allocate` with `bind` (!17569 - merged).

Why

Previously, to obtain a state you needed to allocate using a layout L and a manager M first. That gave you an AllocatedOf<L, M>. Using the bind method of a state you could then instantiate the state.

image.png

While that works, it comes with a few downsides:

  • You almost never allocate without bind (two calls where one would suffice)
  • An intermediate structure (AllocatedOf) is necessary
  • Initialisation is hard
    • Your only way is ConstDefault
    • If the value isn't truely static, you need to perform quite a bit of magic to squeeze the "dynamic" initial value through the type level
    • It is not possible to have two regions of the same type to be initialised in different ways with only one Layout (everything is the same but the initial value)

RISC-V: Initialise Buddy branch correctly (!17570 - merged) is an example of how correct initialisation becomes much easier with this change.

How

We can address these problems by introducing a new method (of trait NewState). This function performs allocation and initialisation in one, but does so within the state data type instead of an intermediary structure. The introduction of such function makes the allocate method of Layout obsolete (to be removed in RISC-V: Abolish `allocate` on `Layouts` (!17566 - merged)). Finally, initialisation now happens entirely through a term-level mechanism, no more extranous types needed.

image.png

Manually Testing

make -C src/riscv all

Benchmarking

This achieves a small runtime performance boost on the reference machine.

master This MR Improvement
M3 MBP 5.640 TPS 5.762 TPS +2.16%
Benchmark Machine 3.803 TPS 3.931 TPS +3.37%

Tasks for the Author

  • Link all Linear issues related to this MR using magic words (e.g. part of, relates to, closes).
  • Eliminate dead code and other spurious artefacts introduced in your changes.
  • Document new public functions, methods and types.
  • Make sure the documentation for updated functions, methods, and types is correct.
  • Add tests for bugs that have been fixed.
  • Put in reasonable effort to ensure that CI will pass.
    • make -C src/riscv
    • dune build src/lib_riscv
    • dune build src/rust_deps
  • Benchmark performance and populate the table above if needed.
  • Explain changes to regression test captures when applicable.
  • Write commit messages to reflect the changes they're about.
  • Self-review your changes to ensure they are high-quality.
  • Complete all of the above before assigning this MR to reviewers.
Edited by Ole Krüger

Merge request reports

Loading