mirror of
https://github.com/torvalds/linux.git
synced 2024-11-08 21:21:47 +00:00
9b1d82fa16
This patch is a version of RCU designed for !SMP provided for a small-footprint RCU implementation. In particular, the implementation of synchronize_rcu() is extremely lightweight and high performance. It passes rcutorture testing in each of the four relevant configurations (combinations of NO_HZ and PREEMPT) on x86. This saves about 1K bytes compared to old Classic RCU (which is no longer in mainline), and more than three kilobytes compared to Hierarchical RCU (updated to 2.6.30): CONFIG_TREE_RCU: text data bss dec filename 183 4 0 187 kernel/rcupdate.o 2783 520 36 3339 kernel/rcutree.o 3526 Total (vs 4565 for v7) CONFIG_TREE_PREEMPT_RCU: text data bss dec filename 263 4 0 267 kernel/rcupdate.o 4594 776 52 5422 kernel/rcutree.o 5689 Total (6155 for v7) CONFIG_TINY_RCU: text data bss dec filename 96 4 0 100 kernel/rcupdate.o 734 24 0 758 kernel/rcutiny.o 858 Total (vs 848 for v7) The above is for x86. Your mileage may vary on other platforms. Further compression is possible, but is being procrastinated. Changes from v7 (http://lkml.org/lkml/2009/10/9/388) o Apply Lai Jiangshan's review comments (aside from might_sleep() in synchronize_sched(), which is covered by SMP builds). o Fix up expedited primitives. Changes from v6 (http://lkml.org/lkml/2009/9/23/293). o Forward ported to put it into the 2.6.33 stream. o Added lockdep support. o Make lightweight rcu_barrier. Changes from v5 (http://lkml.org/lkml/2009/6/23/12). o Ported to latest pre-2.6.32 merge window kernel. - Renamed rcu_qsctr_inc() to rcu_sched_qs(). - Renamed rcu_bh_qsctr_inc() to rcu_bh_qs(). - Provided trivial rcu_cpu_notify(). - Provided trivial exit_rcu(). - Provided trivial rcu_needs_cpu(). - Fixed up the rcu_*_enter/exit() functions in linux/hardirq.h. o Removed the dependence on EMBEDDED, with a view to making TINY_RCU default for !SMP at some time in the future. o Added (trivial) support for expedited grace periods. Changes from v4 (http://lkml.org/lkml/2009/5/2/91) include: o Squeeze the size down a bit further by removing the ->completed field from struct rcu_ctrlblk. o This permits synchronize_rcu() to become the empty function. Previous concerns about rcutorture were unfounded, as rcutorture correctly handles a constant value from rcu_batches_completed() and rcu_batches_completed_bh(). Changes from v3 (http://lkml.org/lkml/2009/3/29/221) include: o Changed rcu_batches_completed(), rcu_batches_completed_bh() rcu_enter_nohz(), rcu_exit_nohz(), rcu_nmi_enter(), and rcu_nmi_exit(), to be static inlines, as suggested by David Howells. Doing this saves about 100 bytes from rcutiny.o. (The numbers between v3 and this v4 of the patch are not directly comparable, since they are against different versions of Linux.) Changes from v2 (http://lkml.org/lkml/2009/2/3/333) include: o Fix whitespace issues. o Change short-circuit "||" operator to instead be "+" in order to fix performance bug noted by "kraai" on LWN. (http://lwn.net/Articles/324348/) Changes from v1 (http://lkml.org/lkml/2009/1/13/440) include: o This version depends on EMBEDDED as well as !SMP, as suggested by Ingo. o Updated rcu_needs_cpu() to unconditionally return zero, permitting the CPU to enter dynticks-idle mode at any time. This works because callbacks can be invoked upon entry to dynticks-idle mode. o Paul is now OK with this being included, based on a poll at the Kernel Miniconf at linux.conf.au, where about ten people said that they cared about saving 900 bytes on single-CPU systems. o Applies to both mainline and tip/core/rcu. Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Acked-by: David Howells <dhowells@redhat.com> Acked-by: Josh Triplett <josh@joshtriplett.org> Reviewed-by: Lai Jiangshan <laijs@cn.fujitsu.com> Cc: dipankar@in.ibm.com Cc: mathieu.desnoyers@polymtl.ca Cc: dvhltc@us.ibm.com Cc: niv@us.ibm.com Cc: peterz@infradead.org Cc: rostedt@goodmis.org Cc: Valdis.Kletnieks@vt.edu Cc: avi@redhat.com Cc: mtosatti@redhat.com LKML-Reference: <12565226351355-git-send-email-> Signed-off-by: Ingo Molnar <mingo@elte.hu>
192 lines
5.8 KiB
C
192 lines
5.8 KiB
C
/*
|
|
* Read-Copy Update mechanism for mutual exclusion
|
|
*
|
|
* 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, write to the Free Software
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
*
|
|
* Copyright IBM Corporation, 2001
|
|
*
|
|
* Authors: Dipankar Sarma <dipankar@in.ibm.com>
|
|
* Manfred Spraul <manfred@colorfullife.com>
|
|
*
|
|
* Based on the original work by Paul McKenney <paulmck@us.ibm.com>
|
|
* and inputs from Rusty Russell, Andrea Arcangeli and Andi Kleen.
|
|
* Papers:
|
|
* http://www.rdrop.com/users/paulmck/paper/rclockpdcsproof.pdf
|
|
* http://lse.sourceforge.net/locking/rclock_OLS.2001.05.01c.sc.pdf (OLS2001)
|
|
*
|
|
* For detailed explanation of Read-Copy Update mechanism see -
|
|
* http://lse.sourceforge.net/locking/rcupdate.html
|
|
*
|
|
*/
|
|
#include <linux/types.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/init.h>
|
|
#include <linux/spinlock.h>
|
|
#include <linux/smp.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/sched.h>
|
|
#include <asm/atomic.h>
|
|
#include <linux/bitops.h>
|
|
#include <linux/percpu.h>
|
|
#include <linux/notifier.h>
|
|
#include <linux/cpu.h>
|
|
#include <linux/mutex.h>
|
|
#include <linux/module.h>
|
|
#include <linux/kernel_stat.h>
|
|
|
|
#ifdef CONFIG_DEBUG_LOCK_ALLOC
|
|
static struct lock_class_key rcu_lock_key;
|
|
struct lockdep_map rcu_lock_map =
|
|
STATIC_LOCKDEP_MAP_INIT("rcu_read_lock", &rcu_lock_key);
|
|
EXPORT_SYMBOL_GPL(rcu_lock_map);
|
|
#endif
|
|
|
|
int rcu_scheduler_active __read_mostly;
|
|
|
|
/*
|
|
* Awaken the corresponding synchronize_rcu() instance now that a
|
|
* grace period has elapsed.
|
|
*/
|
|
void wakeme_after_rcu(struct rcu_head *head)
|
|
{
|
|
struct rcu_synchronize *rcu;
|
|
|
|
rcu = container_of(head, struct rcu_synchronize, head);
|
|
complete(&rcu->completion);
|
|
}
|
|
|
|
#ifndef CONFIG_TINY_RCU
|
|
|
|
#ifdef CONFIG_TREE_PREEMPT_RCU
|
|
|
|
/**
|
|
* synchronize_rcu - wait until a grace period has elapsed.
|
|
*
|
|
* Control will return to the caller some time after a full grace
|
|
* period has elapsed, in other words after all currently executing RCU
|
|
* read-side critical sections have completed. RCU read-side critical
|
|
* sections are delimited by rcu_read_lock() and rcu_read_unlock(),
|
|
* and may be nested.
|
|
*/
|
|
void synchronize_rcu(void)
|
|
{
|
|
struct rcu_synchronize rcu;
|
|
|
|
if (!rcu_scheduler_active)
|
|
return;
|
|
|
|
init_completion(&rcu.completion);
|
|
/* Will wake me after RCU finished. */
|
|
call_rcu(&rcu.head, wakeme_after_rcu);
|
|
/* Wait for it. */
|
|
wait_for_completion(&rcu.completion);
|
|
}
|
|
EXPORT_SYMBOL_GPL(synchronize_rcu);
|
|
|
|
#endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
|
|
|
|
/**
|
|
* synchronize_sched - wait until an rcu-sched grace period has elapsed.
|
|
*
|
|
* Control will return to the caller some time after a full rcu-sched
|
|
* grace period has elapsed, in other words after all currently executing
|
|
* rcu-sched read-side critical sections have completed. These read-side
|
|
* critical sections are delimited by rcu_read_lock_sched() and
|
|
* rcu_read_unlock_sched(), and may be nested. Note that preempt_disable(),
|
|
* local_irq_disable(), and so on may be used in place of
|
|
* rcu_read_lock_sched().
|
|
*
|
|
* This means that all preempt_disable code sequences, including NMI and
|
|
* hardware-interrupt handlers, in progress on entry will have completed
|
|
* before this primitive returns. However, this does not guarantee that
|
|
* softirq handlers will have completed, since in some kernels, these
|
|
* handlers can run in process context, and can block.
|
|
*
|
|
* This primitive provides the guarantees made by the (now removed)
|
|
* synchronize_kernel() API. In contrast, synchronize_rcu() only
|
|
* guarantees that rcu_read_lock() sections will have completed.
|
|
* In "classic RCU", these two guarantees happen to be one and
|
|
* the same, but can differ in realtime RCU implementations.
|
|
*/
|
|
void synchronize_sched(void)
|
|
{
|
|
struct rcu_synchronize rcu;
|
|
|
|
if (rcu_blocking_is_gp())
|
|
return;
|
|
|
|
init_completion(&rcu.completion);
|
|
/* Will wake me after RCU finished. */
|
|
call_rcu_sched(&rcu.head, wakeme_after_rcu);
|
|
/* Wait for it. */
|
|
wait_for_completion(&rcu.completion);
|
|
}
|
|
EXPORT_SYMBOL_GPL(synchronize_sched);
|
|
|
|
/**
|
|
* synchronize_rcu_bh - wait until an rcu_bh grace period has elapsed.
|
|
*
|
|
* Control will return to the caller some time after a full rcu_bh grace
|
|
* period has elapsed, in other words after all currently executing rcu_bh
|
|
* read-side critical sections have completed. RCU read-side critical
|
|
* sections are delimited by rcu_read_lock_bh() and rcu_read_unlock_bh(),
|
|
* and may be nested.
|
|
*/
|
|
void synchronize_rcu_bh(void)
|
|
{
|
|
struct rcu_synchronize rcu;
|
|
|
|
if (rcu_blocking_is_gp())
|
|
return;
|
|
|
|
init_completion(&rcu.completion);
|
|
/* Will wake me after RCU finished. */
|
|
call_rcu_bh(&rcu.head, wakeme_after_rcu);
|
|
/* Wait for it. */
|
|
wait_for_completion(&rcu.completion);
|
|
}
|
|
EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
|
|
|
|
#endif /* #ifndef CONFIG_TINY_RCU */
|
|
|
|
static int __cpuinit rcu_barrier_cpu_hotplug(struct notifier_block *self,
|
|
unsigned long action, void *hcpu)
|
|
{
|
|
return rcu_cpu_notify(self, action, hcpu);
|
|
}
|
|
|
|
void __init rcu_init(void)
|
|
{
|
|
int i;
|
|
|
|
__rcu_init();
|
|
cpu_notifier(rcu_barrier_cpu_hotplug, 0);
|
|
|
|
/*
|
|
* We don't need protection against CPU-hotplug here because
|
|
* this is called early in boot, before either interrupts
|
|
* or the scheduler are operational.
|
|
*/
|
|
for_each_online_cpu(i)
|
|
rcu_barrier_cpu_hotplug(NULL, CPU_UP_PREPARE, (void *)(long)i);
|
|
}
|
|
|
|
void rcu_scheduler_starting(void)
|
|
{
|
|
WARN_ON(num_online_cpus() != 1);
|
|
WARN_ON(nr_context_switches() > 0);
|
|
rcu_scheduler_active = 1;
|
|
}
|