Question: The first three problems in this Exercise refer to a critical section of the form lock(lk); operation unlock(lk); where the operation updates the shared variable

The first three problems in this Exercise refer to a critical section of the form
lock(lk);
operation
unlock(lk);
where the “operation” updates the shared variable shvar using the local (nonshared) variable x as follows:a. shvar=max(shvar,x); b. if(shvar>0) shvar=max(shvar,x); Operation

Compare the best-case performance of your code from 2.29.1 and 2.29.2, assuming that each instruction takes one cycle to execute. Note: best-case means that ll/sc always succeeds, the lock is always free when we want to lock(), and if there is a branch we take the path that completes the operation with fewer executed instructions.

Problem 2.29.1

Write the MIPS assembly code for this critical section, assuming that the address of the lk variable is in $a0, the address of the shvar variable is in $a1, and the value of variable x is in $a2. Your critical section should not contain any function calls, i.e., you should include the MIPS instructions for lock(), unlock(), max(), and min() operations. Use ll/sc instructions to implement the lock() operation, and the unlock() operation is simply an ordinary store instruction.

Problem 2.29.2

The first three problems in this Exercise refer to a critical section of the form
lock(lk);
operation
unlock(lk);
where the “operation” updates the shared variable shvar using the local (nonshared) variable x as follows:a. shvar=max(shvar,x); b. if(shvar>0) shvar=max(shvar,x); Operation

Repeat problem 2.29.1, but this time use ll/sc to perform an atomic update of the shvar variable directly, without using lock() and unlock(). Note that in this problem there is no variable lk.

a. shvar=max(shvar,x); b. if(shvar>0) shvar=max(shvar,x); Operation

Step by Step Solution

3.42 Rating (158 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Problem 2291 Heres the MIPS assembly code for the critical section using lock and unlock operations ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Computer Organization Design Questions!