Skip to content

Commit e32bf2b

Browse files
KAGA-KOKOheftig
authored andcommitted
sched: Initialize idle tasks only once
Idle tasks are initialized via __sched_fork() twice: fork_idle() copy_process() sched_fork() __sched_fork() init_idle() __sched_fork() Instead of cleaning this up, sched_ext hacked around it. Even when analyis and solution were provided in a discussion, nobody cared to clean this up. init_idle() is also invoked from sched_init() to initialize the boot CPU's idle task, which requires the __sched_fork() invocation. But this can be trivially solved by invoking __sched_fork() before init_idle() in sched_init() and removing the __sched_fork() invocation from init_idle(). Do so and clean up the comments explaining this historical leftover. Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lore.kernel.org/r/[email protected] Cherry-picked-for: https://lore.kernel.org/lkml/CAHk-=whGd0dfaJNiWSR60HH5iwxqhUZPDWgHCQd446gH2Wu0yQ@mail.gmail.com/
1 parent 27554e7 commit e32bf2b

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

kernel/sched/core.c

+5-7
Original file line numberDiff line numberDiff line change
@@ -4424,7 +4424,8 @@ int wake_up_state(struct task_struct *p, unsigned int state)
44244424
* Perform scheduler related setup for a newly forked process p.
44254425
* p is forked by current.
44264426
*
4427-
* __sched_fork() is basic setup used by init_idle() too:
4427+
* __sched_fork() is basic setup which is also used by sched_init() to
4428+
* initialize the boot CPU's idle task.
44284429
*/
44294430
static void __sched_fork(unsigned long clone_flags, struct task_struct *p)
44304431
{
@@ -7683,8 +7684,6 @@ void __init init_idle(struct task_struct *idle, int cpu)
76837684
struct rq *rq = cpu_rq(cpu);
76847685
unsigned long flags;
76857686

7686-
__sched_fork(0, idle);
7687-
76887687
raw_spin_lock_irqsave(&idle->pi_lock, flags);
76897688
raw_spin_rq_lock(rq);
76907689

@@ -7699,10 +7698,8 @@ void __init init_idle(struct task_struct *idle, int cpu)
76997698

77007699
#ifdef CONFIG_SMP
77017700
/*
7702-
* It's possible that init_idle() gets called multiple times on a task,
7703-
* in that case do_set_cpus_allowed() will not do the right thing.
7704-
*
7705-
* And since this is boot we can forgo the serialization.
7701+
* No validation and serialization required at boot time and for
7702+
* setting up the idle tasks of not yet online CPUs.
77067703
*/
77077704
set_cpus_allowed_common(idle, &ac);
77087705
#endif
@@ -8546,6 +8543,7 @@ void __init sched_init(void)
85468543
* but because we are the idle thread, we just pick up running again
85478544
* when this runqueue becomes "idle".
85488545
*/
8546+
__sched_fork(0, current);
85498547
init_idle(current, smp_processor_id());
85508548

85518549
calc_load_update = jiffies + LOAD_FREQ;

0 commit comments

Comments
 (0)