Commit af0fffd9 authored by Sebastian Andrzej Siewior's avatar Sebastian Andrzej Siewior Committed by Ingo Molnar

sched/core: Remove get_cpu() from sched_fork()

get_cpu() disables preemption for the entire sched_fork() function.
This get_cpu() was introduced in commit:

  dd41f596 ("sched: cfs core code")

... which also invoked sched_balance_self() and this function
required preemption do be off.

Today, sched_balance_self() seems to be moved to ->task_fork callback
which is invoked while the ->pi_lock is held.

set_load_weight() could invoke reweight_task() which then via $callchain
might end up in smp_processor_id() but since `update_load' is false
this won't happen.

I didn't find any this_cpu*() or similar usage during the initialisation
of the task_struct.

The `cpu' value (from get_cpu()) is only used later in __set_task_cpu()
while the ->pi_lock lock is held.

Based on this it is possible to remove get_cpu() and use
smp_processor_id() for the `cpu' variable without breaking anything.
Signed-off-by: default avatarSebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/20180706130615.g2ex2kmfu5kcvlq6@linutronix.deSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 45f5519e
...@@ -2294,7 +2294,6 @@ static inline void init_schedstats(void) {} ...@@ -2294,7 +2294,6 @@ static inline void init_schedstats(void) {}
int sched_fork(unsigned long clone_flags, struct task_struct *p) int sched_fork(unsigned long clone_flags, struct task_struct *p)
{ {
unsigned long flags; unsigned long flags;
int cpu = get_cpu();
__sched_fork(clone_flags, p); __sched_fork(clone_flags, p);
/* /*
...@@ -2330,14 +2329,12 @@ int sched_fork(unsigned long clone_flags, struct task_struct *p) ...@@ -2330,14 +2329,12 @@ int sched_fork(unsigned long clone_flags, struct task_struct *p)
p->sched_reset_on_fork = 0; p->sched_reset_on_fork = 0;
} }
if (dl_prio(p->prio)) { if (dl_prio(p->prio))
put_cpu();
return -EAGAIN; return -EAGAIN;
} else if (rt_prio(p->prio)) { else if (rt_prio(p->prio))
p->sched_class = &rt_sched_class; p->sched_class = &rt_sched_class;
} else { else
p->sched_class = &fair_sched_class; p->sched_class = &fair_sched_class;
}
init_entity_runnable_average(&p->se); init_entity_runnable_average(&p->se);
...@@ -2353,7 +2350,7 @@ int sched_fork(unsigned long clone_flags, struct task_struct *p) ...@@ -2353,7 +2350,7 @@ int sched_fork(unsigned long clone_flags, struct task_struct *p)
* We're setting the CPU for the first time, we don't migrate, * We're setting the CPU for the first time, we don't migrate,
* so use __set_task_cpu(). * so use __set_task_cpu().
*/ */
__set_task_cpu(p, cpu); __set_task_cpu(p, smp_processor_id());
if (p->sched_class->task_fork) if (p->sched_class->task_fork)
p->sched_class->task_fork(p); p->sched_class->task_fork(p);
raw_spin_unlock_irqrestore(&p->pi_lock, flags); raw_spin_unlock_irqrestore(&p->pi_lock, flags);
...@@ -2370,8 +2367,6 @@ int sched_fork(unsigned long clone_flags, struct task_struct *p) ...@@ -2370,8 +2367,6 @@ int sched_fork(unsigned long clone_flags, struct task_struct *p)
plist_node_init(&p->pushable_tasks, MAX_PRIO); plist_node_init(&p->pushable_tasks, MAX_PRIO);
RB_CLEAR_NODE(&p->pushable_dl_tasks); RB_CLEAR_NODE(&p->pushable_dl_tasks);
#endif #endif
put_cpu();
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment