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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

216 APPENDIX D. READ-COPY UPDATE IMPLEMENTATIONSmynode pointer in this CPU’s rcu_data structure(see Figure D.26). Line 14 picks up a mask withthisCPU’sbitsetforuseontheleafrcu_nodestructure’sqsmask field.The loop spanning lines 15-25 then clears thisCPU’s bits up the rcu_node hierarchy, starting withthisCPU’sleafrcu_nodestructure. Line16acquiresthe current rcu_node structure’s ->lock field, andline 17 clears the bit corresponding to this CPU(or group, higher up in the hierarchy) from the->qsmaskinitfield, sothatfuturegraceperiodswillnotwaitonquiescentstatesfromthisCPU.<strong>If</strong>theresulting->qsmaskinit value is non-zero, as checkedby line 18, then the current rcu_node structure hasother online CPUs that it must track, so line 19 releasesthe current rcu_node structure’s ->lock andline 20 exits the loop. Otherwise, we need to continuewalking up the rcu_node hierarchy. In thiscase, line 22 picks up the mask to apply to the nextlevel up, line 23 releases the current rcu_node structure’s->lock, and line 24 advances up to the nextlevel of the hierarchy. Line 25 exits the loop shouldwe exit out the top of the hierarchy.Quick Quiz D.38: But does line 25 of FigureD.32 ever really exit the loop? Why or whynot?Line 26 picks up the the specified rcu_statestructure’s ->completed field into the local variablelastcomp, line 27 releases ->onofflock (but leavesirqs disabled), and line 28 invokes cpu_quiet() inorder to note that the CPU being offlined is now inan extended quiescent state, passing in lastcomp toavoid reporting this quiescent state against a differentgrace period than it occurred in.Quick Quiz D.39: Suppose that line 26 gotexecuted seriously out of order in Figure D.32, sothat lastcomp is set to some prior grace period, butso that the current grace period is still waiting onthe now-offline CPU? In this case, won’t the call tocpu_quiet() fail to report the quiescent state, thuscausing the grace period to wait forever for this nowofflineCPU?Quick Quiz D.40: Given that an offline CPUis in an extended quiescent state, why does line 28of Figure D.32 need to care which grace period it isdealing with?Lines 29-39 move any RCU callbacks from theCPU going offline to the currently running CPU.This operation must avoid reordering the callbacksbeing moved, as otherwise rcu_barrier() will notwork correctly. Line 29 puts a pointer to the currentlyrunning CPU’s rcu_data structure into localvariable rdp_me. Line 30 then checks to see if theCPU going offline has any RCU callbacks. <strong>If</strong> so,lines 31-38 move them. Line 31 splices the list ofcallbacks onto the end of the running CPU’s list.Lines 32-33 sets the running CPU’s callback tailpointer to that of the CPU going offline, and thenlines34-36initializethegoing-offlineCPU’slisttobeempty. Line 37 adds the length of the going-offlineCPU’s callback list to that of the currently runningCPU, and, finally, line 38 zeroes the going-offlineCPU’s list length.Quick Quiz D.41: But this list movement inFigureD.32makesallofthegoing-offlineCPU’scallbacksgo through another grace period, even if theywere ready to invoke. <strong>Is</strong>n’t that inefficient? Furthermore,couldn’t an unfortunate pattern of CPUsgoingofflinethencomingbackonlinepreventagivencallback from ever being invoked?Finally, line 40 re-enables irqs.D.3.5 Miscellaneous FunctionsThis section describes the miscellaneous utility functions:1. rcu_batches_completed2. rcu_batches_completed_bh3. cpu_has_callbacks_ready_to_invoke4. cpu_needs_another_gp5. rcu_get_rootFigure D.33 shows a number of miscellaneousfunctions. Lines 1-9 shown rcu_batches_completed() and rcu_batches_completed_bh(),whichareusedbythercutorturetestsuite. Lines11-15 show cpu_has_callbacks_ready_to_invoke(),which indicates whether the specified rcu_datastructure has RCU callbacks that have passedthrough their grace period, which is indicated bythe “done” tail pointer no longer pointing to thehead of the list. Lines 17-24 show cpu_needs_another_gp(), which indicates whether the CPUcorresponding to the specified rcu_data structurerequires an additional grace period during a timewhen no grace period is in progress. Note that thespecified rcu_data structure is required to be associatedwith the specified rcu_state structure. Finally,lines 26-30 show rcu_get_root(), which returnsthe root rcu_node structure associated withthe specified rcu_state structure.

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

Saved successfully!

Ooh no, something went wrong!