sched: Sanitize fork() handling
Commit-ID: cd29fe6f2637cc2ccbda5ac65f5332d6bf5fa3c6 Gitweb: http://git.kernel.org/tip/cd29fe6f2637cc2ccbda5ac65f5332d6bf5fa3c6 Author: Peter Zijlstra <[email protected]> AuthorDate: Fri, 27 Nov 2009 17:32:46 +0100 Committer: Ingo Molnar <[email protected]> CommitDate: Wed, 9 Dec 2009 10:03:05 +0100
sched: Sanitize fork() handling
Currently we try to do task placement in wake_up_new_task() after we do the load-balance pass in sched_fork(). This yields complicated semantics in that we have to deal with tasks on different RQs and the set_task_cpu() calls in copy_process() and sched_fork()
Rename ->task_new() to ->task_fork() and call it from sched_fork() before the balancing, this gives the policy a clear point to place the task.
Signed-off-by Peter Zijlstra <[email protected]>
LKML-Reference: <new-submission>
Signed-off-by Ingo Molnar <[email protected]>
--- include/linux/sched.h | 2 +- kernel/sched.c | 47 ++++++++++++++++++----------------------------- kernel/sched_fair.c | 28 +++++++++++++++------------- 3 files changed, 34 insertions(+), 43 deletions(-)
include/linux/sched.h +1 -1
@@ -1102,7 +1102,7 @@ struct sched_class {void (*set_curr_task) (struct rq *rq);void (*task_tick) (struct rq *rq,struct task_struct *p,int queued); -void (*task_new) (struct rq *rq,struct task_struct *p); +void (*task_fork) (struct task_struct *p);void (*switched_from) (struct rq *this_rq,struct task_struct *task,int running);
kernel/sched.c +18 -29
81 lines not on this page · raw message
kernel/sched_fair.c +15 -13
@@ -1922,28 +1922,30 @@ static void task_tick_fair(struct rq *rq, struct task_struct *curr, int queued) }/* -* Share the fairness runtime between parent and child, thus the -* total amount of pressure for CPU stays equal - new tasks -* get a chance to run but frequent forkers are not allowed to -* monopolize the CPU. Note: the parent runqueue is locked, -* the child is not running yet. +* called on fork with the child task as argument from the parent's context +* - child not yet on the tasklist +* - preemption disabled */ -static void task_new_fair (struct rq *rq,struct task_struct *p) +static void task_fork_fair (struct task_struct *p) { -struct cfs_rq *cfs_rq =task_cfs_rq (p); +struct cfs_rq *cfs_rq =task_cfs_rq (current);struct sched_entity *se = &p->se, *curr = cfs_rq->curr;int this_cpu =smp_processor_id (); +struct rq *rq =this_rq (); +unsigned long flags; + +spin_lock_irqsave (&rq->lock, flags); -sched_info_queued (p); +if (unlikely (task_cpu (p) != this_cpu)) +__set_task_cpu (p, this_cpu);update_curr (cfs_rq); +if (curr) se->vruntime = curr->vruntime;place_entity (cfs_rq, se,1 ); -/* 'curr' will be NULL if the child belongs to a different group */ -if (sysctl_sched_child_runs_first && this_cpu ==task_cpu (p) && - curr &&entity_before (curr, se)) { +if (sysctl_sched_child_runs_first && curr &&entity_before (curr, se)) {/* * Upon rescheduling, sched_class::put_prev_task() will place * 'current' within the tree based on its new key value.
@@ -1952,7 +1954,7 @@ static void task_new_fair(struct rq *rq, struct task_struct *p)resched_task (rq->curr); } -enqueue_task_fair (rq, p,0 ); +spin_unlock_irqrestore (&rq->lock, flags); }/*
@@ -2052,7 +2054,7 @@ static const struct sched_class fair_sched_class = { .set_curr_task = set_curr_task_fair, .task_tick = task_tick_fair, - .task_new = task_new_fair, + .task_fork = task_fork_fair, .prio_changed = prio_changed_fair, .switched_to = switched_to_fair,