feature: Add RoundRobin SP_TIMESLICE switch policy #314
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This pull request introduces a new arbitration switch policy named
SP_TIMESLICE
to theRoundRobin
module inmigen.genlib.roundrobin
.Motivation
Consider an arbiter that grants access to a shared book for two writers. One writer just wants to sign their name, while the other plans to write an entire chapter. The question is: "Once the chapter writer starts using the book, is it fair for the signer to wait until the entire chapter is finished, just to sign their name?".
This illustrates a common problem in resource arbitration where long or variable transactions from one master can block others indefinitely, or for a very long time. The
SP_TIMESLICE
policy addresses this by limiting how long a master can hold the grant (max_cycles
), ensuring that long transactions don’t block others, improving the resources allocation and avoiding deadlocks in shared-resource systems.Main Changes
migen/genlib/roundrobin.py
:SP_TIMESLICE
constant and modified the RoundRobin module to handle this new policy.transok
: Input signal (one per master) indicating whether the last transaction was successfully completed. It prevents premature switching in the middle of an active transaction;migen/test/test_roundrobin.py
:SP_TIMESLICE
unit testmigen/genlib/support.py
:**kwargs
toSimCase.run_with()
method, enabling the VCD generation directly from this method.Tests
A new test case,
test_grant_switch
, was added totest_roundrobin.py
to validate theSP_TIMESLICE
behavior. The test ensures that grant switching occurs when the internal counter reachesmax_cycles
and no transaction is currently in progress. To run the test, execute the command below from themigen/migen/test
directory.Evidences
Evidence 1: VCD of unit test
As shown in the image below, the
grant
switches whenmax_cycles
is reached and no transaction is in progress. This VCD waveform was generated usingSimCase.run_with()
with thevcd_name
parameter set accordingly. The snapshot displays the relevant signals in the GTKWave interface.Evidence 2: Vivado FPGA validation
The image below shows the waveform from the Vivado simulator using the RoundRobin arbiter with the implemented
SP_TIMESLICE
policy. In this simulation, two Wishbone masters requests read/write access at the same time to a shared slave memory. The masters' requests can be seen by the CYC and STB signals, while the slave's ACK signal is connected to the arbiter'stransok
input. The equivalent Verilog design was also implemented and validated on a Xilinx Artix-7 FPGA.Checklist