* [PATCH] sched/core: remove get_cpu() from sched_fork()
@ 2018-07-06 13:06 Sebastian Andrzej Siewior
2018-07-06 13:18 ` Peter Zijlstra
2018-07-15 23:34 ` [tip:sched/core] sched/core: Remove " tip-bot for Sebastian Andrzej Siewior
0 siblings, 2 replies; 5+ messages in thread
From: Sebastian Andrzej Siewior @ 2018-07-06 13:06 UTC (permalink / raw)
To: linux-kernel; +Cc: Ingo Molnar, Peter Zijlstra, Thomas Gleixner
get_cpu() disables preemption for the entire sched_fork() function.
This get_cpu() was introduced in commit dd41f596cda0 ("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: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
kernel/sched/core.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 78d8facba456..b6ec6ebe620d 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2318,7 +2318,6 @@ static inline void init_schedstats(void) {}
int sched_fork(unsigned long clone_flags, struct task_struct *p)
{
unsigned long flags;
- int cpu = get_cpu();
__sched_fork(clone_flags, p);
/*
@@ -2354,14 +2353,12 @@ int sched_fork(unsigned long clone_flags, struct task_struct *p)
p->sched_reset_on_fork = 0;
}
- if (dl_prio(p->prio)) {
- put_cpu();
+ if (dl_prio(p->prio))
return -EAGAIN;
- } else if (rt_prio(p->prio)) {
+ else if (rt_prio(p->prio))
p->sched_class = &rt_sched_class;
- } else {
+ else
p->sched_class = &fair_sched_class;
- }
init_entity_runnable_average(&p->se);
@@ -2377,7 +2374,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,
* so use __set_task_cpu().
*/
- __set_task_cpu(p, cpu);
+ __set_task_cpu(p, smp_processor_id());
if (p->sched_class->task_fork)
p->sched_class->task_fork(p);
raw_spin_unlock_irqrestore(&p->pi_lock, flags);
@@ -2394,8 +2391,6 @@ int sched_fork(unsigned long clone_flags, struct task_struct *p)
plist_node_init(&p->pushable_tasks, MAX_PRIO);
RB_CLEAR_NODE(&p->pushable_dl_tasks);
#endif
-
- put_cpu();
return 0;
}
--
2.18.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] sched/core: remove get_cpu() from sched_fork()
2018-07-06 13:06 [PATCH] sched/core: remove get_cpu() from sched_fork() Sebastian Andrzej Siewior
@ 2018-07-06 13:18 ` Peter Zijlstra
2018-07-06 13:32 ` Sebastian Andrzej Siewior
2018-07-15 23:34 ` [tip:sched/core] sched/core: Remove " tip-bot for Sebastian Andrzej Siewior
1 sibling, 1 reply; 5+ messages in thread
From: Peter Zijlstra @ 2018-07-06 13:18 UTC (permalink / raw)
To: Sebastian Andrzej Siewior; +Cc: linux-kernel, Ingo Molnar, Thomas Gleixner
On Fri, Jul 06, 2018 at 03:06:15PM +0200, Sebastian Andrzej Siewior wrote:
> Based on this it is possible to remove get_cpu() and use
> smp_processor_id() for the `cpu' variable without breaking anything.
Almost.. I think, see init_task_preempt_count().
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] sched/core: remove get_cpu() from sched_fork()
2018-07-06 13:18 ` Peter Zijlstra
@ 2018-07-06 13:32 ` Sebastian Andrzej Siewior
2018-07-09 9:01 ` Peter Zijlstra
0 siblings, 1 reply; 5+ messages in thread
From: Sebastian Andrzej Siewior @ 2018-07-06 13:32 UTC (permalink / raw)
To: Peter Zijlstra; +Cc: linux-kernel, Ingo Molnar, Thomas Gleixner
On 2018-07-06 15:18:08 [+0200], Peter Zijlstra wrote:
> On Fri, Jul 06, 2018 at 03:06:15PM +0200, Sebastian Andrzej Siewior wrote:
> > Based on this it is possible to remove get_cpu() and use
> > smp_processor_id() for the `cpu' variable without breaking anything.
>
> Almost.. I think, see init_task_preempt_count().
#define init_task_preempt_count(p) do { \
task_thread_info(p)->preempt_count = FORK_PREEMPT_COUNT; \
} while (0)
and task_thread_info() references p only. It looks good, what did I
miss?
Sebastian
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] sched/core: remove get_cpu() from sched_fork()
2018-07-06 13:32 ` Sebastian Andrzej Siewior
@ 2018-07-09 9:01 ` Peter Zijlstra
0 siblings, 0 replies; 5+ messages in thread
From: Peter Zijlstra @ 2018-07-09 9:01 UTC (permalink / raw)
To: Sebastian Andrzej Siewior; +Cc: linux-kernel, Ingo Molnar, Thomas Gleixner
On Fri, Jul 06, 2018 at 03:32:00PM +0200, Sebastian Andrzej Siewior wrote:
> On 2018-07-06 15:18:08 [+0200], Peter Zijlstra wrote:
> > On Fri, Jul 06, 2018 at 03:06:15PM +0200, Sebastian Andrzej Siewior wrote:
> > > Based on this it is possible to remove get_cpu() and use
> > > smp_processor_id() for the `cpu' variable without breaking anything.
> >
> > Almost.. I think, see init_task_preempt_count().
>
> #define init_task_preempt_count(p) do { \
> task_thread_info(p)->preempt_count = FORK_PREEMPT_COUNT; \
> } while (0)
>
> and task_thread_info() references p only. It looks good, what did I
> miss?
Argh, dammit, I read that with p == current :/
Then yes, looks ok.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [tip:sched/core] sched/core: Remove get_cpu() from sched_fork()
2018-07-06 13:06 [PATCH] sched/core: remove get_cpu() from sched_fork() Sebastian Andrzej Siewior
2018-07-06 13:18 ` Peter Zijlstra
@ 2018-07-15 23:34 ` tip-bot for Sebastian Andrzej Siewior
1 sibling, 0 replies; 5+ messages in thread
From: tip-bot for Sebastian Andrzej Siewior @ 2018-07-15 23:34 UTC (permalink / raw)
To: linux-tip-commits
Cc: peterz, linux-kernel, tglx, hpa, bigeasy, torvalds, mingo
Commit-ID: af0fffd9300b97d8875aa745bc78e2f6fdb3c1f0
Gitweb: https://git.kernel.org/tip/af0fffd9300b97d8875aa745bc78e2f6fdb3c1f0
Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
AuthorDate: Fri, 6 Jul 2018 15:06:15 +0200
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Mon, 16 Jul 2018 00:16:29 +0200
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:
dd41f596cda0 ("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: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Peter 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.de
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
kernel/sched/core.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index ba6bb805693a..c3cf7d992159 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2294,7 +2294,6 @@ static inline void init_schedstats(void) {}
int sched_fork(unsigned long clone_flags, struct task_struct *p)
{
unsigned long flags;
- int cpu = get_cpu();
__sched_fork(clone_flags, p);
/*
@@ -2330,14 +2329,12 @@ int sched_fork(unsigned long clone_flags, struct task_struct *p)
p->sched_reset_on_fork = 0;
}
- if (dl_prio(p->prio)) {
- put_cpu();
+ if (dl_prio(p->prio))
return -EAGAIN;
- } else if (rt_prio(p->prio)) {
+ else if (rt_prio(p->prio))
p->sched_class = &rt_sched_class;
- } else {
+ else
p->sched_class = &fair_sched_class;
- }
init_entity_runnable_average(&p->se);
@@ -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,
* so use __set_task_cpu().
*/
- __set_task_cpu(p, cpu);
+ __set_task_cpu(p, smp_processor_id());
if (p->sched_class->task_fork)
p->sched_class->task_fork(p);
raw_spin_unlock_irqrestore(&p->pi_lock, flags);
@@ -2370,8 +2367,6 @@ int sched_fork(unsigned long clone_flags, struct task_struct *p)
plist_node_init(&p->pushable_tasks, MAX_PRIO);
RB_CLEAR_NODE(&p->pushable_dl_tasks);
#endif
-
- put_cpu();
return 0;
}
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2018-07-15 23:35 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-06 13:06 [PATCH] sched/core: remove get_cpu() from sched_fork() Sebastian Andrzej Siewior
2018-07-06 13:18 ` Peter Zijlstra
2018-07-06 13:32 ` Sebastian Andrzej Siewior
2018-07-09 9:01 ` Peter Zijlstra
2018-07-15 23:34 ` [tip:sched/core] sched/core: Remove " tip-bot for Sebastian Andrzej Siewior
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).