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.

222 APPENDIX D. READ-COPY UPDATE IMPLEMENTATIONS−>levelspread[]−>levelcnt[]−>level[]−>node[][0]2[0]1[0][0]parent[1]3[1]2[1][2][3]60[1] parent [2]parentrcu_state−>rda[][0][1][2][3][4][5]mynodemynodemynodemynodemynodemynodeFigure D.42: Scanning rcu node Structures When Applying Quiescent Statesstates. In this case, line 24 updates the rcu_statestructure’s ->completed field to match the numberof the newly ended grace period, indicating that thegrace period has in fact ended. Line 24 then invokesrcu_process_gp_end() to advance the runningCPU’s RCU callbacks, and, finally, line 26 invokesrcu_start_gp() in order to start a new graceperiod should any remaining callbacks on the currentlyrunning CPU require one.Figure D.43 shows rcu_do_batch(), which invokesRCU callbacks whose grace periods haveended. Only callbacks on the running CPU will beinvoked—other CPUs must invoke their own callbacks.Quick Quiz D.49: How do RCU callbacks ondynticks-idle or offline CPUs get invoked?Line 7 invokes cpu_has_callbacks_ready_to_invoke() to see if this CPU has any RCU callbackswhose grace period has completed, and, if not, line 8returns. Lines 9 and 18 disable and re-enable interrupts,respectively. Lines 11-13 remove the readyto-invokecallbacks from ->nxtlist, and lines 14-17make any needed adjustments to the tail pointers.Quick Quiz D.50: Why would lines 14-17 inFigure D.43 need to adjust the tail pointers?Line 19 initializes local variable count to zero inpreparation for counting the number of callbacksthat will actually be invoked. Each pass through theloop spanning lines 20-27 invokes and counts a callback,with lines 25-26 exiting the loop if too manycallbacks are to be invoked at a time (thus preservingresponsiveness). The remainder of the functionthen requeues any callbacks that could not be invokeddue to this limit.Lines 28 and 41 disable and re-enable interrupts,respectively. Line 29 updates the ->qlen field,which maintains a count of the total number of RCUcallbacks for this CPU. Line 30 checks to see if therewere any ready-to-invoke callbacks that could not beinvoked at the moment due to the limit on the numberthat may be invoked at a given time. <strong>If</strong> suchcallbacks remain, lines 30-38 requeue them, againadjusting the tail pointers as needed. Lines 39-40restore the batch limit if it was increased due toexcessive callback backlog, and lines 42-43 cause additionalRCU processing to be scheduled if there areany ready-to-invoke callbacks remaining.D.3.7 Dyntick-Idle FunctionsThe functions in this section are defined only inCONFIG_NO_HZ builds of the Linux kernel, though insome cases, extended-no-op versions are present otherwise.These functions control whether or not RCUpays attention to a given CPU. CPUs in dynticksidlemode are ignored, but only if they are not currentlyinaninterruptorNMIhandler.Thefunctionsin this section communicate this CPU state to RCU.

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

Saved successfully!

Ooh no, something went wrong!