From: anton.vorontsov@linaro.org (Anton Vorontsov)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/4] sched: Introduce idle notifiers API
Date: Wed, 8 Feb 2012 05:41:57 +0400 [thread overview]
Message-ID: <20120208014157.GA459@panacea> (raw)
In-Reply-To: <20120208013959.GA24535@panacea>
Idle notifiers may be used as a hint to the code that needs to know when
there are no tasks to execute, and the scheduler is idling, or when the
idling period ends. This patch implements a simple notifiers API.
Notes:
- Unlike x86 "CPU idle" notifiers API, these notifiers do not run on
every invocation or exit from cpuidle. Instead it is only used
to notify about scheduler state changes, not HW states.
In other words, CPU idle notifiers work inside while(!need_resched())
loop, and scheduler idle notifiers will work outside of this loop.
- rcu_idle_{enter,exit} are wired as built-ins, bypassing
sched_idle_notifier chain.
We might change it later to get rid of sched_idle_enter_condrcu()
stuff on powerpc and x86. But that's just an implementation detail,
so let's keep things simple for now.
- tick_nohz_idle_enter() is also wired as built-in, there is no much
gain in moving to to sched_idle_notifier chain.
Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
---
include/linux/sched.h | 10 ++++++++++
kernel/sched/core.c | 38 ++++++++++++++++++++++++++++++++++++++
2 files changed, 48 insertions(+), 0 deletions(-)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 4032ec1..e82f721 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1960,6 +1960,16 @@ extern void sched_clock_idle_sleep_event(void);
extern void sched_clock_idle_wakeup_event(u64 delta_ns);
#endif
+#define SCHED_IDLE_START 1
+#define SCHED_IDLE_END 2
+extern void sched_idle_notifier_register(struct notifier_block *nb);
+extern void sched_idle_notifier_unregister(struct notifier_block *nb);
+extern void sched_idle_notifier_call_chain(unsigned long val);
+extern void sched_idle_enter_condrcu(bool idle_uses_rcu);
+extern void sched_idle_exit_condrcu(bool idle_uses_rcu);
+static inline void sched_idle_enter(void) { sched_idle_enter_condrcu(0); }
+static inline void sched_idle_exit(void) { sched_idle_exit_condrcu(0); }
+
#ifdef CONFIG_IRQ_TIME_ACCOUNTING
/*
* An i/f to runtime opt-in for irq time accounting based off of sched_clock.
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index fd7b25e..62798ac 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -1810,6 +1810,44 @@ void wake_up_new_task(struct task_struct *p)
task_rq_unlock(rq, p, &flags);
}
+static ATOMIC_NOTIFIER_HEAD(sched_idle_notifier);
+
+void sched_idle_notifier_register(struct notifier_block *nb)
+{
+ atomic_notifier_chain_register(&sched_idle_notifier, nb);
+}
+EXPORT_SYMBOL_GPL(sched_idle_notifier_register);
+
+void sched_idle_notifier_unregister(struct notifier_block *nb)
+{
+ atomic_notifier_chain_unregister(&sched_idle_notifier, nb);
+}
+EXPORT_SYMBOL_GPL(sched_idle_notifier_unregister);
+
+void sched_idle_notifier_call_chain(unsigned long val)
+{
+ atomic_notifier_call_chain(&sched_idle_notifier, val, NULL);
+}
+EXPORT_SYMBOL_GPL(sched_idle_notifier_call_chain);
+
+void sched_idle_enter_condrcu(bool idle_uses_rcu)
+{
+ tick_nohz_idle_enter();
+ if (!idle_uses_rcu)
+ rcu_idle_enter();
+ sched_idle_notifier_call_chain(SCHED_IDLE_START);
+}
+EXPORT_SYMBOL_GPL(sched_idle_enter_condrcu);
+
+void sched_idle_exit_condrcu(bool idle_uses_rcu)
+{
+ sched_idle_notifier_call_chain(SCHED_IDLE_END);
+ if (!idle_uses_rcu)
+ rcu_idle_exit();
+ tick_nohz_idle_exit();
+}
+EXPORT_SYMBOL_GPL(sched_idle_exit_condrcu);
+
#ifdef CONFIG_PREEMPT_NOTIFIERS
/**
--
1.7.7.6
next prev parent reply other threads:[~2012-02-08 1:41 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-08 1:39 [PATCH RFC 0/4] Scheduler idle notifiers and users Anton Vorontsov
2012-02-08 1:41 ` Anton Vorontsov [this message]
2012-02-08 1:43 ` [PATCH 2/4] sched: Wire up idle notifiers Anton Vorontsov
2012-02-08 1:44 ` [PATCH 3/4] cpufreq: New 'interactive' governor Anton Vorontsov
2012-02-08 23:00 ` Vincent Guittot
2012-02-09 0:32 ` Anton Vorontsov
2012-02-08 1:44 ` [PATCH 4/4] ARM: Move leds idle start/stop calls to sched idle notifiers Anton Vorontsov
2012-02-08 3:05 ` [PATCH RFC 0/4] Scheduler idle notifiers and users Peter Zijlstra
2012-02-08 20:23 ` Dave Jones
2012-02-08 21:33 ` Benjamin Herrenschmidt
2012-02-09 7:51 ` Ingo Molnar
2012-02-11 3:15 ` Saravana Kannan
2012-02-11 14:39 ` Mark Brown
2012-02-11 14:53 ` Peter Zijlstra
2012-02-11 15:33 ` Mark Brown
2012-02-15 13:38 ` Peter Zijlstra
2012-02-15 16:04 ` Mark Brown
2012-02-12 21:33 ` Benjamin Herrenschmidt
2012-02-11 14:45 ` Ingo Molnar
2012-02-14 23:20 ` Saravana Kannan
2012-02-15 13:38 ` Peter Zijlstra
2012-02-15 14:02 ` Russell King - ARM Linux
2012-02-15 15:01 ` Peter Zijlstra
2012-02-15 16:00 ` Russell King - ARM Linux
2012-02-15 16:09 ` Peter Zijlstra
2012-02-16 3:31 ` Benjamin Herrenschmidt
2012-02-16 10:14 ` Peter Zijlstra
2012-02-17 9:00 ` Dominik Brodowski
2012-02-20 11:03 ` Peter Zijlstra
2012-02-21 12:38 ` Pantelis Antoniou
2012-02-21 12:56 ` Peter Zijlstra
2012-02-21 13:31 ` Pantelis Antoniou
2012-02-21 14:52 ` Amit Kucheria
2012-02-21 17:06 ` Pantelis Antoniou
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=20120208014157.GA459@panacea \
--to=anton.vorontsov@linaro.org \
--cc=linux-arm-kernel@lists.infradead.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).