Docsity

Homework 5 for Computer System Organization | CS 433, Assignments of Computer Architecture and Organization

Partial preview of the text

Download Homework 5 for Computer System Organization | CS 433 and more Assignments Computer Architecture and Organization in PDF only on Docsity!

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.

  1. [8 points] Snooping Cache Coherence Protocols I We are adding a Owned state to the basic MSI snooping cache protocol (Figure 4.7). More specifically:
  • One node at most may have a block of data in the owned state; if another node has the data as well, it should be in the shared state.
  • When a read miss occurs and another processor has the data in the Owned or Modified, that processor provides the data and the block, in that processor, transitions to (or stays in) Owned.
  • When a write miss occurs and another processor has the data in the Owned or Modified state, that processor provides the data and the block, in that processor, transitions to Invalid.
  • Main memory is updated when a block in the modified/dirty state or owned state is replaced.
  • A processor write to Owned state will transition the state to Modified.

(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.

  1. [10 points] Snooping Cache Coherence Protocols II (a) [2 points] How does the Valid Exclusive state in the MESI (Illinois) Protocol improve performance over the basic MSI scheme? Solution: It reduces the amount of bus traffic. When a block is in the exclusive state, the node with the block does not need to send out any information on a write since the node knows it has the only copy. Grading: 1 point for correct answer, 1 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.

  1. [6 points] Synchronization Compare-and-swap(R1,R2,L) is an atomic synchronization primitive which atomically compares the value in memory location L with R1, and if and only if they are equal, exchanges the values in R2 and L. Compare-and-Swap(R1,R2,L) can be used to efficiently emulate many other primitives.

(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

GRADUATE PROBLEM

Problem 5 [8 points]

Consider the following system S :

  • The system S contains a cache per processor that can contain shared read/write data. Cache coherence is maintained through an invalidation snooping protocol.
  • When a processor’s cache controller sees an invalidate on the bus for a line present in its cache, it buffers this invalidate in a local buffer. The bus is free for the next transaction as soon as such buffering is done. The cache controller will apply the invalidate to its cache line some time later (e.g., when the cache is not being used by the processor). It is also possible that the buffered invalidates are applied to a cache in an order different from the order in which they were received from the bus.
  • A processor is allowed to have multiple outstanding memory accesses and these accesses could occur out of program order.
  • An instruction called memory _ barrier , denoted by MB , is provided with the following specification.
  • An MB by processor P is not issued until the following is true of all operations op of processor P that are before MB by program order: o if op is a read, then it has returned its value, and o if op is a write, then the invalidate for that write has been applied to all the cache lines with an older value.
  • Further, processor P does not issue any memory operation until all preceding MB instructions (by program order) have been issued.
  • The memory consistency model of system S is not sequential consistency and does not impose any constraints on the ordering of loads and stores other than that due to the MB instruction.

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

P1 P2 P

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]