blob: 2963f080e48db31e3e4c67fb7913996ce57ad926 [file] [log] [blame]
Paul E. McKenneye260be62008-01-25 21:08:24 +01001/*
2 * Read-Copy Update mechanism for mutual exclusion (RT implementation)
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 *
18 * Copyright (C) IBM Corporation, 2006
19 *
20 * Author: Paul McKenney <paulmck@us.ibm.com>
21 *
22 * Based on the original work by Paul McKenney <paul.mckenney@us.ibm.com>
23 * and inputs from Rusty Russell, Andrea Arcangeli and Andi Kleen.
24 * Papers:
25 * http://www.rdrop.com/users/paulmck/paper/rclockpdcsproof.pdf
26 * http://lse.sourceforge.net/locking/rclock_OLS.2001.05.01c.sc.pdf (OLS2001)
27 *
28 * For detailed explanation of Read-Copy Update mechanism see -
29 * Documentation/RCU
30 *
31 */
32
33#ifndef __LINUX_RCUPREEMPT_H
34#define __LINUX_RCUPREEMPT_H
35
Paul E. McKenneye260be62008-01-25 21:08:24 +010036#include <linux/cache.h>
37#include <linux/spinlock.h>
38#include <linux/threads.h>
Eduard - Gabriel Munteanuac440212009-03-23 15:12:21 +020039#include <linux/smp.h>
Paul E. McKenneye260be62008-01-25 21:08:24 +010040#include <linux/cpumask.h>
41#include <linux/seqlock.h>
42
Paul E. McKenneyd6714c22009-08-22 13:56:46 -070043extern void rcu_sched_qs(int cpu);
44static inline void rcu_bh_qs(int cpu) { }
Steven Rostedtdd0078f2008-07-30 14:20:54 -040045
46/*
47 * Someone might want to pass call_rcu_bh as a function pointer.
48 * So this needs to just be a rename and not a macro function.
49 * (no parentheses)
50 */
Ingo Molnara9792412009-03-25 16:42:24 +010051#define call_rcu_bh call_rcu
Paul E. McKenneye260be62008-01-25 21:08:24 +010052
Paul E. McKenney4446a362008-05-12 21:21:05 +020053/**
54 * call_rcu_sched - Queue RCU callback for invocation after sched grace period.
55 * @head: structure to be used for queueing the RCU updates.
56 * @func: actual update function to be invoked after the grace period
57 *
58 * The update function will be invoked some time after a full
59 * synchronize_sched()-style grace period elapses, in other words after
60 * all currently executing preempt-disabled sections of code (including
61 * hardirq handlers, NMI handlers, and local_irq_save() blocks) have
62 * completed.
63 */
64extern void call_rcu_sched(struct rcu_head *head,
65 void (*func)(struct rcu_head *head));
66
Patrick McHardyb55ab612008-02-08 04:21:59 -080067extern void __rcu_read_lock(void) __acquires(RCU);
68extern void __rcu_read_unlock(void) __releases(RCU);
Paul E. McKenneye260be62008-01-25 21:08:24 +010069extern int rcu_pending(int cpu);
70extern int rcu_needs_cpu(int cpu);
71
72#define __rcu_read_lock_bh() { rcu_read_lock(); local_bh_disable(); }
73#define __rcu_read_unlock_bh() { local_bh_enable(); rcu_read_unlock(); }
74
75extern void __synchronize_sched(void);
76
Paul E. McKenney03b042b2009-06-25 09:08:16 -070077static inline void synchronize_rcu_expedited(void)
78{
79 synchronize_rcu(); /* Placeholder for new rcupreempt implementation. */
80}
81
82static inline void synchronize_rcu_bh_expedited(void)
83{
84 synchronize_rcu_bh(); /* Placeholder for new rcupreempt impl. */
85}
86
Paul E. McKenneye260be62008-01-25 21:08:24 +010087extern void __rcu_init(void);
Paul E. McKenney4446a362008-05-12 21:21:05 +020088extern void rcu_init_sched(void);
Paul E. McKenneye260be62008-01-25 21:08:24 +010089extern void rcu_check_callbacks(int cpu, int user);
90extern void rcu_restart_cpu(int cpu);
91extern long rcu_batches_completed(void);
92
93/*
94 * Return the number of RCU batches processed thus far. Useful for debug
95 * and statistic. The _bh variant is identifcal to straight RCU
96 */
97static inline long rcu_batches_completed_bh(void)
98{
99 return rcu_batches_completed();
100}
101
102#ifdef CONFIG_RCU_TRACE
103struct rcupreempt_trace;
104extern long *rcupreempt_flipctr(int cpu);
105extern long rcupreempt_data_completed(void);
106extern int rcupreempt_flip_flag(int cpu);
107extern int rcupreempt_mb_flag(int cpu);
108extern char *rcupreempt_try_flip_state_name(void);
109extern struct rcupreempt_trace *rcupreempt_trace_cpu(int cpu);
110#endif
111
112struct softirq_action;
113
Steven Rostedt2232c2d2008-02-29 18:46:50 +0100114#ifdef CONFIG_NO_HZ
Ingo Molnara9792412009-03-25 16:42:24 +0100115extern void rcu_enter_nohz(void);
116extern void rcu_exit_nohz(void);
117#else
118# define rcu_enter_nohz() do { } while (0)
119# define rcu_exit_nohz() do { } while (0)
120#endif
Steven Rostedt2232c2d2008-02-29 18:46:50 +0100121
Paul E. McKenneya6826042009-02-25 18:03:42 -0800122/*
123 * A context switch is a grace period for rcupreempt synchronize_rcu()
124 * only during early boot, before the scheduler has been initialized.
125 * So, how the heck do we get a context switch? Well, if the caller
126 * invokes synchronize_rcu(), they are willing to accept a context
127 * switch, so we simply pretend that one happened.
128 *
129 * After boot, there might be a blocked or preempted task in an RCU
130 * read-side critical section, so we cannot then take the fastpath.
131 */
132static inline int rcu_blocking_is_gp(void)
133{
134 return num_online_cpus() == 1 && !rcu_scheduler_active;
135}
136
Paul E. McKenneye260be62008-01-25 21:08:24 +0100137#endif /* __LINUX_RCUPREEMPT_H */