14102adabSPaul E. McKenney /* 24102adabSPaul E. McKenney * Read-Copy Update definitions shared among RCU implementations. 34102adabSPaul E. McKenney * 44102adabSPaul E. McKenney * This program is free software; you can redistribute it and/or modify 54102adabSPaul E. McKenney * it under the terms of the GNU General Public License as published by 64102adabSPaul E. McKenney * the Free Software Foundation; either version 2 of the License, or 74102adabSPaul E. McKenney * (at your option) any later version. 84102adabSPaul E. McKenney * 94102adabSPaul E. McKenney * This program is distributed in the hope that it will be useful, 104102adabSPaul E. McKenney * but WITHOUT ANY WARRANTY; without even the implied warranty of 114102adabSPaul E. McKenney * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 124102adabSPaul E. McKenney * GNU General Public License for more details. 134102adabSPaul E. McKenney * 144102adabSPaul E. McKenney * You should have received a copy of the GNU General Public License 1587de1cfdSPaul E. McKenney * along with this program; if not, you can access it online at 1687de1cfdSPaul E. McKenney * http://www.gnu.org/licenses/gpl-2.0.html. 174102adabSPaul E. McKenney * 184102adabSPaul E. McKenney * Copyright IBM Corporation, 2011 194102adabSPaul E. McKenney * 204102adabSPaul E. McKenney * Author: Paul E. McKenney <paulmck@linux.vnet.ibm.com> 214102adabSPaul E. McKenney */ 224102adabSPaul E. McKenney 234102adabSPaul E. McKenney #ifndef __LINUX_RCU_H 244102adabSPaul E. McKenney #define __LINUX_RCU_H 254102adabSPaul E. McKenney 265cb5c6e1SPaul Gortmaker #include <trace/events/rcu.h> 274102adabSPaul E. McKenney #ifdef CONFIG_RCU_TRACE 284102adabSPaul E. McKenney #define RCU_TRACE(stmt) stmt 294102adabSPaul E. McKenney #else /* #ifdef CONFIG_RCU_TRACE */ 304102adabSPaul E. McKenney #define RCU_TRACE(stmt) 314102adabSPaul E. McKenney #endif /* #else #ifdef CONFIG_RCU_TRACE */ 324102adabSPaul E. McKenney 3351a1fd30SPaul E. McKenney /* Offset to allow for unmatched rcu_irq_{enter,exit}(). */ 3484585aa8SPaul E. McKenney #define DYNTICK_IRQ_NONIDLE ((LONG_MAX / 2) + 1) 356136d6e4SPaul E. McKenney 362e8c28c2SPaul E. McKenney 372e8c28c2SPaul E. McKenney /* 382e8c28c2SPaul E. McKenney * Grace-period counter management. 392e8c28c2SPaul E. McKenney */ 402e8c28c2SPaul E. McKenney 41f1ec57a4SPaul E. McKenney #define RCU_SEQ_CTR_SHIFT 2 42031aeee0SPaul E. McKenney #define RCU_SEQ_STATE_MASK ((1 << RCU_SEQ_CTR_SHIFT) - 1) 43031aeee0SPaul E. McKenney 44031aeee0SPaul E. McKenney /* 45031aeee0SPaul E. McKenney * Return the counter portion of a sequence number previously returned 46031aeee0SPaul E. McKenney * by rcu_seq_snap() or rcu_seq_current(). 47031aeee0SPaul E. McKenney */ 48031aeee0SPaul E. McKenney static inline unsigned long rcu_seq_ctr(unsigned long s) 49031aeee0SPaul E. McKenney { 50031aeee0SPaul E. McKenney return s >> RCU_SEQ_CTR_SHIFT; 51031aeee0SPaul E. McKenney } 52031aeee0SPaul E. McKenney 53031aeee0SPaul E. McKenney /* 54031aeee0SPaul E. McKenney * Return the state portion of a sequence number previously returned 55031aeee0SPaul E. McKenney * by rcu_seq_snap() or rcu_seq_current(). 56031aeee0SPaul E. McKenney */ 57031aeee0SPaul E. McKenney static inline int rcu_seq_state(unsigned long s) 58031aeee0SPaul E. McKenney { 59031aeee0SPaul E. McKenney return s & RCU_SEQ_STATE_MASK; 60031aeee0SPaul E. McKenney } 61031aeee0SPaul E. McKenney 6280a7956fSPaul E. McKenney /* 6380a7956fSPaul E. McKenney * Set the state portion of the pointed-to sequence number. 6480a7956fSPaul E. McKenney * The caller is responsible for preventing conflicting updates. 6580a7956fSPaul E. McKenney */ 6680a7956fSPaul E. McKenney static inline void rcu_seq_set_state(unsigned long *sp, int newstate) 6780a7956fSPaul E. McKenney { 6880a7956fSPaul E. McKenney WARN_ON_ONCE(newstate & ~RCU_SEQ_STATE_MASK); 6980a7956fSPaul E. McKenney WRITE_ONCE(*sp, (*sp & ~RCU_SEQ_STATE_MASK) + newstate); 7080a7956fSPaul E. McKenney } 7180a7956fSPaul E. McKenney 722e8c28c2SPaul E. McKenney /* Adjust sequence number for start of update-side operation. */ 732e8c28c2SPaul E. McKenney static inline void rcu_seq_start(unsigned long *sp) 742e8c28c2SPaul E. McKenney { 752e8c28c2SPaul E. McKenney WRITE_ONCE(*sp, *sp + 1); 762e8c28c2SPaul E. McKenney smp_mb(); /* Ensure update-side operation after counter increment. */ 77031aeee0SPaul E. McKenney WARN_ON_ONCE(rcu_seq_state(*sp) != 1); 782e8c28c2SPaul E. McKenney } 792e8c28c2SPaul E. McKenney 809a414201SPaul E. McKenney /* Compute the end-of-grace-period value for the specified sequence number. */ 819a414201SPaul E. McKenney static inline unsigned long rcu_seq_endval(unsigned long *sp) 829a414201SPaul E. McKenney { 839a414201SPaul E. McKenney return (*sp | RCU_SEQ_STATE_MASK) + 1; 849a414201SPaul E. McKenney } 859a414201SPaul E. McKenney 862e8c28c2SPaul E. McKenney /* Adjust sequence number for end of update-side operation. */ 872e8c28c2SPaul E. McKenney static inline void rcu_seq_end(unsigned long *sp) 882e8c28c2SPaul E. McKenney { 892e8c28c2SPaul E. McKenney smp_mb(); /* Ensure update-side operation before counter increment. */ 90031aeee0SPaul E. McKenney WARN_ON_ONCE(!rcu_seq_state(*sp)); 919a414201SPaul E. McKenney WRITE_ONCE(*sp, rcu_seq_endval(sp)); 922e8c28c2SPaul E. McKenney } 932e8c28c2SPaul E. McKenney 942e8c28c2SPaul E. McKenney /* Take a snapshot of the update side's sequence number. */ 952e8c28c2SPaul E. McKenney static inline unsigned long rcu_seq_snap(unsigned long *sp) 962e8c28c2SPaul E. McKenney { 972e8c28c2SPaul E. McKenney unsigned long s; 982e8c28c2SPaul E. McKenney 99031aeee0SPaul E. McKenney s = (READ_ONCE(*sp) + 2 * RCU_SEQ_STATE_MASK + 1) & ~RCU_SEQ_STATE_MASK; 1002e8c28c2SPaul E. McKenney smp_mb(); /* Above access must not bleed into critical section. */ 1012e8c28c2SPaul E. McKenney return s; 1022e8c28c2SPaul E. McKenney } 1032e8c28c2SPaul E. McKenney 1048660b7d8SPaul E. McKenney /* Return the current value the update side's sequence number, no ordering. */ 1058660b7d8SPaul E. McKenney static inline unsigned long rcu_seq_current(unsigned long *sp) 1068660b7d8SPaul E. McKenney { 1078660b7d8SPaul E. McKenney return READ_ONCE(*sp); 1088660b7d8SPaul E. McKenney } 1098660b7d8SPaul E. McKenney 1102e8c28c2SPaul E. McKenney /* 1112e8c28c2SPaul E. McKenney * Given a snapshot from rcu_seq_snap(), determine whether or not a 1122e8c28c2SPaul E. McKenney * full update-side operation has occurred. 1132e8c28c2SPaul E. McKenney */ 1142e8c28c2SPaul E. McKenney static inline bool rcu_seq_done(unsigned long *sp, unsigned long s) 1152e8c28c2SPaul E. McKenney { 1162e8c28c2SPaul E. McKenney return ULONG_CMP_GE(READ_ONCE(*sp), s); 1172e8c28c2SPaul E. McKenney } 1182e8c28c2SPaul E. McKenney 1194102adabSPaul E. McKenney /* 120*67e14c1eSPaul E. McKenney * Has a grace period completed since the time the old gp_seq was collected? 121*67e14c1eSPaul E. McKenney */ 122*67e14c1eSPaul E. McKenney static inline bool rcu_seq_completed_gp(unsigned long old, unsigned long new) 123*67e14c1eSPaul E. McKenney { 124*67e14c1eSPaul E. McKenney return ULONG_CMP_LT(old, new & ~RCU_SEQ_STATE_MASK); 125*67e14c1eSPaul E. McKenney } 126*67e14c1eSPaul E. McKenney 127*67e14c1eSPaul E. McKenney /* 128*67e14c1eSPaul E. McKenney * Has a grace period started since the time the old gp_seq was collected? 129*67e14c1eSPaul E. McKenney */ 130*67e14c1eSPaul E. McKenney static inline bool rcu_seq_new_gp(unsigned long old, unsigned long new) 131*67e14c1eSPaul E. McKenney { 132*67e14c1eSPaul E. McKenney return ULONG_CMP_LT((old + RCU_SEQ_STATE_MASK) & ~RCU_SEQ_STATE_MASK, 133*67e14c1eSPaul E. McKenney new); 134*67e14c1eSPaul E. McKenney } 135*67e14c1eSPaul E. McKenney 136*67e14c1eSPaul E. McKenney /* 1374102adabSPaul E. McKenney * debug_rcu_head_queue()/debug_rcu_head_unqueue() are used internally 1384102adabSPaul E. McKenney * by call_rcu() and rcu callback execution, and are therefore not part of the 1394102adabSPaul E. McKenney * RCU API. Leaving in rcupdate.h because they are used by all RCU flavors. 1404102adabSPaul E. McKenney */ 1414102adabSPaul E. McKenney 1424102adabSPaul E. McKenney #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD 1434102adabSPaul E. McKenney # define STATE_RCU_HEAD_READY 0 1444102adabSPaul E. McKenney # define STATE_RCU_HEAD_QUEUED 1 1454102adabSPaul E. McKenney 1464102adabSPaul E. McKenney extern struct debug_obj_descr rcuhead_debug_descr; 1474102adabSPaul E. McKenney 1484102adabSPaul E. McKenney static inline int debug_rcu_head_queue(struct rcu_head *head) 1494102adabSPaul E. McKenney { 1504102adabSPaul E. McKenney int r1; 1514102adabSPaul E. McKenney 1524102adabSPaul E. McKenney r1 = debug_object_activate(head, &rcuhead_debug_descr); 1534102adabSPaul E. McKenney debug_object_active_state(head, &rcuhead_debug_descr, 1544102adabSPaul E. McKenney STATE_RCU_HEAD_READY, 1554102adabSPaul E. McKenney STATE_RCU_HEAD_QUEUED); 1564102adabSPaul E. McKenney return r1; 1574102adabSPaul E. McKenney } 1584102adabSPaul E. McKenney 1594102adabSPaul E. McKenney static inline void debug_rcu_head_unqueue(struct rcu_head *head) 1604102adabSPaul E. McKenney { 1614102adabSPaul E. McKenney debug_object_active_state(head, &rcuhead_debug_descr, 1624102adabSPaul E. McKenney STATE_RCU_HEAD_QUEUED, 1634102adabSPaul E. McKenney STATE_RCU_HEAD_READY); 1644102adabSPaul E. McKenney debug_object_deactivate(head, &rcuhead_debug_descr); 1654102adabSPaul E. McKenney } 1664102adabSPaul E. McKenney #else /* !CONFIG_DEBUG_OBJECTS_RCU_HEAD */ 1674102adabSPaul E. McKenney static inline int debug_rcu_head_queue(struct rcu_head *head) 1684102adabSPaul E. McKenney { 1694102adabSPaul E. McKenney return 0; 1704102adabSPaul E. McKenney } 1714102adabSPaul E. McKenney 1724102adabSPaul E. McKenney static inline void debug_rcu_head_unqueue(struct rcu_head *head) 1734102adabSPaul E. McKenney { 1744102adabSPaul E. McKenney } 1754102adabSPaul E. McKenney #endif /* #else !CONFIG_DEBUG_OBJECTS_RCU_HEAD */ 1764102adabSPaul E. McKenney 177bd73a7f5STeodora Baluta void kfree(const void *); 1784102adabSPaul E. McKenney 179406e3e53SPaul E. McKenney /* 180406e3e53SPaul E. McKenney * Reclaim the specified callback, either by invoking it (non-lazy case) 181406e3e53SPaul E. McKenney * or freeing it directly (lazy case). Return true if lazy, false otherwise. 182406e3e53SPaul E. McKenney */ 1834102adabSPaul E. McKenney static inline bool __rcu_reclaim(const char *rn, struct rcu_head *head) 1844102adabSPaul E. McKenney { 1854102adabSPaul E. McKenney unsigned long offset = (unsigned long)head->func; 1864102adabSPaul E. McKenney 18724ef659aSPaul E. McKenney rcu_lock_acquire(&rcu_callback_map); 1884102adabSPaul E. McKenney if (__is_kfree_rcu_offset(offset)) { 189dffd06a7SPaul E. McKenney RCU_TRACE(trace_rcu_invoke_kfree_callback(rn, head, offset);) 1904102adabSPaul E. McKenney kfree((void *)head - offset); 19124ef659aSPaul E. McKenney rcu_lock_release(&rcu_callback_map); 192406e3e53SPaul E. McKenney return true; 1934102adabSPaul E. McKenney } else { 194dffd06a7SPaul E. McKenney RCU_TRACE(trace_rcu_invoke_callback(rn, head);) 1954102adabSPaul E. McKenney head->func(head); 19624ef659aSPaul E. McKenney rcu_lock_release(&rcu_callback_map); 197406e3e53SPaul E. McKenney return false; 1984102adabSPaul E. McKenney } 1994102adabSPaul E. McKenney } 2004102adabSPaul E. McKenney 2014102adabSPaul E. McKenney #ifdef CONFIG_RCU_STALL_COMMON 2024102adabSPaul E. McKenney 2034102adabSPaul E. McKenney extern int rcu_cpu_stall_suppress; 2044102adabSPaul E. McKenney int rcu_jiffies_till_stall_check(void); 2054102adabSPaul E. McKenney 206f22ce091SPaul E. McKenney #define rcu_ftrace_dump_stall_suppress() \ 207f22ce091SPaul E. McKenney do { \ 208f22ce091SPaul E. McKenney if (!rcu_cpu_stall_suppress) \ 209f22ce091SPaul E. McKenney rcu_cpu_stall_suppress = 3; \ 210f22ce091SPaul E. McKenney } while (0) 211f22ce091SPaul E. McKenney 212f22ce091SPaul E. McKenney #define rcu_ftrace_dump_stall_unsuppress() \ 213f22ce091SPaul E. McKenney do { \ 214f22ce091SPaul E. McKenney if (rcu_cpu_stall_suppress == 3) \ 215f22ce091SPaul E. McKenney rcu_cpu_stall_suppress = 0; \ 216f22ce091SPaul E. McKenney } while (0) 217f22ce091SPaul E. McKenney 218f22ce091SPaul E. McKenney #else /* #endif #ifdef CONFIG_RCU_STALL_COMMON */ 219f22ce091SPaul E. McKenney #define rcu_ftrace_dump_stall_suppress() 220f22ce091SPaul E. McKenney #define rcu_ftrace_dump_stall_unsuppress() 2214102adabSPaul E. McKenney #endif /* #ifdef CONFIG_RCU_STALL_COMMON */ 2224102adabSPaul E. McKenney 2234102adabSPaul E. McKenney /* 2244102adabSPaul E. McKenney * Strings used in tracepoints need to be exported via the 2254102adabSPaul E. McKenney * tracing system such that tools like perf and trace-cmd can 2264102adabSPaul E. McKenney * translate the string address pointers to actual text. 2274102adabSPaul E. McKenney */ 2284102adabSPaul E. McKenney #define TPS(x) tracepoint_string(x) 2294102adabSPaul E. McKenney 230b8989b76SPaul E. McKenney /* 231b8989b76SPaul E. McKenney * Dump the ftrace buffer, but only one time per callsite per boot. 232b8989b76SPaul E. McKenney */ 233b8989b76SPaul E. McKenney #define rcu_ftrace_dump(oops_dump_mode) \ 234b8989b76SPaul E. McKenney do { \ 235b8989b76SPaul E. McKenney static atomic_t ___rfd_beenhere = ATOMIC_INIT(0); \ 236b8989b76SPaul E. McKenney \ 237b8989b76SPaul E. McKenney if (!atomic_read(&___rfd_beenhere) && \ 23883b6ca1fSPaul E. McKenney !atomic_xchg(&___rfd_beenhere, 1)) { \ 23983b6ca1fSPaul E. McKenney tracing_off(); \ 240f22ce091SPaul E. McKenney rcu_ftrace_dump_stall_suppress(); \ 241b8989b76SPaul E. McKenney ftrace_dump(oops_dump_mode); \ 242f22ce091SPaul E. McKenney rcu_ftrace_dump_stall_unsuppress(); \ 24383b6ca1fSPaul E. McKenney } \ 244b8989b76SPaul E. McKenney } while (0) 245b8989b76SPaul E. McKenney 246aa23c6fbSPranith Kumar void rcu_early_boot_tests(void); 24752d7e48bSPaul E. McKenney void rcu_test_sync_prims(void); 248aa23c6fbSPranith Kumar 2495f6130faSLai Jiangshan /* 2505f6130faSLai Jiangshan * This function really isn't for public consumption, but RCU is special in 2515f6130faSLai Jiangshan * that context switches can allow the state machine to make progress. 2525f6130faSLai Jiangshan */ 2535f6130faSLai Jiangshan extern void resched_cpu(int cpu); 2545f6130faSLai Jiangshan 2552b34c43cSPaul E. McKenney #if defined(SRCU) || !defined(TINY_RCU) 2562b34c43cSPaul E. McKenney 2572b34c43cSPaul E. McKenney #include <linux/rcu_node_tree.h> 2582b34c43cSPaul E. McKenney 2592b34c43cSPaul E. McKenney extern int rcu_num_lvls; 260e95d68d2SPaul E. McKenney extern int num_rcu_lvl[]; 2612b34c43cSPaul E. McKenney extern int rcu_num_nodes; 2622b34c43cSPaul E. McKenney static bool rcu_fanout_exact; 2632b34c43cSPaul E. McKenney static int rcu_fanout_leaf; 2642b34c43cSPaul E. McKenney 2652b34c43cSPaul E. McKenney /* 2662b34c43cSPaul E. McKenney * Compute the per-level fanout, either using the exact fanout specified 2672b34c43cSPaul E. McKenney * or balancing the tree, depending on the rcu_fanout_exact boot parameter. 2682b34c43cSPaul E. McKenney */ 2692b34c43cSPaul E. McKenney static inline void rcu_init_levelspread(int *levelspread, const int *levelcnt) 2702b34c43cSPaul E. McKenney { 2712b34c43cSPaul E. McKenney int i; 2722b34c43cSPaul E. McKenney 2732b34c43cSPaul E. McKenney if (rcu_fanout_exact) { 2742b34c43cSPaul E. McKenney levelspread[rcu_num_lvls - 1] = rcu_fanout_leaf; 2752b34c43cSPaul E. McKenney for (i = rcu_num_lvls - 2; i >= 0; i--) 2762b34c43cSPaul E. McKenney levelspread[i] = RCU_FANOUT; 2772b34c43cSPaul E. McKenney } else { 2782b34c43cSPaul E. McKenney int ccur; 2792b34c43cSPaul E. McKenney int cprv; 2802b34c43cSPaul E. McKenney 2812b34c43cSPaul E. McKenney cprv = nr_cpu_ids; 2822b34c43cSPaul E. McKenney for (i = rcu_num_lvls - 1; i >= 0; i--) { 2832b34c43cSPaul E. McKenney ccur = levelcnt[i]; 2842b34c43cSPaul E. McKenney levelspread[i] = (cprv + ccur - 1) / ccur; 2852b34c43cSPaul E. McKenney cprv = ccur; 2862b34c43cSPaul E. McKenney } 2872b34c43cSPaul E. McKenney } 2882b34c43cSPaul E. McKenney } 2892b34c43cSPaul E. McKenney 2905b4c11d5SPaul E. McKenney /* Returns first leaf rcu_node of the specified RCU flavor. */ 2915b4c11d5SPaul E. McKenney #define rcu_first_leaf_node(rsp) ((rsp)->level[rcu_num_lvls - 1]) 2925b4c11d5SPaul E. McKenney 2935b4c11d5SPaul E. McKenney /* Is this rcu_node a leaf? */ 2945b4c11d5SPaul E. McKenney #define rcu_is_leaf_node(rnp) ((rnp)->level == rcu_num_lvls - 1) 2955b4c11d5SPaul E. McKenney 2965257514dSPaul E. McKenney /* Is this rcu_node the last leaf? */ 2975257514dSPaul E. McKenney #define rcu_is_last_leaf_node(rsp, rnp) ((rnp) == &(rsp)->node[rcu_num_nodes - 1]) 2985257514dSPaul E. McKenney 299efbe451dSPaul E. McKenney /* 300efbe451dSPaul E. McKenney * Do a full breadth-first scan of the rcu_node structures for the 301efbe451dSPaul E. McKenney * specified rcu_state structure. 302efbe451dSPaul E. McKenney */ 303efbe451dSPaul E. McKenney #define rcu_for_each_node_breadth_first(rsp, rnp) \ 304efbe451dSPaul E. McKenney for ((rnp) = &(rsp)->node[0]; \ 305efbe451dSPaul E. McKenney (rnp) < &(rsp)->node[rcu_num_nodes]; (rnp)++) 306efbe451dSPaul E. McKenney 307efbe451dSPaul E. McKenney /* 308efbe451dSPaul E. McKenney * Do a breadth-first scan of the non-leaf rcu_node structures for the 309efbe451dSPaul E. McKenney * specified rcu_state structure. Note that if there is a singleton 310efbe451dSPaul E. McKenney * rcu_node tree with but one rcu_node structure, this loop is a no-op. 311efbe451dSPaul E. McKenney */ 312efbe451dSPaul E. McKenney #define rcu_for_each_nonleaf_node_breadth_first(rsp, rnp) \ 3135b4c11d5SPaul E. McKenney for ((rnp) = &(rsp)->node[0]; !rcu_is_leaf_node(rsp, rnp); (rnp)++) 314efbe451dSPaul E. McKenney 315efbe451dSPaul E. McKenney /* 316efbe451dSPaul E. McKenney * Scan the leaves of the rcu_node hierarchy for the specified rcu_state 317efbe451dSPaul E. McKenney * structure. Note that if there is a singleton rcu_node tree with but 318efbe451dSPaul E. McKenney * one rcu_node structure, this loop -will- visit the rcu_node structure. 319efbe451dSPaul E. McKenney * It is still a leaf node, even if it is also the root node. 320efbe451dSPaul E. McKenney */ 321efbe451dSPaul E. McKenney #define rcu_for_each_leaf_node(rsp, rnp) \ 3225b4c11d5SPaul E. McKenney for ((rnp) = rcu_first_leaf_node(rsp); \ 323efbe451dSPaul E. McKenney (rnp) < &(rsp)->node[rcu_num_nodes]; (rnp)++) 324efbe451dSPaul E. McKenney 325efbe451dSPaul E. McKenney /* 326efbe451dSPaul E. McKenney * Iterate over all possible CPUs in a leaf RCU node. 327efbe451dSPaul E. McKenney */ 328efbe451dSPaul E. McKenney #define for_each_leaf_node_possible_cpu(rnp, cpu) \ 32965963d24SPaul E. McKenney for ((cpu) = cpumask_next((rnp)->grplo - 1, cpu_possible_mask); \ 33065963d24SPaul E. McKenney (cpu) <= rnp->grphi; \ 33165963d24SPaul E. McKenney (cpu) = cpumask_next((cpu), cpu_possible_mask)) 33265963d24SPaul E. McKenney 33365963d24SPaul E. McKenney /* 33465963d24SPaul E. McKenney * Iterate over all CPUs in a leaf RCU node's specified mask. 33565963d24SPaul E. McKenney */ 33665963d24SPaul E. McKenney #define rcu_find_next_bit(rnp, cpu, mask) \ 33765963d24SPaul E. McKenney ((rnp)->grplo + find_next_bit(&(mask), BITS_PER_LONG, (cpu))) 33865963d24SPaul E. McKenney #define for_each_leaf_node_cpu_mask(rnp, cpu, mask) \ 33965963d24SPaul E. McKenney for ((cpu) = rcu_find_next_bit((rnp), 0, (mask)); \ 34065963d24SPaul E. McKenney (cpu) <= rnp->grphi; \ 34165963d24SPaul E. McKenney (cpu) = rcu_find_next_bit((rnp), (cpu) + 1 - (rnp->grplo), (mask))) 342efbe451dSPaul E. McKenney 34383d40bd3SPaul E. McKenney /* 34483d40bd3SPaul E. McKenney * Wrappers for the rcu_node::lock acquire and release. 34583d40bd3SPaul E. McKenney * 34683d40bd3SPaul E. McKenney * Because the rcu_nodes form a tree, the tree traversal locking will observe 34783d40bd3SPaul E. McKenney * different lock values, this in turn means that an UNLOCK of one level 34883d40bd3SPaul E. McKenney * followed by a LOCK of another level does not imply a full memory barrier; 34983d40bd3SPaul E. McKenney * and most importantly transitivity is lost. 35083d40bd3SPaul E. McKenney * 35183d40bd3SPaul E. McKenney * In order to restore full ordering between tree levels, augment the regular 35283d40bd3SPaul E. McKenney * lock acquire functions with smp_mb__after_unlock_lock(). 35383d40bd3SPaul E. McKenney * 35483d40bd3SPaul E. McKenney * As ->lock of struct rcu_node is a __private field, therefore one should use 35583d40bd3SPaul E. McKenney * these wrappers rather than directly call raw_spin_{lock,unlock}* on ->lock. 35683d40bd3SPaul E. McKenney */ 35783d40bd3SPaul E. McKenney #define raw_spin_lock_rcu_node(p) \ 35883d40bd3SPaul E. McKenney do { \ 35983d40bd3SPaul E. McKenney raw_spin_lock(&ACCESS_PRIVATE(p, lock)); \ 36083d40bd3SPaul E. McKenney smp_mb__after_unlock_lock(); \ 36183d40bd3SPaul E. McKenney } while (0) 36283d40bd3SPaul E. McKenney 36383d40bd3SPaul E. McKenney #define raw_spin_unlock_rcu_node(p) raw_spin_unlock(&ACCESS_PRIVATE(p, lock)) 36483d40bd3SPaul E. McKenney 36583d40bd3SPaul E. McKenney #define raw_spin_lock_irq_rcu_node(p) \ 36683d40bd3SPaul E. McKenney do { \ 36783d40bd3SPaul E. McKenney raw_spin_lock_irq(&ACCESS_PRIVATE(p, lock)); \ 36883d40bd3SPaul E. McKenney smp_mb__after_unlock_lock(); \ 36983d40bd3SPaul E. McKenney } while (0) 37083d40bd3SPaul E. McKenney 37183d40bd3SPaul E. McKenney #define raw_spin_unlock_irq_rcu_node(p) \ 37283d40bd3SPaul E. McKenney raw_spin_unlock_irq(&ACCESS_PRIVATE(p, lock)) 37383d40bd3SPaul E. McKenney 3744e4bea74SPaul E. McKenney #define raw_spin_lock_irqsave_rcu_node(p, flags) \ 37583d40bd3SPaul E. McKenney do { \ 3764e4bea74SPaul E. McKenney raw_spin_lock_irqsave(&ACCESS_PRIVATE(p, lock), flags); \ 37783d40bd3SPaul E. McKenney smp_mb__after_unlock_lock(); \ 37883d40bd3SPaul E. McKenney } while (0) 37983d40bd3SPaul E. McKenney 3804e4bea74SPaul E. McKenney #define raw_spin_unlock_irqrestore_rcu_node(p, flags) \ 381a32e01eeSMatthew Wilcox raw_spin_unlock_irqrestore(&ACCESS_PRIVATE(p, lock), flags) 38283d40bd3SPaul E. McKenney 38383d40bd3SPaul E. McKenney #define raw_spin_trylock_rcu_node(p) \ 38483d40bd3SPaul E. McKenney ({ \ 38583d40bd3SPaul E. McKenney bool ___locked = raw_spin_trylock(&ACCESS_PRIVATE(p, lock)); \ 38683d40bd3SPaul E. McKenney \ 38783d40bd3SPaul E. McKenney if (___locked) \ 38883d40bd3SPaul E. McKenney smp_mb__after_unlock_lock(); \ 38983d40bd3SPaul E. McKenney ___locked; \ 39083d40bd3SPaul E. McKenney }) 39183d40bd3SPaul E. McKenney 392a32e01eeSMatthew Wilcox #define raw_lockdep_assert_held_rcu_node(p) \ 393a32e01eeSMatthew Wilcox lockdep_assert_held(&ACCESS_PRIVATE(p, lock)) 394a32e01eeSMatthew Wilcox 3952b34c43cSPaul E. McKenney #endif /* #if defined(SRCU) || !defined(TINY_RCU) */ 3962b34c43cSPaul E. McKenney 39725c36329SPaul E. McKenney #ifdef CONFIG_TINY_RCU 39825c36329SPaul E. McKenney /* Tiny RCU doesn't expedite, as its purpose in life is instead to be tiny. */ 3997414fac0SPaul E. McKenney static inline bool rcu_gp_is_normal(void) { return true; } 4007414fac0SPaul E. McKenney static inline bool rcu_gp_is_expedited(void) { return false; } 4017414fac0SPaul E. McKenney static inline void rcu_expedite_gp(void) { } 4027414fac0SPaul E. McKenney static inline void rcu_unexpedite_gp(void) { } 403bfbd767dSPaul E. McKenney static inline void rcu_request_urgent_qs_task(struct task_struct *t) { } 40425c36329SPaul E. McKenney #else /* #ifdef CONFIG_TINY_RCU */ 40525c36329SPaul E. McKenney bool rcu_gp_is_normal(void); /* Internal RCU use. */ 40625c36329SPaul E. McKenney bool rcu_gp_is_expedited(void); /* Internal RCU use. */ 40725c36329SPaul E. McKenney void rcu_expedite_gp(void); 40825c36329SPaul E. McKenney void rcu_unexpedite_gp(void); 40925c36329SPaul E. McKenney void rcupdate_announce_bootup_oddness(void); 410bfbd767dSPaul E. McKenney void rcu_request_urgent_qs_task(struct task_struct *t); 41125c36329SPaul E. McKenney #endif /* #else #ifdef CONFIG_TINY_RCU */ 41225c36329SPaul E. McKenney 41382118249SPaul E. McKenney #define RCU_SCHEDULER_INACTIVE 0 41482118249SPaul E. McKenney #define RCU_SCHEDULER_INIT 1 41582118249SPaul E. McKenney #define RCU_SCHEDULER_RUNNING 2 41682118249SPaul E. McKenney 417cad7b389SPaul E. McKenney enum rcutorture_type { 418cad7b389SPaul E. McKenney RCU_FLAVOR, 419cad7b389SPaul E. McKenney RCU_BH_FLAVOR, 420cad7b389SPaul E. McKenney RCU_SCHED_FLAVOR, 421cad7b389SPaul E. McKenney RCU_TASKS_FLAVOR, 422cad7b389SPaul E. McKenney SRCU_FLAVOR, 423cad7b389SPaul E. McKenney INVALID_RCU_FLAVOR 424cad7b389SPaul E. McKenney }; 425cad7b389SPaul E. McKenney 426cad7b389SPaul E. McKenney #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU) 427cad7b389SPaul E. McKenney void rcutorture_get_gp_data(enum rcutorture_type test_type, int *flags, 428cad7b389SPaul E. McKenney unsigned long *gpnum, unsigned long *completed); 429cad7b389SPaul E. McKenney void rcutorture_record_test_transition(void); 430cad7b389SPaul E. McKenney void rcutorture_record_progress(unsigned long vernum); 431cad7b389SPaul E. McKenney void do_trace_rcu_torture_read(const char *rcutorturename, 432cad7b389SPaul E. McKenney struct rcu_head *rhp, 433cad7b389SPaul E. McKenney unsigned long secs, 434cad7b389SPaul E. McKenney unsigned long c_old, 435cad7b389SPaul E. McKenney unsigned long c); 436cad7b389SPaul E. McKenney #else 437cad7b389SPaul E. McKenney static inline void rcutorture_get_gp_data(enum rcutorture_type test_type, 438cad7b389SPaul E. McKenney int *flags, 439cad7b389SPaul E. McKenney unsigned long *gpnum, 440cad7b389SPaul E. McKenney unsigned long *completed) 441cad7b389SPaul E. McKenney { 442cad7b389SPaul E. McKenney *flags = 0; 443cad7b389SPaul E. McKenney *gpnum = 0; 444cad7b389SPaul E. McKenney *completed = 0; 445cad7b389SPaul E. McKenney } 4467414fac0SPaul E. McKenney static inline void rcutorture_record_test_transition(void) { } 4477414fac0SPaul E. McKenney static inline void rcutorture_record_progress(unsigned long vernum) { } 448cad7b389SPaul E. McKenney #ifdef CONFIG_RCU_TRACE 449cad7b389SPaul E. McKenney void do_trace_rcu_torture_read(const char *rcutorturename, 450cad7b389SPaul E. McKenney struct rcu_head *rhp, 451cad7b389SPaul E. McKenney unsigned long secs, 452cad7b389SPaul E. McKenney unsigned long c_old, 453cad7b389SPaul E. McKenney unsigned long c); 454cad7b389SPaul E. McKenney #else 455cad7b389SPaul E. McKenney #define do_trace_rcu_torture_read(rcutorturename, rhp, secs, c_old, c) \ 456cad7b389SPaul E. McKenney do { } while (0) 457cad7b389SPaul E. McKenney #endif 458cad7b389SPaul E. McKenney #endif 459cad7b389SPaul E. McKenney 460cad7b389SPaul E. McKenney #ifdef CONFIG_TINY_SRCU 461cad7b389SPaul E. McKenney 462cad7b389SPaul E. McKenney static inline void srcutorture_get_gp_data(enum rcutorture_type test_type, 463cad7b389SPaul E. McKenney struct srcu_struct *sp, int *flags, 464cad7b389SPaul E. McKenney unsigned long *gpnum, 465cad7b389SPaul E. McKenney unsigned long *completed) 466cad7b389SPaul E. McKenney { 467cad7b389SPaul E. McKenney if (test_type != SRCU_FLAVOR) 468cad7b389SPaul E. McKenney return; 469cad7b389SPaul E. McKenney *flags = 0; 4702464dd94SPaul E. McKenney *completed = sp->srcu_idx; 471cad7b389SPaul E. McKenney *gpnum = *completed; 472cad7b389SPaul E. McKenney } 473cad7b389SPaul E. McKenney 474cad7b389SPaul E. McKenney #elif defined(CONFIG_TREE_SRCU) 475cad7b389SPaul E. McKenney 476cad7b389SPaul E. McKenney void srcutorture_get_gp_data(enum rcutorture_type test_type, 477cad7b389SPaul E. McKenney struct srcu_struct *sp, int *flags, 478cad7b389SPaul E. McKenney unsigned long *gpnum, unsigned long *completed); 479cad7b389SPaul E. McKenney 480cad7b389SPaul E. McKenney #endif 481cad7b389SPaul E. McKenney 482e3c8d51eSPaul E. McKenney #ifdef CONFIG_TINY_RCU 48317ef2fe9SPaul E. McKenney static inline unsigned long rcu_get_gp_seq(void) { return 0; } 48417ef2fe9SPaul E. McKenney static inline unsigned long rcu_bh_get_gp_seq(void) { return 0; } 48517ef2fe9SPaul E. McKenney static inline unsigned long rcu_sched_get_gp_seq(void) { return 0; } 4867414fac0SPaul E. McKenney static inline unsigned long rcu_exp_batches_completed(void) { return 0; } 4877414fac0SPaul E. McKenney static inline unsigned long rcu_exp_batches_completed_sched(void) { return 0; } 4887414fac0SPaul E. McKenney static inline unsigned long 4897414fac0SPaul E. McKenney srcu_batches_completed(struct srcu_struct *sp) { return 0; } 4907414fac0SPaul E. McKenney static inline void rcu_force_quiescent_state(void) { } 4917414fac0SPaul E. McKenney static inline void rcu_bh_force_quiescent_state(void) { } 4927414fac0SPaul E. McKenney static inline void rcu_sched_force_quiescent_state(void) { } 4937414fac0SPaul E. McKenney static inline void show_rcu_gp_kthreads(void) { } 494e3c8d51eSPaul E. McKenney #else /* #ifdef CONFIG_TINY_RCU */ 495e3c8d51eSPaul E. McKenney extern unsigned long rcutorture_testseq; 496e3c8d51eSPaul E. McKenney extern unsigned long rcutorture_vernum; 49717ef2fe9SPaul E. McKenney unsigned long rcu_get_gp_seq(void); 49817ef2fe9SPaul E. McKenney unsigned long rcu_bh_get_gp_seq(void); 49917ef2fe9SPaul E. McKenney unsigned long rcu_sched_get_gp_seq(void); 500e3c8d51eSPaul E. McKenney unsigned long rcu_exp_batches_completed(void); 501e3c8d51eSPaul E. McKenney unsigned long rcu_exp_batches_completed_sched(void); 5025a0465e1SPaul E. McKenney unsigned long srcu_batches_completed(struct srcu_struct *sp); 503e3c8d51eSPaul E. McKenney void show_rcu_gp_kthreads(void); 504e3c8d51eSPaul E. McKenney void rcu_force_quiescent_state(void); 505e3c8d51eSPaul E. McKenney void rcu_bh_force_quiescent_state(void); 506e3c8d51eSPaul E. McKenney void rcu_sched_force_quiescent_state(void); 507ad7c946bSPaul E. McKenney extern struct workqueue_struct *rcu_gp_wq; 50825f3d7efSPaul E. McKenney extern struct workqueue_struct *rcu_par_gp_wq; 509e3c8d51eSPaul E. McKenney #endif /* #else #ifdef CONFIG_TINY_RCU */ 510e3c8d51eSPaul E. McKenney 51144c65ff2SPaul E. McKenney #ifdef CONFIG_RCU_NOCB_CPU 5123d54f798SPaul E. McKenney bool rcu_is_nocb_cpu(int cpu); 5133d54f798SPaul E. McKenney #else 5143d54f798SPaul E. McKenney static inline bool rcu_is_nocb_cpu(int cpu) { return false; } 5153d54f798SPaul E. McKenney #endif 5163d54f798SPaul E. McKenney 5174102adabSPaul E. McKenney #endif /* __LINUX_RCU_H */ 518