Skip to content

Commit

Permalink
kthread: move sched-realeted initialization from kthreadd context
Browse files Browse the repository at this point in the history
kthreadd is the single thread which implements ths "create" request, move
sched_setscheduler/etc from create_kthread() to kthread_create() to
improve the scalability.

We should be careful with sched_setscheduler(), use _nochek helper.

Signed-off-by: Oleg Nesterov <[email protected]>
Cc: Christoph Hellwig <[email protected]>
Cc: "Eric W. Biederman" <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Pavel Emelyanov <[email protected]>
Cc: Vitaliy Gusev <[email protected]
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Rusty Russell <[email protected]>
  • Loading branch information
oleg-nesterov authored and rustyrussell committed Apr 9, 2009
1 parent 3217ab9 commit 1c99315
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions kernel/kthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,10 @@ static void create_kthread(struct kthread_create_info *create)

/* We want our own signal handler (we take no signals by default). */
pid = kernel_thread(kthread, create, CLONE_FS | CLONE_FILES | SIGCHLD);
if (pid < 0) {
if (pid < 0)
create->result = ERR_PTR(pid);
} else {
struct sched_param param = { .sched_priority = 0 };
else
wait_for_completion(&create->started);
/*
* root may have changed our (kthreadd's) priority or CPU mask.
* The kernel thread should not inherit these properties.
*/
sched_setscheduler(create->result, SCHED_NORMAL, &param);
set_user_nice(create->result, KTHREAD_NICE_LEVEL);
set_cpus_allowed_ptr(create->result, cpu_all_mask);
}
complete(&create->done);
}

Expand Down Expand Up @@ -152,11 +143,20 @@ struct task_struct *kthread_create(int (*threadfn)(void *data),
wait_for_completion(&create.done);

if (!IS_ERR(create.result)) {
struct sched_param param = { .sched_priority = 0 };
va_list args;

va_start(args, namefmt);
vsnprintf(create.result->comm, sizeof(create.result->comm),
namefmt, args);
va_end(args);
/*
* root may have changed our (kthreadd's) priority or CPU mask.
* The kernel thread should not inherit these properties.
*/
sched_setscheduler_nocheck(create.result, SCHED_NORMAL, &param);
set_user_nice(create.result, KTHREAD_NICE_LEVEL);
set_cpus_allowed_ptr(create.result, cpu_all_mask);
}
return create.result;
}
Expand Down

0 comments on commit 1c99315

Please sign in to comment.