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.

Appendix DRead-Copy Update ImplementationsThis appendix describes several fully functionalproduction-quality RCU implementations. Understandingof these implementations requires a thoroughunderstanding of the material in Chapters 1and 8, as well as a reasonably good understandingof the Linux kernel, the latter of which may be foundin several textbooks and websites [BC05, CRKH05,Cor08, Lov05].<strong>If</strong> you are new to RCU implementations, youshould start with the simpler “toy” RCU implementationsthat may be found in Section 8.3.4.Section D.1 presents “Sleepable RCU”, or SRCU,which allows SRCU readers to sleep arbitrarily. Thisis a simple implementation, as production-qualityRCU implementations go, and a good place to startlearning about such implementations.Section D.2 gives an overview of a highly scalableimplementation of Classic RCU, designed for SMPsystems sporting thousands of CPUs. Section D.3takes the reader on a code walkthrough of this sameimplementation (as of late 2008).Finally, SectionD.4providesadetailedviewofthepreemptable RCU implementation used in real-timesystems.D.1 Sleepable RCU ImplementationClassic RCU requires that read-side critical sectionsobey the same rules obeyed by the critical sectionsof pure spinlocks: blocking or sleeping of any sortis strictly prohibited. This has frequently been anobstacle to the use of RCU, and Paul has receivednumerous requests for a “sleepable RCU” (SRCU)that permits arbitrary sleeping (or blocking) withinRCU read-side critical sections. Paul had previouslyrejected all such requests as unworkable, since arbitrarysleeping in RCU read-side could indefinitelyextend grace periods, which in turn could result inarbitrarily large amounts of memory awaiting theFigure D.1: Sleeping While RCU Reading ConsideredHarmfulend of a grace period, which finally would result indisaster, as fancifully depicted in Figure D.1, withthe most likely disaster being hangs due to memoryexhaustion. After all, any concurrency-controlprimitive that could result in system hangs — evenwhen used correctly – does not deserve to exist.However, the realtime kernels that require spinlockcritical sections be preemptible [Mol05] also requirethat RCU read-side critical sections be preemptible[MS05]. Preemptible critical sections inturn require that lock-acquisition primitives blockin order to avoid deadlock, which in turns meansthat both RCU’s and spinlocks’ critical sections beable to block awaiting a lock. However, these twoforms of sleeping have the special property that priorityboosting and priority inheritance may be usedto awaken the sleeping tasks in short order.Nevertheless, use of RCU in realtime kernels wasthe first crack in the tablets of stone on which wereinscribed “RCU read-side critical sections can neversleep”. That said, indefinite sleeping, such as blockingwaiting for an incoming TCP connection, isstrictly verboten even in realtime kernels.Quick Quiz D.1: Why is sleeping prohibited

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

Saved successfully!

Ooh no, something went wrong!