






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







CS433: Computer Systems Organization Fall 2008
Homework 5
Assigned: Nov/
Due in class Oct/
Total points: 32 for undergraduate students, 40 for graduate students.
Instructions:
Please write your name, NetID and an alias on your homework submissions for posting grades (If you don’t want your grades posted, then don’t write an alias). We will use this alias throughout the semester. Homeworks are due in class on the date posted.
(a) [5 points] Draw the state transition diagram. Solution: This is the MOSI Protocol.
Grading:
(b) [3 points] How does adding this new state improve performance over the basic MSI snoopin
protocol?
Solution: Reduces the number of reads to memory. The node that has the data in state Owned will provide the data if someone reads it, not memory. Recall the data is not modified. Memory will only provide the data if it is not in state Owned or Modified in any cache. Grading: 1 point for correct answer, 2 point for explaination.
(b) [2 points] In the MESI (Illinois) Protocol, why can’t a node transition from the shared state to the excusive state if all other nodes have had a particular block evicted from the cache, leaving that node with the only copy in memory? Solution: When a block is in the shared state, it has no information about how many other nodes might possibly have the same block. This information is not broadcasted. Grading: 1 point for correct answer, 1 point for explaination.
(c) [6 points] Suppose we want to combine the protocol in question 1 with the MESI (Illinois) Protocol to improve efficiency even further. What modifications will be needed to incorporate the Owned state into the MESI Protocol. You don’t need to draw the state transition diagram, just describe what needs to be done.
Solution: This is the MOESI Protocol. A processor transitions to the owned state when there is a bus-read while the processor is in the Modified or Exclusive states and puts its data on the bus. While in the owned state, on a processor-read it stays in the owned state. While in the owned state, on a bus-read it stays in the owned state and puts its data on the bus. While in the owned state, on a bus-write, the processor transitions to the Invalid state and puts its data on the bus. While in the owned state, on a processor-write, the processor transitions to the Modified state and puts its data on the bus. Main memory is updated when a block in the modified/dirty state or owned state is evicted. Grading: 1 point for each.
invalid state. In update schemes, on a write, the new value is put on the bus so all other caches which have a copy of the block can update their copies. Invalidate schemes perform poorly in a producer-consumer model discussed in class. This is bad because each individual processor has to keep making requests for the data where in an update scheme a single broadcast would put the most recent value in all other caches. Update schemes perform poorly when there are multiple writes to a single block which other caches may only need once in a while or may not need at all. This is bad because each write is broadcasted on the bus, where in an invalidate protocol, all other caches would be invalidated on the first write and no other communication would be needed. Grading: 1 point for differences, 1 point for each example of poor performance.
(a) [2 points] Implement an atomic test-and-set on memory address L in assembly using Compareand-Swap(R1,R2,L) as the only atomic primitive. Let L = 1 when the lock is taken and L = 0 when it is free. You may use any registers you like. Solution: R1 Å 0 R2 Å 1 Compare-and-Swap(R1,R2,L)
(b) [2 points] Implement the test-and-test-and-set semantics on memory address L in assembly
using compare-and-swap as the only atomic primitive. Let L =1 when the lock is taken, and L =
when it is free. You can use any registers you like as well as ordinary loads and stores.
Solution
If the student neglects the last loop-back branch, do not deduct any points.
R2 <- 1
LOCK: R1 <- LOAD(L)
BNEZ R1, LOCK
C&S R1, R2, L
BNEZ R2, LOCK
(c)[2 points] Use compare-and-swap to implement an atomic fetch-and-increment(R1,L) in
assembly, which atomically copies the value in L to R1, then increments the value in L by 1.
Again, you can use any registers you like well as ordinary loads and stores.
Solution
Problem 5 [8 points]
Consider the following system S :
Answer the following two parts for the above system.
Part A [4 points]
Consider the following program.
(Note: Operations in a vertical column are issued by the same processor, and appear in program
order.)
Initially X = Y = 0
X = 1 tmp1 = X tmp2 = Y
Y = 1 tmp3 = X
Suppose processor P2’s read of X and processor P3’s read of Y both return the value 1.
Then what values could processor P3’s read of X return on a sequentially consistent system?
What values could it return on system S.
Solution:
Under sequential consistency, memory operations appear to execute atomically and in program
order. Since we are told that P2's read of X and P3's read of Y both return the value 1, we can
conclude that the order of memory operations as seen by the system is:
(X=1)Æ(tmp1=X) Æ(Y=1) Æ(tmp2=Y) Æ(tmp3=X)
Therefore, the read of X by P3 returns a 1. The above order is correct because of the following
reasons: We are given that the read of X at P2 returns a 1. This implies that the write of 1 to X by
P1 happened before it. The store to Y by P2 comes after reading X in program order. The same
store happens before the read of Y on P3 since we are told that the read of Y at P3 returns a 1.
Finally, the read of X by P3 occurs after the read of Y in program order and therefore appears
after it in the system.
On system S , since there are no guarantees on the order in which loads and stores are executed
by each processor, P3 could either read a 0 or a 1 for the value of X.
Grading: 2 points for the answer about sequentially consistent system and 2 points for the
answer for the hypothetical system.
Part B [4 points]