10.07.2015 Views

Is Parallel Programming Hard, And, If So, What Can You Do About It?

Is Parallel Programming Hard, And, If So, What Can You Do About It?

Is Parallel Programming Hard, And, If So, What Can You Do About It?

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

326 APPENDIX F. ANSWERS TO QUICK QUIZZES3. The atomic block covering the assertion codeshould be extended to include the initializationof sum and j, and also to cover the assertion.This also reduces the state space (again, by howmuch?).Quick Quiz E.3:<strong>Is</strong> there a more straightforward way to code thedo-od statement?Answer:Yes. Replace it with if-fi and remove the twobreak statements.Quick Quiz E.4:Why are there atomic blocks at lines 12-21 and lines44-56, when the operations within those atomicblocks have no atomic implementation on anycurrent production microprocessor?Answer:Because those operations are for the benefit of theassertion only. They are not part of the algorithmitself. There is therefore no harm in marking thematomic, and so marking them greatly reduces thestate space that must be searched by the Promelamodel.Quick Quiz E.5:<strong>Is</strong> the re-summing of the counters on lines 24-27really necessary???Answer:Yes. To see this, delete these lines and run themodel.Alternatively, consider the following sequence ofsteps:1. One process is within its RCU read-side criticalsection, so that the value of ctr[0] is zero andthe value of ctr[1] is two.2. An updater starts executing, and sees that thesum of the counters is two so that the fastpathcannot be executed. <strong>It</strong> therefore acquires thelock.3. A second updater starts executing, and fetchesthe value of ctr[0], which is zero.4. The first updater adds one to ctr[0], flips theindex(which nowbecomeszero), thensubtractsone from ctr[1] (which now becomes one).5. Thesecondupdaterfetchesthevalueofctr[1],which is now one.6. The second updater now incorrectly concludesthat it is safe to proceed on the fastpath, despitethe fact that the original reader has notyet completed.Quick Quiz E.6:Yeah, that’s great!!! Now, just what am I supposedto do if I don’t happen to have a machine with40GB of main memory???Answer:Relax, there are a number of lawful answers to thisquestion:1. Further optimize the model, reducing its memoryconsumption.2. Work out a pencil-and-paper proof, perhapsstarting with the comments in the code in theLinux kernel.3. Devise careful torture tests, which, though theycannot prove the code correct, can find hiddenbugs.4. There is some movement towards tools that domodel checking on clusters of smaller machines.However, please note that we have not actuallyused such tools myself, courtesy of some largemachines that Paul has occasional access to.Quick Quiz E.7:Why not simply increment rcu_update_flag, andthen only increment dynticks_progress_counterif the old value of rcu_update_flag was zero???Answer:This fails in presence of NM<strong>Is</strong>. To see this, supposean NMI was received just after rcu_irq_enter()incremented rcu_update_flag, but before itincremented dynticks_progress_counter.The instance of rcu_irq_enter() invokedby the NMI would see that the originalvalue of rcu_update_flag was non-zero, andwould therefore refrain from incrementingdynticks_progress_counter. This would leavethe RCU grace-period machinery no clue that theNMI handler was executing on this CPU, so that

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!