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.

226 APPENDIX D. READ-COPY UPDATE IMPLEMENTATION<strong>So</strong>ther CPUs to be gathered prior to subsequent RCUprocessing. As with dyntick_save_progress_counter(), this memory barrier pairs with thoseinrcu_enter_nohz(),rcu_exit_nohz(),rcu_nmi_enter(), rcu_nmi_exit(), rcu_irq_enter(), andrcu_irq_exit(). Lines 14-15 then check to makesure that this CPU is either currently in dynticksidlemode ((curr&0x1)==0 and (curr_nmi&0x1)==0) or has passed through dynticks-idle mode sincethelastcalltodyntick_save_progress_counter()(curr!=snap and curr_nmi!=snap_nmi). <strong>If</strong> so,line 16 increments the ->dynticks_fqs statisticalcounter (again, used only for tracing) and line 17returns non-zero to indicate that the specified CPUhas passed through a quiescent state. Otherwise,line 19 invokes rcu_implicit_offline_qs() (describedin Section D.3.8) to check whether the specifiedCPU is currently offline.D.3.8 Forcing Quiescent StatesNormally, CPUspassthroughquiescentstateswhichare duly recorded, so that grace periods end in atimely manner. However, any of the following threeconditions can prevent CPUs from passing throughquiescent states:1. The CPU is in dyntick-idle state, and is sleepingin a low-power mode. Although such a CPUis officially in an extended quiescent state, becauseit is not executing instructions, it cannotdo anything on its own.2. TheCPUisintheprocessofcomingonline, andRCU has been informed that it is online, butthis CPU is not yet actually executing code, noris it marked as online in cpu_online_map. Thecurrent grace period will therefore wait on it,but it cannot yet pass through quiescent stateson its own.3. The CPU is running user-level code, but hasavoided entering the scheduler for an extendedtime period.In each of these cases, RCU needs to take actionon behalf of the non-responding CPU. Thefollowing sections describe the functions that takesuch action. Section D.3.8.1 describes the functionsthat record and recall the dynticks-idle grace-periodnumber (in order to avoid incorrectly applying adynticks-idle quiescent state to the wrong grace period),Section D.3.8.2 describes functions that detectoffline and holdout CPUs, Section D.3.8.3 coversrcu_process_dyntick(), which scans for holdoutCPUs, and Section D.3.8.4 describes force_1 static void2 dyntick_record_completed(struct rcu_state *rsp,3 long comp)4 {5 rsp->dynticks_completed = comp;6 }78 static long9 dyntick_recall_completed(struct rcu_state *rsp)10 {11 return rsp->dynticks_completed;12 }Figure D.49: Recording and Recalling Dynticks-IdleGrace Period1 static int rcu_implicit_offline_qs(struct rcu_data *rdp)2 {3 if (cpu_is_offline(rdp->cpu)) {4 rdp->offline_fqs++;5 return 1;6 }7 if (rdp->cpu != smp_processor_id())8 smp_send_reschedule(rdp->cpu);9 else10 set_need_resched();11 rdp->resched_ipi++;12 return 0;13 }Figure D.50: Handling Offline and Holdout CPUsquiescent_state(), which drives the process of detectingextended quiescent states and forcing quiescentstates on holdout CPUs.D.3.8.1 Recording and Recalling Dynticks-Idle Grace PeriodFigure D.49 shows the code for dyntick_record_completed() and dyntick_recall_completed().Thesefunctionsaredefinedasshownonlyifdynticksis enabled (in other words, the CONFIG_NO_HZ kernelparameter is selected), otherwise they are essentiallyno-ops. The purpose of these functions is to ensurethat a given observation of a CPU in dynticks-idlemode is associated with the correct grace period infaceofracesbetweenreportingthisCPUindynticksidlemode and this CPU coming out of dynticks-idlemode and reporting a quiescent state on its own.Lines 1-6 show dyntick_record_completed(),which stores the value specified by its comp argumentinto the specified rcu_state structure’s->dynticks_completed field. Lines 8-12 showdyntick_recall_completed(), which returns thevalue stored by the most recent call to dyntick_record_completed() for this combination of CPUand rcu_state structure.

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

Saved successfully!

Ooh no, something went wrong!