Follow two harts through one spin lock by hand: who holds it on which edge, how many swaps are wasted, and when the second hart gets in.
Hardware context: Two harts of ap_soc that share a lock word and a data word in SRAM. Spin locks, exclusive transfers and locked transfers on a bus with several managers
This is the spin lock of lesson S9.7 with a longer critical section. Two harts each make one update. An update takes the lock with a swap of 1, changes three data words, and gives the lock back with a store of 0. For each data word the hart makes one load and one store, and it adds 1. A hart that gets 1 back from its swap tries the swap again.
This worksheet uses named constants. The first three entries show how to record your decisions.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
question | 8 | input of each check |
Full specification
| Item | Value |
|---|---|
| Before the run | The lock word and the three data words hold 0. |
| Turns while both harts ask | The bus serves one access on each clock edge: hart 0 on odd edges, hart 1 on even edges, from edge 1 on. |
| Turns when one hart asks | A hart that is alone is served on every second edge. Hart 1 stays on the even edges. |
| The order inside the lock | Load word 0, store word 0, load word 1, store word 1, load word 2, store word 2, then the store of 0 to the lock word. |
Enter an edge as its number: 5 for edge 5.
| Entry | Your decision |
|---|---|
| H0_TAKES | The edge on which the swap of hart 0 returns 0. |
| H1_FIRST | What the first swap of hart 1, on edge 2, returns. |
| H0_DATA | How many accesses to the data does hart 0 make inside the lock? |
| H0_LAST_DATA | The edge of the last data store of hart 0. |
| H0_GIVES | The edge on which hart 0 stores 0 to the lock word. |
| SPINS | How many swaps of hart 1 return 1? |
| H1_TAKES | The edge on which a swap of hart 1 returns 0. |
| H1_FIRST_LOAD | The edge of the first load of hart 1. |
| H1_LOADS | The value that this load returns. |
| H1_GIVES | The edge on which hart 1 stores 0 to the lock word. |
| WORD_END | What each data word holds at the end. |
| SWAPS | How many swaps were made in all, by both harts? |
| SPINS_N | Suppose one update changed N words under the lock in place of 3. How many swaps of hart 1 would return 1? |
Examples
Example 1
H0 TAKES- Input
The edge on which the swap of hart 0 returns 0.
- Output
matches = 1
Hart 0 is served first, and the lock word holds 0.
Example 2
H1 FIRST- Input
What the first swap of hart 1, on edge 2, returns.
- Output
matches = 1
Hart 0 wrote a 1 on edge 1. Hart 1 gets that 1 back.
Example 3
H0 DATA- Input
How many accesses to the data does hart 0 make inside the lock?
- Output
matches = 1
A load and a store for each of three words.
Constraints and Contract
- Keep the parameter and named constants. Use the numeric codes and units on this page.
- For SPINS_N, enter a constant expression using N. Only this entry changes with the parameter. The supported integer range is 3 through 6, inclusive.
Hints
Hint 1
Hart 0 has the odd edges: one swap, six data accesses, one store to the lock word.
Hint 2
Hart 1 swaps on every even edge until the lock word holds 0.
Hint 3
From its good swap on, hart 1 is served on every second edge.
What the grader checks: Each check compares the full eight-bit answer. Parameter trials change one condition and keep the other decisions fixed.
13 checks on Icarus Verilog · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your source only; samples require the simulation service. A passing result establishes the tested cases, not a proof for all possible inputs.
See all 1 problem on this path