RCU changes for v4.12
Subsystems (29)
Linus,
Please pull the latest core-rcu-for-linus git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git core-rcu-for-linus
# HEAD: b5fe223a4bd0217a657ff084e48752c367a8a55f srcu: Adjust default auto-expediting holdoff
The main changes are:
- Parallelize SRCU callback handling (plus overlapping patches)
- Improve the performance of Tree SRCU on a CPU-hotplug stress test
- Documentation updates
- Miscellaneous fixes
Thanks,
Ingo
------------------>
Dmitry Vyukov (1):
rcu: Fix warning in rcu_seq_end()
Michael S. Tsirkin (1):
hlist_add_tail_rcu disable sparse warning
Michalis Kokologiannakis (1):
doc: Update the comparisons rule in rcu_dereference.txt
Nicholas Mc Guire (2):
rcu: Use bool value directly
rcu: Use true/false in assignment to bool
Paul E. McKenney (63):
doc: Synchronous RCU grace periods are now legal throughout boot
doc: Add mid-boot operation to expedited grace periods
doc: Update stallwarn.txt to make causes more prominent
doc: Update RCU data-structure documentation for rcu_segcblist
doc: Update requirements based on recent changes
doc: Update rcu_assign_pointer() definition in whatisRCU.txt
doc: Emphasize that "toy" RCU requires recursive rwlock
rcu: Maintain special bits at bottom of ->dynticks counter
rcu: Make arch select smp_mb__after_unlock_lock() strength
srcu: Consolidate batch checking into rcu_all_batches_empty()
srcu: Check for tardy grace-period activity in cleanup_srcu_struct()
rcu: Semicolon inside RCU_TRACE() for rcu.h
rcu: Semicolon inside RCU_TRACE() for Tiny RCU
rcu: Semicolon inside RCU_TRACE() for tree.c
rcu: Pull rcu_sched_qs_mask into rcu_dynticks structure
rcu: Pull rcu_qs_ctr into rcu_dynticks structure
rcu: Eliminate flavor scan in rcu_momentary_dyntick_idle()
rcu: Place guard on rcu_all_qs() and rcu_note_context_switch() actions
rcu: Default RCU_FANOUT_LEAF to 16 unless explicitly changed
srcu: Abstract multi-tail callback list handling
srcu: Allow SRCU to access rcu_scheduler_active
srcu: Allow early boot use of synchronize_srcu()
rcu: Add single-element dequeue functions to rcu_segcblist
srcu: Move rcu_seq_start() and friends to rcu.h
rcu: Expedited wakeups need to be fully ordered
srcu: Push srcu_advance_batches() fastpath into common case
srcu: Move to state-based grace-period sequencing
srcu: Add grace-period sequence numbers
srcu: Use rcu_segcblist to track SRCU callbacks
srcu: Move combining-tree definitions for SRCU's benefit
srcu: Move rcu_init_levelspread() to rcu_tree_node.h
rcu: Remove redundant levelcnt[] array from rcu_init_one()
srcu: Move rcu_node traversal macros to rcu.h
srcu: Make num_rcu_lvl[] array be external
srcu: Fix bogus try_check_zero() comment
srcu: Improve rcu_seq grace-period-counter abstraction
srcu: Allow a second bit in rcu_seq for SRCU state
srcu: Merge ->srcu_state into ->srcu_gp_seq
srcu: Crude control of expedited grace periods
mm: Use static initialization for "srcu"
srcu: Create a tiny SRCU
srcutorture: Print Tiny SRCU reader statistics
srcu: Introduce CLASSIC_SRCU Kconfig option
mm: Rename SLAB_DESTROY_BY_RCU to SLAB_TYPESAFE_BY_RCU
lockdep: Use "WARNING" tag on lockdep splats
types: Update obsolete callback_head comment
rcu: Make RCU_FANOUT_LEAF help text more explicit about skew_tick
rcu: Remove obsolete comment from rcu_future_gp_cleanup() header
rcu: Improve comments for hotplug/suspend/hibernate functions
torture: Use correct path for Kconfig fragment for duplicates
rcu: Fix typo in PER_RCU_NODE_PERIOD header comment
kvm: Move srcu_struct fields to end of struct kvm
srcu: Parallelize callback handling
srcu: Expedite srcu_schedule_cbs_snp() callback invocation
rcu: Make non-preemptive schedule be Tasks RCU quiescent state
srcu: Fix Kconfig botch when SRCU not selected
srcu: Make SRCU be built by default
srcu: Exact tracking of srcu_data structures containing callbacks
srcu: Make rcutorture writer stalls print SRCU GP state
srcu: Expedited grace periods with reduced memory contention
srcu: Expedite first synchronize_srcu() when idle
srcu: Specify auto-expedite holdoff time
srcu: Adjust default auto-expediting holdoff
pierre Kuo (1):
doc: Update control-dependencies section of memory-barriers.txt
Documentation/RCU/00-INDEX | 2 +- .../Design/Data-Structures/Data-Structures.html | 233 ++-- .../RCU/Design/Data-Structures/nxtlist.svg | 34 +- .../Expedited-Grace-Periods.html | 47 +- .../RCU/Design/Requirements/Requirements.html | 195 +++- Documentation/RCU/rcu_dereference.txt | 9 + Documentation/RCU/rculist_nulls.txt | 6 +- Documentation/RCU/stallwarn.txt | 190 ++-- Documentation/RCU/whatisRCU.txt | 32 +- Documentation/admin-guide/kernel-parameters.txt | 8 + Documentation/memory-barriers.txt | 2 +- arch/Kconfig | 3 + arch/powerpc/Kconfig | 1 + drivers/gpu/drm/i915/i915_gem.c | 2 +- drivers/gpu/drm/i915/i915_gem_request.h | 2 +- drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c | 2 +- fs/jbd2/journal.c | 2 +- fs/signalfd.c | 2 +- include/linux/dma-fence.h | 4 +- include/linux/kvm_host.h | 4 +- include/linux/rcu_node_tree.h | 99 ++ include/linux/rcu_segcblist.h | 712 ++++++++++++ include/linux/rculist.h | 3 +- include/linux/rcupdate.h | 17 +- include/linux/rcutiny.h | 24 +- include/linux/rcutree.h | 5 +- include/linux/slab.h | 6 +- include/linux/srcu.h | 84 +- include/linux/srcuclassic.h | 115 ++ include/linux/srcutiny.h | 93 ++ include/linux/srcutree.h | 150 +++ include/linux/types.h | 2 +- include/net/sock.h | 2 +- init/Kconfig | 40 +- kernel/fork.c | 4 +- kernel/locking/lockdep.c | 86 +- kernel/locking/rtmutex-debug.c | 9 +- kernel/rcu/Makefile | 4 +- kernel/rcu/rcu.h | 153 ++- kernel/rcu/rcutorture.c | 43 +- kernel/rcu/srcu.c | 12 +- kernel/rcu/srcutiny.c | 215 ++++ kernel/rcu/srcutree.c | 1154 ++++++++++++++++++++ kernel/rcu/tiny.c | 20 +- kernel/rcu/tiny_plugin.h | 13 +- kernel/rcu/tree.c | 708 +++++------- kernel/rcu/tree.h | 164 +-- kernel/rcu/tree_exp.h | 25 +- kernel/rcu/tree_plugin.h | 64 +- kernel/rcu/tree_trace.c | 26 +- kernel/rcu/update.c | 53 +- kernel/sched/core.c | 2 +- kernel/signal.c | 2 +- mm/kasan/kasan.c | 6 +- mm/kmemcheck.c | 2 +- mm/mmu_notifier.c | 14 +- mm/rmap.c | 4 +- mm/slab.c | 6 +- mm/slab.h | 4 +- mm/slab_common.c | 6 +- mm/slob.c | 6 +- mm/slub.c | 12 +- net/dccp/ipv4.c | 2 +- net/dccp/ipv6.c | 2 +- net/ipv4/tcp_ipv4.c | 2 +- net/ipv6/tcp_ipv6.c | 2 +- net/llc/af_llc.c | 2 +- net/llc/llc_conn.c | 4 +- net/llc/llc_sap.c | 2 +- net/netfilter/nf_conntrack_core.c | 8 +- net/smc/af_smc.c | 2 +- .../selftests/rcutorture/bin/kvm-test-1-run.sh | 2 +- 72 files changed, 3850 insertions(+), 1127 deletions(-) create mode 100644 include/linux/rcu_node_tree.h create mode 100644 include/linux/rcu_segcblist.h create mode 100644 include/linux/srcuclassic.h create mode 100644 include/linux/srcutiny.h create mode 100644 include/linux/srcutree.h create mode 100644 kernel/rcu/srcutiny.c create mode 100644 kernel/rcu/srcutree.c
Documentation/RCU/00-INDEX +1 -1
@@ -17,7 +17,7 @@ rcu_dereference.txt rcubarrier.txt - RCU and Unloadable Modules rculist_nulls.txt - - RCU list primitives for use with SLAB_DESTROY_BY_RCU + - RCU list primitives for use with SLAB_TYPESAFE_BY_RCU rcuref.txt - Reference-count design for elements of lists/arrays protected by RCU rcu.txt
Documentation/RCU/Design/Data-Structures/Data-Structures.html +169 -64
282 lines not on this page · raw message
Documentation/RCU/Design/Data-Structures/nxtlist.svg +12 -22
@@ -19,7 +19,7 @@ id="svg2" version="1.1" inkscape:version="0.48.4 r9939" - sodipodi:docname="nxtlist.fig"> + sodipodi:docname="segcblist.svg"> <metadata id="metadata94"> <rdf:RDF>
@@ -28,7 +28,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata>
@@ -241,61 +241,51 @@ xml:space="preserve" x="225" y="675" - fill="#000000" - font-family="Courier" font-style="normal" font-weight="bold" font-size="324" - text-anchor="start" - id="text64">nxtlist</text> + id="text64" + style="font-size:324px;font-style:normal;font-weight:bold;text-anchor:start;fill:#000000;font-family:Courier">->head</text> <!-- Text --> <text xml:space="preserve" x="225" y="1800" - fill="#000000" - font-family="Courier" font-style="normal" font-weight="bold" font-size="324" - text-anchor="start" - id="text66">nxttail[RCU_DONE_TAIL]</text> + id="text66" + style="font-size:324px;font-style:normal;font-weight:bold;text-anchor:start;fill:#000000;font-family:Courier">->tails[RCU_DONE_TAIL]</text> <!-- Text --> <text xml:space="preserve" x="225" y="2925" - fill="#000000" - font-family="Courier" font-style="normal" font-weight="bold" font-size="324" - text-anchor="start" - id="text68">nxttail[RCU_WAIT_TAIL]</text> + id="text68" + style="font-size:324px;font-style:normal;font-weight:bold;text-anchor:start;fill:#000000;font-family:Courier">->tails[RCU_WAIT_TAIL]</text> <!-- Text --> <text xml:space="preserve" x="225" y="4050" - fill="#000000" - font-family="Courier" font-style="normal" font-weight="bold" font-size="324" - text-anchor="start" - id="text70">nxttail[RCU_NEXT_READY_TAIL]</text> + id="text70" + style="font-size:324px;font-style:normal;font-weight:bold;text-anchor:start;fill:#000000;font-family:Courier">->tails[RCU_NEXT_READY_TAIL]</text> <!-- Text --> <text xml:space="preserve" x="225" y="5175" - fill="#000000" - font-family="Courier" font-style="normal" font-weight="bold" font-size="324" - text-anchor="start" - id="text72">nxttail[RCU_NEXT_TAIL]</text> + id="text72" + style="font-size:324px;font-style:normal;font-weight:bold;text-anchor:start;fill:#000000;font-family:Courier">->tails[RCU_NEXT_TAIL]</text> <!-- Text --> <text xml:space="preserve"
Documentation/RCU/Design/Expedited-Grace-Periods/Expedited-Grace-Periods.html +44 -3
71 lines not on this page · raw message
Documentation/RCU/Design/Requirements/Requirements.html +138 -57
288 lines not on this page · raw message
Documentation/RCU/rcu_dereference.txt +9 -0
@@ -138,6 +138,15 @@ o Be very careful about comparing pointers obtained from This sort of comparison occurs frequently when scanning RCU-protected circular linked lists. + Note that if checks for being within an RCU read-side + critical section are not required and the pointer is never + dereferenced, rcu_access_pointer() should be used in place + of rcu_dereference(). The rcu_access_pointer() primitive + does not require an enclosing read-side critical section, + and also omits the smp_read_barrier_depends() included in + rcu_dereference(), which in turn should provide a small + performance gain in some CPUs (e.g., the DEC Alpha). + o The comparison is against a pointer that references memory that was initialized "a long time ago." The reason this is safe is that even if misordering occurs, the
Documentation/RCU/rculist_nulls.txt +3 -3
@@ -1,5 +1,5 @@ Using hlist_nulls to protect read-mostly linked lists and -objects using SLAB_DESTROY_BY_RCU allocations. +objects using SLAB_TYPESAFE_BY_RCU allocations. Please read the basics in Documentation/RCU/listRCU.txt
@@ -7,7 +7,7 @@ Using special makers (called 'nulls') is a convenient way to solve following problem : A typical RCU linked list managing objects which are -allocated with SLAB_DESTROY_BY_RCU kmem_cache can +allocated with SLAB_TYPESAFE_BY_RCU kmem_cache can use following algos : 1) Lookup algo
@@ -96,7 +96,7 @@ unlock_chain(); // typically a spin_unlock() 3) Remove algo -------------- Nothing special here, we can use a standard RCU hlist deletion. -But thanks to SLAB_DESTROY_BY_RCU, beware a deleted object can be reused +But thanks to SLAB_TYPESAFE_BY_RCU, beware a deleted object can be reused very very fast (before the end of RCU grace period) if (put_last_reference_on(obj) {
Documentation/RCU/stallwarn.txt +100 -90
204 lines not on this page · raw message
Documentation/RCU/whatisRCU.txt +18 -14
@@ -562,7 +562,9 @@ This section presents a "toy" RCU implementation that is based on familiar locking primitives. Its overhead makes it a non-starter for real-life use, as does its lack of scalability. It is also unsuitable for realtime use, since it allows scheduling latency to "bleed" from -one read-side critical section to another. +one read-side critical section to another. It also assumes recursive +reader-writer locks: If you try this with non-recursive locks, and +you allow nested rcu_read_lock() calls, you can deadlock. However, it is probably the easiest implementation to relate to, so is a good starting point.
@@ -587,20 +589,21 @@ a good starting point. write_unlock(&rcu_gp_mutex); } -[You can ignore rcu_assign_pointer() and rcu_dereference() without -missing much. But here they are anyway. And whatever you do, don't -forget about them when submitting patches making use of RCU!] +[You can ignore rcu_assign_pointer() and rcu_dereference() without missing +much. But here are simplified versions anyway. And whatever you do, +don't forget about them when submitting patches making use of RCU!] - #define rcu_assign_pointer(p, v) ({ \ - smp_wmb(); \ - (p) = (v); \ - }) + #define rcu_assign_pointer(p, v) \ + ({ \ + smp_store_release(&(p), (v)); \ + }) - #define rcu_dereference(p) ({ \ - typeof(p) _________p1 = p; \ - smp_read_barrier_depends(); \ - (_________p1); \ - }) + #define rcu_dereference(p) \ + ({ \ + typeof(p) _________p1 = p; \ + smp_read_barrier_depends(); \ + (_________p1); \ + }) The rcu_read_lock() and rcu_read_unlock() primitive read-acquire
@@ -925,7 +928,8 @@ d. Do you need RCU grace periods to complete even in the face e. Is your workload too update-intensive for normal use of RCU, but inappropriate for other synchronization mechanisms? - If so, consider SLAB_DESTROY_BY_RCU. But please be careful! + If so, consider SLAB_TYPESAFE_BY_RCU (which was originally + named SLAB_DESTROY_BY_RCU). But please be careful! f. Do you need read-side critical sections that are respected even though they are in the middle of the idle loop, during
Documentation/admin-guide/kernel-parameters.txt +8 -0
@@ -3779,6 +3779,14 @@ spia_pedr= spia_peddr= + srcutree.exp_holdoff [KNL] + Specifies how many nanoseconds must elapse + since the end of the last SRCU grace period for + a given srcu_struct until the next normal SRCU + grace period will be considered for automatic + expediting. Set to zero to disable automatic + expediting. + stacktrace [FTRACE] Enabled the stack tracer on boot up.
Documentation/memory-barriers.txt +1 -1
@@ -768,7 +768,7 @@ equal to zero, in which case the compiler is within its rights to transform the above code into the following: q = READ_ONCE(a); - WRITE_ONCE(b, 1); + WRITE_ONCE(b, 2); do_something_else(); Given this transformation, the CPU is not required to respect the ordering
arch/Kconfig +3 -0
@@ -320,6 +320,9 @@ config HAVE_CMPXCHG_LOCAL config HAVE_CMPXCHG_DOUBLE bool +config ARCH_WEAK_RELEASE_ACQUIRE + bool + config ARCH_WANT_IPC_PARSE_VERSION bool
arch/powerpc/Kconfig +1 -0
@@ -99,6 +99,7 @@ config PPC select ARCH_USE_BUILTIN_BSWAP select ARCH_USE_CMPXCHG_LOCKREF if PPC64 select ARCH_WANT_IPC_PARSE_VERSION + select ARCH_WEAK_RELEASE_ACQUIRE select BINFMT_ELF select BUILDTIME_EXTABLE_SORT select CLONE_BACKWARDS
drivers/gpu/drm/i915/i915_gem.c +1 -1
@@ -4665,7 +4665,7 @@ i915_gem_load_init(struct drm_i915_private *dev_priv) dev_priv->requests =KMEM_CACHE (drm_i915_gem_request,SLAB_HWCACHE_ALIGN |SLAB_RECLAIM_ACCOUNT | -SLAB_DESTROY_BY_RCU ); +SLAB_TYPESAFE_BY_RCU );if (!dev_priv->requests) goto err_vmas;
drivers/gpu/drm/i915/i915_gem_request.h +1 -1
@@ -493,7 +493,7 @@ static inline struct drm_i915_gem_request * __i915_gem_active_get_rcu(const struct i915_gem_active *active) {/* Performing a lockless retrieval of the active request is super -* tricky. SLAB_DESTROY_BY_RCU merely guarantees that the backing +* tricky. SLAB_TYPESAFE_BY_RCU merely guarantees that the backing * slab of request objects will not be freed whilst we hold the * RCU read lock. It does not guarantee that the request itself * will not be freed and then *reused*. Viz,
drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c +1 -1
@@ -1071,7 +1071,7 @@ int ldlm_init(void) ldlm_lock_slab =kmem_cache_create ("ldlm_locks" ,sizeof (struct ldlm_lock ),0 ,SLAB_HWCACHE_ALIGN | -SLAB_DESTROY_BY_RCU ,NULL ); +SLAB_TYPESAFE_BY_RCU ,NULL );if (!ldlm_lock_slab) {kmem_cache_destroy (ldlm_resource_slab);return -ENOMEM ;
fs/jbd2/journal.c +1 -1
@@ -2340,7 +2340,7 @@ static int jbd2_journal_init_journal_head_cache(void) jbd2_journal_head_cache =kmem_cache_create ("jbd2_journal_head" ,sizeof (struct journal_head ),0 ,/* offset */ -SLAB_TEMPORARY |SLAB_DESTROY_BY_RCU , +SLAB_TEMPORARY |SLAB_TYPESAFE_BY_RCU ,NULL );/* ctor */ retval =0 ;if (!jbd2_journal_head_cache) {
fs/signalfd.c +1 -1
@@ -38,7 +38,7 @@ void signalfd_cleanup(struct sighand_struct *sighand)/* * The lockless check can race with remove_wait_queue() in progress, * but in this case its caller should run under rcu_read_lock() and -* sighand_cachep is SLAB_DESTROY_BY_RCU, we can safely return. +* sighand_cachep is SLAB_TYPESAFE_BY_RCU, we can safely return. */ if (likely (!waitqueue_active (wqh)))return ;
include/linux/dma-fence.h +2 -2
@@ -229,7 +229,7 @@ static inline struct dma_fence *dma_fence_get_rcu(struct dma_fence *fence)* * Function returns NULL if no refcount could be obtained, or the fence. * This function handles acquiring a reference to a fence that may be -* reallocated within the RCU grace period (such as with SLAB_DESTROY_BY_RCU), +* reallocated within the RCU grace period (such as with SLAB_TYPESAFE_BY_RCU), * so long as the caller is using RCU on the pointer to the fence. * * An alternative mechanism is to employ a seqlock to protect a bunch of
@@ -257,7 +257,7 @@ dma_fence_get_rcu_safe(struct dma_fence * __rcu *fencep)* have successfully acquire a reference to it. If it no * longer matches, we are holding a reference to some other * reallocated pointer. This is possible if the allocator -* is using a freelist like SLAB_DESTROY_BY_RCU where the +* is using a freelist like SLAB_TYPESAFE_BY_RCU where the * fence remains valid for the RCU grace period, but it * may be reallocated. When using such allocators, we are * responsible for ensuring the reference we get is to
include/linux/kvm_host.h +2 -2
@@ -375,8 +375,6 @@ struct kvm {struct mutex slots_lock;struct mm_struct *mm;/* userspace tied to this vm */ struct kvm_memslots *memslots[KVM_ADDRESS_SPACE_NUM ]; -struct srcu_struct srcu; -struct srcu_struct irq_srcu;struct kvm_vcpu *vcpus[KVM_MAX_VCPUS ];/*
@@ -429,6 +427,8 @@ struct kvm {struct list_head devices;struct dentry *debugfs_dentry;struct kvm_stat_data **debugfs_stat_data; +struct srcu_struct srcu; +struct srcu_struct irq_srcu; };#define kvm_err (fmt, ...) \
include/linux/rcu_node_tree.h new file +99 -0
99 lines not on this page · raw message
include/linux/rcu_segcblist.h new file +712 -0
712 lines not on this page · raw message
include/linux/rculist.h +2 -1
@@ -509,7 +509,8 @@ static inline void hlist_add_tail_rcu(struct hlist_node *n, {struct hlist_node *i, *last =NULL ; -for (i =hlist_first_rcu (h); i; i =hlist_next_rcu (i)) +/* Note: write side code, so rcu accessors are not needed. */ +for (i = h->first; i; i = i->next) last = i;if (last) {
include/linux/rcupdate.h +11 -6
@@ -363,15 +363,20 @@ static inline void rcu_init_nohz(void)#ifdef CONFIG_TASKS_RCU #define TASKS_RCU (x) xextern struct srcu_struct tasks_rcu_exit_srcu; -#define rcu_note_voluntary_context_switch (t) \ +#define rcu_note_voluntary_context_switch_lite (t) \ do { \ - rcu_all_qs(); \ if (READ_ONCE((t)->rcu_tasks_holdout)) \ WRITE_ONCE((t)->rcu_tasks_holdout, false); \ } while (0) +#define rcu_note_voluntary_context_switch (t) \ + do { \ + rcu_all_qs(); \ + rcu_note_voluntary_context_switch_lite(t); \ + } while (0)#else /* #ifdef CONFIG_TASKS_RCU */ #define TASKS_RCU (x) do { } while (0) -#define rcu_note_voluntary_context_switch (t) rcu_all_qs() +#define rcu_note_voluntary_context_switch_lite (t) do { } while (0) +#define rcu_note_voluntary_context_switch (t) rcu_all_qs()#endif /* #else #ifdef CONFIG_TASKS_RCU */ /**
@@ -1127,11 +1132,11 @@ do { \* if the UNLOCK and LOCK are executed by the same CPU or if the * UNLOCK and LOCK operate on the same lock variable. */ -#ifdef CONFIG_PPC +#ifdef CONFIG_ARCH_WEAK_RELEASE_ACQUIRE #define smp_mb__after_unlock_lock () smp_mb()/* Full ordering for lock. */ -#else /* #ifdef CONFIG_PPC */ +#else /* #ifdef CONFIG_ARCH_WEAK_RELEASE_ACQUIRE */ #define smp_mb__after_unlock_lock () do { } while (0) -#endif /* #else #ifdef CONFIG_PPC */ +#endif /* #else #ifdef CONFIG_ARCH_WEAK_RELEASE_ACQUIRE */ #endif /* __LINUX_RCUPDATE_H */
include/linux/rcutiny.h +17 -7
@@ -33,6 +33,11 @@ static inline int rcu_dynticks_snap(struct rcu_dynticks *rdtp)return 0 ; } +static inline bool rcu_eqs_special_set (int cpu) +{ +return false;/* Never flag non-existent other CPUs! */ +} +static inline unsigned long get_state_synchronize_rcu (void ) {return 0 ;
@@ -87,10 +92,11 @@ static inline void kfree_call_rcu(struct rcu_head *head,call_rcu (head, func); } -static inline void rcu_note_context_switch (void ) -{ -rcu_sched_qs (); -} +#define rcu_note_context_switch (preempt) \ + do { \ + rcu_sched_qs(); \ + rcu_note_voluntary_context_switch_lite(current); \ + } while (0)/* * Take advantage of the fact that there is only one CPU, which
@@ -212,14 +218,14 @@ static inline void exit_rcu(void) { } -#ifdef CONFIG_DEBUG_LOCK_ALLOC +#if defined(CONFIG_DEBUG_LOCK_ALLOC ) || defined(CONFIG_SRCU )extern int rcu_scheduler_active__read_mostly ;void rcu_scheduler_starting (void ); -#else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */ +#else /* #if defined(CONFIG_DEBUG_LOCK_ALLOC) || defined(CONFIG_SRCU) */ static inline void rcu_scheduler_starting (void ) { } -#endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */ +#endif /* #else #if defined(CONFIG_DEBUG_LOCK_ALLOC) || defined(CONFIG_SRCU) */ #if defined(CONFIG_DEBUG_LOCK_ALLOC ) || defined(CONFIG_RCU_TRACE )
@@ -237,6 +243,10 @@ static inline bool rcu_is_watching(void)#endif /* #else defined(CONFIG_DEBUG_LOCK_ALLOC) || defined(CONFIG_RCU_TRACE) */ +static inline void rcu_request_urgent_qs_task (struct task_struct *t) +{ +} +static inline void rcu_all_qs (void ) {barrier ();/* Avoid RCU read-side critical sections leaking across. */
include/linux/rcutree.h +3 -2
@@ -30,7 +30,7 @@#ifndef __LINUX_RCUTREE_H#define __LINUX_RCUTREE_H -void rcu_note_context_switch (void ); +void rcu_note_context_switch (bool preempt);int rcu_needs_cpu (u64 basem,u64 *nextevt);void rcu_cpu_stall_reset (void );
@@ -41,7 +41,7 @@ void rcu_cpu_stall_reset(void);*/ static inline void rcu_virt_note_context_switch (int cpu) { -rcu_note_context_switch (); +rcu_note_context_switch (false); }void synchronize_rcu_bh (void );
@@ -108,6 +108,7 @@ void rcu_scheduler_starting(void);extern int rcu_scheduler_active__read_mostly ;bool rcu_is_watching (void ); +void rcu_request_urgent_qs_task (struct task_struct *t);void rcu_all_qs (void );
include/linux/slab.h +4 -2
@@ -28,7 +28,7 @@#define SLAB_STORE_USER 0x00010000UL/* DEBUG: Store the last owner for bug hunting */ #define SLAB_PANIC 0x00040000UL/* Panic if kmem_cache_create() fails */ /* -* SLAB_DESTROY_BY_RCU - **WARNING** READ THIS! +* SLAB_TYPESAFE_BY_RCU - **WARNING** READ THIS! * * This delays freeing the SLAB page by a grace period, it does _NOT_ * delay object freeing. This means that if you do kmem_cache_free()
@@ -61,8 +61,10 @@* * rcu_read_lock before reading the address, then rcu_read_unlock after * taking the spinlock within the structure expected at that address. +* +* Note that SLAB_TYPESAFE_BY_RCU was originally named SLAB_DESTROY_BY_RCU. */ -#define SLAB_DESTROY_BY_RCU 0x00080000UL/* Defer freeing slabs to RCU */ +#define SLAB_TYPESAFE_BY_RCU 0x00080000UL/* Defer freeing slabs to RCU */ #define SLAB_MEM_SPREAD 0x00100000UL/* Spread some memory over cpuset */ #define SLAB_TRACE 0x00200000UL/* Trace allocations and frees */
include/linux/srcu.h +12 -72
109 lines not on this page · raw message
include/linux/srcuclassic.h new file +115 -0
115 lines not on this page · raw message
include/linux/srcutiny.h new file +93 -0
93 lines not on this page · raw message
include/linux/srcutree.h new file +150 -0
150 lines not on this page · raw message
include/linux/types.h +1 -1
@@ -209,7 +209,7 @@ struct ustat {* naturally due ABI requirements, but some architectures (like CRIS) have * weird ABI and we need to ask it explicitly. * -* The alignment is required to guarantee that bits 0 and 1 of @next will be +* The alignment is required to guarantee that bit 0 of @next will be * clear under normal conditions -- as long as we use call_rcu(), * call_rcu_bh(), call_rcu_sched(), or call_srcu() to queue callback. *
include/net/sock.h +1 -1
@@ -995,7 +995,7 @@ struct smc_hashinfo;struct module ;/* -* caches using SLAB_DESTROY_BY_RCU should let .next pointer from nulls nodes +* caches using SLAB_TYPESAFE_BY_RCU should let .next pointer from nulls nodes * un-modified. Special care is taken when initializing object to zero. */ static inline void sk_prot_clear_nulls (struct sock *sk,int size)
init/Kconfig +38 -2
@@ -521,11 +521,41 @@ config RCU_EXPERT config SRCU bool + default y help This option selects the sleepable version of RCU. This version permits arbitrary sleeping or blocking within RCU read-side critical sections. +config CLASSIC_SRCU + bool "Use v4.11 classic SRCU implementation" + default n + depends on RCU_EXPERT && SRCU + help + This option selects the traditional well-tested classic SRCU + implementation from v4.11, as might be desired for enterprise + Linux distributions. Without this option, the shiny new + Tiny SRCU and Tree SRCU implementations are used instead. + At some point, it is hoped that Tiny SRCU and Tree SRCU + will accumulate enough test time and confidence to allow + Classic SRCU to be dropped entirely. + + Say Y if you need a rock-solid SRCU. + + Say N if you would like help test Tree SRCU. + +config TINY_SRCU + bool + default y if SRCU && TINY_RCU && !CLASSIC_SRCU + help + This option selects the single-CPU non-preemptible version of SRCU. + +config TREE_SRCU + bool + default y if SRCU && !TINY_RCU && !CLASSIC_SRCU + help + This option selects the full-fledged version of SRCU. + config TASKS_RCU bool default n
@@ -612,11 +642,17 @@ config RCU_FANOUT_LEAF initialization. These systems tend to run CPU-bound, and thus are not helped by synchronized interrupts, and thus tend to skew them, which reduces lock contention enough that large - leaf-level fanouts work well. + leaf-level fanouts work well. That said, setting leaf-level + fanout to a large number will likely cause problematic + lock contention on the leaf-level rcu_node structures unless + you boot with the skew_tick kernel parameter. Select a specific number if testing RCU itself. - Select the maximum permissible value for large systems. + Select the maximum permissible value for large systems, but + please understand that you may also need to set the skew_tick + kernel boot parameter to avoid contention on the rcu_node + structure's locks. Take the default if unsure.
kernel/fork.c +2 -2
@@ -1313,7 +1313,7 @@ void __cleanup_sighand(struct sighand_struct *sighand)if (atomic_dec_and_test (&sighand->count)) {signalfd_cleanup (sighand);/* -* sighand_cachep is SLAB_DESTROY_BY_RCU so we can free it +* sighand_cachep is SLAB_TYPESAFE_BY_RCU so we can free it * without an RCU grace period, see __lock_task_sighand(). */ kmem_cache_free (sighand_cachep, sighand);
@@ -2144,7 +2144,7 @@ void __init proc_caches_init(void) { sighand_cachep =kmem_cache_create ("sighand_cache" ,sizeof (struct sighand_struct ),0 , -SLAB_HWCACHE_ALIGN |SLAB_PANIC |SLAB_DESTROY_BY_RCU | +SLAB_HWCACHE_ALIGN |SLAB_PANIC |SLAB_TYPESAFE_BY_RCU |SLAB_NOTRACK |SLAB_ACCOUNT , sighand_ctor); signal_cachep = kmem_cache_create("signal_cache", sizeof(struct signal_struct), 0,
kernel/locking/lockdep.c +43 -43
185 lines not on this page · raw message
kernel/locking/rtmutex-debug.c +5 -4
@@ -102,10 +102,11 @@ void debug_rt_mutex_print_deadlock(struct rt_mutex_waiter *waiter)return ; } -printk ("\n============================================\n" ); -printk ("[ BUG: circular locking deadlock detected! ]\n" ); -printk ("%s\n" ,print_tainted ()); -printk ("--------------------------------------------\n" ); +pr_warn ("\n" ); +pr_warn ("============================================\n" ); +pr_warn ("WARNING: circular locking deadlock detected!\n" ); +pr_warn ("%s\n" ,print_tainted ()); +pr_warn ("--------------------------------------------\n" );printk ("%s/%d is deadlocking current task %s/%d\n\n" , task->comm,task_pid_nr (task), current->comm,task_pid_nr (current));
kernel/rcu/Makefile +3 -1
@@ -3,7 +3,9 @@ KCOV_INSTRUMENT := n obj-y += update.o sync.o -obj-$(CONFIG_SRCU) += srcu.o +obj-$(CONFIG_CLASSIC_SRCU) += srcu.o +obj-$(CONFIG_TREE_SRCU) += srcutree.o +obj-$(CONFIG_TINY_SRCU) += srcutiny.o obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o obj-$(CONFIG_RCU_PERF_TEST) += rcuperf.o obj-$(CONFIG_TREE_RCU) += tree.o
kernel/rcu/rcu.h +151 -2
140 lines not on this page · raw message
kernel/rcu/rcutorture.c +36 -7
43 lines not on this page · raw message
kernel/rcu/srcutiny.c new file +215 -0
215 lines not on this page · raw message
kernel/rcu/srcutree.c new file +1154 -0
1,154 lines not on this page · raw message
kernel/rcu/tree.c +293 -415
708 lines not on this page · raw message
kernel/rcu/tree.h +20 -144
164 lines not on this page · raw message
kernel/rcu/tree_plugin.h +32 -32
64 lines not on this page · raw message
kernel/rcu/update.c +35 -18
53 lines not on this page · raw message
tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh +1 -1
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
Quoted 5 lines · Ingo Molnar
Linus,
Please pull the latest core-rcu-for-linus git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.gitcore-rcu-for-linus
I pulled this, and then after looking at it, ended up un-pulling it again.
I refuse to take that nasty <linux/rcu_segcblist.h> header file from hell.
I see absolutely no point in taking a header file of several hundred lines of code.
We have traditionally done too much inline code anyway, but we've learnt our lesson - and even back when we did too much of it, we didn't put random code that nobody uses and by definition cannot be performance-critical in big inline functions in header files.
If it was some one-liner helper function, that would be one thing. But there are functions that don't even fit on the screen, and that have multiple loops and memory barriers in them.
The one function I decided to grep for was used EXACTLY NOWHERE. Yet it was apparently SO INCREDIBLY important that it needed to be inlined in a huge header file despite being huge and complicated.
So no. This is too ugly to live, and certainly too ugly to be pulled.
The RCU code needs to start showing some good taste.
There are valid reasons to inline even large functions, if they have constant arguments that make us expect them to generate a single instruction of code in the end. But that was very much not the case here.
Not pulling. Try again next merge window when the code has been cleaned up and isn't too ugly to live.
Linus
Quoted 31 lines · Linus Torvalds
Quoted 5 lines · Ingo Molnar
Linus,
Please pull the latest core-rcu-for-linus git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.gitcore-rcu-for-linusI pulled this, and then after looking at it, ended up un-pulling it again.
I refuse to take that nasty <
linux/rcu_segcblist.h> header file from hell.I see absolutely no point in taking a header file of several hundred lines of code.
We have traditionally done too much inline code anyway, but we've learnt our lesson - and even back when we did too much of it, we didn't put random code that nobody uses and by definition cannot be performance-critical in big inline functions in header files.
If it was some one-liner helper function, that would be one thing. But there are functions that don't even fit on the screen, and that have multiple loops and memory barriers in them.
The one function I decided to grep for was used EXACTLY NOWHERE. Yet it was apparently SO INCREDIBLY important that it needed to be inlined in a huge header file despite being huge and complicated.
So no. This is too ugly to live, and certainly too ugly to be pulled.
The RCU code needs to start showing some good taste.
Quoted 7 lines
There are valid reasons to inline even large functions, if they have constant arguments that make us expect them to generate a single instruction of code in the end. But that was very much not the case here.
Not pulling. Try again next merge window when the code has been cleaned up and isn't too ugly to live.
Please accept my apologies!
I was patterning this code too much after the various *list*.h header files, and failed to notice that the functions were getting large. I will get rid of the unused rcu_segcblist_extract_all() function and create a kernel/rcu/segcblist.c for the functions that are either non-trivial or performance-insensitive.
Does that cover it, or am I missing something?
Thanx, Paul
Quoted 6 lines · Paul E. McKenney
I will get rid of the unused
rcu_segcblist_extract_all()function and create akernel/rcu/segcblist.cfor the functions that are either non-trivial or performance-insensitive.Does that cover it, or am I missing something?
That's the part I reacted to while reading through the patch, and your suggested fix sounds good to me.
Linus
Quoted 11 lines · Linus Torvalds
Quoted 6 lines · Paul E. McKenney
I will get rid of the unused
rcu_segcblist_extract_all()function and create akernel/rcu/segcblist.cfor the functions that are either non-trivial or performance-insensitive.Does that cover it, or am I missing something?
That's the part I reacted to while reading through the patch, and your suggested fix sounds good to me.
Thank you for the confirmation!
Thanx, Paul
Quoted 37 lines · Paul E. McKenney
Quoted 36 lines · Linus Torvalds
Quoted 5 lines · Ingo Molnar
Linus,
Please pull the latest core-rcu-for-linus git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.gitcore-rcu-for-linusI pulled this, and then after looking at it, ended up un-pulling it again.
I refuse to take that nasty <
linux/rcu_segcblist.h> header file from hell.I see absolutely no point in taking a header file of several hundred lines of code.
We have traditionally done too much inline code anyway, but we've learnt our lesson - and even back when we did too much of it, we didn't put random code that nobody uses and by definition cannot be performance-critical in big inline functions in header files.
If it was some one-liner helper function, that would be one thing. But there are functions that don't even fit on the screen, and that have multiple loops and memory barriers in them.
The one function I decided to grep for was used EXACTLY NOWHERE. Yet it was apparently SO INCREDIBLY important that it needed to be inlined in a huge header file despite being huge and complicated.
So no. This is too ugly to live, and certainly too ugly to be pulled.
The RCU code needs to start showing some good taste.
There are valid reasons to inline even large functions, if they have constant arguments that make us expect them to generate a single instruction of code in the end. But that was very much not the case here.
Quoted 7 lines
Quoted 2 lines
Not pulling. Try again next merge window when the code has been cleaned up and isn't too ugly to live.
Please accept my apologies!
I was patterning this code too much after the various *list*.h header files, and failed to notice that the functions were getting large.
I too should have noticed the large inline functions when pulling it. :-/
Header file bloat is a creeping problem that has gotten (much) worse over the last 10 years, so the pushback from Linus against adding more bloat to include/linux/ is fully justified.
Quoted 5 lines
I will get rid of the unused
rcu_segcblist_extract_all()function and create akernel/rcu/segcblist.cfor the functions that are either non-trivial or performance-insensitive.Does that cover it, or am I missing something?
I'd also suggest moving as much of the RCU internal data types into kernel/rcu/ as possible. It's not clear to me which part of it is supposed to be a public API and which bits are internal. It might make sense to keep it internal for the time being, and only export things once there are users.
I.e. a pretty good solution would be to move all of include/linux/rcu_segcblist.h to kernel/rcu/rcu_segcblist.c or so - and do a kernel/rcu/rcu_segcblist.h with the data types and function prototypes.
There's also appears to be inline functions wrappery that I think obfuscates the
code: for example why is there rcu_cblist_n_cbs()? Users could directly dereference ->len. Once these are eliminated there's very few inline functions remaining that should truly be inline.
Thanks,
Ingo
PATCH 1/1 srcu: Debloat the <linux/rcu_segcblist.h> header
Quoted 6 lines · Ingo Molnar
Quoted 5 lines
I will get rid of the unused
rcu_segcblist_extract_all()function and create akernel/rcu/segcblist.cfor the functions that are either non-trivial or performance-insensitive.Does that cover it, or am I missing something?
Quoted 8 lines
I'd also suggest moving as much of the RCU internal data types into
kernel/rcu/as possible. It's not clear to me which part of it is supposed to be a public API and which bits are internal. It might make sense to keep it internal for the time being, and only export things once there are users.I.e. a pretty good solution would be to move all of
include/linux/rcu_segcblist.htokernel/rcu/rcu_segcblist.cor so - and do akernel/rcu/rcu_segcblist.hwith the data types and function prototypes.
I.e. the attached patch as a first step.
Only minimally build tested, but it appears to be do the trick.
This changes the <linux/rcu_segcblist.h> header from ~700 lines to only 90 lines - 60% of which is comments.
The deinlining of the inline functions within kernel/rcu/ should also be done, as a separate patch on top of this.
What do you think?
This could also be a model to factor out and deinline other bits of the RCU machinery as much as possible.
Thanks,
Ingo
====================>
Quoted 1 line
From
484c73f6a8b28d018d1988e55e38178aac83a1d7Mon Sep 17 00:00:00 2001
From: Ingo Molnar <[email protected]>
Date: Tue, 2 May 2017 10:17:10 +0200
Subject: [PATCH] srcu: Debloat the <linux/rcu_segcblist.h> header
Linus noticed that the <linux/rcu_segcblist.h> has huge inline functions which should not be inline at all.
As a first step in cleaning this up, move them all to kernel/rcu/ and only keep an absolute minimum of data type defines in the header:
before: -rw-r--r-- 1 mingo mingo 22284 May 2 10:25 include/linux/rcu_segcblist.h after: -rw-r--r-- 1 mingo mingo 3180 May 2 10:22 include/linux/rcu_segcblist.h
More can be done, such as uninlining the large functions, which inlining is unjustified even if it's an RCU internal matter.
--- include/linux/rcu_segcblist.h | 628 +--------------------------------------- kernel/rcu/rcu_segcblist.h | 645 ++++++++++++++++++++++++++++++++++++++++++ kernel/rcu/srcutree.c | 1 + kernel/rcu/tree.h | 3 +- 4 files changed, 651 insertions(+), 626 deletions(-)
include/linux/rcu_segcblist.h +3 -625
@@ -20,8 +20,8 @@* Authors: Paul E. McKenney <[email protected]> */ -#ifndef __KERNEL_RCU_SEGCBLIST_H -#define __KERNEL_RCU_SEGCBLIST_H +#ifndef __INCLUDE_LINUX_RCU_SEGCBLIST_H +#define __INCLUDE_LINUX_RCU_SEGCBLIST_H/* Simple unsegmented callback lists. */ struct rcu_cblist {
@@ -33,102 +33,6 @@ struct rcu_cblist {#define RCU_CBLIST_INITIALIZER (n) { .head = NULL, .tail = &n.head } -/* Initialize simple callback list. */ -static inline void rcu_cblist_init (struct rcu_cblist *rclp) -{ - rclp->head =NULL ; - rclp->tail = &rclp->head; - rclp->len =0 ; - rclp->len_lazy =0 ; -} - -/* Is simple callback list empty? */ -static inline bool rcu_cblist_empty (struct rcu_cblist *rclp) -{ -return !rclp->head; -} - -/* Return number of callbacks in simple callback list. */ -static inline long rcu_cblist_n_cbs (struct rcu_cblist *rclp) -{ -return rclp->len; -} - -/* Return number of lazy callbacks in simple callback list. */ -static inline long rcu_cblist_n_lazy_cbs (struct rcu_cblist *rclp) -{ -return rclp->len_lazy; -} - -/* -* Debug function to actually count the number of callbacks. -* If the number exceeds the limit specified, return -1. -*/ -static inline long rcu_cblist_count_cbs (struct rcu_cblist *rclp,long lim) -{ -int cnt =0 ; -struct rcu_head **rhpp = &rclp->head; - -for (;;) { -if (!*rhpp) -return cnt; -if (++cnt > lim) -return -1 ; - rhpp = &(*rhpp)->next; - } -} - -/* -* Dequeue the oldest rcu_head structure from the specified callback -* list. This function assumes that the callback is non-lazy, but -* the caller can later invoke rcu_cblist_dequeued_lazy() if it -* finds otherwise (and if it cares about laziness). This allows -* different users to have different ways of determining laziness. -*/ -static inline struct rcu_head *rcu_cblist_dequeue (struct rcu_cblist *rclp) -{ -struct rcu_head *rhp; - - rhp = rclp->head; -if (!rhp) -return NULL ; - rclp->len--; - rclp->head = rhp->next; -if (!rclp->head) - rclp->tail = &rclp->head; -return rhp; -} - -/* -* Account for the fact that a previously dequeued callback turned out -* to be marked as lazy. -*/ -static inline void rcu_cblist_dequeued_lazy (struct rcu_cblist *rclp) -{ - rclp->len_lazy--; -} - -/* -* Interim function to return rcu_cblist head pointer. Longer term, the -* rcu_cblist will be used more pervasively, removing the need for this -* function. -*/ -static inline struct rcu_head *rcu_cblist_head (struct rcu_cblist *rclp) -{ -return rclp->head; -} - -/* -* Interim function to return rcu_cblist head pointer. Longer term, the -* rcu_cblist will be used more pervasively, removing the need for this -* function. -*/ -static inline struct rcu_head **rcu_cblist_tail (struct rcu_cblist *rclp) -{ -WARN_ON_ONCE (rcu_cblist_empty (rclp)); -return rclp->tail; -} -/* Complicated segmented callback lists. ;-) */ /*
@@ -183,530 +87,4 @@ struct rcu_segcblist { .tails[RCU_NEXT_TAIL] = &n.head, \ } -/* -* Initialize an rcu_segcblist structure. -*/ -static inline void rcu_segcblist_init (struct rcu_segcblist *rsclp) -{ -int i; - -BUILD_BUG_ON (RCU_NEXT_TAIL +1 !=ARRAY_SIZE (rsclp->gp_seq)); -BUILD_BUG_ON (ARRAY_SIZE (rsclp->tails) !=ARRAY_SIZE (rsclp->gp_seq)); - rsclp->head =NULL ; -for (i =0 ; i <RCU_CBLIST_NSEGS ; i++) - rsclp->tails[i] = &rsclp->head; - rsclp->len =0 ; - rsclp->len_lazy =0 ; -} - -/* -* Is the specified rcu_segcblist structure empty? -* -* But careful! The fact that the ->head field is NULL does not -* necessarily imply that there are no callbacks associated with -* this structure. When callbacks are being invoked, they are -* removed as a group. If callback invocation must be preempted, -* the remaining callbacks will be added back to the list. Either -* way, the counts are updated later. -* -* So it is often the case that rcu_segcblist_n_cbs() should be used -* instead. -*/ -static inline bool rcu_segcblist_empty (struct rcu_segcblist *rsclp) -{ -return !rsclp->head; -} - -/* Return number of callbacks in segmented callback list. */ -static inline long rcu_segcblist_n_cbs (struct rcu_segcblist *rsclp) -{ -return READ_ONCE (rsclp->len); -} - -/* Return number of lazy callbacks in segmented callback list. */ -static inline long rcu_segcblist_n_lazy_cbs (struct rcu_segcblist *rsclp) -{ -return rsclp->len_lazy; -} - -/* Return number of lazy callbacks in segmented callback list. */ -static inline long rcu_segcblist_n_nonlazy_cbs (struct rcu_segcblist *rsclp) -{ -return rsclp->len - rsclp->len_lazy; -} - -/* -* Is the specified rcu_segcblist enabled, for example, not corresponding -* to an offline or callback-offloaded CPU? -*/ -static inline bool rcu_segcblist_is_enabled (struct rcu_segcblist *rsclp) -{ -return !!rsclp->tails[RCU_NEXT_TAIL ]; -} - -/* -* Disable the specified rcu_segcblist structure, so that callbacks can -* no longer be posted to it. This structure must be empty. -*/ -static inline void rcu_segcblist_disable (struct rcu_segcblist *rsclp) -{ -WARN_ON_ONCE (!rcu_segcblist_empty (rsclp)); -WARN_ON_ONCE (rcu_segcblist_n_cbs (rsclp)); -WARN_ON_ONCE (rcu_segcblist_n_lazy_cbs (rsclp)); - rsclp->tails[RCU_NEXT_TAIL ] =NULL ; -} - -/* -* Is the specified segment of the specified rcu_segcblist structure -* empty of callbacks? -*/ -static inline bool rcu_segcblist_segempty (struct rcu_segcblist *rsclp,int seg) -{ -if (seg ==RCU_DONE_TAIL ) -return &rsclp->head == rsclp->tails[RCU_DONE_TAIL ]; -return rsclp->tails[seg -1 ] == rsclp->tails[seg]; -} - -/* -* Are all segments following the specified segment of the specified -* rcu_segcblist structure empty of callbacks? (The specified -* segment might well contain callbacks.) -*/ -static inline bool rcu_segcblist_restempty (struct rcu_segcblist *rsclp,int seg) -{ -return !*rsclp->tails[seg]; -} - -/* -* Does the specified rcu_segcblist structure contain callbacks that -* are ready to be invoked? -*/ -static inline bool rcu_segcblist_ready_cbs (struct rcu_segcblist *rsclp) -{ -return rcu_segcblist_is_enabled (rsclp) && - &rsclp->head != rsclp->tails[RCU_DONE_TAIL ]; -} - -/* -* Does the specified rcu_segcblist structure contain callbacks that -* are still pending, that is, not yet ready to be invoked? -*/ -static inline bool rcu_segcblist_pend_cbs (struct rcu_segcblist *rsclp) -{ -return rcu_segcblist_is_enabled (rsclp) && - !rcu_segcblist_restempty (rsclp,RCU_DONE_TAIL ); -} - -/* -* Dequeue and return the first ready-to-invoke callback. If there -* are no ready-to-invoke callbacks, return NULL. Disables interrupts -* to avoid interference. Does not protect from interference from other -* CPUs or tasks. -*/ -static inline struct rcu_head * -rcu_segcblist_dequeue (struct rcu_segcblist *rsclp) -{ -unsigned long flags; -int i; -struct rcu_head *rhp; - -local_irq_save (flags); -if (!rcu_segcblist_ready_cbs (rsclp)) { -local_irq_restore (flags); -return NULL ; - } - rhp = rsclp->head; -BUG_ON (!rhp); - rsclp->head = rhp->next; -for (i =RCU_DONE_TAIL ; i <RCU_CBLIST_NSEGS ; i++) { -if (rsclp->tails[i] != &rhp->next) -break ; - rsclp->tails[i] = &rsclp->head; - } -smp_mb ();/* Dequeue before decrement for rcu_barrier(). */ -WRITE_ONCE (rsclp->len, rsclp->len -1 ); -local_irq_restore (flags); -return rhp; -} - -/* -* Account for the fact that a previously dequeued callback turned out -* to be marked as lazy. -*/ -static inline void rcu_segcblist_dequeued_lazy (struct rcu_segcblist *rsclp) -{ -unsigned long flags; - -local_irq_save (flags); - rsclp->len_lazy--; -local_irq_restore (flags); -} - -/* -* Return a pointer to the first callback in the specified rcu_segcblist -* structure. This is useful for diagnostics. -*/ -static inline struct rcu_head * -rcu_segcblist_first_cb (struct rcu_segcblist *rsclp) -{ -if (rcu_segcblist_is_enabled (rsclp)) -return rsclp->head; -return NULL ; -} - -/* -* Return a pointer to the first pending callback in the specified -* rcu_segcblist structure. This is useful just after posting a given -* callback -- if that callback is the first pending callback, then -* you cannot rely on someone else having already started up the required -* grace period. -*/ -static inline struct rcu_head * -rcu_segcblist_first_pend_cb (struct rcu_segcblist *rsclp) -{ -if (rcu_segcblist_is_enabled (rsclp)) -return *rsclp->tails[RCU_DONE_TAIL ]; -return NULL ; -} - -/* -* Does the specified rcu_segcblist structure contain callbacks that -* have not yet been processed beyond having been posted, that is, -* does it contain callbacks in its last segment? -*/ -static inline bool rcu_segcblist_new_cbs (struct rcu_segcblist *rsclp) -{ -return rcu_segcblist_is_enabled (rsclp) && - !rcu_segcblist_restempty (rsclp,RCU_NEXT_READY_TAIL ); -} - -/* -* Enqueue the specified callback onto the specified rcu_segcblist -* structure, updating accounting as needed. Note that the ->len -* field may be accessed locklessly, hence the WRITE_ONCE(). -* The ->len field is used by rcu_barrier() and friends to determine -* if it must post a callback on this structure, and it is OK -* for rcu_barrier() to sometimes post callbacks needlessly, but -* absolutely not OK for it to ever miss posting a callback. -*/ -static inline void rcu_segcblist_enqueue (struct rcu_segcblist *rsclp, -struct rcu_head *rhp,bool lazy) -{ -WRITE_ONCE (rsclp->len, rsclp->len +1 );/* ->len sampled locklessly. */ -if (lazy) - rsclp->len_lazy++; -smp_mb ();/* Ensure counts are updated before callback is enqueued. */ - rhp->next =NULL ; - *rsclp->tails[RCU_NEXT_TAIL ] = rhp; - rsclp->tails[RCU_NEXT_TAIL ] = &rhp->next; -} - -/* -* Entrain the specified callback onto the specified rcu_segcblist at -* the end of the last non-empty segment. If the entire rcu_segcblist -* is empty, make no change, but return false. -* -* This is intended for use by rcu_barrier()-like primitives, -not- -* for normal grace-period use. IMPORTANT: The callback you enqueue -* will wait for all prior callbacks, NOT necessarily for a grace -* period. You have been warned. -*/ -static inline bool rcu_segcblist_entrain (struct rcu_segcblist *rsclp, -struct rcu_head *rhp,bool lazy) -{ -int i; - -if (rcu_segcblist_n_cbs (rsclp) ==0 ) -return false; -WRITE_ONCE (rsclp->len, rsclp->len +1 ); -if (lazy) - rsclp->len_lazy++; -smp_mb ();/* Ensure counts are updated before callback is entrained. */ - rhp->next =NULL ; -for (i =RCU_NEXT_TAIL ; i >RCU_DONE_TAIL ; i--) -if (rsclp->tails[i] != rsclp->tails[i -1 ]) -break ; - *rsclp->tails[i] = rhp; -for (; i <=RCU_NEXT_TAIL ; i++) - rsclp->tails[i] = &rhp->next; -return true; -} - -/* -* Extract only the counts from the specified rcu_segcblist structure, -* and place them in the specified rcu_cblist structure. This function -* supports both callback orphaning and invocation, hence the separation -* of counts and callbacks. (Callbacks ready for invocation must be -* orphaned and adopted separately from pending callbacks, but counts -* apply to all callbacks. Locking must be used to make sure that -* both orphaned-callbacks lists are consistent.) -*/ -static inline void rcu_segcblist_extract_count (struct rcu_segcblist *rsclp, -struct rcu_cblist *rclp) -{ - rclp->len_lazy += rsclp->len_lazy; - rclp->len += rsclp->len; - rsclp->len_lazy =0 ; -WRITE_ONCE (rsclp->len,0 );/* ->len sampled locklessly. */ -} - -/* -* Extract only those callbacks ready to be invoked from the specified -* rcu_segcblist structure and place them in the specified rcu_cblist -* structure. -*/ -static inline void rcu_segcblist_extract_done_cbs (struct rcu_segcblist *rsclp, -struct rcu_cblist *rclp) -{ -int i; - -if (!rcu_segcblist_ready_cbs (rsclp)) -return ;/* Nothing to do. */ - *rclp->tail = rsclp->head; - rsclp->head = *rsclp->tails[RCU_DONE_TAIL ]; - *rsclp->tails[RCU_DONE_TAIL ] =NULL ; - rclp->tail = rsclp->tails[RCU_DONE_TAIL ]; -for (i =RCU_CBLIST_NSEGS -1 ; i >=RCU_DONE_TAIL ; i--) -if (rsclp->tails[i] == rsclp->tails[RCU_DONE_TAIL ]) - rsclp->tails[i] = &rsclp->head; -} - -/* -* Extract only those callbacks still pending (not yet ready to be -* invoked) from the specified rcu_segcblist structure and place them in -* the specified rcu_cblist structure. Note that this loses information -* about any callbacks that might have been partway done waiting for -* their grace period. Too bad! They will have to start over. -*/ -static inline void -rcu_segcblist_extract_pend_cbs (struct rcu_segcblist *rsclp, -struct rcu_cblist *rclp) -{ -int i; - -if (!rcu_segcblist_pend_cbs (rsclp)) -return ;/* Nothing to do. */ - *rclp->tail = *rsclp->tails[RCU_DONE_TAIL ]; - rclp->tail = rsclp->tails[RCU_NEXT_TAIL ]; - *rsclp->tails[RCU_DONE_TAIL ] =NULL ; -for (i =RCU_DONE_TAIL +1 ; i <RCU_CBLIST_NSEGS ; i++) - rsclp->tails[i] = rsclp->tails[RCU_DONE_TAIL ]; -} - -/* -* Move the entire contents of the specified rcu_segcblist structure, -* counts, callbacks, and all, to the specified rcu_cblist structure. -* @@@ Why do we need this??? Moving early-boot CBs to NOCB lists? -* @@@ Memory barrier needed? (Not if only used at boot time...) -*/ -static inline void rcu_segcblist_extract_all (struct rcu_segcblist *rsclp, -struct rcu_cblist *rclp) -{ -rcu_segcblist_extract_done_cbs (rsclp, rclp); -rcu_segcblist_extract_pend_cbs (rsclp, rclp); -rcu_segcblist_extract_count (rsclp, rclp); -} - -/* -* Insert counts from the specified rcu_cblist structure in the -* specified rcu_segcblist structure. -*/ -static inline void rcu_segcblist_insert_count (struct rcu_segcblist *rsclp, -struct rcu_cblist *rclp) -{ - rsclp->len_lazy += rclp->len_lazy; -/* ->len sampled locklessly. */ -WRITE_ONCE (rsclp->len, rsclp->len + rclp->len); - rclp->len_lazy =0 ; - rclp->len =0 ; -} - -/* -* Move callbacks from the specified rcu_cblist to the beginning of the -* done-callbacks segment of the specified rcu_segcblist. -*/ -static inline void rcu_segcblist_insert_done_cbs (struct rcu_segcblist *rsclp, -struct rcu_cblist *rclp) -{ -int i; - -if (!rclp->head) -return ;/* No callbacks to move. */ - *rclp->tail = rsclp->head; - rsclp->head = rclp->head; -for (i =RCU_DONE_TAIL ; i <RCU_CBLIST_NSEGS ; i++) -if (&rsclp->head == rsclp->tails[i]) - rsclp->tails[i] = rclp->tail; -else -break ; - rclp->head =NULL ; - rclp->tail = &rclp->head; -} - -/* -* Move callbacks from the specified rcu_cblist to the end of the -* new-callbacks segment of the specified rcu_segcblist. -*/ -static inline void rcu_segcblist_insert_pend_cbs (struct rcu_segcblist *rsclp, -struct rcu_cblist *rclp) -{ -if (!rclp->head) -return ;/* Nothing to do. */ - *rsclp->tails[RCU_NEXT_TAIL ] = rclp->head; - rsclp->tails[RCU_NEXT_TAIL ] = rclp->tail; - rclp->head =NULL ; - rclp->tail = &rclp->head; -} - -/* -* Advance the callbacks in the specified rcu_segcblist structure based -* on the current value passed in for the grace-period counter. -*/ -static inline void rcu_segcblist_advance (struct rcu_segcblist *rsclp, -unsigned long seq) -{ -int i, j; - -WARN_ON_ONCE (!rcu_segcblist_is_enabled (rsclp)); -if (rcu_segcblist_restempty (rsclp,RCU_DONE_TAIL )) -return ; - -/* -* Find all callbacks whose ->gp_seq numbers indicate that they -* are ready to invoke, and put them into the RCU_DONE_TAIL segment. -*/ -for (i =RCU_WAIT_TAIL ; i <RCU_NEXT_TAIL ; i++) { -if (ULONG_CMP_LT (seq, rsclp->gp_seq[i])) -break ; - rsclp->tails[RCU_DONE_TAIL ] = rsclp->tails[i]; - } - -/* If no callbacks moved, nothing more need be done. */ -if (i ==RCU_WAIT_TAIL ) -return ; - -/* Clean up tail pointers that might have been misordered above. */ -for (j =RCU_WAIT_TAIL ; j < i; j++) - rsclp->tails[j] = rsclp->tails[RCU_DONE_TAIL ]; - -/* -* Callbacks moved, so clean up the misordered ->tails[] pointers -* that now point into the middle of the list of ready-to-invoke -* callbacks. The overall effect is to copy down the later pointers -* into the gap that was created by the now-ready segments. -*/ -for (j =RCU_WAIT_TAIL ; i <RCU_NEXT_TAIL ; i++, j++) { -if (rsclp->tails[j] == rsclp->tails[RCU_NEXT_TAIL ]) -break ;/* No more callbacks. */ - rsclp->tails[j] = rsclp->tails[i]; - rsclp->gp_seq[j] = rsclp->gp_seq[i]; - } -} - -/* -* "Accelerate" callbacks based on more-accurate grace-period information. -* The reason for this is that RCU does not synchronize the beginnings and -* ends of grace periods, and that callbacks are posted locally. This in -* turn means that the callbacks must be labelled conservatively early -* on, as getting exact information would degrade both performance and -* scalability. When more accurate grace-period information becomes -* available, previously posted callbacks can be "accelerated", marking -* them to complete at the end of the earlier grace period. -* -* This function operates on an rcu_segcblist structure, and also the -* grace-period sequence number seq at which new callbacks would become -* ready to invoke. Returns true if there are callbacks that won't be -* ready to invoke until seq, false otherwise. -*/ -static inline bool rcu_segcblist_accelerate (struct rcu_segcblist *rsclp, -unsigned long seq) -{ -int i; - -WARN_ON_ONCE (!rcu_segcblist_is_enabled (rsclp)); -if (rcu_segcblist_restempty (rsclp,RCU_DONE_TAIL )) -return false; - -/* -* Find the segment preceding the oldest segment of callbacks -* whose ->gp_seq[] completion is at or after that passed in via -* "seq", skipping any empty segments. This oldest segment, along -* with any later segments, can be merged in with any newly arrived -* callbacks in the RCU_NEXT_TAIL segment, and assigned "seq" -* as their ->gp_seq[] grace-period completion sequence number. -*/ -for (i =RCU_NEXT_READY_TAIL ; i >RCU_DONE_TAIL ; i--) -if (rsclp->tails[i] != rsclp->tails[i -1 ] && -ULONG_CMP_LT (rsclp->gp_seq[i], seq)) -break ; - -/* -* If all the segments contain callbacks that correspond to -* earlier grace-period sequence numbers than "seq", leave. -* Assuming that the rcu_segcblist structure has enough -* segments in its arrays, this can only happen if some of -* the non-done segments contain callbacks that really are -* ready to invoke. This situation will get straightened -* out by the next call to rcu_segcblist_advance(). -* -* Also advance to the oldest segment of callbacks whose -* ->gp_seq[] completion is at or after that passed in via "seq", -* skipping any empty segments. -*/ -if (++i >=RCU_NEXT_TAIL ) -return false; - -/* -* Merge all later callbacks, including newly arrived callbacks, -* into the segment located by the for-loop above. Assign "seq" -* as the ->gp_seq[] value in order to correctly handle the case -* where there were no pending callbacks in the rcu_segcblist -* structure other than in the RCU_NEXT_TAIL segment. -*/ -for (; i <RCU_NEXT_TAIL ; i++) { - rsclp->tails[i] = rsclp->tails[RCU_NEXT_TAIL ]; - rsclp->gp_seq[i] = seq; - } -return true; -} - -/* -* Scan the specified rcu_segcblist structure for callbacks that need -* a grace period later than the one specified by "seq". We don't look -* at the RCU_DONE_TAIL or RCU_NEXT_TAIL segments because they don't -* have a grace-period sequence number. -*/ -static inline bool rcu_segcblist_future_gp_needed (struct rcu_segcblist *rsclp, -unsigned long seq) -{ -int i; - -for (i =RCU_WAIT_TAIL ; i <RCU_NEXT_TAIL ; i++) -if (rsclp->tails[i -1 ] != rsclp->tails[i] && -ULONG_CMP_LT (seq, rsclp->gp_seq[i])) -return true; -return false; -} - -/* -* Interim function to return rcu_segcblist head pointer. Longer term, the -* rcu_segcblist will be used more pervasively, removing the need for this -* function. -*/ -static inline struct rcu_head *rcu_segcblist_head (struct rcu_segcblist *rsclp) -{ -return rsclp->head; -} - -/* -* Interim function to return rcu_segcblist head pointer. Longer term, the -* rcu_segcblist will be used more pervasively, removing the need for this -* function. -*/ -static inline struct rcu_head **rcu_segcblist_tail (struct rcu_segcblist *rsclp) -{ -WARN_ON_ONCE (rcu_segcblist_empty (rsclp)); -return rsclp->tails[RCU_NEXT_TAIL ]; -} - -#endif /* __KERNEL_RCU_SEGCBLIST_H */ +#endif /* __INCLUDE_LINUX_RCU_SEGCBLIST_H */
kernel/rcu/rcu_segcblist.h new file +645 -0
645 lines not on this page · raw message
kernel/rcu/srcutree.c +1 -0
@@ -38,6 +38,7 @@#include <linux/srcu.h> #include "rcu.h" +#include "rcu_segcblist.h" ulong exp_holdoff =25 *1000 ;/* Holdoff (ns) for auto-expediting. */ module_param (exp_holdoff, ulong,0444 );
kernel/rcu/tree.h +2 -1
@@ -30,9 +30,10 @@#include <linux/seqlock.h> #include <linux/swait.h> #include <linux/stop_machine.h> -#include <linux/rcu_segcblist.h> #include <linux/rcu_node_tree.h> +#include "rcu_segcblist.h" +/* * Dynticks per-CPU state. */
Re: [PATCH] srcu: Debloat the <linux/rcu_segcblist.h> header
Quoted 22 lines · Ingo Molnar
Quoted 6 lines · Ingo Molnar
Quoted 5 lines
I will get rid of the unused
rcu_segcblist_extract_all()function and create akernel/rcu/segcblist.cfor the functions that are either non-trivial or performance-insensitive.Does that cover it, or am I missing something?
Quoted 8 lines
I'd also suggest moving as much of the RCU internal data types into
kernel/rcu/as possible. It's not clear to me which part of it is supposed to be a public API and which bits are internal. It might make sense to keep it internal for the time being, and only export things once there are users.I.e. a pretty good solution would be to move all of
include/linux/rcu_segcblist.htokernel/rcu/rcu_segcblist.cor so - and do akernel/rcu/rcu_segcblist.hwith the data types and function prototypes.I.e. the attached patch as a first step.
Only minimally build tested, but it appears to be do the trick.
Quoted 7 lines
This changes the <
linux/rcu_segcblist.h> header from ~700 lines to only 90 lines - 60% of which is comments.The deinlining of the inline functions within
kernel/rcu/should also be done, as a separate patch on top of this.What do you think?
Thank you very much!
I have pulled this in and started a short rcutorture run. I will do de-inline and create a .c file on top of this and retest after the rcutorture has finished.
Quoted 2 lines
This could also be a model to factor out and deinline other bits of the RCU machinery as much as possible.
The other bits being kernel/rcu/tree_plugin.h and so on?
Thanx, Paul
Quoted 1,365 lines
Thanks,
Ingo
====================>
Quoted 1 line
From
484c73f6a8b28d018d1988e55e38178aac83a1d7Mon Sep 17 00:00:00 2001From: Ingo Molnar <[email protected]>
Date: Tue, 2 May 2017 10:17:10 +0200
Subject: [PATCH] srcu: Debloat the <linux/rcu_segcblist.h> headerLinus noticed that the <
linux/rcu_segcblist.h> has huge inline functions which should not be inline at all.As a first step in cleaning this up, move them all to
kernel/rcu/and only keep an absolute minimum of data type defines in the header:before: -rw-r--r-- 1 mingo mingo 22284 May 2 10:25 include/linux/rcu_segcblist.h after: -rw-r--r-- 1 mingo mingo 3180 May 2 10:22 include/linux/rcu_segcblist.hMore can be done, such as uninlining the large functions, which inlining is unjustified even if it's an RCU internal matter.
Reported-by Linus Torvalds <[email protected]>Cc Paul E. McKenney <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Thomas Gleixner <[email protected]>Signed-off-by Ingo Molnar <[email protected]>--- include/linux/rcu_segcblist.h | 628 +--------------------------------------- kernel/rcu/rcu_segcblist.h | 645 ++++++++++++++++++++++++++++++++++++++++++ kernel/rcu/srcutree.c | 1 + kernel/rcu/tree.h | 3 +- 4 files changed, 651 insertions(+), 626 deletions(-)include/linux/rcu_segcblist.h +3
-625@@ -20,8 +20,8 @@* Authors: Paul E. McKenney <[email protected]> */ -#ifndef __KERNEL_RCU_SEGCBLIST_H -#define __KERNEL_RCU_SEGCBLIST_H +#ifndef __INCLUDE_LINUX_RCU_SEGCBLIST_H +#define __INCLUDE_LINUX_RCU_SEGCBLIST_H/* Simple unsegmented callback lists. */ struct rcu_cblist {@@ -33,102 +33,6 @@ struct rcu_cblist {#define RCU_CBLIST_INITIALIZER (n) { .head = NULL, .tail = &n.head } -/* Initialize simple callback list. */ -static inline void rcu_cblist_init (struct rcu_cblist *rclp) -{ - rclp->head =NULL ; - rclp->tail = &rclp->head; - rclp->len =0 ; - rclp->len_lazy =0 ; -} - -/* Is simple callback list empty? */ -static inline bool rcu_cblist_empty (struct rcu_cblist *rclp) -{ -return !rclp->head; -} - -/* Return number of callbacks in simple callback list. */ -static inline long rcu_cblist_n_cbs (struct rcu_cblist *rclp) -{ -return rclp->len; -} - -/* Return number of lazy callbacks in simple callback list. */ -static inline long rcu_cblist_n_lazy_cbs (struct rcu_cblist *rclp) -{ -return rclp->len_lazy; -} - -/* -* Debug function to actually count the number of callbacks. -* If the number exceeds the limit specified, return -1. -*/ -static inline long rcu_cblist_count_cbs (struct rcu_cblist *rclp,long lim) -{ -int cnt =0 ; -struct rcu_head **rhpp = &rclp->head; - -for (;;) { -if (!*rhpp) -return cnt; -if (++cnt > lim) -return -1 ; - rhpp = &(*rhpp)->next; - } -} - -/* -* Dequeue the oldest rcu_head structure from the specified callback -* list. This function assumes that the callback is non-lazy, but -* the caller can later invoke rcu_cblist_dequeued_lazy() if it -* finds otherwise (and if it cares about laziness). This allows -* different users to have different ways of determining laziness. -*/ -static inline struct rcu_head *rcu_cblist_dequeue (struct rcu_cblist *rclp) -{ -struct rcu_head *rhp; - - rhp = rclp->head; -if (!rhp) -return NULL ; - rclp->len--; - rclp->head = rhp->next; -if (!rclp->head) - rclp->tail = &rclp->head; -return rhp; -} - -/* -* Account for the fact that a previously dequeued callback turned out -* to be marked as lazy. -*/ -static inline void rcu_cblist_dequeued_lazy (struct rcu_cblist *rclp) -{ - rclp->len_lazy--; -} - -/* -* Interim function to return rcu_cblist head pointer. Longer term, the -* rcu_cblist will be used more pervasively, removing the need for this -* function. -*/ -static inline struct rcu_head *rcu_cblist_head (struct rcu_cblist *rclp) -{ -return rclp->head; -} - -/* -* Interim function to return rcu_cblist head pointer. Longer term, the -* rcu_cblist will be used more pervasively, removing the need for this -* function. -*/ -static inline struct rcu_head **rcu_cblist_tail (struct rcu_cblist *rclp) -{ -WARN_ON_ONCE (rcu_cblist_empty (rclp)); -return rclp->tail; -} -/* Complicated segmented callback lists. ;-) */ /* @@ -183,530 +87,4 @@ struct rcu_segcblist { .tails[RCU_NEXT_TAIL] = &n.head, \ } -/* -* Initialize an rcu_segcblist structure. -*/ -static inline void rcu_segcblist_init (struct rcu_segcblist *rsclp) -{ -int i; - -BUILD_BUG_ON (RCU_NEXT_TAIL +1 !=ARRAY_SIZE (rsclp->gp_seq)); -BUILD_BUG_ON (ARRAY_SIZE (rsclp->tails) !=ARRAY_SIZE (rsclp->gp_seq)); - rsclp->head =NULL ; -for (i =0 ; i <RCU_CBLIST_NSEGS ; i++) - rsclp->tails[i] = &rsclp->head; - rsclp->len =0 ; - rsclp->len_lazy =0 ; -} - -/* -* Is the specified rcu_segcblist structure empty? -* -* But careful! The fact that the ->head field is NULL does not -* necessarily imply that there are no callbacks associated with -* this structure. When callbacks are being invoked, they are -* removed as a group. If callback invocation must be preempted, -* the remaining callbacks will be added back to the list. Either -* way, the counts are updated later. -* -* So it is often the case that rcu_segcblist_n_cbs() should be used -* instead. -*/ -static inline bool rcu_segcblist_empty (struct rcu_segcblist *rsclp) -{ -return !rsclp->head; -} - -/* Return number of callbacks in segmented callback list. */ -static inline long rcu_segcblist_n_cbs (struct rcu_segcblist *rsclp) -{ -return READ_ONCE (rsclp->len); -} - -/* Return number of lazy callbacks in segmented callback list. */ -static inline long rcu_segcblist_n_lazy_cbs (struct rcu_segcblist *rsclp) -{ -return rsclp->len_lazy; -} - -/* Return number of lazy callbacks in segmented callback list. */ -static inline long rcu_segcblist_n_nonlazy_cbs (struct rcu_segcblist *rsclp) -{ -return rsclp->len - rsclp->len_lazy; -} - -/* -* Is the specified rcu_segcblist enabled, for example, not corresponding -* to an offline or callback-offloaded CPU? -*/ -static inline bool rcu_segcblist_is_enabled (struct rcu_segcblist *rsclp) -{ -return !!rsclp->tails[RCU_NEXT_TAIL ]; -} - -/* -* Disable the specified rcu_segcblist structure, so that callbacks can -* no longer be posted to it. This structure must be empty. -*/ -static inline void rcu_segcblist_disable (struct rcu_segcblist *rsclp) -{ -WARN_ON_ONCE (!rcu_segcblist_empty (rsclp)); -WARN_ON_ONCE (rcu_segcblist_n_cbs (rsclp)); -WARN_ON_ONCE (rcu_segcblist_n_lazy_cbs (rsclp)); - rsclp->tails[RCU_NEXT_TAIL ] =NULL ; -} - -/* -* Is the specified segment of the specified rcu_segcblist structure -* empty of callbacks? -*/ -static inline bool rcu_segcblist_segempty (struct rcu_segcblist *rsclp,int seg) -{ -if (seg ==RCU_DONE_TAIL ) -return &rsclp->head == rsclp->tails[RCU_DONE_TAIL ]; -return rsclp->tails[seg -1 ] == rsclp->tails[seg]; -} - -/* -* Are all segments following the specified segment of the specified -* rcu_segcblist structure empty of callbacks? (The specified -* segment might well contain callbacks.) -*/ -static inline bool rcu_segcblist_restempty (struct rcu_segcblist *rsclp,int seg) -{ -return !*rsclp->tails[seg]; -} - -/* -* Does the specified rcu_segcblist structure contain callbacks that -* are ready to be invoked? -*/ -static inline bool rcu_segcblist_ready_cbs (struct rcu_segcblist *rsclp) -{ -return rcu_segcblist_is_enabled (rsclp) && - &rsclp->head != rsclp->tails[RCU_DONE_TAIL ]; -} - -/* -* Does the specified rcu_segcblist structure contain callbacks that -* are still pending, that is, not yet ready to be invoked? -*/ -static inline bool rcu_segcblist_pend_cbs (struct rcu_segcblist *rsclp) -{ -return rcu_segcblist_is_enabled (rsclp) && - !rcu_segcblist_restempty (rsclp,RCU_DONE_TAIL ); -} - -/* -* Dequeue and return the first ready-to-invoke callback. If there -* are no ready-to-invoke callbacks, return NULL. Disables interrupts -* to avoid interference. Does not protect from interference from other -* CPUs or tasks. -*/ -static inline struct rcu_head * -rcu_segcblist_dequeue (struct rcu_segcblist *rsclp) -{ -unsigned long flags; -int i; -struct rcu_head *rhp; - -local_irq_save (flags); -if (!rcu_segcblist_ready_cbs (rsclp)) { -local_irq_restore (flags); -return NULL ; - } - rhp = rsclp->head; -BUG_ON (!rhp); - rsclp->head = rhp->next; -for (i =RCU_DONE_TAIL ; i <RCU_CBLIST_NSEGS ; i++) { -if (rsclp->tails[i] != &rhp->next) -break ; - rsclp->tails[i] = &rsclp->head; - } -smp_mb ();/* Dequeue before decrement for rcu_barrier(). */ -WRITE_ONCE (rsclp->len, rsclp->len -1 ); -local_irq_restore (flags); -return rhp; -} - -/* -* Account for the fact that a previously dequeued callback turned out -* to be marked as lazy. -*/ -static inline void rcu_segcblist_dequeued_lazy (struct rcu_segcblist *rsclp) -{ -unsigned long flags; - -local_irq_save (flags); - rsclp->len_lazy--; -local_irq_restore (flags); -} - -/* -* Return a pointer to the first callback in the specified rcu_segcblist -* structure. This is useful for diagnostics. -*/ -static inline struct rcu_head * -rcu_segcblist_first_cb (struct rcu_segcblist *rsclp) -{ -if (rcu_segcblist_is_enabled (rsclp)) -return rsclp->head; -return NULL ; -} - -/* -* Return a pointer to the first pending callback in the specified -* rcu_segcblist structure. This is useful just after posting a given -* callback -- if that callback is the first pending callback, then -* you cannot rely on someone else having already started up the required -* grace period. -*/ -static inline struct rcu_head * -rcu_segcblist_first_pend_cb (struct rcu_segcblist *rsclp) -{ -if (rcu_segcblist_is_enabled (rsclp)) -return *rsclp->tails[RCU_DONE_TAIL ]; -return NULL ; -} - -/* -* Does the specified rcu_segcblist structure contain callbacks that -* have not yet been processed beyond having been posted, that is, -* does it contain callbacks in its last segment? -*/ -static inline bool rcu_segcblist_new_cbs (struct rcu_segcblist *rsclp) -{ -return rcu_segcblist_is_enabled (rsclp) && - !rcu_segcblist_restempty (rsclp,RCU_NEXT_READY_TAIL ); -} - -/* -* Enqueue the specified callback onto the specified rcu_segcblist -* structure, updating accounting as needed. Note that the ->len -* field may be accessed locklessly, hence the WRITE_ONCE(). -* The ->len field is used by rcu_barrier() and friends to determine -* if it must post a callback on this structure, and it is OK -* for rcu_barrier() to sometimes post callbacks needlessly, but -* absolutely not OK for it to ever miss posting a callback. -*/ -static inline void rcu_segcblist_enqueue (struct rcu_segcblist *rsclp, -struct rcu_head *rhp,bool lazy) -{ -WRITE_ONCE (rsclp->len, rsclp->len +1 );/* ->len sampled locklessly. */ -if (lazy) - rsclp->len_lazy++; -smp_mb ();/* Ensure counts are updated before callback is enqueued. */ - rhp->next =NULL ; - *rsclp->tails[RCU_NEXT_TAIL ] = rhp; - rsclp->tails[RCU_NEXT_TAIL ] = &rhp->next; -} - -/* -* Entrain the specified callback onto the specified rcu_segcblist at -* the end of the last non-empty segment. If the entire rcu_segcblist -* is empty, make no change, but return false. -* -* This is intended for use by rcu_barrier()-like primitives, -not- -* for normal grace-period use. IMPORTANT: The callback you enqueue -* will wait for all prior callbacks, NOT necessarily for a grace -* period. You have been warned. -*/ -static inline bool rcu_segcblist_entrain (struct rcu_segcblist *rsclp, -struct rcu_head *rhp,bool lazy) -{ -int i; - -if (rcu_segcblist_n_cbs (rsclp) ==0 ) -return false; -WRITE_ONCE (rsclp->len, rsclp->len +1 ); -if (lazy) - rsclp->len_lazy++; -smp_mb ();/* Ensure counts are updated before callback is entrained. */ - rhp->next =NULL ; -for (i =RCU_NEXT_TAIL ; i >RCU_DONE_TAIL ; i--) -if (rsclp->tails[i] != rsclp->tails[i -1 ]) -break ; - *rsclp->tails[i] = rhp; -for (; i <=RCU_NEXT_TAIL ; i++) - rsclp->tails[i] = &rhp->next; -return true; -} - -/* -* Extract only the counts from the specified rcu_segcblist structure, -* and place them in the specified rcu_cblist structure. This function -* supports both callback orphaning and invocation, hence the separation -* of counts and callbacks. (Callbacks ready for invocation must be -* orphaned and adopted separately from pending callbacks, but counts -* apply to all callbacks. Locking must be used to make sure that -* both orphaned-callbacks lists are consistent.) -*/ -static inline void rcu_segcblist_extract_count (struct rcu_segcblist *rsclp, -struct rcu_cblist *rclp) -{ - rclp->len_lazy += rsclp->len_lazy; - rclp->len += rsclp->len; - rsclp->len_lazy =0 ; -WRITE_ONCE (rsclp->len,0 );/* ->len sampled locklessly. */ -} - -/* -* Extract only those callbacks ready to be invoked from the specified -* rcu_segcblist structure and place them in the specified rcu_cblist -* structure. -*/ -static inline void rcu_segcblist_extract_done_cbs (struct rcu_segcblist *rsclp, -struct rcu_cblist *rclp) -{ -int i; - -if (!rcu_segcblist_ready_cbs (rsclp)) -return ;/* Nothing to do. */ - *rclp->tail = rsclp->head; - rsclp->head = *rsclp->tails[RCU_DONE_TAIL ]; - *rsclp->tails[RCU_DONE_TAIL ] =NULL ; - rclp->tail = rsclp->tails[RCU_DONE_TAIL ]; -for (i =RCU_CBLIST_NSEGS -1 ; i >=RCU_DONE_TAIL ; i--) -if (rsclp->tails[i] == rsclp->tails[RCU_DONE_TAIL ]) - rsclp->tails[i] = &rsclp->head; -} - -/* -* Extract only those callbacks still pending (not yet ready to be -* invoked) from the specified rcu_segcblist structure and place them in -* the specified rcu_cblist structure. Note that this loses information -* about any callbacks that might have been partway done waiting for -* their grace period. Too bad! They will have to start over. -*/ -static inline void -rcu_segcblist_extract_pend_cbs (struct rcu_segcblist *rsclp, -struct rcu_cblist *rclp) -{ -int i; - -if (!rcu_segcblist_pend_cbs (rsclp)) -return ;/* Nothing to do. */ - *rclp->tail = *rsclp->tails[RCU_DONE_TAIL ]; - rclp->tail = rsclp->tails[RCU_NEXT_TAIL ]; - *rsclp->tails[RCU_DONE_TAIL ] =NULL ; -for (i =RCU_DONE_TAIL +1 ; i <RCU_CBLIST_NSEGS ; i++) - rsclp->tails[i] = rsclp->tails[RCU_DONE_TAIL ]; -} - -/* -* Move the entire contents of the specified rcu_segcblist structure, -* counts, callbacks, and all, to the specified rcu_cblist structure. -* @@@ Why do we need this??? Moving early-boot CBs to NOCB lists? -* @@@ Memory barrier needed? (Not if only used at boot time...) -*/ -static inline void rcu_segcblist_extract_all (struct rcu_segcblist *rsclp, -struct rcu_cblist *rclp) -{ -rcu_segcblist_extract_done_cbs (rsclp, rclp); -rcu_segcblist_extract_pend_cbs (rsclp, rclp); -rcu_segcblist_extract_count (rsclp, rclp); -} - -/* -* Insert counts from the specified rcu_cblist structure in the -* specified rcu_segcblist structure. -*/ -static inline void rcu_segcblist_insert_count (struct rcu_segcblist *rsclp, -struct rcu_cblist *rclp) -{ - rsclp->len_lazy += rclp->len_lazy; -/* ->len sampled locklessly. */ -WRITE_ONCE (rsclp->len, rsclp->len + rclp->len); - rclp->len_lazy =0 ; - rclp->len =0 ; -} - -/* -* Move callbacks from the specified rcu_cblist to the beginning of the -* done-callbacks segment of the specified rcu_segcblist. -*/ -static inline void rcu_segcblist_insert_done_cbs (struct rcu_segcblist *rsclp, -struct rcu_cblist *rclp) -{ -int i; - -if (!rclp->head) -return ;/* No callbacks to move. */ - *rclp->tail = rsclp->head; - rsclp->head = rclp->head; -for (i =RCU_DONE_TAIL ; i <RCU_CBLIST_NSEGS ; i++) -if (&rsclp->head == rsclp->tails[i]) - rsclp->tails[i] = rclp->tail; -else -break ; - rclp->head =NULL ; - rclp->tail = &rclp->head; -} - -/* -* Move callbacks from the specified rcu_cblist to the end of the -* new-callbacks segment of the specified rcu_segcblist. -*/ -static inline void rcu_segcblist_insert_pend_cbs (struct rcu_segcblist *rsclp, -struct rcu_cblist *rclp) -{ -if (!rclp->head) -return ;/* Nothing to do. */ - *rsclp->tails[RCU_NEXT_TAIL ] = rclp->head; - rsclp->tails[RCU_NEXT_TAIL ] = rclp->tail; - rclp->head =NULL ; - rclp->tail = &rclp->head; -} - -/* -* Advance the callbacks in the specified rcu_segcblist structure based -* on the current value passed in for the grace-period counter. -*/ -static inline void rcu_segcblist_advance (struct rcu_segcblist *rsclp, -unsigned long seq) -{ -int i, j; - -WARN_ON_ONCE (!rcu_segcblist_is_enabled (rsclp)); -if (rcu_segcblist_restempty (rsclp,RCU_DONE_TAIL )) -return ; - -/* -* Find all callbacks whose ->gp_seq numbers indicate that they -* are ready to invoke, and put them into the RCU_DONE_TAIL segment. -*/ -for (i =RCU_WAIT_TAIL ; i <RCU_NEXT_TAIL ; i++) { -if (ULONG_CMP_LT (seq, rsclp->gp_seq[i])) -break ; - rsclp->tails[RCU_DONE_TAIL ] = rsclp->tails[i]; - } - -/* If no callbacks moved, nothing more need be done. */ -if (i ==RCU_WAIT_TAIL ) -return ; - -/* Clean up tail pointers that might have been misordered above. */ -for (j =RCU_WAIT_TAIL ; j < i; j++) - rsclp->tails[j] = rsclp->tails[RCU_DONE_TAIL ]; - -/* -* Callbacks moved, so clean up the misordered ->tails[] pointers -* that now point into the middle of the list of ready-to-invoke -* callbacks. The overall effect is to copy down the later pointers -* into the gap that was created by the now-ready segments. -*/ -for (j =RCU_WAIT_TAIL ; i <RCU_NEXT_TAIL ; i++, j++) { -if (rsclp->tails[j] == rsclp->tails[RCU_NEXT_TAIL ]) -break ;/* No more callbacks. */ - rsclp->tails[j] = rsclp->tails[i]; - rsclp->gp_seq[j] = rsclp->gp_seq[i]; - } -} - -/* -* "Accelerate" callbacks based on more-accurate grace-period information. -* The reason for this is that RCU does not synchronize the beginnings and -* ends of grace periods, and that callbacks are posted locally. This in -* turn means that the callbacks must be labelled conservatively early -* on, as getting exact information would degrade both performance and -* scalability. When more accurate grace-period information becomes -* available, previously posted callbacks can be "accelerated", marking -* them to complete at the end of the earlier grace period. -* -* This function operates on an rcu_segcblist structure, and also the -* grace-period sequence number seq at which new callbacks would become -* ready to invoke. Returns true if there are callbacks that won't be -* ready to invoke until seq, false otherwise. -*/ -static inline bool rcu_segcblist_accelerate (struct rcu_segcblist *rsclp, -unsigned long seq) -{ -int i; - -WARN_ON_ONCE (!rcu_segcblist_is_enabled (rsclp)); -if (rcu_segcblist_restempty (rsclp,RCU_DONE_TAIL )) -return false; - -/* -* Find the segment preceding the oldest segment of callbacks -* whose ->gp_seq[] completion is at or after that passed in via -* "seq", skipping any empty segments. This oldest segment, along -* with any later segments, can be merged in with any newly arrived -* callbacks in the RCU_NEXT_TAIL segment, and assigned "seq" -* as their ->gp_seq[] grace-period completion sequence number. -*/ -for (i =RCU_NEXT_READY_TAIL ; i >RCU_DONE_TAIL ; i--) -if (rsclp->tails[i] != rsclp->tails[i -1 ] && -ULONG_CMP_LT (rsclp->gp_seq[i], seq)) -break ; - -/* -* If all the segments contain callbacks that correspond to -* earlier grace-period sequence numbers than "seq", leave. -* Assuming that the rcu_segcblist structure has enough -* segments in its arrays, this can only happen if some of -* the non-done segments contain callbacks that really are -* ready to invoke. This situation will get straightened -* out by the next call to rcu_segcblist_advance(). -* -* Also advance to the oldest segment of callbacks whose -* ->gp_seq[] completion is at or after that passed in via "seq", -* skipping any empty segments. -*/ -if (++i >=RCU_NEXT_TAIL ) -return false; - -/* -* Merge all later callbacks, including newly arrived callbacks, -* into the segment located by the for-loop above. Assign "seq" -* as the ->gp_seq[] value in order to correctly handle the case -* where there were no pending callbacks in the rcu_segcblist -* structure other than in the RCU_NEXT_TAIL segment. -*/ -for (; i <RCU_NEXT_TAIL ; i++) { - rsclp->tails[i] = rsclp->tails[RCU_NEXT_TAIL ]; - rsclp->gp_seq[i] = seq; - } -return true; -} - -/* -* Scan the specified rcu_segcblist structure for callbacks that need -* a grace period later than the one specified by "seq". We don't look -* at the RCU_DONE_TAIL or RCU_NEXT_TAIL segments because they don't -* have a grace-period sequence number. -*/ -static inline bool rcu_segcblist_future_gp_needed (struct rcu_segcblist *rsclp, -unsigned long seq) -{ -int i; - -for (i =RCU_WAIT_TAIL ; i <RCU_NEXT_TAIL ; i++) -if (rsclp->tails[i -1 ] != rsclp->tails[i] && -ULONG_CMP_LT (seq, rsclp->gp_seq[i])) -return true; -return false; -} - -/* -* Interim function to return rcu_segcblist head pointer. Longer term, the -* rcu_segcblist will be used more pervasively, removing the need for this -* function. -*/ -static inline struct rcu_head *rcu_segcblist_head (struct rcu_segcblist *rsclp) -{ -return rsclp->head; -} - -/* -* Interim function to return rcu_segcblist head pointer. Longer term, the -* rcu_segcblist will be used more pervasively, removing the need for this -* function. -*/ -static inline struct rcu_head **rcu_segcblist_tail (struct rcu_segcblist *rsclp) -{ -WARN_ON_ONCE (rcu_segcblist_empty (rsclp)); -return rsclp->tails[RCU_NEXT_TAIL ]; -} - -#endif /* __KERNEL_RCU_SEGCBLIST_H */ +#endif /* __INCLUDE_LINUX_RCU_SEGCBLIST_H */ kernel/rcu/rcu_segcblist.h new file +645
-0@@ -0,0 +1,645 @@ +/* +* RCU segmented callback lists +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, you can access it online at +* http://www.gnu.org/licenses/gpl-2.0.html. +* +* Copyright IBM Corporation, 2017 +* +* Authors: Paul E. McKenney <[email protected]> +*/ + +#include <linux/rcu_segcblist.h> + +/* Initialize simple callback list. */ +static inline void rcu_cblist_init (struct rcu_cblist *rclp) +{ + rclp->head =NULL ; + rclp->tail = &rclp->head; + rclp->len =0 ; + rclp->len_lazy =0 ; +} + +/* Is simple callback list empty? */ +static inline bool rcu_cblist_empty (struct rcu_cblist *rclp) +{ +return !rclp->head; +} + +/* Return number of callbacks in simple callback list. */ +static inline long rcu_cblist_n_cbs (struct rcu_cblist *rclp) +{ +return rclp->len; +} + +/* Return number of lazy callbacks in simple callback list. */ +static inline long rcu_cblist_n_lazy_cbs (struct rcu_cblist *rclp) +{ +return rclp->len_lazy; +} + +/* +* Debug function to actually count the number of callbacks. +* If the number exceeds the limit specified, return -1. +*/ +static inline long rcu_cblist_count_cbs (struct rcu_cblist *rclp,long lim) +{ +int cnt =0 ; +struct rcu_head **rhpp = &rclp->head; + +for (;;) { +if (!*rhpp) +return cnt; +if (++cnt > lim) +return -1 ; + rhpp = &(*rhpp)->next; + } +} + +/* +* Dequeue the oldest rcu_head structure from the specified callback +* list. This function assumes that the callback is non-lazy, but +* the caller can later invoke rcu_cblist_dequeued_lazy() if it +* finds otherwise (and if it cares about laziness). This allows +* different users to have different ways of determining laziness. +*/ +static inline struct rcu_head *rcu_cblist_dequeue (struct rcu_cblist *rclp) +{ +struct rcu_head *rhp; + + rhp = rclp->head; +if (!rhp) +return NULL ; + rclp->len--; + rclp->head = rhp->next; +if (!rclp->head) + rclp->tail = &rclp->head; +return rhp; +} + +/* +* Account for the fact that a previously dequeued callback turned out +* to be marked as lazy. +*/ +static inline void rcu_cblist_dequeued_lazy (struct rcu_cblist *rclp) +{ + rclp->len_lazy--; +} + +/* +* Interim function to return rcu_cblist head pointer. Longer term, the +* rcu_cblist will be used more pervasively, removing the need for this +* function. +*/ +static inline struct rcu_head *rcu_cblist_head (struct rcu_cblist *rclp) +{ +return rclp->head; +} + +/* +* Interim function to return rcu_cblist head pointer. Longer term, the +* rcu_cblist will be used more pervasively, removing the need for this +* function. +*/ +static inline struct rcu_head **rcu_cblist_tail (struct rcu_cblist *rclp) +{ +WARN_ON_ONCE (rcu_cblist_empty (rclp)); +return rclp->tail; +} + +/* +* Initialize an rcu_segcblist structure. +*/ +static inline void rcu_segcblist_init (struct rcu_segcblist *rsclp) +{ +int i; + +BUILD_BUG_ON (RCU_NEXT_TAIL +1 !=ARRAY_SIZE (rsclp->gp_seq)); +BUILD_BUG_ON (ARRAY_SIZE (rsclp->tails) !=ARRAY_SIZE (rsclp->gp_seq)); + rsclp->head =NULL ; +for (i =0 ; i <RCU_CBLIST_NSEGS ; i++) + rsclp->tails[i] = &rsclp->head; + rsclp->len =0 ; + rsclp->len_lazy =0 ; +} + +/* +* Is the specified rcu_segcblist structure empty? +* +* But careful! The fact that the ->head field is NULL does not +* necessarily imply that there are no callbacks associated with +* this structure. When callbacks are being invoked, they are +* removed as a group. If callback invocation must be preempted, +* the remaining callbacks will be added back to the list. Either +* way, the counts are updated later. +* +* So it is often the case that rcu_segcblist_n_cbs() should be used +* instead. +*/ +static inline bool rcu_segcblist_empty (struct rcu_segcblist *rsclp) +{ +return !rsclp->head; +} + +/* Return number of callbacks in segmented callback list. */ +static inline long rcu_segcblist_n_cbs (struct rcu_segcblist *rsclp) +{ +return READ_ONCE (rsclp->len); +} + +/* Return number of lazy callbacks in segmented callback list. */ +static inline long rcu_segcblist_n_lazy_cbs (struct rcu_segcblist *rsclp) +{ +return rsclp->len_lazy; +} + +/* Return number of lazy callbacks in segmented callback list. */ +static inline long rcu_segcblist_n_nonlazy_cbs (struct rcu_segcblist *rsclp) +{ +return rsclp->len - rsclp->len_lazy; +} + +/* +* Is the specified rcu_segcblist enabled, for example, not corresponding +* to an offline or callback-offloaded CPU? +*/ +static inline bool rcu_segcblist_is_enabled (struct rcu_segcblist *rsclp) +{ +return !!rsclp->tails[RCU_NEXT_TAIL ]; +} + +/* +* Disable the specified rcu_segcblist structure, so that callbacks can +* no longer be posted to it. This structure must be empty. +*/ +static inline void rcu_segcblist_disable (struct rcu_segcblist *rsclp) +{ +WARN_ON_ONCE (!rcu_segcblist_empty (rsclp)); +WARN_ON_ONCE (rcu_segcblist_n_cbs (rsclp)); +WARN_ON_ONCE (rcu_segcblist_n_lazy_cbs (rsclp)); + rsclp->tails[RCU_NEXT_TAIL ] =NULL ; +} + +/* +* Is the specified segment of the specified rcu_segcblist structure +* empty of callbacks? +*/ +static inline bool rcu_segcblist_segempty (struct rcu_segcblist *rsclp,int seg) +{ +if (seg ==RCU_DONE_TAIL ) +return &rsclp->head == rsclp->tails[RCU_DONE_TAIL ]; +return rsclp->tails[seg -1 ] == rsclp->tails[seg]; +} + +/* +* Are all segments following the specified segment of the specified +* rcu_segcblist structure empty of callbacks? (The specified +* segment might well contain callbacks.) +*/ +static inline bool rcu_segcblist_restempty (struct rcu_segcblist *rsclp,int seg) +{ +return !*rsclp->tails[seg]; +} + +/* +* Does the specified rcu_segcblist structure contain callbacks that +* are ready to be invoked? +*/ +static inline bool rcu_segcblist_ready_cbs (struct rcu_segcblist *rsclp) +{ +return rcu_segcblist_is_enabled (rsclp) && + &rsclp->head != rsclp->tails[RCU_DONE_TAIL ]; +} + +/* +* Does the specified rcu_segcblist structure contain callbacks that +* are still pending, that is, not yet ready to be invoked? +*/ +static inline bool rcu_segcblist_pend_cbs (struct rcu_segcblist *rsclp) +{ +return rcu_segcblist_is_enabled (rsclp) && + !rcu_segcblist_restempty (rsclp,RCU_DONE_TAIL ); +} + +/* +* Dequeue and return the first ready-to-invoke callback. If there +* are no ready-to-invoke callbacks, return NULL. Disables interrupts +* to avoid interference. Does not protect from interference from other +* CPUs or tasks. +*/ +static inline struct rcu_head * +rcu_segcblist_dequeue (struct rcu_segcblist *rsclp) +{ +unsigned long flags; +int i; +struct rcu_head *rhp; + +local_irq_save (flags); +if (!rcu_segcblist_ready_cbs (rsclp)) { +local_irq_restore (flags); +return NULL ; + } + rhp = rsclp->head; +BUG_ON (!rhp); + rsclp->head = rhp->next; +for (i =RCU_DONE_TAIL ; i <RCU_CBLIST_NSEGS ; i++) { +if (rsclp->tails[i] != &rhp->next) +break ; + rsclp->tails[i] = &rsclp->head; + } +smp_mb ();/* Dequeue before decrement for rcu_barrier(). */ +WRITE_ONCE (rsclp->len, rsclp->len -1 ); +local_irq_restore (flags); +return rhp; +} + +/* +* Account for the fact that a previously dequeued callback turned out +* to be marked as lazy. +*/ +static inline void rcu_segcblist_dequeued_lazy (struct rcu_segcblist *rsclp) +{ +unsigned long flags; + +local_irq_save (flags); + rsclp->len_lazy--; +local_irq_restore (flags); +} + +/* +* Return a pointer to the first callback in the specified rcu_segcblist +* structure. This is useful for diagnostics. +*/ +static inline struct rcu_head * +rcu_segcblist_first_cb (struct rcu_segcblist *rsclp) +{ +if (rcu_segcblist_is_enabled (rsclp)) +return rsclp->head; +return NULL ; +} + +/* +* Return a pointer to the first pending callback in the specified +* rcu_segcblist structure. This is useful just after posting a given +* callback -- if that callback is the first pending callback, then +* you cannot rely on someone else having already started up the required +* grace period. +*/ +static inline struct rcu_head * +rcu_segcblist_first_pend_cb (struct rcu_segcblist *rsclp) +{ +if (rcu_segcblist_is_enabled (rsclp)) +return *rsclp->tails[RCU_DONE_TAIL ]; +return NULL ; +} + +/* +* Does the specified rcu_segcblist structure contain callbacks that +* have not yet been processed beyond having been posted, that is, +* does it contain callbacks in its last segment? +*/ +static inline bool rcu_segcblist_new_cbs (struct rcu_segcblist *rsclp) +{ +return rcu_segcblist_is_enabled (rsclp) && + !rcu_segcblist_restempty (rsclp,RCU_NEXT_READY_TAIL ); +} + +/* +* Enqueue the specified callback onto the specified rcu_segcblist +* structure, updating accounting as needed. Note that the ->len +* field may be accessed locklessly, hence the WRITE_ONCE(). +* The ->len field is used by rcu_barrier() and friends to determine +* if it must post a callback on this structure, and it is OK +* for rcu_barrier() to sometimes post callbacks needlessly, but +* absolutely not OK for it to ever miss posting a callback. +*/ +static inline void rcu_segcblist_enqueue (struct rcu_segcblist *rsclp, +struct rcu_head *rhp,bool lazy) +{ +WRITE_ONCE (rsclp->len, rsclp->len +1 );/* ->len sampled locklessly. */ +if (lazy) + rsclp->len_lazy++; +smp_mb ();/* Ensure counts are updated before callback is enqueued. */ + rhp->next =NULL ; + *rsclp->tails[RCU_NEXT_TAIL ] = rhp; + rsclp->tails[RCU_NEXT_TAIL ] = &rhp->next; +} + +/* +* Entrain the specified callback onto the specified rcu_segcblist at +* the end of the last non-empty segment. If the entire rcu_segcblist +* is empty, make no change, but return false. +* +* This is intended for use by rcu_barrier()-like primitives, -not- +* for normal grace-period use. IMPORTANT: The callback you enqueue +* will wait for all prior callbacks, NOT necessarily for a grace +* period. You have been warned. +*/ +static inline bool rcu_segcblist_entrain (struct rcu_segcblist *rsclp, +struct rcu_head *rhp,bool lazy) +{ +int i; + +if (rcu_segcblist_n_cbs (rsclp) ==0 ) +return false; +WRITE_ONCE (rsclp->len, rsclp->len +1 ); +if (lazy) + rsclp->len_lazy++; +smp_mb ();/* Ensure counts are updated before callback is entrained. */ + rhp->next =NULL ; +for (i =RCU_NEXT_TAIL ; i >RCU_DONE_TAIL ; i--) +if (rsclp->tails[i] != rsclp->tails[i -1 ]) +break ; + *rsclp->tails[i] = rhp; +for (; i <=RCU_NEXT_TAIL ; i++) + rsclp->tails[i] = &rhp->next; +return true; +} + +/* +* Extract only the counts from the specified rcu_segcblist structure, +* and place them in the specified rcu_cblist structure. This function +* supports both callback orphaning and invocation, hence the separation +* of counts and callbacks. (Callbacks ready for invocation must be +* orphaned and adopted separately from pending callbacks, but counts +* apply to all callbacks. Locking must be used to make sure that +* both orphaned-callbacks lists are consistent.) +*/ +static inline void rcu_segcblist_extract_count (struct rcu_segcblist *rsclp, +struct rcu_cblist *rclp) +{ + rclp->len_lazy += rsclp->len_lazy; + rclp->len += rsclp->len; + rsclp->len_lazy =0 ; +WRITE_ONCE (rsclp->len,0 );/* ->len sampled locklessly. */ +} + +/* +* Extract only those callbacks ready to be invoked from the specified +* rcu_segcblist structure and place them in the specified rcu_cblist +* structure. +*/ +static inline void rcu_segcblist_extract_done_cbs (struct rcu_segcblist *rsclp, +struct rcu_cblist *rclp) +{ +int i; + +if (!rcu_segcblist_ready_cbs (rsclp)) +return ;/* Nothing to do. */ + *rclp->tail = rsclp->head; + rsclp->head = *rsclp->tails[RCU_DONE_TAIL ]; + *rsclp->tails[RCU_DONE_TAIL ] =NULL ; + rclp->tail = rsclp->tails[RCU_DONE_TAIL ]; +for (i =RCU_CBLIST_NSEGS -1 ; i >=RCU_DONE_TAIL ; i--) +if (rsclp->tails[i] == rsclp->tails[RCU_DONE_TAIL ]) + rsclp->tails[i] = &rsclp->head; +} + +/* +* Extract only those callbacks still pending (not yet ready to be +* invoked) from the specified rcu_segcblist structure and place them in +* the specified rcu_cblist structure. Note that this loses information +* about any callbacks that might have been partway done waiting for +* their grace period. Too bad! They will have to start over. +*/ +static inline void +rcu_segcblist_extract_pend_cbs (struct rcu_segcblist *rsclp, +struct rcu_cblist *rclp) +{ +int i; + +if (!rcu_segcblist_pend_cbs (rsclp)) +return ;/* Nothing to do. */ + *rclp->tail = *rsclp->tails[RCU_DONE_TAIL ]; + rclp->tail = rsclp->tails[RCU_NEXT_TAIL ]; + *rsclp->tails[RCU_DONE_TAIL ] =NULL ; +for (i =RCU_DONE_TAIL +1 ; i <RCU_CBLIST_NSEGS ; i++) + rsclp->tails[i] = rsclp->tails[RCU_DONE_TAIL ]; +} + +/* +* Move the entire contents of the specified rcu_segcblist structure, +* counts, callbacks, and all, to the specified rcu_cblist structure. +* @@@ Why do we need this??? Moving early-boot CBs to NOCB lists? +* @@@ Memory barrier needed? (Not if only used at boot time...) +*/ +static inline void rcu_segcblist_extract_all (struct rcu_segcblist *rsclp, +struct rcu_cblist *rclp) +{ +rcu_segcblist_extract_done_cbs (rsclp, rclp); +rcu_segcblist_extract_pend_cbs (rsclp, rclp); +rcu_segcblist_extract_count (rsclp, rclp); +} + +/* +* Insert counts from the specified rcu_cblist structure in the +* specified rcu_segcblist structure. +*/ +static inline void rcu_segcblist_insert_count (struct rcu_segcblist *rsclp, +struct rcu_cblist *rclp) +{ + rsclp->len_lazy += rclp->len_lazy; +/* ->len sampled locklessly. */ +WRITE_ONCE (rsclp->len, rsclp->len + rclp->len); + rclp->len_lazy =0 ; + rclp->len =0 ; +} + +/* +* Move callbacks from the specified rcu_cblist to the beginning of the +* done-callbacks segment of the specified rcu_segcblist. +*/ +static inline void rcu_segcblist_insert_done_cbs (struct rcu_segcblist *rsclp, +struct rcu_cblist *rclp) +{ +int i; + +if (!rclp->head) +return ;/* No callbacks to move. */ + *rclp->tail = rsclp->head; + rsclp->head = rclp->head; +for (i =RCU_DONE_TAIL ; i <RCU_CBLIST_NSEGS ; i++) +if (&rsclp->head == rsclp->tails[i]) + rsclp->tails[i] = rclp->tail; +else +break ; + rclp->head =NULL ; + rclp->tail = &rclp->head; +} + +/* +* Move callbacks from the specified rcu_cblist to the end of the +* new-callbacks segment of the specified rcu_segcblist. +*/ +static inline void rcu_segcblist_insert_pend_cbs (struct rcu_segcblist *rsclp, +struct rcu_cblist *rclp) +{ +if (!rclp->head) +return ;/* Nothing to do. */ + *rsclp->tails[RCU_NEXT_TAIL ] = rclp->head; + rsclp->tails[RCU_NEXT_TAIL ] = rclp->tail; + rclp->head =NULL ; + rclp->tail = &rclp->head; +} + +/* +* Advance the callbacks in the specified rcu_segcblist structure based +* on the current value passed in for the grace-period counter. +*/ +static inline void rcu_segcblist_advance (struct rcu_segcblist *rsclp, +unsigned long seq) +{ +int i, j; + +WARN_ON_ONCE (!rcu_segcblist_is_enabled (rsclp)); +if (rcu_segcblist_restempty (rsclp,RCU_DONE_TAIL )) +return ; + +/* +* Find all callbacks whose ->gp_seq numbers indicate that they +* are ready to invoke, and put them into the RCU_DONE_TAIL segment. +*/ +for (i =RCU_WAIT_TAIL ; i <RCU_NEXT_TAIL ; i++) { +if (ULONG_CMP_LT (seq, rsclp->gp_seq[i])) +break ; + rsclp->tails[RCU_DONE_TAIL ] = rsclp->tails[i]; + } + +/* If no callbacks moved, nothing more need be done. */ +if (i ==RCU_WAIT_TAIL ) +return ; + +/* Clean up tail pointers that might have been misordered above. */ +for (j =RCU_WAIT_TAIL ; j < i; j++) + rsclp->tails[j] = rsclp->tails[RCU_DONE_TAIL ]; + +/* +* Callbacks moved, so clean up the misordered ->tails[] pointers +* that now point into the middle of the list of ready-to-invoke +* callbacks. The overall effect is to copy down the later pointers +* into the gap that was created by the now-ready segments. +*/ +for (j =RCU_WAIT_TAIL ; i <RCU_NEXT_TAIL ; i++, j++) { +if (rsclp->tails[j] == rsclp->tails[RCU_NEXT_TAIL ]) +break ;/* No more callbacks. */ + rsclp->tails[j] = rsclp->tails[i]; + rsclp->gp_seq[j] = rsclp->gp_seq[i]; + } +} + +/* +* "Accelerate" callbacks based on more-accurate grace-period information. +* The reason for this is that RCU does not synchronize the beginnings and +* ends of grace periods, and that callbacks are posted locally. This in +* turn means that the callbacks must be labelled conservatively early +* on, as getting exact information would degrade both performance and +* scalability. When more accurate grace-period information becomes +* available, previously posted callbacks can be "accelerated", marking +* them to complete at the end of the earlier grace period. +* +* This function operates on an rcu_segcblist structure, and also the +* grace-period sequence number seq at which new callbacks would become +* ready to invoke. Returns true if there are callbacks that won't be +* ready to invoke until seq, false otherwise. +*/ +static inline bool rcu_segcblist_accelerate (struct rcu_segcblist *rsclp, +unsigned long seq) +{ +int i; + +WARN_ON_ONCE (!rcu_segcblist_is_enabled (rsclp)); +if (rcu_segcblist_restempty (rsclp,RCU_DONE_TAIL )) +return false; + +/* +* Find the segment preceding the oldest segment of callbacks +* whose ->gp_seq[] completion is at or after that passed in via +* "seq", skipping any empty segments. This oldest segment, along +* with any later segments, can be merged in with any newly arrived +* callbacks in the RCU_NEXT_TAIL segment, and assigned "seq" +* as their ->gp_seq[] grace-period completion sequence number. +*/ +for (i =RCU_NEXT_READY_TAIL ; i >RCU_DONE_TAIL ; i--) +if (rsclp->tails[i] != rsclp->tails[i -1 ] && +ULONG_CMP_LT (rsclp->gp_seq[i], seq)) +break ; + +/* +* If all the segments contain callbacks that correspond to +* earlier grace-period sequence numbers than "seq", leave. +* Assuming that the rcu_segcblist structure has enough +* segments in its arrays, this can only happen if some of +* the non-done segments contain callbacks that really are +* ready to invoke. This situation will get straightened +* out by the next call to rcu_segcblist_advance(). +* +* Also advance to the oldest segment of callbacks whose +* ->gp_seq[] completion is at or after that passed in via "seq", +* skipping any empty segments. +*/ +if (++i >=RCU_NEXT_TAIL ) +return false; + +/* +* Merge all later callbacks, including newly arrived callbacks, +* into the segment located by the for-loop above. Assign "seq" +* as the ->gp_seq[] value in order to correctly handle the case +* where there were no pending callbacks in the rcu_segcblist +* structure other than in the RCU_NEXT_TAIL segment. +*/ +for (; i <RCU_NEXT_TAIL ; i++) { + rsclp->tails[i] = rsclp->tails[RCU_NEXT_TAIL ]; + rsclp->gp_seq[i] = seq; + } +return true; +} + +/* +* Scan the specified rcu_segcblist structure for callbacks that need +* a grace period later than the one specified by "seq". We don't look +* at the RCU_DONE_TAIL or RCU_NEXT_TAIL segments because they don't +* have a grace-period sequence number. +*/ +static inline bool rcu_segcblist_future_gp_needed (struct rcu_segcblist *rsclp, +unsigned long seq) +{ +int i; + +for (i =RCU_WAIT_TAIL ; i <RCU_NEXT_TAIL ; i++) +if (rsclp->tails[i -1 ] != rsclp->tails[i] && +ULONG_CMP_LT (seq, rsclp->gp_seq[i])) +return true; +return false; +} + +/* +* Interim function to return rcu_segcblist head pointer. Longer term, the +* rcu_segcblist will be used more pervasively, removing the need for this +* function. +*/ +static inline struct rcu_head *rcu_segcblist_head (struct rcu_segcblist *rsclp) +{ +return rsclp->head; +} + +/* +* Interim function to return rcu_segcblist head pointer. Longer term, the +* rcu_segcblist will be used more pervasively, removing the need for this +* function. +*/ +static inline struct rcu_head **rcu_segcblist_tail (struct rcu_segcblist *rsclp) +{ +WARN_ON_ONCE (rcu_segcblist_empty (rsclp)); +return rsclp->tails[RCU_NEXT_TAIL ]; +}kernel/rcu/srcutree.c +1
-0@@ -38,6 +38,7 @@#include <linux/srcu.h> #include "rcu.h" +#include "rcu_segcblist.h" ulong exp_holdoff =25 *1000 ;/* Holdoff (ns) for auto-expediting. */ module_param (exp_holdoff, ulong,0444 );kernel/rcu/tree.h +2
-1@@ -30,9 +30,10 @@#include <linux/seqlock.h> #include <linux/swait.h> #include <linux/stop_machine.h> -#include <linux/rcu_segcblist.h> #include <linux/rcu_node_tree.h> +#include "rcu_segcblist.h" +/* * Dynticks per-CPU state. */
Re: [PATCH] srcu: Debloat the <linux/rcu_segcblist.h> header
Quoted 29 lines · Paul E. McKenney
Quoted 28 lines · Ingo Molnar
Quoted 6 lines · Ingo Molnar
Quoted 5 lines
I will get rid of the unused
rcu_segcblist_extract_all()function and create akernel/rcu/segcblist.cfor the functions that are either non-trivial or performance-insensitive.Does that cover it, or am I missing something?
Quoted 8 lines
I'd also suggest moving as much of the RCU internal data types into
kernel/rcu/as possible. It's not clear to me which part of it is supposed to be a public API and which bits are internal. It might make sense to keep it internal for the time being, and only export things once there are users.I.e. a pretty good solution would be to move all of
include/linux/rcu_segcblist.htokernel/rcu/rcu_segcblist.cor so - and do akernel/rcu/rcu_segcblist.hwith the data types and function prototypes.I.e. the attached patch as a first step.
Only minimally build tested, but it appears to be do the trick.
This changes the <
linux/rcu_segcblist.h> header from ~700 lines to only 90 lines - 60% of which is comments.The deinlining of the inline functions within
kernel/rcu/should also be done, as a separate patch on top of this.
Quoted 7 lines
Quoted 1 line
What do you think?
Thank you very much!
I have pulled this in and started a short rcutorture run. I will do de-inline and create a .c file on top of this and retest after the rcutorture has finished.
And I am applying the following fixlet for !SMP builds, which I am retesting. Other than that, initial rcutorture ran fine!
Thanx, Paul
------------------------------------------------------------------------
kernel/rcu/srcutiny.c +1 -0
@@ -30,6 +30,7 @@#include <linux/srcu.h> #include <linux/rcu_node_tree.h> +#include "rcu_segcblist.h" #include "rcu.h" static int init_srcu_struct_fields (struct srcu_struct *sp)
Linus,
Please pull the latest core-rcu-for-linus git tree from:
git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git core-rcu-for-linus
# HEAD: 20652ed6e44f4963281b65209b917be86ac6765b Merge branch 'for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu into core/rcu
This is the second version, with the header bloat bugs you pointed out in the first pull request (hopefully) fixed and tested. Here's the biggest header changes from the diffstat:
include/linux/rcu_node_tree.h | 99 ++ include/linux/rcu_segcblist.h | 90 ++ include/linux/srcuclassic.h | 115 ++ include/linux/srcutiny.h | 93 ++ include/linux/srcutree.h | 150 +++
these headers look pretty well concentrated now (to me).
There are no other changes over the v1 pull request.
The main changes are:
- Debloat RCU headers
- Parallelize SRCU callback handling (plus overlapping patches)
- Improve the performance of Tree SRCU on a CPU-hotplug stress test
- Documentation updates
- Miscellaneous fixes
Thanks,
Ingo
------------------>
Dmitry Vyukov (1):
rcu: Fix warning in rcu_seq_end()
Ingo Molnar (1):
srcu: Debloat the <linux/rcu_segcblist.h> header
Michael S. Tsirkin (1):
hlist_add_tail_rcu disable sparse warning
Michalis Kokologiannakis (1):
doc: Update the comparisons rule in rcu_dereference.txt
Nicholas Mc Guire (2):
rcu: Use bool value directly
rcu: Use true/false in assignment to bool
Paul E. McKenney (67):
doc: Synchronous RCU grace periods are now legal throughout boot
doc: Add mid-boot operation to expedited grace periods
doc: Update stallwarn.txt to make causes more prominent
doc: Update RCU data-structure documentation for rcu_segcblist
doc: Update requirements based on recent changes
doc: Update rcu_assign_pointer() definition in whatisRCU.txt
doc: Emphasize that "toy" RCU requires recursive rwlock
rcu: Maintain special bits at bottom of ->dynticks counter
rcu: Make arch select smp_mb__after_unlock_lock() strength
srcu: Consolidate batch checking into rcu_all_batches_empty()
srcu: Check for tardy grace-period activity in cleanup_srcu_struct()
rcu: Semicolon inside RCU_TRACE() for rcu.h
rcu: Semicolon inside RCU_TRACE() for Tiny RCU
rcu: Semicolon inside RCU_TRACE() for tree.c
rcu: Pull rcu_sched_qs_mask into rcu_dynticks structure
rcu: Pull rcu_qs_ctr into rcu_dynticks structure
rcu: Eliminate flavor scan in rcu_momentary_dyntick_idle()
rcu: Place guard on rcu_all_qs() and rcu_note_context_switch() actions
rcu: Default RCU_FANOUT_LEAF to 16 unless explicitly changed
srcu: Abstract multi-tail callback list handling
srcu: Allow SRCU to access rcu_scheduler_active
srcu: Allow early boot use of synchronize_srcu()
rcu: Add single-element dequeue functions to rcu_segcblist
srcu: Move rcu_seq_start() and friends to rcu.h
rcu: Expedited wakeups need to be fully ordered
srcu: Push srcu_advance_batches() fastpath into common case
srcu: Move to state-based grace-period sequencing
srcu: Add grace-period sequence numbers
srcu: Use rcu_segcblist to track SRCU callbacks
srcu: Move combining-tree definitions for SRCU's benefit
srcu: Move rcu_init_levelspread() to rcu_tree_node.h
rcu: Remove redundant levelcnt[] array from rcu_init_one()
srcu: Move rcu_node traversal macros to rcu.h
srcu: Make num_rcu_lvl[] array be external
srcu: Fix bogus try_check_zero() comment
srcu: Improve rcu_seq grace-period-counter abstraction
srcu: Allow a second bit in rcu_seq for SRCU state
srcu: Merge ->srcu_state into ->srcu_gp_seq
srcu: Crude control of expedited grace periods
mm: Use static initialization for "srcu"
srcu: Create a tiny SRCU
srcutorture: Print Tiny SRCU reader statistics
srcu: Introduce CLASSIC_SRCU Kconfig option
mm: Rename SLAB_DESTROY_BY_RCU to SLAB_TYPESAFE_BY_RCU
lockdep: Use "WARNING" tag on lockdep splats
types: Update obsolete callback_head comment
rcu: Make RCU_FANOUT_LEAF help text more explicit about skew_tick
rcu: Remove obsolete comment from rcu_future_gp_cleanup() header
rcu: Improve comments for hotplug/suspend/hibernate functions
torture: Use correct path for Kconfig fragment for duplicates
rcu: Fix typo in PER_RCU_NODE_PERIOD header comment
kvm: Move srcu_struct fields to end of struct kvm
srcu: Parallelize callback handling
srcu: Expedite srcu_schedule_cbs_snp() callback invocation
rcu: Make non-preemptive schedule be Tasks RCU quiescent state
srcu: Fix Kconfig botch when SRCU not selected
srcu: Make SRCU be built by default
srcu: Exact tracking of srcu_data structures containing callbacks
srcu: Make rcutorture writer stalls print SRCU GP state
srcu: Expedited grace periods with reduced memory contention
srcu: Expedite first synchronize_srcu() when idle
srcu: Specify auto-expedite holdoff time
srcu: Adjust default auto-expediting holdoff
rcu: Separately compile large rcu_segcblist functions
rcu: Open-code the rcu_cblist_empty() function
rcu: Open-code the rcu_cblist_n_cbs() function
rcu: Open-code the rcu_cblist_n_lazy_cbs() function
pierre Kuo (1):
doc: Update control-dependencies section of memory-barriers.txt
Documentation/RCU/00-INDEX | 2 +- .../Design/Data-Structures/Data-Structures.html | 233 ++-- .../RCU/Design/Data-Structures/nxtlist.svg | 34 +- .../Expedited-Grace-Periods.html | 47 +- .../RCU/Design/Requirements/Requirements.html | 195 +++- Documentation/RCU/rcu_dereference.txt | 9 + Documentation/RCU/rculist_nulls.txt | 6 +- Documentation/RCU/stallwarn.txt | 190 ++-- Documentation/RCU/whatisRCU.txt | 32 +- Documentation/admin-guide/kernel-parameters.txt | 8 + Documentation/memory-barriers.txt | 2 +- arch/Kconfig | 3 + arch/powerpc/Kconfig | 1 + drivers/gpu/drm/i915/i915_gem.c | 2 +- drivers/gpu/drm/i915/i915_gem_request.h | 2 +- drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c | 2 +- fs/jbd2/journal.c | 2 +- fs/signalfd.c | 2 +- include/linux/dma-fence.h | 4 +- include/linux/kvm_host.h | 4 +- include/linux/rcu_node_tree.h | 99 ++ include/linux/rcu_segcblist.h | 90 ++ include/linux/rculist.h | 3 +- include/linux/rcupdate.h | 17 +- include/linux/rcutiny.h | 24 +- include/linux/rcutree.h | 5 +- include/linux/slab.h | 6 +- include/linux/srcu.h | 84 +- include/linux/srcuclassic.h | 115 ++ include/linux/srcutiny.h | 93 ++ include/linux/srcutree.h | 150 +++ include/linux/types.h | 2 +- include/net/sock.h | 2 +- init/Kconfig | 43 +- kernel/fork.c | 4 +- kernel/locking/lockdep.c | 86 +- kernel/locking/rtmutex-debug.c | 9 +- kernel/rcu/Makefile | 5 +- kernel/rcu/rcu.h | 153 ++- kernel/rcu/rcu_segcblist.c | 505 +++++++++ kernel/rcu/rcu_segcblist.h | 164 +++ kernel/rcu/rcutorture.c | 43 +- kernel/rcu/srcu.c | 12 +- kernel/rcu/srcutiny.c | 216 ++++ kernel/rcu/srcutree.c | 1155 ++++++++++++++++++++ kernel/rcu/tiny.c | 20 +- kernel/rcu/tiny_plugin.h | 13 +- kernel/rcu/tree.c | 710 +++++------- kernel/rcu/tree.h | 163 +-- kernel/rcu/tree_exp.h | 25 +- kernel/rcu/tree_plugin.h | 64 +- kernel/rcu/tree_trace.c | 26 +- kernel/rcu/update.c | 53 +- kernel/sched/core.c | 2 +- kernel/signal.c | 2 +- mm/kasan/kasan.c | 6 +- mm/kmemcheck.c | 2 +- mm/mmu_notifier.c | 14 +- mm/rmap.c | 4 +- mm/slab.c | 6 +- mm/slab.h | 4 +- mm/slab_common.c | 6 +- mm/slob.c | 6 +- mm/slub.c | 12 +- net/dccp/ipv4.c | 2 +- net/dccp/ipv6.c | 2 +- net/ipv4/tcp_ipv4.c | 2 +- net/ipv6/tcp_ipv6.c | 2 +- net/llc/af_llc.c | 2 +- net/llc/llc_conn.c | 4 +- net/llc/llc_sap.c | 2 +- net/netfilter/nf_conntrack_core.c | 8 +- net/smc/af_smc.c | 2 +- .../selftests/rcutorture/bin/kvm-test-1-run.sh | 2 +- 74 files changed, 3903 insertions(+), 1128 deletions(-) create mode 100644 include/linux/rcu_node_tree.h create mode 100644 include/linux/rcu_segcblist.h create mode 100644 include/linux/srcuclassic.h create mode 100644 include/linux/srcutiny.h create mode 100644 include/linux/srcutree.h create mode 100644 kernel/rcu/rcu_segcblist.c create mode 100644 kernel/rcu/rcu_segcblist.h create mode 100644 kernel/rcu/srcutiny.c create mode 100644 kernel/rcu/srcutree.c
Documentation/RCU/00-INDEX +1 -1
@@ -17,7 +17,7 @@ rcu_dereference.txt rcubarrier.txt - RCU and Unloadable Modules rculist_nulls.txt - - RCU list primitives for use with SLAB_DESTROY_BY_RCU + - RCU list primitives for use with SLAB_TYPESAFE_BY_RCU rcuref.txt - Reference-count design for elements of lists/arrays protected by RCU rcu.txt
Documentation/RCU/Design/Data-Structures/Data-Structures.html +169 -64
282 lines not on this page · raw message
Documentation/RCU/Design/Data-Structures/nxtlist.svg +12 -22
@@ -19,7 +19,7 @@ id="svg2" version="1.1" inkscape:version="0.48.4 r9939" - sodipodi:docname="nxtlist.fig"> + sodipodi:docname="segcblist.svg"> <metadata id="metadata94"> <rdf:RDF>
@@ -28,7 +28,7 @@ <dc:format>image/svg+xml</dc:format> <dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> + <dc:title /> </cc:Work> </rdf:RDF> </metadata>
@@ -241,61 +241,51 @@ xml:space="preserve" x="225" y="675" - fill="#000000" - font-family="Courier" font-style="normal" font-weight="bold" font-size="324" - text-anchor="start" - id="text64">nxtlist</text> + id="text64" + style="font-size:324px;font-style:normal;font-weight:bold;text-anchor:start;fill:#000000;font-family:Courier">->head</text> <!-- Text --> <text xml:space="preserve" x="225" y="1800" - fill="#000000" - font-family="Courier" font-style="normal" font-weight="bold" font-size="324" - text-anchor="start" - id="text66">nxttail[RCU_DONE_TAIL]</text> + id="text66" + style="font-size:324px;font-style:normal;font-weight:bold;text-anchor:start;fill:#000000;font-family:Courier">->tails[RCU_DONE_TAIL]</text> <!-- Text --> <text xml:space="preserve" x="225" y="2925" - fill="#000000" - font-family="Courier" font-style="normal" font-weight="bold" font-size="324" - text-anchor="start" - id="text68">nxttail[RCU_WAIT_TAIL]</text> + id="text68" + style="font-size:324px;font-style:normal;font-weight:bold;text-anchor:start;fill:#000000;font-family:Courier">->tails[RCU_WAIT_TAIL]</text> <!-- Text --> <text xml:space="preserve" x="225" y="4050" - fill="#000000" - font-family="Courier" font-style="normal" font-weight="bold" font-size="324" - text-anchor="start" - id="text70">nxttail[RCU_NEXT_READY_TAIL]</text> + id="text70" + style="font-size:324px;font-style:normal;font-weight:bold;text-anchor:start;fill:#000000;font-family:Courier">->tails[RCU_NEXT_READY_TAIL]</text> <!-- Text --> <text xml:space="preserve" x="225" y="5175" - fill="#000000" - font-family="Courier" font-style="normal" font-weight="bold" font-size="324" - text-anchor="start" - id="text72">nxttail[RCU_NEXT_TAIL]</text> + id="text72" + style="font-size:324px;font-style:normal;font-weight:bold;text-anchor:start;fill:#000000;font-family:Courier">->tails[RCU_NEXT_TAIL]</text> <!-- Text --> <text xml:space="preserve"
Documentation/RCU/Design/Expedited-Grace-Periods/Expedited-Grace-Periods.html +44 -3
71 lines not on this page · raw message
Documentation/RCU/Design/Requirements/Requirements.html +138 -57
288 lines not on this page · raw message
Documentation/RCU/rcu_dereference.txt +9 -0
@@ -138,6 +138,15 @@ o Be very careful about comparing pointers obtained from This sort of comparison occurs frequently when scanning RCU-protected circular linked lists. + Note that if checks for being within an RCU read-side + critical section are not required and the pointer is never + dereferenced, rcu_access_pointer() should be used in place + of rcu_dereference(). The rcu_access_pointer() primitive + does not require an enclosing read-side critical section, + and also omits the smp_read_barrier_depends() included in + rcu_dereference(), which in turn should provide a small + performance gain in some CPUs (e.g., the DEC Alpha). + o The comparison is against a pointer that references memory that was initialized "a long time ago." The reason this is safe is that even if misordering occurs, the
Documentation/RCU/rculist_nulls.txt +3 -3
@@ -1,5 +1,5 @@ Using hlist_nulls to protect read-mostly linked lists and -objects using SLAB_DESTROY_BY_RCU allocations. +objects using SLAB_TYPESAFE_BY_RCU allocations. Please read the basics in Documentation/RCU/listRCU.txt
@@ -7,7 +7,7 @@ Using special makers (called 'nulls') is a convenient way to solve following problem : A typical RCU linked list managing objects which are -allocated with SLAB_DESTROY_BY_RCU kmem_cache can +allocated with SLAB_TYPESAFE_BY_RCU kmem_cache can use following algos : 1) Lookup algo
@@ -96,7 +96,7 @@ unlock_chain(); // typically a spin_unlock() 3) Remove algo -------------- Nothing special here, we can use a standard RCU hlist deletion. -But thanks to SLAB_DESTROY_BY_RCU, beware a deleted object can be reused +But thanks to SLAB_TYPESAFE_BY_RCU, beware a deleted object can be reused very very fast (before the end of RCU grace period) if (put_last_reference_on(obj) {
Documentation/RCU/stallwarn.txt +100 -90
204 lines not on this page · raw message
Documentation/RCU/whatisRCU.txt +18 -14
@@ -562,7 +562,9 @@ This section presents a "toy" RCU implementation that is based on familiar locking primitives. Its overhead makes it a non-starter for real-life use, as does its lack of scalability. It is also unsuitable for realtime use, since it allows scheduling latency to "bleed" from -one read-side critical section to another. +one read-side critical section to another. It also assumes recursive +reader-writer locks: If you try this with non-recursive locks, and +you allow nested rcu_read_lock() calls, you can deadlock. However, it is probably the easiest implementation to relate to, so is a good starting point.
@@ -587,20 +589,21 @@ a good starting point. write_unlock(&rcu_gp_mutex); } -[You can ignore rcu_assign_pointer() and rcu_dereference() without -missing much. But here they are anyway. And whatever you do, don't -forget about them when submitting patches making use of RCU!] +[You can ignore rcu_assign_pointer() and rcu_dereference() without missing +much. But here are simplified versions anyway. And whatever you do, +don't forget about them when submitting patches making use of RCU!] - #define rcu_assign_pointer(p, v) ({ \ - smp_wmb(); \ - (p) = (v); \ - }) + #define rcu_assign_pointer(p, v) \ + ({ \ + smp_store_release(&(p), (v)); \ + }) - #define rcu_dereference(p) ({ \ - typeof(p) _________p1 = p; \ - smp_read_barrier_depends(); \ - (_________p1); \ - }) + #define rcu_dereference(p) \ + ({ \ + typeof(p) _________p1 = p; \ + smp_read_barrier_depends(); \ + (_________p1); \ + }) The rcu_read_lock() and rcu_read_unlock() primitive read-acquire
@@ -925,7 +928,8 @@ d. Do you need RCU grace periods to complete even in the face e. Is your workload too update-intensive for normal use of RCU, but inappropriate for other synchronization mechanisms? - If so, consider SLAB_DESTROY_BY_RCU. But please be careful! + If so, consider SLAB_TYPESAFE_BY_RCU (which was originally + named SLAB_DESTROY_BY_RCU). But please be careful! f. Do you need read-side critical sections that are respected even though they are in the middle of the idle loop, during
Documentation/admin-guide/kernel-parameters.txt +8 -0
@@ -3779,6 +3779,14 @@ spia_pedr= spia_peddr= + srcutree.exp_holdoff [KNL] + Specifies how many nanoseconds must elapse + since the end of the last SRCU grace period for + a given srcu_struct until the next normal SRCU + grace period will be considered for automatic + expediting. Set to zero to disable automatic + expediting. + stacktrace [FTRACE] Enabled the stack tracer on boot up.
Documentation/memory-barriers.txt +1 -1
@@ -768,7 +768,7 @@ equal to zero, in which case the compiler is within its rights to transform the above code into the following: q = READ_ONCE(a); - WRITE_ONCE(b, 1); + WRITE_ONCE(b, 2); do_something_else(); Given this transformation, the CPU is not required to respect the ordering
arch/Kconfig +3 -0
@@ -320,6 +320,9 @@ config HAVE_CMPXCHG_LOCAL config HAVE_CMPXCHG_DOUBLE bool +config ARCH_WEAK_RELEASE_ACQUIRE + bool + config ARCH_WANT_IPC_PARSE_VERSION bool
arch/powerpc/Kconfig +1 -0
@@ -99,6 +99,7 @@ config PPC select ARCH_USE_BUILTIN_BSWAP select ARCH_USE_CMPXCHG_LOCKREF if PPC64 select ARCH_WANT_IPC_PARSE_VERSION + select ARCH_WEAK_RELEASE_ACQUIRE select BINFMT_ELF select BUILDTIME_EXTABLE_SORT select CLONE_BACKWARDS
drivers/gpu/drm/i915/i915_gem.c +1 -1
@@ -4665,7 +4665,7 @@ i915_gem_load_init(struct drm_i915_private *dev_priv) dev_priv->requests =KMEM_CACHE (drm_i915_gem_request,SLAB_HWCACHE_ALIGN |SLAB_RECLAIM_ACCOUNT | -SLAB_DESTROY_BY_RCU ); +SLAB_TYPESAFE_BY_RCU );if (!dev_priv->requests) goto err_vmas;
drivers/gpu/drm/i915/i915_gem_request.h +1 -1
@@ -493,7 +493,7 @@ static inline struct drm_i915_gem_request * __i915_gem_active_get_rcu(const struct i915_gem_active *active) {/* Performing a lockless retrieval of the active request is super -* tricky. SLAB_DESTROY_BY_RCU merely guarantees that the backing +* tricky. SLAB_TYPESAFE_BY_RCU merely guarantees that the backing * slab of request objects will not be freed whilst we hold the * RCU read lock. It does not guarantee that the request itself * will not be freed and then *reused*. Viz,
drivers/staging/lustre/lustre/ldlm/ldlm_lockd.c +1 -1
@@ -1071,7 +1071,7 @@ int ldlm_init(void) ldlm_lock_slab =kmem_cache_create ("ldlm_locks" ,sizeof (struct ldlm_lock ),0 ,SLAB_HWCACHE_ALIGN | -SLAB_DESTROY_BY_RCU ,NULL ); +SLAB_TYPESAFE_BY_RCU ,NULL );if (!ldlm_lock_slab) {kmem_cache_destroy (ldlm_resource_slab);return -ENOMEM ;
fs/jbd2/journal.c +1 -1
@@ -2340,7 +2340,7 @@ static int jbd2_journal_init_journal_head_cache(void) jbd2_journal_head_cache =kmem_cache_create ("jbd2_journal_head" ,sizeof (struct journal_head ),0 ,/* offset */ -SLAB_TEMPORARY |SLAB_DESTROY_BY_RCU , +SLAB_TEMPORARY |SLAB_TYPESAFE_BY_RCU ,NULL );/* ctor */ retval =0 ;if (!jbd2_journal_head_cache) {
fs/signalfd.c +1 -1
@@ -38,7 +38,7 @@ void signalfd_cleanup(struct sighand_struct *sighand)/* * The lockless check can race with remove_wait_queue() in progress, * but in this case its caller should run under rcu_read_lock() and -* sighand_cachep is SLAB_DESTROY_BY_RCU, we can safely return. +* sighand_cachep is SLAB_TYPESAFE_BY_RCU, we can safely return. */ if (likely (!waitqueue_active (wqh)))return ;
include/linux/dma-fence.h +2 -2
@@ -229,7 +229,7 @@ static inline struct dma_fence *dma_fence_get_rcu(struct dma_fence *fence)* * Function returns NULL if no refcount could be obtained, or the fence. * This function handles acquiring a reference to a fence that may be -* reallocated within the RCU grace period (such as with SLAB_DESTROY_BY_RCU), +* reallocated within the RCU grace period (such as with SLAB_TYPESAFE_BY_RCU), * so long as the caller is using RCU on the pointer to the fence. * * An alternative mechanism is to employ a seqlock to protect a bunch of
@@ -257,7 +257,7 @@ dma_fence_get_rcu_safe(struct dma_fence * __rcu *fencep)* have successfully acquire a reference to it. If it no * longer matches, we are holding a reference to some other * reallocated pointer. This is possible if the allocator -* is using a freelist like SLAB_DESTROY_BY_RCU where the +* is using a freelist like SLAB_TYPESAFE_BY_RCU where the * fence remains valid for the RCU grace period, but it * may be reallocated. When using such allocators, we are * responsible for ensuring the reference we get is to
include/linux/kvm_host.h +2 -2
@@ -375,8 +375,6 @@ struct kvm {struct mutex slots_lock;struct mm_struct *mm;/* userspace tied to this vm */ struct kvm_memslots *memslots[KVM_ADDRESS_SPACE_NUM ]; -struct srcu_struct srcu; -struct srcu_struct irq_srcu;struct kvm_vcpu *vcpus[KVM_MAX_VCPUS ];/*
@@ -429,6 +427,8 @@ struct kvm {struct list_head devices;struct dentry *debugfs_dentry;struct kvm_stat_data **debugfs_stat_data; +struct srcu_struct srcu; +struct srcu_struct irq_srcu; };#define kvm_err (fmt, ...) \
include/linux/rcu_node_tree.h new file +99 -0
99 lines not on this page · raw message
include/linux/rcu_segcblist.h new file +90 -0
90 lines not on this page · raw message
include/linux/rculist.h +2 -1
@@ -509,7 +509,8 @@ static inline void hlist_add_tail_rcu(struct hlist_node *n, {struct hlist_node *i, *last =NULL ; -for (i =hlist_first_rcu (h); i; i =hlist_next_rcu (i)) +/* Note: write side code, so rcu accessors are not needed. */ +for (i = h->first; i; i = i->next) last = i;if (last) {
include/linux/rcupdate.h +11 -6
@@ -363,15 +363,20 @@ static inline void rcu_init_nohz(void)#ifdef CONFIG_TASKS_RCU #define TASKS_RCU (x) xextern struct srcu_struct tasks_rcu_exit_srcu; -#define rcu_note_voluntary_context_switch (t) \ +#define rcu_note_voluntary_context_switch_lite (t) \ do { \ - rcu_all_qs(); \ if (READ_ONCE((t)->rcu_tasks_holdout)) \ WRITE_ONCE((t)->rcu_tasks_holdout, false); \ } while (0) +#define rcu_note_voluntary_context_switch (t) \ + do { \ + rcu_all_qs(); \ + rcu_note_voluntary_context_switch_lite(t); \ + } while (0)#else /* #ifdef CONFIG_TASKS_RCU */ #define TASKS_RCU (x) do { } while (0) -#define rcu_note_voluntary_context_switch (t) rcu_all_qs() +#define rcu_note_voluntary_context_switch_lite (t) do { } while (0) +#define rcu_note_voluntary_context_switch (t) rcu_all_qs()#endif /* #else #ifdef CONFIG_TASKS_RCU */ /**
@@ -1127,11 +1132,11 @@ do { \* if the UNLOCK and LOCK are executed by the same CPU or if the * UNLOCK and LOCK operate on the same lock variable. */ -#ifdef CONFIG_PPC +#ifdef CONFIG_ARCH_WEAK_RELEASE_ACQUIRE #define smp_mb__after_unlock_lock () smp_mb()/* Full ordering for lock. */ -#else /* #ifdef CONFIG_PPC */ +#else /* #ifdef CONFIG_ARCH_WEAK_RELEASE_ACQUIRE */ #define smp_mb__after_unlock_lock () do { } while (0) -#endif /* #else #ifdef CONFIG_PPC */ +#endif /* #else #ifdef CONFIG_ARCH_WEAK_RELEASE_ACQUIRE */ #endif /* __LINUX_RCUPDATE_H */
include/linux/rcutiny.h +17 -7
@@ -33,6 +33,11 @@ static inline int rcu_dynticks_snap(struct rcu_dynticks *rdtp)return 0 ; } +static inline bool rcu_eqs_special_set (int cpu) +{ +return false;/* Never flag non-existent other CPUs! */ +} +static inline unsigned long get_state_synchronize_rcu (void ) {return 0 ;
@@ -87,10 +92,11 @@ static inline void kfree_call_rcu(struct rcu_head *head,call_rcu (head, func); } -static inline void rcu_note_context_switch (void ) -{ -rcu_sched_qs (); -} +#define rcu_note_context_switch (preempt) \ + do { \ + rcu_sched_qs(); \ + rcu_note_voluntary_context_switch_lite(current); \ + } while (0)/* * Take advantage of the fact that there is only one CPU, which
@@ -212,14 +218,14 @@ static inline void exit_rcu(void) { } -#ifdef CONFIG_DEBUG_LOCK_ALLOC +#if defined(CONFIG_DEBUG_LOCK_ALLOC ) || defined(CONFIG_SRCU )extern int rcu_scheduler_active__read_mostly ;void rcu_scheduler_starting (void ); -#else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */ +#else /* #if defined(CONFIG_DEBUG_LOCK_ALLOC) || defined(CONFIG_SRCU) */ static inline void rcu_scheduler_starting (void ) { } -#endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */ +#endif /* #else #if defined(CONFIG_DEBUG_LOCK_ALLOC) || defined(CONFIG_SRCU) */ #if defined(CONFIG_DEBUG_LOCK_ALLOC ) || defined(CONFIG_RCU_TRACE )
@@ -237,6 +243,10 @@ static inline bool rcu_is_watching(void)#endif /* #else defined(CONFIG_DEBUG_LOCK_ALLOC) || defined(CONFIG_RCU_TRACE) */ +static inline void rcu_request_urgent_qs_task (struct task_struct *t) +{ +} +static inline void rcu_all_qs (void ) {barrier ();/* Avoid RCU read-side critical sections leaking across. */
include/linux/rcutree.h +3 -2
@@ -30,7 +30,7 @@#ifndef __LINUX_RCUTREE_H#define __LINUX_RCUTREE_H -void rcu_note_context_switch (void ); +void rcu_note_context_switch (bool preempt);int rcu_needs_cpu (u64 basem,u64 *nextevt);void rcu_cpu_stall_reset (void );
@@ -41,7 +41,7 @@ void rcu_cpu_stall_reset(void);*/ static inline void rcu_virt_note_context_switch (int cpu) { -rcu_note_context_switch (); +rcu_note_context_switch (false); }void synchronize_rcu_bh (void );
@@ -108,6 +108,7 @@ void rcu_scheduler_starting(void);extern int rcu_scheduler_active__read_mostly ;bool rcu_is_watching (void ); +void rcu_request_urgent_qs_task (struct task_struct *t);void rcu_all_qs (void );
include/linux/slab.h +4 -2
@@ -28,7 +28,7 @@#define SLAB_STORE_USER 0x00010000UL/* DEBUG: Store the last owner for bug hunting */ #define SLAB_PANIC 0x00040000UL/* Panic if kmem_cache_create() fails */ /* -* SLAB_DESTROY_BY_RCU - **WARNING** READ THIS! +* SLAB_TYPESAFE_BY_RCU - **WARNING** READ THIS! * * This delays freeing the SLAB page by a grace period, it does _NOT_ * delay object freeing. This means that if you do kmem_cache_free()
@@ -61,8 +61,10 @@* * rcu_read_lock before reading the address, then rcu_read_unlock after * taking the spinlock within the structure expected at that address. +* +* Note that SLAB_TYPESAFE_BY_RCU was originally named SLAB_DESTROY_BY_RCU. */ -#define SLAB_DESTROY_BY_RCU 0x00080000UL/* Defer freeing slabs to RCU */ +#define SLAB_TYPESAFE_BY_RCU 0x00080000UL/* Defer freeing slabs to RCU */ #define SLAB_MEM_SPREAD 0x00100000UL/* Spread some memory over cpuset */ #define SLAB_TRACE 0x00200000UL/* Trace allocations and frees */
include/linux/srcu.h +12 -72
109 lines not on this page · raw message
include/linux/srcuclassic.h new file +115 -0
115 lines not on this page · raw message
include/linux/srcutiny.h new file +93 -0
93 lines not on this page · raw message
include/linux/srcutree.h new file +150 -0
150 lines not on this page · raw message
include/linux/types.h +1 -1
@@ -209,7 +209,7 @@ struct ustat {* naturally due ABI requirements, but some architectures (like CRIS) have * weird ABI and we need to ask it explicitly. * -* The alignment is required to guarantee that bits 0 and 1 of @next will be +* The alignment is required to guarantee that bit 0 of @next will be * clear under normal conditions -- as long as we use call_rcu(), * call_rcu_bh(), call_rcu_sched(), or call_srcu() to queue callback. *
include/net/sock.h +1 -1
@@ -995,7 +995,7 @@ struct smc_hashinfo;struct module ;/* -* caches using SLAB_DESTROY_BY_RCU should let .next pointer from nulls nodes +* caches using SLAB_TYPESAFE_BY_RCU should let .next pointer from nulls nodes * un-modified. Special care is taken when initializing object to zero. */ static inline void sk_prot_clear_nulls (struct sock *sk,int size)
init/Kconfig +41 -2
69 lines not on this page · raw message
kernel/fork.c +2 -2
@@ -1313,7 +1313,7 @@ void __cleanup_sighand(struct sighand_struct *sighand)if (atomic_dec_and_test (&sighand->count)) {signalfd_cleanup (sighand);/* -* sighand_cachep is SLAB_DESTROY_BY_RCU so we can free it +* sighand_cachep is SLAB_TYPESAFE_BY_RCU so we can free it * without an RCU grace period, see __lock_task_sighand(). */ kmem_cache_free (sighand_cachep, sighand);
@@ -2144,7 +2144,7 @@ void __init proc_caches_init(void) { sighand_cachep =kmem_cache_create ("sighand_cache" ,sizeof (struct sighand_struct ),0 , -SLAB_HWCACHE_ALIGN |SLAB_PANIC |SLAB_DESTROY_BY_RCU | +SLAB_HWCACHE_ALIGN |SLAB_PANIC |SLAB_TYPESAFE_BY_RCU |SLAB_NOTRACK |SLAB_ACCOUNT , sighand_ctor); signal_cachep = kmem_cache_create("signal_cache", sizeof(struct signal_struct), 0,
kernel/locking/lockdep.c +43 -43
185 lines not on this page · raw message
kernel/locking/rtmutex-debug.c +5 -4
@@ -102,10 +102,11 @@ void debug_rt_mutex_print_deadlock(struct rt_mutex_waiter *waiter)return ; } -printk ("\n============================================\n" ); -printk ("[ BUG: circular locking deadlock detected! ]\n" ); -printk ("%s\n" ,print_tainted ()); -printk ("--------------------------------------------\n" ); +pr_warn ("\n" ); +pr_warn ("============================================\n" ); +pr_warn ("WARNING: circular locking deadlock detected!\n" ); +pr_warn ("%s\n" ,print_tainted ()); +pr_warn ("--------------------------------------------\n" );printk ("%s/%d is deadlocking current task %s/%d\n\n" , task->comm,task_pid_nr (task), current->comm,task_pid_nr (current));
kernel/rcu/Makefile +4 -1
@@ -3,10 +3,13 @@ KCOV_INSTRUMENT := n obj-y += update.o sync.o -obj-$(CONFIG_SRCU) += srcu.o +obj-$(CONFIG_CLASSIC_SRCU) += srcu.o +obj-$(CONFIG_TREE_SRCU) += srcutree.o +obj-$(CONFIG_TINY_SRCU) += srcutiny.o obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o obj-$(CONFIG_RCU_PERF_TEST) += rcuperf.o obj-$(CONFIG_TREE_RCU) += tree.o obj-$(CONFIG_PREEMPT_RCU) += tree.o obj-$(CONFIG_TREE_RCU_TRACE) += tree_trace.o obj-$(CONFIG_TINY_RCU) += tiny.o +obj-$(CONFIG_RCU_NEED_SEGCBLIST) += rcu_segcblist.o
kernel/rcu/rcu.h +151 -2
173 lines not on this page · raw message
kernel/rcu/rcu_segcblist.c new file +505 -0
505 lines not on this page · raw message
kernel/rcu/rcu_segcblist.h new file +164 -0
71 lines not on this page · raw message
kernel/rcu/rcutorture.c +36 -7
43 lines not on this page · raw message
kernel/rcu/srcutiny.c new file +216 -0
216 lines not on this page · raw message
kernel/rcu/srcutree.c new file +1155 -0
1,155 lines not on this page · raw message
kernel/rcu/tree.c +293 -417
710 lines not on this page · raw message
kernel/rcu/tree.h +20 -143
163 lines not on this page · raw message
kernel/rcu/tree_plugin.h +32 -32
64 lines not on this page · raw message
kernel/rcu/update.c +35 -18
53 lines not on this page · raw message
tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh +1 -1
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
Quoted 2 lines · Ingo Molnar
The main changes are:
So I've pulled it now (although it is showing signs of semantic conflicts, so I'll have to look at those), but I've got two requests, one for Ingo, one for Paul.
Ingo: please don't bother sending me stupid crap.
And by that I mean the whole patch WHEN IT IS 300kB IN SIZE!
That's just idiotic. Nobody is ever going to review a 300kB patch that is ~7500 lines. All it does is waste time, and make it a pain to even reply to your emails (since I have "include quoted original" on by default in order to be able to quote and reply sanely).
There's a reason "git request-pull" only does the diffstat and the shortlog.
So please fix your scripts. If a patch is so big that is is not worth reviewing, don't include it. I don't know exactly where that limit is, but I would suggest that it is on the order of 1000 lines or so.
This is particularly annoying, because your pull request is one huge pile of shit. It has all that completely useless stuff that nobody is ever going to look at, and it didn't actually mention the *important* parts, namely how the RCU changes apparently mess with the DRM selftest changes.
So stop sending me stupid crap, and please send me the *relevant* stuff instead.
Quoted 5 lines
- Debloat RCU headers
- Parallelize SRCU callback handling (plus overlapping patches)
- Improve the performance of Tree SRCU on a CPU-hotplug stress test
And for Paul: the RCU subsystem is starting to get ridiculous. Seriously.
That is *particularly* true for srcu. We don't even have all that many users, and I suspect a large subset of those users are just crap to begin with. The biggest reason for srcu seems to be bad callbacks, particularly shit like the mmu notifier code. Things that we probably shouldn't have done in the first place, and where srcu just encouraged people to do bad things.
Seriously, do this:
git grep srcu.*lock -- :^Documentation/ :^kernel/rcu/
and notice that we have only a few hundred lines in the kernel that do srcu locking. kvm seems to be the main big user.
This annoys me, because the main reason people use srcu is bad design and lazyness, where they can't be arsed to try to minimize locking and sleeping things. The "sleeping callbacks" in particular tend to be a huge design mistake.
Yet, despite this fairly limited use, rscu seems to be just growing and bloating, and making more and more excuses fro bad behavior.
And it was *years* since I asked you to look at getting rid of the absolutely insane proliferations of different RCU models. I don't think anything ever happened. We *still* have TREE_RCU,| PREEMPT_RCU, and TINY_SRCU.
And with this pull request we now have CLASSIC_SRCU, TINY_SRCU, TREE_SRCU and TASKS_RCU.
That's in addition to all the other insane tweaks that nobody uses (eg RCU_FANOUT etc) and that I made sure got removed from any sane questionnaire.
Paul, this really needs to stop.
I'm now going to stop pulling any more crazy RCU crap. Seriously. If the RCU subsystem doesn't start shrinking, I'm no longer pulling. Send me fixes, but don't send me more of this crazy stuff.
So this is me putting my foot down. I should have done it long ago. I'm done with crazy. Don't waste your time doing yet another RCU mode, because I will not take it. And don't waste your time expanding on the existing ones without looking at which of those things can be removed.
Linus
Quoted 8 lines · Linus Torvalds
Quoted 2 lines · Ingo Molnar
The main changes are:
So I've pulled it now (although it is showing signs of semantic conflicts, so I'll have to look at those), but I've got two requests, one for Ingo, one for Paul.
Quoted 8 lines
Ingo: please don't bother sending me stupid crap.
And by that I mean the whole patch WHEN IT IS 300kB IN SIZE!
That's just idiotic. Nobody is ever going to review a 300kB patch that is ~7500 lines. All it does is waste time, and make it a pain to even reply to your emails (since I have "include quoted original" on by default in order to be able to quote and reply sanely).
Yeah, you are right and sorry about that - I have removed the patch generation from my pull request scripts, so it shouldn't happen in the future.
Thanks,
Ingo
On Wed, May 10, 2017 at 10:27:24AM -0700, Linus Torvalds wrote:
[ . . . ]
Quoted 2 lines
parts, namely how the RCU changes apparently mess with the DRM selftest changes.
I am testing a merge with current linus/master, and I looked through the commits in -next selected by:
gitk v4.11.. --no-merges --all-match --grep=drm --grep=selftest
I didn't find anything obvious. If the tests complete successfully, I will try running the DRM selftest.
[ . . . ]
Quoted 16 lines
And for Paul: the RCU subsystem is starting to get ridiculous. Seriously.
That is *particularly* true for srcu. We don't even have all that many users, and I suspect a large subset of those users are just crap to begin with. The biggest reason for srcu seems to be bad callbacks, particularly shit like the mmu notifier code. Things that we probably shouldn't have done in the first place, and where srcu just encouraged people to do bad things.
Seriously, do this:
git grep srcu.*lock -- :^Documentation/ :^kernel/rcu/
and notice that we have only a few hundred lines in the kernel that do srcu locking. kvm seems to be the main big user.
Quoted 7 lines
This annoys me, because the main reason people use srcu is bad design and lazyness, where they can't be arsed to try to minimize locking and sleeping things. The "sleeping callbacks" in particular tend to be a huge design mistake.
Yet, despite this fairly limited use, rscu seems to be just growing and bloating, and making more and more excuses fro bad behavior.
I can certainly revisit the uses. If it ends up that no SRCU users really need SRCU, then it should of course be removed.
Quoted 4 lines
And it was *years* since I asked you to look at getting rid of the absolutely insane proliferations of different RCU models. I don't think anything ever happened. We *still* have TREE_RCU,|
PREEMPT_RCU, andTINY_SRCU.
I did remove TINY_PREEMPT_RCU in response to your request.
I have also removed the Kconfig parameters SRCU_SYNCHRONIZE_DELAY, RCU_CPU_STALL_DETECTOR, PROVE_RCU_DELAY, RCU_CPU_STALL_VERBOSE, CONFIG_RCU_FANOUT_EXACT, CONFIG_RCU_CPU_STALL_INFO, and RCU_TORTURE_TEST_RUNNABLE. There are quite a few more that could be removed:
o RCU_TORTURE_TEST_SLOW_PREINIT, RCU_TORTURE_TEST_SLOW_PREINIT_DELAY,
RCU_TORTURE_TEST_SLOW_PREINIT_DELAY, RCU_TORTURE_TEST_SLOW_INIT, RCU_TORTURE_TEST_SLOW_INIT_DELAY, RCU_TORTURE_TEST_SLOW_CLEANUP, and RCU_TORTURE_TEST_SLOW_CLEANUP_DELAY. I will queue patches to remove these.
o I believe that RCU_CPU_STALL_TIMEOUT could be dropped in favor
of the existing rcupdate.rcu_cpu_stall_timeout kernel parameter, I will queue a patch and see if anyone screams.
o RCU_KTHREAD_PRIO could be dropped in favor of the existing
rcutree.kthread_prio kernel parameter. I will queue a patch, and I would be very surprised if anyone screamed.
o RCU_BOOST_DELAY could be a boot parameter. I will queue a
patch.
o I believe that PROVE_RCU_REPEATEDLY could be a boot parameter,
I will queue a patch and see if anyone screams.
o Not sure about SPARSE_RCU_POINTER, will try making this
unconditional and see if anyone screams.
o It might be possible to eliminate RCU_NOCB_CPU_NONE,
RCU_NOCB_CPU_ZERO, and RCU_NOCB_CPU_ALL. I will look into this.
Quoted 2 lines
And with this pull request we now have
CLASSIC_SRCU,TINY_SRCU,TREE_SRCUandTASKS_RCU.
I have a calendar reminder to remove CLASSIC_SRCU near the end of this year. Given the testing results thus far, I would be happy to remove it sooner if you would prefer.
Quoted 3 lines
That's in addition to all the other insane tweaks that nobody uses (eg
RCU_FANOUTetc) and that I made sure got removed from any sane questionnaire.
I use RCU_FANOUT and RCU_FANOUT_LEAF to test code paths on small systems that would otherwise only be exercised on systems with thousands of CPUs. I am not aware of any other use. If it would help, I would be happy to move them to lib/Kconfig.debug and make them depend on TORTURE_TEST.
Quoted 10 lines
Paul, this really needs to stop.
I'm now going to stop pulling any more crazy RCU crap. Seriously. If the RCU subsystem doesn't start shrinking, I'm no longer pulling. Send me fixes, but don't send me more of this crazy stuff.
So this is me putting my foot down. I should have done it long ago. I'm done with crazy. Don't waste your time doing yet another RCU mode, because I will not take it. And don't waste your time expanding on the existing ones without looking at which of those things can be removed.
OK, nothing more from RCU other than fixes, code reduction, and documentation for the time being.
Thanx, Paul
Quoted 4 lines · Ingo Molnar
Yeah, you are right and sorry about that - I have removed the patch generation from my pull request scripts, so it shouldn't happen in the future.
I do have to say, that during the later -rc series in particular when people send me smaller fixes, I enjoy seeing the full patches.
But that's generally when they fit in a screenful or two (eg 100 lines of actual unified diff or less - which tends to imply that maybe 10-20 lines were actually changed).
So the patches are fine when they are manageable and useful to see details. It's just that 7500 lines of diff is definitely not manageable.
Linus
Quoted 8 lines · Paul E. McKenney
I am testing a merge with current linus/master, and I looked through the commits in -next selected by:
gitk v4.11.. --no-merges --all-match --grep=drm --grep=selftestI didn't find anything obvious. If the tests complete successfully, I will try running the DRM selftest.
The drivers/gpu/drm/i915/selftests/mock_gem_device.c had a new use of SLAB_DESTROY_BY_RCU, which obviously conflicted with the rename to SLAB_TYPESAFE_BY_RCU.
It doesn't show up as a merge-time code conflict, only as a build-time failure. It's why I do allmodconfig builds after every pull. That doesn't catch everything (I only do it for x86-64, for example), but it catches a lot.
And no, it's not a problem. These things happen, and it's literally my job to make sure my merges work out.
I don't actually expect submaintainers to figure things like that out, although this *did* show up in linux-next, and it's a bit disappointing how that information got lost somewhere on the way.
It kind of implies that the prep work that linux-next does doesn't get fully used.
Normally I wouldn't even have mentioned it, if it wasn't for the fact that I got a 300kB data dump in my mailbox, and that huge amount of data wasn't actually even very relevant.
Linus
Quoted 23 lines · Linus Torvalds
Quoted 8 lines · Paul E. McKenney
I am testing a merge with current linus/master, and I looked through the commits in -next selected by:
gitk v4.11.. --no-merges --all-match --grep=drm --grep=selftestI didn't find anything obvious. If the tests complete successfully, I will try running the DRM selftest.
The
drivers/gpu/drm/i915/selftests/mock_gem_device.chad a new use ofSLAB_DESTROY_BY_RCU, which obviously conflicted with the rename toSLAB_TYPESAFE_BY_RCU.It doesn't show up as a merge-time code conflict, only as a build-time failure. It's why I do allmodconfig builds after every pull. That doesn't catch everything (I only do it for x86-64, for example), but it catches a lot.
And no, it's not a problem. These things happen, and it's literally my job to make sure my merges work out.
Quoted 6 lines
I don't actually expect submaintainers to figure things like that out, although this *did* show up in linux-next, and it's a bit disappointing how that information got lost somewhere on the way.
It kind of implies that the prep work that linux-next does doesn't get fully used.
I did see that from linux-next. For future reference, what should I have done with it? Added it to my pull request or to the commit log of my merge commit?
Quoted 3 lines
Normally I wouldn't even have mentioned it, if it wasn't for the fact that I got a 300kB data dump in my mailbox, and that huge amount of data wasn't actually even very relevant.
Well, my testing did find a lockdep splat, so the effort was not wasted. ;-)
Thanx, Paul
Quoted 8 lines · Paul E. McKenney
Quoted 3 lines · Linus Torvalds
It kind of implies that the prep work that linux-next does doesn't get fully used.
I did see that from linux-next. For future reference, what should I have done with it? Added it to my pull request or to the commit log of my merge commit?
Basically, just forward the information along with the description of what's in the branch, so that I know to expect it.
In this case it didn't actually *matter*, since I noticed it on my own, but particularly if I'm on the road I don't generally have the compute power with me to do a full allmodconfig build between each pull (I usually do one or two a day), so I can miss these things more easily. And if it happens on other architectures, I wouldn't notice.
It doesn't have to be exhaustive. Just a note saying that "there's going to be a semantic merge conflict in file xyz due to abc" means that I can then specifically take it into account. Even if I were to be on the road, I can then check that particular driver out and make sure to check that it builds, etc.
[ Sometimes I also take those kinds of conflict notes into account for pull scheduling. For example, back when the kids were small, and I ended up having to occasionally drive them around, I used to aim to do the simple quick pulls first, delaying things that might need more care until I didn't have some driving schedule over my head. That happens less these days when the kids are off to college and the sole remaining one mostly drives herself around. ]
Linus
Quoted 20 lines · Linus Torvalds
Quoted 8 lines · Paul E. McKenney
Quoted 3 lines · Linus Torvalds
It kind of implies that the prep work that linux-next does doesn't get fully used.
I did see that from linux-next. For future reference, what should I have done with it? Added it to my pull request or to the commit log of my merge commit?
Basically, just forward the information along with the description of what's in the branch, so that I know to expect it.
In this case it didn't actually *matter*, since I noticed it on my own, but particularly if I'm on the road I don't generally have the compute power with me to do a full allmodconfig build between each pull (I usually do one or two a day), so I can miss these things more easily. And if it happens on other architectures, I wouldn't notice.
Quoted 5 lines
It doesn't have to be exhaustive. Just a note saying that "there's going to be a semantic merge conflict in file xyz due to abc" means that I can then specifically take it into account. Even if I were to be on the road, I can then check that particular driver out and make sure to check that it builds, etc.
Got it, thank you!
Quoted 7 lines
[ Sometimes I also take those kinds of conflict notes into account for pull scheduling. For example, back when the kids were small, and I ended up having to occasionally drive them around, I used to aim to do the simple quick pulls first, delaying things that might need more care until I didn't have some driving schedule over my head. That happens less these days when the kids are off to college and the sole remaining one mostly drives herself around. ]
Time does fly -- my youngest graduated from college a couple of years ago.
Thanx, Paul
Quoted 8 lines · Linus Torvalds
Quoted 4 lines · Ingo Molnar
Yeah, you are right and sorry about that - I have removed the patch generation from my pull request scripts, so it shouldn't happen in the future.
I do have to say, that during the later -rc series in particular when people send me smaller fixes, I enjoy seeing the full patches.
I find them useful too, and to answer your original question:
Quoted 1 line
Quoted 1 line
Nobody is ever going to review a 300kB patch that is ~7500 lines.
I _did_ skim over that 300K patch, because I always try to do a final manual check on the raw diffs I'm sending to you, and also to make it very clear what was sent from a full disclosure and security log POV, independent of the Git pull space.
When patches are way too long, for example as the perf pull request diffs often are, I trim them, so it's never an absolute, script-only thing.
Still it's not an excuse:
- I doubt anyone else but me would skim over a 30K (let alone a 300K) patch,
- I also missed the pain large patches cause in Gmail replies (with Mutt that pain is considerably less),
- plus, most importantly, I didn't notice that the extra RCU mode bloat was one too many in an already sizable line-up of RCU complexity ...
Thanks,
Ingo