Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions W13D2/W13D2_Wei_Jie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#### Hardware Support for Memory Reference Speculation

We have just one LR register, so we can do ll/sc in ll/sc which called nested ll/sc.

When $M_{x}\not= M_{y}$,

1. store $M_{y}$
2. load $M_{x}$

We can first load $M_{x}$, then store $M_{y}$. It is an optimization.

When $M_{x}= M_{y}$, we must obey the order----Hazard: error occurs when Mx = My.

#### Spinlock

A locking mechanism is called a spinlock (non-blocking locker).

In spinlock, the task cannot sleep while waiting for the lock, whereas in mutex, the task can sleep while waiting for the lock.

Load link & Store conditional:

eg1:

1. mov R3, R4
2. ll R2, 0(R1)
3. sc R3, 0(R1)
4. beqz R3
5. mov R4, R2

eg2:

1. ll R2, 0(R1)
2. addi R2, R2 #1
3. sc R2, 0(R1)
4. beqz R2



Compare and swap is different from ll/sc because it just compares the value but not pays attention to whether it has been modified.