aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/rcutree_plugin.h
diff options
context:
space:
mode:
authorPaul E. McKenney <paul.mckenney@linaro.org>2011-11-02 09:54:54 -0400
committerPaul E. McKenney <paulmck@linux.vnet.ibm.com>2011-12-11 13:31:43 -0500
commitaea1b35e29e658d42d7ba2237f3aa7f93e18509d (patch)
tree0221b1c12b5c3e3ed7f2bb2ffc957b09891bcb51 /kernel/rcutree_plugin.h
parent0989cb46783188ea7346ba6490be0046b9b7a725 (diff)
rcu: Allow dyntick-idle mode for CPUs with callbacks
Currently, RCU does not permit a CPU to enter dyntick-idle mode if that CPU has any RCU callbacks queued. This means that workloads for which each CPU wakes up and does some RCU updates every few ticks will never enter dyntick-idle mode. This can result in significant unnecessary power consumption, so this patch permits a given to enter dyntick-idle mode if it has callbacks, but only if that same CPU has completed all current work for the RCU core. We determine use rcu_pending() to determine whether a given CPU has completed all current work for the RCU core. Signed-off-by: Paul E. McKenney <paul.mckenney@linaro.org> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Diffstat (limited to 'kernel/rcutree_plugin.h')
-rw-r--r--kernel/rcutree_plugin.h156
1 files changed, 124 insertions, 32 deletions
diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
index 7a7961feeecf..b70ca8cc52e1 100644
--- a/kernel/rcutree_plugin.h
+++ b/kernel/rcutree_plugin.h
@@ -1953,7 +1953,31 @@ EXPORT_SYMBOL_GPL(synchronize_sched_expedited);
1953 */ 1953 */
1954int rcu_needs_cpu(int cpu) 1954int rcu_needs_cpu(int cpu)
1955{ 1955{
1956 return rcu_needs_cpu_quick_check(cpu); 1956 return rcu_cpu_has_callbacks(cpu);
1957}
1958
1959/*
1960 * Do the idle-entry grace-period work, which, because CONFIG_RCU_FAST_NO_HZ=y,
1961 * is nothing.
1962 */
1963static void rcu_prepare_for_idle(int cpu)
1964{
1965}
1966
1967/*
1968 * CPUs are never putting themselves to sleep with callbacks pending,
1969 * so there is no need to awaken them.
1970 */
1971static void rcu_wake_cpus_for_gp_end(void)
1972{
1973}
1974
1975/*
1976 * CPUs are never putting themselves to sleep with callbacks pending,
1977 * so there is no need to schedule the act of awakening them.
1978 */
1979static void rcu_schedule_wake_gp_end(void)
1980{
1957} 1981}
1958 1982
1959#else /* #if !defined(CONFIG_RCU_FAST_NO_HZ) */ 1983#else /* #if !defined(CONFIG_RCU_FAST_NO_HZ) */
@@ -1961,47 +1985,56 @@ int rcu_needs_cpu(int cpu)
1961#define RCU_NEEDS_CPU_FLUSHES 5 1985#define RCU_NEEDS_CPU_FLUSHES 5
1962static DEFINE_PER_CPU(int, rcu_dyntick_drain); 1986static DEFINE_PER_CPU(int, rcu_dyntick_drain);
1963static DEFINE_PER_CPU(unsigned long, rcu_dyntick_holdoff); 1987static DEFINE_PER_CPU(unsigned long, rcu_dyntick_holdoff);
1988static DEFINE_PER_CPU(bool, rcu_awake_at_gp_end);
1964 1989
1965/* 1990/*
1966 * Check to see if any future RCU-related work will need to be done 1991 * Allow the CPU to enter dyntick-idle mode if either: (1) There are no
1967 * by the current CPU, even if none need be done immediately, returning 1992 * callbacks on this CPU, (2) this CPU has not yet attempted to enter
1968 * 1 if so. This function is part of the RCU implementation; it is -not- 1993 * dyntick-idle mode, or (3) this CPU is in the process of attempting to
1969 * an exported member of the RCU API. 1994 * enter dyntick-idle mode. Otherwise, if we have recently tried and failed
1995 * to enter dyntick-idle mode, we refuse to try to enter it. After all,
1996 * it is better to incur scheduling-clock interrupts than to spin
1997 * continuously for the same time duration!
1998 */
1999int rcu_needs_cpu(int cpu)
2000{
2001 /* If no callbacks, RCU doesn't need the CPU. */
2002 if (!rcu_cpu_has_callbacks(cpu))
2003 return 0;
2004 /* Otherwise, RCU needs the CPU only if it recently tried and failed. */
2005 return per_cpu(rcu_dyntick_holdoff, cpu) == jiffies;
2006}
2007
2008/*
2009 * Check to see if any RCU-related work can be done by the current CPU,
2010 * and if so, schedule a softirq to get it done. This function is part
2011 * of the RCU implementation; it is -not- an exported member of the RCU API.
1970 * 2012 *
1971 * Because we are not supporting preemptible RCU, attempt to accelerate 2013 * The idea is for the current CPU to clear out all work required by the
1972 * any current grace periods so that RCU no longer needs this CPU, but 2014 * RCU core for the current grace period, so that this CPU can be permitted
1973 * only if all other CPUs are already in dynticks-idle mode. This will 2015 * to enter dyntick-idle mode. In some cases, it will need to be awakened
1974 * allow the CPU cores to be powered down immediately, as opposed to after 2016 * at the end of the grace period by whatever CPU ends the grace period.
1975 * waiting many milliseconds for grace periods to elapse. 2017 * This allows CPUs to go dyntick-idle more quickly, and to reduce the
2018 * number of wakeups by a modest integer factor.
1976 * 2019 *
1977 * Because it is not legal to invoke rcu_process_callbacks() with irqs 2020 * Because it is not legal to invoke rcu_process_callbacks() with irqs
1978 * disabled, we do one pass of force_quiescent_state(), then do a 2021 * disabled, we do one pass of force_quiescent_state(), then do a
1979 * invoke_rcu_core() to cause rcu_process_callbacks() to be invoked 2022 * invoke_rcu_core() to cause rcu_process_callbacks() to be invoked
1980 * later. The per-cpu rcu_dyntick_drain variable controls the sequencing. 2023 * later. The per-cpu rcu_dyntick_drain variable controls the sequencing.
2024 *
2025 * The caller must have disabled interrupts.
1981 */ 2026 */
1982int rcu_needs_cpu(int cpu) 2027static void rcu_prepare_for_idle(int cpu)
1983{ 2028{
1984 int c = 0; 2029 int c = 0;
1985 int snap;
1986 int thatcpu;
1987 2030
1988 /* Check for being in the holdoff period. */ 2031 /* If no callbacks or in the holdoff period, enter dyntick-idle. */
1989 if (per_cpu(rcu_dyntick_holdoff, cpu) == jiffies) 2032 if (!rcu_cpu_has_callbacks(cpu)) {
1990 return rcu_needs_cpu_quick_check(cpu); 2033 per_cpu(rcu_dyntick_holdoff, cpu) = jiffies - 1;
1991 2034 return;
1992 /* Don't bother unless we are the last non-dyntick-idle CPU. */
1993 for_each_online_cpu(thatcpu) {
1994 if (thatcpu == cpu)
1995 continue;
1996 snap = atomic_add_return(0, &per_cpu(rcu_dynticks,
1997 thatcpu).dynticks);
1998 smp_mb(); /* Order sampling of snap with end of grace period. */
1999 if ((snap & 0x1) != 0) {
2000 per_cpu(rcu_dyntick_drain, cpu) = 0;
2001 per_cpu(rcu_dyntick_holdoff, cpu) = jiffies - 1;
2002 return rcu_needs_cpu_quick_check(cpu);
2003 }
2004 } 2035 }
2036 if (per_cpu(rcu_dyntick_holdoff, cpu) == jiffies)
2037 return;
2005 2038
2006 /* Check and update the rcu_dyntick_drain sequencing. */ 2039 /* Check and update the rcu_dyntick_drain sequencing. */
2007 if (per_cpu(rcu_dyntick_drain, cpu) <= 0) { 2040 if (per_cpu(rcu_dyntick_drain, cpu) <= 0) {
@@ -2010,10 +2043,25 @@ int rcu_needs_cpu(int cpu)
2010 } else if (--per_cpu(rcu_dyntick_drain, cpu) <= 0) { 2043 } else if (--per_cpu(rcu_dyntick_drain, cpu) <= 0) {
2011 /* We have hit the limit, so time to give up. */ 2044 /* We have hit the limit, so time to give up. */
2012 per_cpu(rcu_dyntick_holdoff, cpu) = jiffies; 2045 per_cpu(rcu_dyntick_holdoff, cpu) = jiffies;
2013 return rcu_needs_cpu_quick_check(cpu); 2046 if (!rcu_pending(cpu)) {
2047 per_cpu(rcu_awake_at_gp_end, cpu) = 1;
2048 return; /* Nothing to do immediately. */
2049 }
2050 invoke_rcu_core(); /* Force the CPU out of dyntick-idle. */
2051 return;
2014 } 2052 }
2015 2053
2016 /* Do one step pushing remaining RCU callbacks through. */ 2054 /*
2055 * Do one step of pushing the remaining RCU callbacks through
2056 * the RCU core state machine.
2057 */
2058#ifdef CONFIG_TREE_PREEMPT_RCU
2059 if (per_cpu(rcu_preempt_data, cpu).nxtlist) {
2060 rcu_preempt_qs(cpu);
2061 force_quiescent_state(&rcu_preempt_state, 0);
2062 c = c || per_cpu(rcu_preempt_data, cpu).nxtlist;
2063 }
2064#endif /* #ifdef CONFIG_TREE_PREEMPT_RCU */
2017 if (per_cpu(rcu_sched_data, cpu).nxtlist) { 2065 if (per_cpu(rcu_sched_data, cpu).nxtlist) {
2018 rcu_sched_qs(cpu); 2066 rcu_sched_qs(cpu);
2019 force_quiescent_state(&rcu_sched_state, 0); 2067 force_quiescent_state(&rcu_sched_state, 0);
@@ -2028,7 +2076,51 @@ int rcu_needs_cpu(int cpu)
2028 /* If RCU callbacks are still pending, RCU still needs this CPU. */ 2076 /* If RCU callbacks are still pending, RCU still needs this CPU. */
2029 if (c) 2077 if (c)
2030 invoke_rcu_core(); 2078 invoke_rcu_core();
2031 return c;
2032} 2079}
2033 2080
2081/*
2082 * Wake up a CPU by invoking the RCU core. Intended for use by
2083 * rcu_wake_cpus_for_gp_end(), which passes this function to
2084 * smp_call_function_single().
2085 */
2086static void rcu_wake_cpu(void *unused)
2087{
2088 invoke_rcu_core();
2089}
2090
2091/*
2092 * If an RCU grace period ended recently, scan the rcu_awake_at_gp_end
2093 * per-CPU variables, and wake up any CPUs that requested a wakeup.
2094 */
2095static void rcu_wake_cpus_for_gp_end(void)
2096{
2097 int cpu;
2098 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
2099
2100 if (!rdtp->wake_gp_end)
2101 return;
2102 rdtp->wake_gp_end = 0;
2103 for_each_online_cpu(cpu) {
2104 if (per_cpu(rcu_awake_at_gp_end, cpu)) {
2105 per_cpu(rcu_awake_at_gp_end, cpu) = 0;
2106 smp_call_function_single(cpu, rcu_wake_cpu, NULL, 0);
2107 }
2108 }
2109}
2110
2111/*
2112 * A grace period has just ended, and so we will need to awaken CPUs
2113 * that now have work to do. But we cannot send IPIs with interrupts
2114 * disabled, so just set a flag so that this will happen upon exit
2115 * from RCU core processing.
2116 */
2117static void rcu_schedule_wake_gp_end(void)
2118{
2119 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
2120
2121 rdtp->wake_gp_end = 1;
2122}
2123
2124/* @@@ need tracing as well. */
2125
2034#endif /* #else #if !defined(CONFIG_RCU_FAST_NO_HZ) */ 2126#endif /* #else #if !defined(CONFIG_RCU_FAST_NO_HZ) */