[PATCH 05/19] sched: implement sched_notifier_wake_up_process()

From: Tejun Heo
Date: Thu Nov 19 2009 - 23:51:44 EST


Implement sched_notifier_wake_up_process() which can be called from
wakeup, sleep and in scheduler notifiers to wake up a task which is
bound to the same cpu. This will be used to implement concurrency
managed workqueue.

Signed-off-by: Tejun Heo <tj@xxxxxxxxxx>
---
include/linux/sched.h | 1 +
kernel/sched.c | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/include/linux/sched.h b/include/linux/sched.h
index 657372f..6889a6c 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1246,6 +1246,7 @@ struct sched_notifier {

void sched_notifier_register(struct sched_notifier *notifier);
void sched_notifier_unregister(struct sched_notifier *notifier);
+bool sched_notifier_wake_up_process(struct task_struct *p);

static inline void sched_notifier_init(struct sched_notifier *notifier,
struct sched_notifier_ops *ops)
diff --git a/kernel/sched.c b/kernel/sched.c
index 88c0fda..b53db19 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -2665,6 +2665,43 @@ void sched_notifier_unregister(struct sched_notifier *notifier)
EXPORT_SYMBOL_GPL(sched_notifier_unregister);

/**
+ * sched_notifier_wake_up_process - wake up a process from sched notifier
+ * @p: task to wake up
+ *
+ * Wake up @p. This function can only be called from wakeup, sleep
+ * and in scheduler notifiers and can only wake up tasks which are
+ * already bound to the cpu in question.
+ *
+ * CONTEXT:
+ * Scheduler notifiers.
+ *
+ * RETURNS:
+ * true if @p was waken up, false if @p was already awake.
+ */
+bool sched_notifier_wake_up_process(struct task_struct *p)
+{
+ struct rq *rq = task_rq(p);
+ bool success = false;
+
+ assert_spin_locked(&rq->lock);
+
+ if (!p->se.on_rq) {
+ schedstat_inc(p, se.nr_wakeups);
+ schedstat_inc(p, se.nr_wakeups_local);
+ activate_task(rq, p, 1);
+ success = true;
+ }
+
+ trace_sched_wakeup(rq, p, success);
+ p->state = TASK_RUNNING;
+#ifdef CONFIG_SMP
+ if (p->sched_class->task_wake_up)
+ p->sched_class->task_wake_up(rq, p);
+#endif
+ return success;
+}
+
+/**
* prepare_task_switch - prepare to switch tasks
* @rq: the runqueue preparing to switch
* @prev: the current task that is being switched out
--
1.6.4.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/