From: Thomas Gleixner <tglx@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: linux-arch@vger.kernel.org,
Linus Torvalds <torvalds@linux-foundation.org>,
Andrew Morton <akpm@linux-foundation.org>,
Rusty Russell <rusty@rustcorp.com.au>,
Paul McKenney <paulmck@linux.vnet.ibm.com>,
Ingo Molnar <mingo@elte.hu>,
Peter Zijlstra <peterz@infradead.org>,
"Srivatsa S. Bhat" <srivatsa.bhat@linux.vnet.ibm.com>,
Magnus Damm <magnus.damm@gmail.com>
Subject: [patch 05/34] idle: Implement generic idle function
Date: Thu, 21 Mar 2013 21:53:00 -0000 [thread overview]
Message-ID: <20130321215233.646635455@linutronix.de> (raw)
In-Reply-To: 20130321214930.752934102@linutronix.de
[-- Attachment #1: smpboot-implement-common-idle-functionality.patch --]
[-- Type: text/plain, Size: 3966 bytes --]
All idle functions in arch/* are more or less the same, plus minus a
few bugs and extra instrumentation, tickless support and other
optional items.
Implement a generic idle function which resembles the functionality
found in arch/. Provide weak arch_cpu_idle_* functions which can be
overridden by the architecture code if needed.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
arch/Kconfig | 3 +
include/linux/cpu.h | 8 +++
kernel/cpu/idle.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 116 insertions(+)
Index: linux-2.6/arch/Kconfig
===================================================================
--- linux-2.6.orig/arch/Kconfig
+++ linux-2.6/arch/Kconfig
@@ -216,6 +216,9 @@ config USE_GENERIC_SMP_HELPERS
config GENERIC_SMP_IDLE_THREAD
bool
+config GENERIC_IDLE_LOOP
+ bool
+
# Select if arch init_task initializer is different to init/init_task.c
config ARCH_INIT_TASK
bool
Index: linux-2.6/include/linux/cpu.h
===================================================================
--- linux-2.6.orig/include/linux/cpu.h
+++ linux-2.6/include/linux/cpu.h
@@ -220,4 +220,12 @@ enum cpuhp_state {
void cpu_startup_entry(enum cpuhp_state state);
void cpu_idle(void);
+void cpu_idle_poll_ctrl(bool enable);
+
+void arch_cpu_idle(void);
+void arch_cpu_idle_prepare(void);
+void arch_cpu_idle_enter(void);
+void arch_cpu_idle_exit(void);
+void arch_cpu_idle_dead(void);
+
#endif /* _LINUX_CPU_H_ */
Index: linux-2.6/kernel/cpu/idle.c
===================================================================
--- linux-2.6.orig/kernel/cpu/idle.c
+++ linux-2.6/kernel/cpu/idle.c
@@ -3,8 +3,113 @@
*/
#include <linux/sched.h>
#include <linux/cpu.h>
+#include <linux/tick.h>
+#include <linux/mm.h>
+#include <asm/tlb.h>
+
+#include <trace/events/power.h>
+
+#ifndef CONFIG_GENERIC_IDLE_LOOP
void cpu_startup_entry(enum cpuhp_state state)
{
cpu_idle();
}
+#else
+
+static int __read_mostly cpu_idle_force_poll;
+
+void cpu_idle_poll_ctrl(bool enable)
+{
+ if (enable) {
+ cpu_idle_force_poll++;
+ } else {
+ cpu_idle_force_poll--;
+ WARN_ON_ONCE(cpu_idle_force_poll < 0);
+ }
+}
+
+#ifdef CONFIG_GENERIC_IDLE_POLL_SETUP
+static int __init cpu_idle_poll_setup(char *__unused)
+{
+ cpu_idle_force_poll = 1;
+ return 1;
+}
+__setup("nohlt", cpu_idle_poll_setup);
+
+static int __init cpu_idle_nopoll_setup(char *__unused)
+{
+ cpu_idle_force_poll = 0;
+ return 1;
+}
+__setup("hlt", cpu_idle_nopoll_setup);
+#endif
+
+static inline int cpu_idle_poll(void)
+{
+ trace_cpu_idle_rcuidle(0, smp_processor_id());
+ local_irq_enable();
+ while (!need_resched())
+ cpu_relax();
+ trace_cpu_idle_rcuidle(PWR_EVENT_EXIT, smp_processor_id());
+ return 1;
+}
+
+/* Weak implementations for optional arch specific functions */
+void __weak arch_cpu_idle_prepare(void) { }
+void __weak arch_cpu_idle_enter(void) { }
+void __weak arch_cpu_idle_exit(void) { }
+void __weak arch_cpu_idle_dead(void) { }
+void __weak arch_cpu_idle(void)
+{
+ cpu_idle_poll();
+}
+
+/*
+ * Generic idle loop implementation
+ */
+static void cpu_idle_loop(void)
+{
+ while (1) {
+ tick_nohz_idle_enter();
+
+ while (!need_resched()) {
+ check_pgt_cache();
+ rmb();
+
+ if (cpu_is_offline(smp_processor_id()))
+ arch_cpu_idle_dead();
+
+ local_irq_disable();
+ arch_cpu_idle_enter();
+
+ if (cpu_idle_force_poll) {
+ cpu_idle_poll();
+ } else {
+ current_clr_polling();
+ if (!need_resched()) {
+ stop_critical_timings();
+ rcu_idle_enter();
+ arch_cpu_idle();
+ WARN_ON_ONCE(!irqs_disabled());
+ rcu_idle_exit();
+ start_critical_timings();
+ } else {
+ local_irq_enable();
+ }
+ current_set_polling();
+ }
+ arch_cpu_idle_exit();
+ }
+ tick_nohz_idle_exit();
+ schedule_preempt_disabled();
+ }
+}
+
+void cpu_startup_entry(enum cpuhp_state state)
+{
+ current_set_polling();
+ arch_cpu_idle_prepare();
+ cpu_idle_loop();
+}
+#endif
next prev parent reply other threads:[~2013-03-21 21:53 UTC|newest]
Thread overview: 140+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-21 21:52 [patch 00/34] idle: Consolidate idle implementations Thomas Gleixner
2013-03-21 21:52 ` [patch 01/34] arch: Cleanup enable/disable_hlt Thomas Gleixner
2013-03-21 21:52 ` Thomas Gleixner
2013-03-21 21:52 ` [patch 02/34] arch: Consolidate tsk_is_polling() Thomas Gleixner
2013-03-21 21:52 ` Thomas Gleixner
2013-03-22 5:01 ` Tony Breeds
2013-03-22 5:20 ` Tony Breeds
2013-03-22 9:26 ` Thomas Gleixner
2013-03-21 21:52 ` [patch 03/34] idle: Implement set/clr functions for need_resched poll Thomas Gleixner
2013-03-21 21:52 ` Thomas Gleixner
2013-03-22 9:38 ` James Hogan
2013-03-21 21:52 ` [patch 04/34] idle: Provide a generic entry point for the idle code Thomas Gleixner
2013-03-21 21:52 ` Thomas Gleixner
2013-03-21 21:53 ` Thomas Gleixner [this message]
2013-03-23 8:56 ` [patch 05/34] idle: Implement generic idle function Heiko Carstens
2013-03-25 10:39 ` Thomas Gleixner
2013-03-28 15:39 ` Srivatsa S. Bhat
2013-11-18 6:05 ` Viresh Kumar
2013-11-22 22:32 ` Thomas Gleixner
2013-03-21 21:53 ` [patch 06/34] arc: Use generic idle loop Thomas Gleixner
2013-03-22 9:02 ` Vineet Gupta
2013-03-21 21:53 ` [patch 07/34] alpha: " Thomas Gleixner
2013-03-21 21:53 ` Thomas Gleixner
2013-03-28 15:37 ` Srivatsa S. Bhat
2013-03-29 11:22 ` Thomas Gleixner
2013-03-21 21:53 ` [patch 08/34] arm: " Thomas Gleixner
2013-03-21 21:53 ` Thomas Gleixner
2013-03-22 21:24 ` Kevin Hilman
2013-03-22 21:24 ` Kevin Hilman
2013-03-25 11:31 ` Thomas Gleixner
2013-03-25 11:48 ` Russell King - ARM Linux
2013-03-25 11:48 ` Russell King - ARM Linux
2013-03-25 14:02 ` Thomas Gleixner
2013-04-08 21:47 ` Russell King - ARM Linux
2013-04-09 9:20 ` Thomas Gleixner
2013-04-09 9:20 ` Thomas Gleixner
2013-04-09 9:38 ` Russell King - ARM Linux
2013-04-09 9:38 ` Russell King - ARM Linux
2013-04-25 20:03 ` Stephen Boyd
2013-04-25 21:01 ` Thomas Gleixner
2013-04-25 21:01 ` Thomas Gleixner
2013-05-01 0:49 ` Stephen Boyd
2013-05-01 0:55 ` Paul E. McKenney
2013-05-21 0:57 ` [PATCH] ARM: smp: Drop RCU_NONIDLE usage in cpu_die() Stephen Boyd
2013-03-21 21:53 ` [patch 09/34] arm64: Use generic idle loop Thomas Gleixner
2013-03-21 21:53 ` Thomas Gleixner
2013-03-25 18:06 ` Catalin Marinas
2013-03-21 21:53 ` [patch 10/34] avr32: " Thomas Gleixner
2013-03-21 21:53 ` Thomas Gleixner
2013-03-21 21:53 ` [patch 12/34] c6x: " Thomas Gleixner
2013-03-21 21:53 ` Thomas Gleixner
2013-03-21 21:53 ` [patch 11/34] bfin: " Thomas Gleixner
2013-03-21 21:53 ` Thomas Gleixner
2013-03-21 21:53 ` [patch 13/34] cris: " Thomas Gleixner
2013-03-21 21:53 ` Thomas Gleixner
2013-03-27 15:04 ` Jesper Nilsson
2013-03-27 15:04 ` Jesper Nilsson
2013-03-27 17:10 ` Thomas Gleixner
2013-03-21 21:53 ` [patch 14/34] frv: " Thomas Gleixner
2013-03-21 21:53 ` Thomas Gleixner
2013-03-21 21:53 ` [patch 15/34] h8300: " Thomas Gleixner
2013-03-21 21:53 ` Thomas Gleixner
2013-03-21 21:53 ` [patch 16/34] hexagon: " Thomas Gleixner
2013-03-21 21:53 ` Thomas Gleixner
2013-03-21 21:53 ` [patch 17/34] ia64: " Thomas Gleixner
2013-03-21 21:53 ` Thomas Gleixner
2013-03-28 15:40 ` Srivatsa S. Bhat
2013-03-28 15:40 ` Srivatsa S. Bhat
2013-03-21 21:53 ` [patch 18/34] m32r: " Thomas Gleixner
2013-03-21 21:53 ` Thomas Gleixner
2013-03-21 21:53 ` [patch 19/34] m68k: " Thomas Gleixner
2013-03-21 21:53 ` Thomas Gleixner
2013-03-21 21:53 ` [patch 20/34] metag: " Thomas Gleixner
2013-03-21 21:53 ` Thomas Gleixner
2013-03-22 10:16 ` James Hogan
2013-03-25 11:26 ` Thomas Gleixner
2013-03-21 21:53 ` [patch 21/34] microblaze: " Thomas Gleixner
2013-03-21 21:53 ` [patch 22/34] mips: " Thomas Gleixner
2013-03-21 21:53 ` Thomas Gleixner
2013-03-28 15:42 ` Srivatsa S. Bhat
2013-03-28 15:42 ` Srivatsa S. Bhat
2013-03-21 21:53 ` [patch 24/34] openrisc: " Thomas Gleixner
2013-03-21 21:53 ` Thomas Gleixner
2013-03-21 21:53 ` [patch 23/34] mn10300: " Thomas Gleixner
2013-03-21 21:53 ` [patch 25/34] parisc: " Thomas Gleixner
2013-03-21 21:53 ` [patch 26/34] powerpc: " Thomas Gleixner
2013-03-21 21:53 ` Thomas Gleixner
2013-03-28 15:40 ` Srivatsa S. Bhat
2013-03-28 15:40 ` Srivatsa S. Bhat
2013-04-01 9:13 ` Deepthi Dharwar
2013-04-01 9:13 ` Deepthi Dharwar
2013-03-21 21:53 ` [patch 27/34] s390: " Thomas Gleixner
2013-03-21 21:53 ` Thomas Gleixner
2013-03-23 9:38 ` Heiko Carstens
2013-03-23 9:38 ` Heiko Carstens
2013-03-23 9:39 ` Heiko Carstens
2013-03-21 21:53 ` [patch 28/34] score: " Thomas Gleixner
2013-03-21 21:53 ` [patch 30/34] tile: Enter idle with preemption disabled Thomas Gleixner
2013-03-21 21:53 ` Thomas Gleixner
2013-03-22 20:34 ` Chris Metcalf
2013-03-22 20:40 ` Chris Metcalf
2013-03-28 15:43 ` Srivatsa S. Bhat
2013-03-28 15:43 ` Srivatsa S. Bhat
2013-03-21 21:53 ` [patch 29/34] sh: Use generic idle loop Thomas Gleixner
2013-03-21 21:53 ` Thomas Gleixner
2013-03-28 15:40 ` Srivatsa S. Bhat
2013-03-21 21:53 ` [patch 31/34] tile: " Thomas Gleixner
2013-03-21 21:53 ` Thomas Gleixner
2013-03-28 15:41 ` Srivatsa S. Bhat
2013-03-29 11:24 ` Thomas Gleixner
2013-03-21 21:53 ` [patch 32/34] unicore: " Thomas Gleixner
2013-03-21 21:53 ` Thomas Gleixner
2013-03-21 21:53 ` [patch 33/34] x86: " Thomas Gleixner
2013-03-21 21:53 ` Thomas Gleixner
2013-03-28 15:43 ` Srivatsa S. Bhat
2013-03-28 15:43 ` Srivatsa S. Bhat
2013-03-21 21:53 ` [patch 34/34] xtensa: " Thomas Gleixner
2013-03-21 21:53 ` Thomas Gleixner
2013-03-22 12:37 ` Max Filippov
2013-03-22 12:37 ` Max Filippov
2013-03-22 20:09 ` [patch 00/34] idle: Consolidate idle implementations Sam Ravnborg
[not found] ` <alpine.LFD.2.02.1303271940150.22263@ionos>
[not found] ` <5153EC43.7070808@zankel.net>
2013-03-28 9:24 ` Thomas Gleixner
2013-03-28 22:16 ` Chris Zankel
2013-03-29 16:19 ` Sam Ravnborg
2013-03-29 16:19 ` Sam Ravnborg
2013-03-29 20:29 ` [PATCH] sparc: Use generic idle loop Sam Ravnborg
2013-03-31 23:46 ` David Miller
2013-04-01 6:53 ` Srivatsa S. Bhat
2013-04-01 6:53 ` Srivatsa S. Bhat
2013-04-01 9:06 ` Sam Ravnborg
2013-04-01 9:06 ` Sam Ravnborg
2013-04-08 12:33 ` Srivatsa S. Bhat
2013-04-08 12:33 ` Srivatsa S. Bhat
2013-04-08 17:10 ` Sam Ravnborg
2013-04-08 19:24 ` David Miller
2013-04-11 19:38 ` [PATCH v2] " Sam Ravnborg
2013-04-11 19:38 ` Sam Ravnborg
2013-04-12 18:56 ` Thomas Gleixner
2013-04-12 18:58 ` David Miller
2013-05-03 9:47 ` [patch 00/34] idle: Consolidate idle implementations Geert Uytterhoeven
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130321215233.646635455@linutronix.de \
--to=tglx@linutronix.de \
--cc=akpm@linux-foundation.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=magnus.damm@gmail.com \
--cc=mingo@elte.hu \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=rusty@rustcorp.com.au \
--cc=srivatsa.bhat@linux.vnet.ibm.com \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).