tree.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Read-Copy Update mechanism for mutual exclusion (tree-based version)
  4. * Internal non-public definitions.
  5. *
  6. * Copyright IBM Corporation, 2008
  7. *
  8. * Author: Ingo Molnar <mingo@elte.hu>
  9. * Paul E. McKenney <paulmck@linux.ibm.com>
  10. */
  11. #include <linux/cache.h>
  12. #include <linux/kthread.h>
  13. #include <linux/spinlock.h>
  14. #include <linux/rtmutex.h>
  15. #include <linux/threads.h>
  16. #include <linux/cpumask.h>
  17. #include <linux/seqlock.h>
  18. #include <linux/swait.h>
  19. #include <linux/rcu_node_tree.h>
  20. #include "rcu_segcblist.h"
  21. /* Communicate arguments to a kthread worker handler. */
  22. struct rcu_exp_work {
  23. unsigned long rew_s;
  24. struct kthread_work rew_work;
  25. };
  26. /* RCU's kthread states for tracing. */
  27. #define RCU_KTHREAD_STOPPED 0
  28. #define RCU_KTHREAD_RUNNING 1
  29. #define RCU_KTHREAD_WAITING 2
  30. #define RCU_KTHREAD_OFFCPU 3
  31. #define RCU_KTHREAD_YIELDING 4
  32. #define RCU_KTHREAD_MAX 4
  33. /*
  34. * Definition for node within the RCU grace-period-detection hierarchy.
  35. */
  36. struct rcu_node {
  37. raw_spinlock_t __private lock; /* Root rcu_node's lock protects */
  38. /* some rcu_state fields as well as */
  39. /* following. */
  40. unsigned long gp_seq; /* Track rsp->gp_seq. */
  41. unsigned long gp_seq_needed; /* Track furthest future GP request. */
  42. unsigned long completedqs; /* All QSes done for this node. */
  43. unsigned long qsmask; /* CPUs or groups that need to switch in */
  44. /* order for current grace period to proceed.*/
  45. /* In leaf rcu_node, each bit corresponds to */
  46. /* an rcu_data structure, otherwise, each */
  47. /* bit corresponds to a child rcu_node */
  48. /* structure. */
  49. unsigned long rcu_gp_init_mask; /* Mask of offline CPUs at GP init. */
  50. unsigned long qsmaskinit;
  51. /* Per-GP initial value for qsmask. */
  52. /* Initialized from ->qsmaskinitnext at the */
  53. /* beginning of each grace period. */
  54. unsigned long qsmaskinitnext;
  55. unsigned long expmask; /* CPUs or groups that need to check in */
  56. /* to allow the current expedited GP */
  57. /* to complete. */
  58. unsigned long expmaskinit;
  59. /* Per-GP initial values for expmask. */
  60. /* Initialized from ->expmaskinitnext at the */
  61. /* beginning of each expedited GP. */
  62. unsigned long expmaskinitnext;
  63. /* Online CPUs for next expedited GP. */
  64. /* Any CPU that has ever been online will */
  65. /* have its bit set. */
  66. struct kthread_worker *exp_kworker;
  67. /* Workers performing per node expedited GP */
  68. /* initialization. */
  69. unsigned long cbovldmask;
  70. /* CPUs experiencing callback overload. */
  71. unsigned long ffmask; /* Fully functional CPUs. */
  72. unsigned long grpmask; /* Mask to apply to parent qsmask. */
  73. /* Only one bit will be set in this mask. */
  74. int grplo; /* lowest-numbered CPU here. */
  75. int grphi; /* highest-numbered CPU here. */
  76. u8 grpnum; /* group number for next level up. */
  77. u8 level; /* root is at level 0. */
  78. bool wait_blkd_tasks;/* Necessary to wait for blocked tasks to */
  79. /* exit RCU read-side critical sections */
  80. /* before propagating offline up the */
  81. /* rcu_node tree? */
  82. struct rcu_node *parent;
  83. struct list_head blkd_tasks;
  84. /* Tasks blocked in RCU read-side critical */
  85. /* section. Tasks are placed at the head */
  86. /* of this list and age towards the tail. */
  87. struct list_head *gp_tasks;
  88. /* Pointer to the first task blocking the */
  89. /* current grace period, or NULL if there */
  90. /* is no such task. */
  91. struct list_head *exp_tasks;
  92. /* Pointer to the first task blocking the */
  93. /* current expedited grace period, or NULL */
  94. /* if there is no such task. If there */
  95. /* is no current expedited grace period, */
  96. /* then there can cannot be any such task. */
  97. struct list_head *boost_tasks;
  98. /* Pointer to first task that needs to be */
  99. /* priority boosted, or NULL if no priority */
  100. /* boosting is needed for this rcu_node */
  101. /* structure. If there are no tasks */
  102. /* queued on this rcu_node structure that */
  103. /* are blocking the current grace period, */
  104. /* there can be no such task. */
  105. struct rt_mutex boost_mtx;
  106. /* Used only for the priority-boosting */
  107. /* side effect, not as a lock. */
  108. unsigned long boost_time;
  109. /* When to start boosting (jiffies). */
  110. struct mutex kthread_mutex;
  111. /* Exclusion for thread spawning and affinity */
  112. /* manipulation. */
  113. struct task_struct *boost_kthread_task;
  114. /* kthread that takes care of priority */
  115. /* boosting for this rcu_node structure. */
  116. unsigned int boost_kthread_status;
  117. /* State of boost_kthread_task for tracing. */
  118. unsigned long n_boosts; /* Number of boosts for this rcu_node structure. */
  119. #ifdef CONFIG_RCU_NOCB_CPU
  120. struct swait_queue_head nocb_gp_wq[2];
  121. /* Place for rcu_nocb_kthread() to wait GP. */
  122. #endif /* #ifdef CONFIG_RCU_NOCB_CPU */
  123. raw_spinlock_t fqslock ____cacheline_internodealigned_in_smp;
  124. spinlock_t exp_lock ____cacheline_internodealigned_in_smp;
  125. unsigned long exp_seq_rq;
  126. wait_queue_head_t exp_wq[4];
  127. struct rcu_exp_work rew;
  128. bool exp_need_flush; /* Need to flush workitem? */
  129. raw_spinlock_t exp_poll_lock;
  130. /* Lock and data for polled expedited grace periods. */
  131. unsigned long exp_seq_poll_rq;
  132. struct work_struct exp_poll_wq;
  133. } ____cacheline_internodealigned_in_smp;
  134. /*
  135. * Bitmasks in an rcu_node cover the interval [grplo, grphi] of CPU IDs, and
  136. * are indexed relative to this interval rather than the global CPU ID space.
  137. * This generates the bit for a CPU in node-local masks.
  138. */
  139. #define leaf_node_cpu_bit(rnp, cpu) (BIT((cpu) - (rnp)->grplo))
  140. /*
  141. * Union to allow "aggregate OR" operation on the need for a quiescent
  142. * state by the normal and expedited grace periods.
  143. */
  144. union rcu_noqs {
  145. struct {
  146. u8 norm;
  147. u8 exp;
  148. } b; /* Bits. */
  149. u16 s; /* Set of bits, aggregate OR here. */
  150. };
  151. /*
  152. * Record the snapshot of the core stats at half of the first RCU stall timeout.
  153. * The member gp_seq is used to ensure that all members are updated only once
  154. * during the sampling period. The snapshot is taken only if this gp_seq is not
  155. * equal to rdp->gp_seq.
  156. */
  157. struct rcu_snap_record {
  158. unsigned long gp_seq; /* Track rdp->gp_seq counter */
  159. u64 cputime_irq; /* Accumulated cputime of hard irqs */
  160. u64 cputime_softirq;/* Accumulated cputime of soft irqs */
  161. u64 cputime_system; /* Accumulated cputime of kernel tasks */
  162. u64 nr_hardirqs; /* Accumulated number of hard irqs */
  163. unsigned int nr_softirqs; /* Accumulated number of soft irqs */
  164. unsigned long long nr_csw; /* Accumulated number of task switches */
  165. unsigned long jiffies; /* Track jiffies value */
  166. };
  167. /*
  168. * An IRQ work (deferred_qs_iw) is used by RCU to get the scheduler's attention.
  169. * to report quiescent states at the soonest possible time.
  170. * The request can be in one of the following states:
  171. * - DEFER_QS_IDLE: An IRQ work is yet to be scheduled.
  172. * - DEFER_QS_PENDING: An IRQ work was scheduled but either not yet run, or it
  173. * ran and we still haven't reported a quiescent state.
  174. */
  175. #define DEFER_QS_IDLE 0
  176. #define DEFER_QS_PENDING 1
  177. /* Per-CPU data for read-copy update. */
  178. struct rcu_data {
  179. /* 1) quiescent-state and grace-period handling : */
  180. unsigned long gp_seq; /* Track rsp->gp_seq counter. */
  181. unsigned long gp_seq_needed; /* Track furthest future GP request. */
  182. union rcu_noqs cpu_no_qs; /* No QSes yet for this CPU. */
  183. bool core_needs_qs; /* Core waits for quiescent state. */
  184. bool beenonline; /* CPU online at least once. */
  185. bool gpwrap; /* Possible ->gp_seq wrap. */
  186. bool cpu_started; /* RCU watching this onlining CPU. */
  187. struct rcu_node *mynode; /* This CPU's leaf of hierarchy */
  188. unsigned long grpmask; /* Mask to apply to leaf qsmask. */
  189. unsigned long ticks_this_gp; /* The number of scheduling-clock */
  190. /* ticks this CPU has handled */
  191. /* during and after the last grace */
  192. /* period it is aware of. */
  193. struct irq_work defer_qs_iw; /* Obtain later scheduler attention. */
  194. int defer_qs_iw_pending; /* Scheduler attention pending? */
  195. struct work_struct strict_work; /* Schedule readers for strict GPs. */
  196. /* 2) batch handling */
  197. struct rcu_segcblist cblist; /* Segmented callback list, with */
  198. /* different callbacks waiting for */
  199. /* different grace periods. */
  200. long qlen_last_fqs_check;
  201. /* qlen at last check for QS forcing */
  202. unsigned long n_cbs_invoked; /* # callbacks invoked since boot. */
  203. unsigned long n_force_qs_snap;
  204. /* did other CPU force QS recently? */
  205. long blimit; /* Upper limit on a processed batch */
  206. /* 3) dynticks interface. */
  207. int watching_snap; /* Per-GP tracking for dynticks. */
  208. bool rcu_need_heavy_qs; /* GP old, so heavy quiescent state! */
  209. bool rcu_urgent_qs; /* GP old need light quiescent state. */
  210. bool rcu_forced_tick; /* Forced tick to provide QS. */
  211. bool rcu_forced_tick_exp; /* ... provide QS to expedited GP. */
  212. /* 4) rcu_barrier(), OOM callbacks, and expediting. */
  213. unsigned long barrier_seq_snap; /* Snap of rcu_state.barrier_sequence. */
  214. struct rcu_head barrier_head;
  215. int exp_watching_snap; /* Double-check need for IPI. */
  216. /* 5) Callback offloading. */
  217. #ifdef CONFIG_RCU_NOCB_CPU
  218. struct swait_queue_head nocb_cb_wq; /* For nocb kthreads to sleep on. */
  219. struct swait_queue_head nocb_state_wq; /* For offloading state changes */
  220. struct task_struct *nocb_gp_kthread;
  221. raw_spinlock_t nocb_lock; /* Guard following pair of fields. */
  222. int nocb_defer_wakeup; /* Defer wakeup of nocb_kthread. */
  223. struct timer_list nocb_timer; /* Enforce finite deferral. */
  224. unsigned long nocb_gp_adv_time; /* Last call_rcu() CB adv (jiffies). */
  225. struct mutex nocb_gp_kthread_mutex; /* Exclusion for nocb gp kthread */
  226. /* spawning */
  227. /* The following fields are used by call_rcu, hence own cacheline. */
  228. raw_spinlock_t nocb_bypass_lock ____cacheline_internodealigned_in_smp;
  229. struct rcu_cblist nocb_bypass; /* Lock-contention-bypass CB list. */
  230. unsigned long nocb_bypass_first; /* Time (jiffies) of first enqueue. */
  231. unsigned long nocb_nobypass_last; /* Last ->cblist enqueue (jiffies). */
  232. int nocb_nobypass_count; /* # ->cblist enqueues at ^^^ time. */
  233. /* The following fields are used by GP kthread, hence own cacheline. */
  234. raw_spinlock_t nocb_gp_lock ____cacheline_internodealigned_in_smp;
  235. u8 nocb_gp_sleep; /* Is the nocb GP thread asleep? */
  236. u8 nocb_gp_bypass; /* Found a bypass on last scan? */
  237. u8 nocb_gp_gp; /* GP to wait for on last scan? */
  238. unsigned long nocb_gp_seq; /* If so, ->gp_seq to wait for. */
  239. unsigned long nocb_gp_loops; /* # passes through wait code. */
  240. struct swait_queue_head nocb_gp_wq; /* For nocb kthreads to sleep on. */
  241. bool nocb_cb_sleep; /* Is the nocb CB thread asleep? */
  242. struct task_struct *nocb_cb_kthread;
  243. struct list_head nocb_head_rdp; /*
  244. * Head of rcu_data list in wakeup chain,
  245. * if rdp_gp.
  246. */
  247. struct list_head nocb_entry_rdp; /* rcu_data node in wakeup chain. */
  248. struct rcu_data *nocb_toggling_rdp; /* rdp queued for (de-)offloading */
  249. /* The following fields are used by CB kthread, hence new cacheline. */
  250. struct rcu_data *nocb_gp_rdp ____cacheline_internodealigned_in_smp;
  251. /* GP rdp takes GP-end wakeups. */
  252. #endif /* #ifdef CONFIG_RCU_NOCB_CPU */
  253. /* 6) RCU priority boosting. */
  254. struct task_struct *rcu_cpu_kthread_task;
  255. /* rcuc per-CPU kthread or NULL. */
  256. unsigned int rcu_cpu_kthread_status;
  257. char rcu_cpu_has_work;
  258. unsigned long rcuc_activity;
  259. /* 7) Diagnostic data, including RCU CPU stall warnings. */
  260. unsigned int softirq_snap; /* Snapshot of softirq activity. */
  261. /* ->rcu_iw* fields protected by leaf rcu_node ->lock. */
  262. struct irq_work rcu_iw; /* Check for non-irq activity. */
  263. bool rcu_iw_pending; /* Is ->rcu_iw pending? */
  264. unsigned long rcu_iw_gp_seq; /* ->gp_seq associated with ->rcu_iw. */
  265. unsigned long rcu_ofl_gp_seq; /* ->gp_seq at last offline. */
  266. short rcu_ofl_gp_state; /* ->gp_state at last offline. */
  267. unsigned long rcu_onl_gp_seq; /* ->gp_seq at last online. */
  268. short rcu_onl_gp_state; /* ->gp_state at last online. */
  269. unsigned long last_fqs_resched; /* Time of last rcu_resched(). */
  270. unsigned long last_sched_clock; /* Jiffies of last rcu_sched_clock_irq(). */
  271. struct rcu_snap_record snap_record; /* Snapshot of core stats at half of */
  272. /* the first RCU stall timeout */
  273. long lazy_len; /* Length of buffered lazy callbacks. */
  274. int cpu;
  275. };
  276. /* Values for nocb_defer_wakeup field in struct rcu_data. */
  277. #define RCU_NOCB_WAKE_NOT 0
  278. #define RCU_NOCB_WAKE_BYPASS 1
  279. #define RCU_NOCB_WAKE_LAZY 2
  280. #define RCU_NOCB_WAKE 3
  281. #define RCU_NOCB_WAKE_FORCE 4
  282. #define RCU_JIFFIES_TILL_FORCE_QS (1 + (HZ > 250) + (HZ > 500))
  283. /* For jiffies_till_first_fqs and */
  284. /* and jiffies_till_next_fqs. */
  285. #define RCU_JIFFIES_FQS_DIV 256 /* Very large systems need more */
  286. /* delay between bouts of */
  287. /* quiescent-state forcing. */
  288. #define RCU_STALL_RAT_DELAY 2 /* Allow other CPUs time to take */
  289. /* at least one scheduling clock */
  290. /* irq before ratting on them. */
  291. #define rcu_wait(cond) \
  292. do { \
  293. for (;;) { \
  294. set_current_state(TASK_INTERRUPTIBLE); \
  295. if (cond) \
  296. break; \
  297. schedule(); \
  298. } \
  299. __set_current_state(TASK_RUNNING); \
  300. } while (0)
  301. /*
  302. * A max threshold for synchronize_rcu() users which are
  303. * awaken directly by the rcu_gp_kthread(). Left part is
  304. * deferred to the main worker.
  305. */
  306. #define SR_MAX_USERS_WAKE_FROM_GP 5
  307. #define SR_NORMAL_GP_WAIT_HEAD_MAX 5
  308. struct sr_wait_node {
  309. atomic_t inuse;
  310. struct llist_node node;
  311. };
  312. /*
  313. * RCU global state, including node hierarchy. This hierarchy is
  314. * represented in "heap" form in a dense array. The root (first level)
  315. * of the hierarchy is in ->node[0] (referenced by ->level[0]), the second
  316. * level in ->node[1] through ->node[m] (->node[1] referenced by ->level[1]),
  317. * and the third level in ->node[m+1] and following (->node[m+1] referenced
  318. * by ->level[2]). The number of levels is determined by the number of
  319. * CPUs and by CONFIG_RCU_FANOUT. Small systems will have a "hierarchy"
  320. * consisting of a single rcu_node.
  321. */
  322. struct rcu_state {
  323. struct rcu_node node[NUM_RCU_NODES]; /* Hierarchy. */
  324. struct rcu_node *level[RCU_NUM_LVLS + 1];
  325. /* Hierarchy levels (+1 to */
  326. /* shut bogus gcc warning) */
  327. int ncpus; /* # CPUs seen so far. */
  328. int n_online_cpus; /* # CPUs online for RCU. */
  329. /* The following fields are guarded by the root rcu_node's lock. */
  330. unsigned long gp_seq ____cacheline_internodealigned_in_smp;
  331. /* Grace-period sequence #. */
  332. unsigned long gp_max; /* Maximum GP duration in */
  333. /* jiffies. */
  334. struct task_struct *gp_kthread; /* Task for grace periods. */
  335. struct swait_queue_head gp_wq; /* Where GP task waits. */
  336. short gp_flags; /* Commands for GP task. */
  337. short gp_state; /* GP kthread sleep state. */
  338. unsigned long gp_wake_time; /* Last GP kthread wake. */
  339. unsigned long gp_wake_seq; /* ->gp_seq at ^^^. */
  340. unsigned long gp_seq_polled; /* GP seq for polled API. */
  341. unsigned long gp_seq_polled_snap; /* ->gp_seq_polled at normal GP start. */
  342. unsigned long gp_seq_polled_exp_snap; /* ->gp_seq_polled at expedited GP start. */
  343. /* End of fields guarded by root rcu_node's lock. */
  344. struct mutex barrier_mutex; /* Guards barrier fields. */
  345. atomic_t barrier_cpu_count; /* # CPUs waiting on. */
  346. struct completion barrier_completion; /* Wake at barrier end. */
  347. unsigned long barrier_sequence; /* ++ at start and end of */
  348. /* rcu_barrier(). */
  349. /* End of fields guarded by barrier_mutex. */
  350. raw_spinlock_t barrier_lock; /* Protects ->barrier_seq_snap. */
  351. struct mutex exp_mutex; /* Serialize expedited GP. */
  352. struct mutex exp_wake_mutex; /* Serialize wakeup. */
  353. unsigned long expedited_sequence; /* Take a ticket. */
  354. atomic_t expedited_need_qs; /* # CPUs left to check in. */
  355. struct swait_queue_head expedited_wq; /* Wait for check-ins. */
  356. int ncpus_snap; /* # CPUs seen last time. */
  357. u8 cbovld; /* Callback overload now? */
  358. u8 cbovldnext; /* ^ ^ next time? */
  359. unsigned long jiffies_force_qs; /* Time at which to invoke */
  360. /* force_quiescent_state(). */
  361. unsigned long jiffies_kick_kthreads; /* Time at which to kick */
  362. /* kthreads, if configured. */
  363. unsigned long n_force_qs; /* Number of calls to */
  364. /* force_quiescent_state(). */
  365. unsigned long gp_start; /* Time at which GP started, */
  366. /* but in jiffies. */
  367. unsigned long gp_end; /* Time last GP ended, again */
  368. /* in jiffies. */
  369. unsigned long gp_activity; /* Time of last GP kthread */
  370. /* activity in jiffies. */
  371. unsigned long gp_req_activity; /* Time of last GP request */
  372. /* in jiffies. */
  373. unsigned long jiffies_stall; /* Time at which to check */
  374. /* for CPU stalls. */
  375. int nr_fqs_jiffies_stall; /* Number of fqs loops after
  376. * which read jiffies and set
  377. * jiffies_stall. Stall
  378. * warnings disabled if !0. */
  379. unsigned long jiffies_resched; /* Time at which to resched */
  380. /* a reluctant CPU. */
  381. unsigned long n_force_qs_gpstart; /* Snapshot of n_force_qs at */
  382. /* GP start. */
  383. const char *name; /* Name of structure. */
  384. char abbr; /* Abbreviated name. */
  385. arch_spinlock_t ofl_lock ____cacheline_internodealigned_in_smp;
  386. /* Synchronize offline with */
  387. /* GP pre-initialization. */
  388. /* synchronize_rcu() part. */
  389. struct llist_head srs_next; /* request a GP users. */
  390. struct llist_node *srs_wait_tail; /* wait for GP users. */
  391. struct llist_node *srs_done_tail; /* ready for GP users. */
  392. struct sr_wait_node srs_wait_nodes[SR_NORMAL_GP_WAIT_HEAD_MAX];
  393. struct work_struct srs_cleanup_work;
  394. atomic_t srs_cleanups_pending; /* srs inflight worker cleanups. */
  395. #ifdef CONFIG_RCU_NOCB_CPU
  396. struct mutex nocb_mutex; /* Guards (de-)offloading */
  397. int nocb_is_setup; /* nocb is setup from boot */
  398. #endif
  399. };
  400. /* Values for rcu_state structure's gp_flags field. */
  401. #define RCU_GP_FLAG_INIT 0x1 /* Need grace-period initialization. */
  402. #define RCU_GP_FLAG_FQS 0x2 /* Need grace-period quiescent-state forcing. */
  403. #define RCU_GP_FLAG_OVLD 0x4 /* Experiencing callback overload. */
  404. /* Values for rcu_state structure's gp_state field. */
  405. #define RCU_GP_IDLE 0 /* Initial state and no GP in progress. */
  406. #define RCU_GP_WAIT_GPS 1 /* Wait for grace-period start. */
  407. #define RCU_GP_DONE_GPS 2 /* Wait done for grace-period start. */
  408. #define RCU_GP_ONOFF 3 /* Grace-period initialization hotplug. */
  409. #define RCU_GP_INIT 4 /* Grace-period initialization. */
  410. #define RCU_GP_WAIT_FQS 5 /* Wait for force-quiescent-state time. */
  411. #define RCU_GP_DOING_FQS 6 /* Wait done for force-quiescent-state time. */
  412. #define RCU_GP_CLEANUP 7 /* Grace-period cleanup started. */
  413. #define RCU_GP_CLEANED 8 /* Grace-period cleanup complete. */
  414. /*
  415. * In order to export the rcu_state name to the tracing tools, it
  416. * needs to be added in the __tracepoint_string section.
  417. * This requires defining a separate variable tp_<sname>_varname
  418. * that points to the string being used, and this will allow
  419. * the tracing userspace tools to be able to decipher the string
  420. * address to the matching string.
  421. */
  422. #ifdef CONFIG_PREEMPT_RCU
  423. #define RCU_ABBR 'p'
  424. #define RCU_NAME_RAW "rcu_preempt"
  425. #else /* #ifdef CONFIG_PREEMPT_RCU */
  426. #define RCU_ABBR 's'
  427. #define RCU_NAME_RAW "rcu_sched"
  428. #endif /* #else #ifdef CONFIG_PREEMPT_RCU */
  429. #ifndef CONFIG_TRACING
  430. #define RCU_NAME RCU_NAME_RAW
  431. #else /* #ifdef CONFIG_TRACING */
  432. static char rcu_name[] = RCU_NAME_RAW;
  433. static const char *tp_rcu_varname __used __tracepoint_string = rcu_name;
  434. #define RCU_NAME rcu_name
  435. #endif /* #else #ifdef CONFIG_TRACING */
  436. /* Forward declarations for tree_plugin.h */
  437. static void rcu_bootup_announce(void);
  438. static void rcu_qs(void);
  439. static int rcu_preempt_blocked_readers_cgp(struct rcu_node *rnp);
  440. #ifdef CONFIG_HOTPLUG_CPU
  441. static bool rcu_preempt_has_tasks(struct rcu_node *rnp);
  442. #endif /* #ifdef CONFIG_HOTPLUG_CPU */
  443. static int rcu_print_task_exp_stall(struct rcu_node *rnp);
  444. static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp);
  445. static void rcu_flavor_sched_clock_irq(int user);
  446. static void dump_blkd_tasks(struct rcu_node *rnp, int ncheck);
  447. static void rcu_preempt_deferred_qs_init(struct rcu_data *rdp);
  448. static void rcu_initiate_boost(struct rcu_node *rnp, unsigned long flags);
  449. static void rcu_preempt_boost_start_gp(struct rcu_node *rnp);
  450. static bool rcu_is_callbacks_kthread(struct rcu_data *rdp);
  451. static void rcu_cpu_kthread_setup(unsigned int cpu);
  452. static void rcu_spawn_one_boost_kthread(struct rcu_node *rnp);
  453. static bool rcu_preempt_has_tasks(struct rcu_node *rnp);
  454. static bool rcu_preempt_need_deferred_qs(struct task_struct *t);
  455. static void zero_cpu_stall_ticks(struct rcu_data *rdp);
  456. static struct swait_queue_head *rcu_nocb_gp_get(struct rcu_node *rnp);
  457. static void rcu_nocb_gp_cleanup(struct swait_queue_head *sq);
  458. static void rcu_init_one_nocb(struct rcu_node *rnp);
  459. static bool wake_nocb_gp(struct rcu_data *rdp, bool force);
  460. static bool rcu_nocb_flush_bypass(struct rcu_data *rdp, struct rcu_head *rhp,
  461. unsigned long j, bool lazy);
  462. static void call_rcu_nocb(struct rcu_data *rdp, struct rcu_head *head,
  463. rcu_callback_t func, unsigned long flags, bool lazy);
  464. static void __maybe_unused __call_rcu_nocb_wake(struct rcu_data *rdp, bool was_empty,
  465. unsigned long flags);
  466. static int rcu_nocb_need_deferred_wakeup(struct rcu_data *rdp, int level);
  467. static bool do_nocb_deferred_wakeup(struct rcu_data *rdp);
  468. static void rcu_boot_init_nocb_percpu_data(struct rcu_data *rdp);
  469. static void rcu_spawn_cpu_nocb_kthread(int cpu);
  470. static void show_rcu_nocb_state(struct rcu_data *rdp);
  471. static void rcu_nocb_lock(struct rcu_data *rdp);
  472. static void rcu_nocb_unlock(struct rcu_data *rdp);
  473. static void rcu_nocb_unlock_irqrestore(struct rcu_data *rdp,
  474. unsigned long flags);
  475. static void rcu_lockdep_assert_cblist_protected(struct rcu_data *rdp);
  476. #ifdef CONFIG_RCU_NOCB_CPU
  477. static void __init rcu_organize_nocb_kthreads(void);
  478. /*
  479. * Disable IRQs before checking offloaded state so that local
  480. * locking is safe against concurrent de-offloading.
  481. */
  482. #define rcu_nocb_lock_irqsave(rdp, flags) \
  483. do { \
  484. local_irq_save(flags); \
  485. if (rcu_segcblist_is_offloaded(&(rdp)->cblist)) \
  486. raw_spin_lock(&(rdp)->nocb_lock); \
  487. } while (0)
  488. #else /* #ifdef CONFIG_RCU_NOCB_CPU */
  489. #define rcu_nocb_lock_irqsave(rdp, flags) local_irq_save(flags)
  490. #endif /* #else #ifdef CONFIG_RCU_NOCB_CPU */
  491. static void rcu_bind_gp_kthread(void);
  492. static bool rcu_nohz_full_cpu(void);
  493. /* Forward declarations for tree_stall.h */
  494. static void record_gp_stall_check_time(void);
  495. static void rcu_iw_handler(struct irq_work *iwp);
  496. static void check_cpu_stall(struct rcu_data *rdp);
  497. static void rcu_check_gp_start_stall(struct rcu_node *rnp, struct rcu_data *rdp,
  498. const unsigned long gpssdelay);
  499. /* Forward declarations for tree_exp.h. */
  500. static void sync_rcu_do_polled_gp(struct work_struct *wp);