1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Read-Copy Update mechanism for mutual exclusion, adapted for tracing.
5 * Copyright (C) 2020 Paul E. McKenney.
8 #ifndef __LINUX_RCUPDATE_TRACE_H
9 #define __LINUX_RCUPDATE_TRACE_H
11 #include <linux/sched.h>
12 #include <linux/rcupdate.h>
14 #ifdef CONFIG_DEBUG_LOCK_ALLOC
16 extern struct lockdep_map rcu_trace_lock_map;
18 static inline int rcu_read_lock_trace_held(void)
20 return lock_is_held(&rcu_trace_lock_map);
23 #else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
25 static inline int rcu_read_lock_trace_held(void)
30 #endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */
32 #ifdef CONFIG_TASKS_TRACE_RCU
34 void rcu_read_unlock_trace_special(struct task_struct *t, int nesting);
37 * rcu_read_lock_trace - mark beginning of RCU-trace read-side critical section
39 * When synchronize_rcu_tasks_trace() is invoked by one task, then that
40 * task is guaranteed to block until all other tasks exit their read-side
41 * critical sections. Similarly, if call_rcu_trace() is invoked on one
42 * task while other tasks are within RCU read-side critical sections,
43 * invocation of the corresponding RCU callback is deferred until after
44 * the all the other tasks exit their critical sections.
46 * For more details, please see the documentation for rcu_read_lock().
48 static inline void rcu_read_lock_trace(void)
50 struct task_struct *t = current;
52 WRITE_ONCE(t->trc_reader_nesting, READ_ONCE(t->trc_reader_nesting) + 1);
53 if (IS_ENABLED(CONFIG_TASKS_TRACE_RCU_READ_MB) &&
54 t->trc_reader_special.b.need_mb)
55 smp_mb(); // Pairs with update-side barriers
56 rcu_lock_acquire(&rcu_trace_lock_map);
60 * rcu_read_unlock_trace - mark end of RCU-trace read-side critical section
62 * Pairs with a preceding call to rcu_read_lock_trace(), and nesting is
63 * allowed. Invoking a rcu_read_unlock_trace() when there is no matching
64 * rcu_read_lock_trace() is verboten, and will result in lockdep complaints.
66 * For more details, please see the documentation for rcu_read_unlock().
68 static inline void rcu_read_unlock_trace(void)
71 struct task_struct *t = current;
73 rcu_lock_release(&rcu_trace_lock_map);
74 nesting = READ_ONCE(t->trc_reader_nesting) - 1;
75 if (likely(!READ_ONCE(t->trc_reader_special.s)) || nesting) {
76 WRITE_ONCE(t->trc_reader_nesting, nesting);
77 return; // We assume shallow reader nesting.
79 rcu_read_unlock_trace_special(t, nesting);
82 void call_rcu_tasks_trace(struct rcu_head *rhp, rcu_callback_t func);
83 void synchronize_rcu_tasks_trace(void);
84 void rcu_barrier_tasks_trace(void);
86 #endif /* #ifdef CONFIG_TASKS_TRACE_RCU */
88 #endif /* __LINUX_RCUPDATE_TRACE_H */