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.

228 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.52: Scanning Leaf rcu node Structuresture. Lines 26 and 27 set local variables cpu andbit to reference the lowest-numbered CPU associatedwith this rcu_node structure. Each passthrough the loop spanning lines 28-32 checks oneof the CPUs associated with the current rcu_nodestructure. Line 29 checks to see if the this CPU isstill holding out or if it has already passed througha quiescent state. <strong>If</strong> it is still a holdout, line 30 invokesthe specified function (either dyntick_save_progress_counter() or rcu_implicit_dynticks_qs(), as specified by the caller), and if that functionreturns non-zero (indicating that the current CPUis in an extended quiescent state), then line 31 setsthe current CPU’s bit in mask.Line 33 then checks to see if any CPUs were identifiedas being in extended quiescent states and ifthe current grace period is still in force, and, if so,line 34 invokes cpu_quiet_msk() to report that thegrace period need no longer wait for those CPUs andthenline35restartstheloopwiththenextrcu_nodestructure. (Note that cpu_quiet_msk() releases thecurrent rcu_node structure’s lock, and might wellend the current grace period.) Otherwise, if all holdoutCPUs really are still holding out, line 37 releasesthe current rcu_node structure’s lock.Once all of the leafrcu_node structures have beenprocessed, the loop exits, and line 39 returns zero toindicate that the current grace period is still in fullforce. (Recall that line 20 returns non-zero shouldthe current grace period come to an end.)D.3.8.4 Code for force quiescent state()Figure D.53 shows the code for force_quiescent_state() for CONFIG_SMP, 4 which is invoked whenRCU feels the need to expedite the current graceperiod by forcing CPUs through quiescent states.RCU feels this need when either:1. the current grace period has gone on for morethan three jiffies (or as specified by the compiletimevalue of RCU_JIFFIES_TILL_FORCE_QS),or2. a CPU enqueuing an RCU callback via eithercall_rcu() or call_rcu_bh() sees more than10,000 callbacks enqueued (or as specified bythe boot-time parameter qhimark).Lines10-12checktoseeifthereisagraceperiodinprogress, silently exiting if not. Lines 13-16 attempttoacquire->fqslock, whichpreventsconcurrentattemptsto expedite a grace period. The ->n_force_qs_lh counter is incremented when this lock is alreadyheld, and is visible via the fqlh= field in thercuhier debugfs file when the CONFIG_RCU_TRACEkernel parameter is enabled. Lines 17-21 check tosee if it is really necessary to expedite the currentgrace period, in other words, if (1) the current CPUhas 10,000 RCU callbacks waiting, or (2) at least4 For non-CONFIG_SMP, force_quiescent_state is a simplewrapper around set_need_resched().

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

Saved successfully!

Ooh no, something went wrong!