From: Tejun Heo <tj@kernel.org>
To: Ingo Molnar <mingo@elte.hu>
Cc: Stephen Rothwell <sfr@canb.auug.org.au>,
linux-next@vger.kernel.org, linux-kernel@vger.kernel.org,
Mike Galbraith <efault@gmx.de>,
Thomas Gleixner <tglx@linutronix.de>,
"H. Peter Anvin" <hpa@zytor.com>,
Peter Zijlstra <peterz@infradead.org>
Subject: [PATCH 2/4 tip/sched/core] sched: update sched_notifier and add wakeup/sleep notifications
Date: Thu, 26 Nov 2009 19:13:23 +0900 [thread overview]
Message-ID: <4B0E54C3.7000301@kernel.org> (raw)
In-Reply-To: <20091126095154.GE32275@elte.hu>
Update sched_notifier such that
* in and out ops are symmetric in the parameter they take.
* Use single fire_sched_notifier() macro instead of separate function
for each op.
* Allow NULL ops.
* Add wakeup and sleep notifications.
Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Avi Kivity <avi@redhat.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Mike Galbraith <efault@gmx.de>
---
include/linux/sched.h | 20 +++++++++++++-------
kernel/sched.c | 41 ++++++++++++++++++-----------------------
virt/kvm/kvm_main.c | 4 ++--
3 files changed, 33 insertions(+), 32 deletions(-)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 68fffe8..e03a754 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1214,15 +1214,21 @@ struct sched_notifier;
/**
* sched_notifier_ops - notifiers called for scheduling events
- * @in: we're about to be rescheduled:
- * notifier: struct sched_notifier for the task being scheduled
- * cpu: cpu we're scheduled on
- * @out: we've just been preempted
- * notifier: struct sched_notifier for the task being preempted
- * next: the task that's kicking us out
+ * @wakeup: we're waking up
+ * notifier: struct sched_notifier for the task being woken up
+ * @sleep: we're going to bed
+ * notifier: struct sched_notifier for the task sleeping
+ * @in: we're now running on the cpu
+ * notifier: struct sched_notifier for the task being scheduled in
+ * prev: the task which ran before us
+ * @out: we're leaving the cpu
+ * notifier: struct sched_notifier for the task being scheduled out
+ * next: the task which will run after us
*/
struct sched_notifier_ops {
- void (*in)(struct sched_notifier *notifier, int cpu);
+ void (*wakeup)(struct sched_notifier *notifier);
+ void (*sleep)(struct sched_notifier *notifier);
+ void (*in)(struct sched_notifier *notifier, struct task_struct *prev);
void (*out)(struct sched_notifier *notifier, struct task_struct *next);
};
diff --git a/kernel/sched.c b/kernel/sched.c
index b5278c2..475da1a 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -1389,6 +1389,16 @@ static const u32 prio_to_wmult[40] = {
/* 15 */ 119304647, 148102320, 186737708, 238609294, 286331153,
};
+#define fire_sched_notifier(p, callback, args...) do { \
+ struct task_struct *__p = (p); \
+ struct sched_notifier *__sn; \
+ struct hlist_node *__pos; \
+ \
+ hlist_for_each_entry(__sn, __pos, &__p->sched_notifiers, link) \
+ if (__sn->ops->callback) \
+ __sn->ops->callback(__sn , ##args); \
+} while (0)
+
static void activate_task(struct rq *rq, struct task_struct *p, int wakeup);
/*
@@ -2454,6 +2464,8 @@ out_running:
rq->idle_stamp = 0;
}
#endif
+ if (success)
+ fire_sched_notifier(p, wakeup);
out:
task_rq_unlock(rq, &flags);
put_cpu();
@@ -2670,25 +2682,6 @@ void sched_notifier_unregister(struct sched_notifier *notifier)
}
EXPORT_SYMBOL_GPL(sched_notifier_unregister);
-static void fire_sched_in_notifiers(struct task_struct *curr)
-{
- struct sched_notifier *notifier;
- struct hlist_node *node;
-
- hlist_for_each_entry(notifier, node, &curr->sched_notifiers, link)
- notifier->ops->in(notifier, raw_smp_processor_id());
-}
-
-static void fire_sched_out_notifiers(struct task_struct *curr,
- struct task_struct *next)
-{
- struct sched_notifier *notifier;
- struct hlist_node *node;
-
- hlist_for_each_entry(notifier, node, &curr->sched_notifiers, link)
- notifier->ops->out(notifier, next);
-}
-
/**
* prepare_task_switch - prepare to switch tasks
* @rq: the runqueue preparing to switch
@@ -2706,7 +2699,7 @@ static inline void
prepare_task_switch(struct rq *rq, struct task_struct *prev,
struct task_struct *next)
{
- fire_sched_out_notifiers(prev, next);
+ fire_sched_notifier(current, out, next);
prepare_lock_switch(rq, next);
prepare_arch_switch(next);
}
@@ -2748,7 +2741,7 @@ static void finish_task_switch(struct rq *rq, struct task_struct *prev)
prev_state = prev->state;
finish_arch_switch(prev);
perf_event_task_sched_in(current, cpu_of(rq));
- fire_sched_in_notifiers(current);
+ fire_sched_notifier(current, in, prev);
finish_lock_switch(rq, prev);
if (mm)
@@ -5441,10 +5434,12 @@ need_resched_nonpreemptible:
clear_tsk_need_resched(prev);
if (prev->state && !(preempt_count() & PREEMPT_ACTIVE)) {
- if (unlikely(signal_pending_state(prev->state, prev)))
+ if (unlikely(signal_pending_state(prev->state, prev))) {
prev->state = TASK_RUNNING;
- else
+ } else {
+ fire_sched_notifier(prev, sleep);
deactivate_task(rq, prev, 1);
+ }
switch_count = &prev->nvcsw;
}
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 4e8e33f..006358d 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -2695,11 +2695,11 @@ static inline struct kvm_vcpu *sched_notifier_to_vcpu(struct sched_notifier *sn)
return container_of(sn, struct kvm_vcpu, sched_notifier);
}
-static void kvm_sched_in(struct sched_notifier *sn, int cpu)
+static void kvm_sched_in(struct sched_notifier *sn, struct task_struct *prev)
{
struct kvm_vcpu *vcpu = sched_notifier_to_vcpu(sn);
- kvm_arch_vcpu_load(vcpu, cpu);
+ kvm_arch_vcpu_load(vcpu, smp_processor_id());
}
static void kvm_sched_out(struct sched_notifier *sn, struct task_struct *next)
--
1.6.5.3
next prev parent reply other threads:[~2009-11-26 10:13 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-26 8:00 linux-next: manual merge of the workqueues tree with the tip tree Stephen Rothwell
2009-11-26 8:12 ` Ingo Molnar
2009-11-26 9:15 ` Tejun Heo
2009-11-26 9:26 ` Ingo Molnar
2009-11-26 9:48 ` Tejun Heo
2009-11-26 9:51 ` Ingo Molnar
2009-11-26 10:11 ` [PATCH 1/4 tip/sched/core] sched: rename preempt_notifier to sched_notifier and always enable it Tejun Heo
2009-11-26 10:29 ` Ingo Molnar
2009-11-26 10:32 ` Peter Zijlstra
2009-11-26 11:23 ` Peter Zijlstra
2009-11-26 11:56 ` Ingo Molnar
2009-11-26 12:40 ` Peter Zijlstra
2009-11-27 2:11 ` Tejun Heo
2009-11-27 4:52 ` Ingo Molnar
2009-11-27 5:38 ` Tejun Heo
2009-11-27 5:46 ` Ingo Molnar
2009-11-27 6:01 ` Tejun Heo
2009-11-27 6:13 ` Ingo Molnar
2009-11-27 6:16 ` Tejun Heo
2009-11-27 6:21 ` Ingo Molnar
2009-11-27 6:38 ` Tejun Heo
2009-11-27 7:02 ` Ingo Molnar
2009-11-26 10:44 ` Tejun Heo
2009-11-27 3:33 ` Paul Mackerras
2009-11-27 4:54 ` Ingo Molnar
2009-11-26 10:13 ` Tejun Heo [this message]
2009-11-26 10:13 ` [PATCH 3/4 tip/sched/core] sched: refactor try_to_wake_up() and implement try_to_wake_up_local() Tejun Heo
2009-11-26 10:14 ` [PATCH 4/4 tip/sched/core] sched: implement force_cpus_allowed() Tejun Heo
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=4B0E54C3.7000301@kernel.org \
--to=tj@kernel.org \
--cc=efault@gmx.de \
--cc=hpa@zytor.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-next@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=peterz@infradead.org \
--cc=sfr@canb.auug.org.au \
--cc=tglx@linutronix.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.