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.

94 CHAPTER 8. DEFERRED PROCESSINGCategory Primitives Availability OverheadList traversal list_for_each_entry_rcu() 2.5.59 Simple instructions(memory barrier onAlpha)List update list_add_rcu() 2.5.44 Memory barrierlist_add_tail_rcu() 2.5.44 Memory barrierlist_del_rcu() 2.5.44 Simple instructionslist_replace_rcu() 2.6.9 Memory barrierlist_splice_init_rcu() 2.6.21 Grace-period latencyHlist traversal hlist_for_each_entry_rcu() 2.6.8 Simple instructions(memory barrier onAlpha)hlist_add_after_rcu() 2.6.14 Memory barrierhlist_add_before_rcu() 2.6.14 Memory barrierhlist_add_head_rcu() 2.5.64 Memory barrierhlist_del_rcu() 2.5.64 Simple instructionshlist_replace_rcu() 2.6.15 Memory barrierPointer traversal rcu_dereference() 2.6.9 Simple instructions(memory barrier onAlpha)Pointer update rcu_assign_pointer() 2.6.10 Memory barrierTable 8.6: RCU Publish-Subscribe and Version Maintenance AP<strong>Is</strong>non-list data structures, such as RCU-protected arraysand trees. The rcu_assign_pointer() primitiveensures that any prior initialization remainsordered before the assignment to the pointer onweakly ordered machines. Similarly, the rcu_dereference() primitive ensures that subsequentcode dereferencing the pointer will see the effectsof initialization code prior to the correspondingrcu_assign_pointer() on Alpha CPUs. On non-AlphaCPUs, rcu_dereference()documentswhichpointer dereferences are protected by RCU.Quick Quiz 8.32: Normally, any pointer subjectto rcu_dereference() must always be updated usingrcu_assign_pointer(). <strong>What</strong> is an exceptionto this rule?Quick Quiz 8.33: Are there any downsides tothe fact that these traversal and update primitivescan be used with any of the RCU API family members?8.3.3.3 Where <strong>Can</strong> RCU’s AP<strong>Is</strong> Be Used?Figure 8.26 shows which AP<strong>Is</strong> may be used inwhich in-kernel environments. The RCU read-sideprimitives may be used in any environment, includingNMI, the RCU mutation and asynchronousgrace-period primitives may be used in any environmentother than NMI, and, finally, the RCU synchronousgrace-period primitives may be used onlyNMIIRQProcessrcu_read_lock()rcu_read_unlock()rcu_dereference()RCU List Traversalrcu_assign_pointer()call_rcu()RCU List Mutationsynchronize_rcu()Figure 8.26: RCU API Usage Constraintsin process context. The RCU list-traversal primitivesinclude list_for_each_entry_rcu(), hlist_for_each_entry_rcu(), etc. Similarly, the RCUlist-mutation primitives include list_add_rcu(),hlist_del_rcu(), etc.Note that primitives from other families of RCUmay be substituted, for example, srcu_read_lock() may be used in any context in which rcu_read_lock() may be used.

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

Saved successfully!

Ooh no, something went wrong!