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.

202 APPENDIX D. READ-COPY UPDATE IMPLEMENTATIONSD.3.1.3 Per-CPU DataThe rcu_data structure contains RCU’s per-CPUstate. <strong>It</strong> contains control variables governing graceperiods and quiescent states (completed, gpnum,passed_quiesc_completed, passed_quiesc, qs_pending, beenonline, mynode, and grpmask). Thercu_data structure also contains control variablespertaining to RCU callbacks (nxtlist, nxttail,qlen, and blimit). Kernels with dynticks enabledwill have relevant control variables in the rcu_data structure (dynticks, dynticks_snap, anddynticks_nmi_snap). The rcu_data structure containsevent counters used by tracing (dynticks_fqsgiven dynticks, offline_fqs, and resched_ipi).Finally, a pair of fields count calls torcu_pending()in order to determine when to force quiescentstates (n_rcu_pending andn_rcu_pending_force_qs), and a cpu field indicates which CPU to whicha given rcu_data structure corresponds.Each of these fields is described below.completed: This field contains the number of themostrecentgraceperiodthat thisCPUisawareof having completed.gpnum: This field contains the number of the mostrecent grace period that this CPU is aware ofhaving started.passed_quiesc_completed: This field contains thenumber of the grace period that had most recentlycompleted when this CPU last passedthrough a quiescent state. The ”most recentlycompleted” will be from the viewpoint of theCPU passing through the quiescent state: if theCPU is not yet aware that grace period (say) 42has completed, it will still record the old valueof 41. This is OK, because the only way thatthe grace period can complete is if this CPU hasalready passed through a quiescent state. Thisfield is initialized to a (possibly mythical) pastgrace period number to avoid race conditionswhen booting and when onlining a CPU.passed_quiesc: This field indicates whether thisCPU has passed through a quiescent state sincethe grace period number stored in passed_quiesc_completed completed. This field iscleared each time the corresponding CPU becomesaware of the start of a new grace period.qs_pending: This field indicates that this CPU isaware that the core RCU mechanism is waitingfor it to pass through a quiescent state. Thisfield is set to one when the CPU detects a newgrace period or when a CPU is coming online.Quick Quiz D.21: But why bother settingqs_pending to one when a CPU is coming online,given that being offline is an extended quiescentstatethatshouldcoveranyongoinggraceperiod?Quick Quiz D.22: Why record the last completedgrace period number in passed_quiesc_completed? <strong>Do</strong>esn’t that cause this RCUimplementation to be vulnerable to quiescentstatesseenwhilenograceperiodwasinprogressbeing incorrectly applied to the next grace periodthat starts?beenonline: This field, initially zero, is set to onewhenever the corresponding CPU comes online.This is used to avoid producing useless tracingoutput for CPUs that never have been online,which is usefulin kernels whereNR_CPUS greatlyexceeds the actual number of CPUs.Quick Quiz D.23: <strong>What</strong> is the point of runninga system with NR_CPUS way bigger thanthe actual number of CPUs?mynode: This field is a pointer to the leaf rcu_nodestructure that handles the corresponding CPU.grpmask: This field is a bitmask that has the singlebit set that indicates which bit in mynode->qsmask signifies the corresponding CPU.nxtlist: This field is a pointer to the oldest RCUcallback (rcu_head structure) residing on thisCPU, or NULL if this CPU currently has no suchcallbacks. Additional callbacks may be chainedvia their next pointers.nxttail: This field is an array of double-indirecttail pointers into the nxtlist callback list. <strong>If</strong>nxtlistisempty, thenallofthenxttailpointersdirectly reference the nxtlist field. Eachelement of the nxttail array has meaning asfollows:RCU_DONE_TAIL=0: This element references the->next field of the last callback that haspassed through its grace period and isready to invoke, or references the nxtlistfield if there is no such callback.RCU_WAIT_TAIL=1: This element references thenext field of the last callback that is waitingfor the current grace period to end, oris equal to the RCU_DONE_TAIL element ifthere is no such callback.RCU_NEXT_READY_TAIL=2: This element referencesthe next field of the last callback

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

Saved successfully!

Ooh no, something went wrong!