diff options
-rw-r--r-- | kernel/kthread.c | 26 | ||||
-rw-r--r-- | kernel/workqueue.c | 36 |
2 files changed, 31 insertions, 31 deletions
diff --git a/kernel/kthread.c b/kernel/kthread.c index 84bbadd4d021..4ebaf8519abf 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c | |||
@@ -76,6 +76,7 @@ static int kthread(void *_create) | |||
76 | 76 | ||
77 | /* OK, tell user we're spawned, wait for stop or wakeup */ | 77 | /* OK, tell user we're spawned, wait for stop or wakeup */ |
78 | __set_current_state(TASK_UNINTERRUPTIBLE); | 78 | __set_current_state(TASK_UNINTERRUPTIBLE); |
79 | create->result = current; | ||
79 | complete(&create->started); | 80 | complete(&create->started); |
80 | schedule(); | 81 | schedule(); |
81 | 82 | ||
@@ -96,22 +97,10 @@ static void create_kthread(struct kthread_create_info *create) | |||
96 | 97 | ||
97 | /* We want our own signal handler (we take no signals by default). */ | 98 | /* We want our own signal handler (we take no signals by default). */ |
98 | pid = kernel_thread(kthread, create, CLONE_FS | CLONE_FILES | SIGCHLD); | 99 | pid = kernel_thread(kthread, create, CLONE_FS | CLONE_FILES | SIGCHLD); |
99 | if (pid < 0) { | 100 | if (pid < 0) |
100 | create->result = ERR_PTR(pid); | 101 | create->result = ERR_PTR(pid); |
101 | } else { | 102 | else |
102 | struct sched_param param = { .sched_priority = 0 }; | ||
103 | wait_for_completion(&create->started); | 103 | wait_for_completion(&create->started); |
104 | read_lock(&tasklist_lock); | ||
105 | create->result = find_task_by_pid_ns(pid, &init_pid_ns); | ||
106 | read_unlock(&tasklist_lock); | ||
107 | /* | ||
108 | * root may have changed our (kthreadd's) priority or CPU mask. | ||
109 | * The kernel thread should not inherit these properties. | ||
110 | */ | ||
111 | sched_setscheduler(create->result, SCHED_NORMAL, ¶m); | ||
112 | set_user_nice(create->result, KTHREAD_NICE_LEVEL); | ||
113 | set_cpus_allowed_ptr(create->result, cpu_all_mask); | ||
114 | } | ||
115 | complete(&create->done); | 104 | complete(&create->done); |
116 | } | 105 | } |
117 | 106 | ||
@@ -154,11 +143,20 @@ struct task_struct *kthread_create(int (*threadfn)(void *data), | |||
154 | wait_for_completion(&create.done); | 143 | wait_for_completion(&create.done); |
155 | 144 | ||
156 | if (!IS_ERR(create.result)) { | 145 | if (!IS_ERR(create.result)) { |
146 | struct sched_param param = { .sched_priority = 0 }; | ||
157 | va_list args; | 147 | va_list args; |
148 | |||
158 | va_start(args, namefmt); | 149 | va_start(args, namefmt); |
159 | vsnprintf(create.result->comm, sizeof(create.result->comm), | 150 | vsnprintf(create.result->comm, sizeof(create.result->comm), |
160 | namefmt, args); | 151 | namefmt, args); |
161 | va_end(args); | 152 | va_end(args); |
153 | /* | ||
154 | * root may have changed our (kthreadd's) priority or CPU mask. | ||
155 | * The kernel thread should not inherit these properties. | ||
156 | */ | ||
157 | sched_setscheduler_nocheck(create.result, SCHED_NORMAL, ¶m); | ||
158 | set_user_nice(create.result, KTHREAD_NICE_LEVEL); | ||
159 | set_cpus_allowed_ptr(create.result, cpu_all_mask); | ||
162 | } | 160 | } |
163 | return create.result; | 161 | return create.result; |
164 | } | 162 | } |
diff --git a/kernel/workqueue.c b/kernel/workqueue.c index b6b966ce1451..f71fb2a08950 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c | |||
@@ -966,20 +966,20 @@ undo: | |||
966 | } | 966 | } |
967 | 967 | ||
968 | #ifdef CONFIG_SMP | 968 | #ifdef CONFIG_SMP |
969 | static struct workqueue_struct *work_on_cpu_wq __read_mostly; | ||
970 | 969 | ||
971 | struct work_for_cpu { | 970 | struct work_for_cpu { |
972 | struct work_struct work; | 971 | struct completion completion; |
973 | long (*fn)(void *); | 972 | long (*fn)(void *); |
974 | void *arg; | 973 | void *arg; |
975 | long ret; | 974 | long ret; |
976 | }; | 975 | }; |
977 | 976 | ||
978 | static void do_work_for_cpu(struct work_struct *w) | 977 | static int do_work_for_cpu(void *_wfc) |
979 | { | 978 | { |
980 | struct work_for_cpu *wfc = container_of(w, struct work_for_cpu, work); | 979 | struct work_for_cpu *wfc = _wfc; |
981 | |||
982 | wfc->ret = wfc->fn(wfc->arg); | 980 | wfc->ret = wfc->fn(wfc->arg); |
981 | complete(&wfc->completion); | ||
982 | return 0; | ||
983 | } | 983 | } |
984 | 984 | ||
985 | /** | 985 | /** |
@@ -990,17 +990,23 @@ static void do_work_for_cpu(struct work_struct *w) | |||
990 | * | 990 | * |
991 | * This will return the value @fn returns. | 991 | * This will return the value @fn returns. |
992 | * It is up to the caller to ensure that the cpu doesn't go offline. | 992 | * It is up to the caller to ensure that the cpu doesn't go offline. |
993 | * The caller must not hold any locks which would prevent @fn from completing. | ||
993 | */ | 994 | */ |
994 | long work_on_cpu(unsigned int cpu, long (*fn)(void *), void *arg) | 995 | long work_on_cpu(unsigned int cpu, long (*fn)(void *), void *arg) |
995 | { | 996 | { |
996 | struct work_for_cpu wfc; | 997 | struct task_struct *sub_thread; |
997 | 998 | struct work_for_cpu wfc = { | |
998 | INIT_WORK(&wfc.work, do_work_for_cpu); | 999 | .completion = COMPLETION_INITIALIZER_ONSTACK(wfc.completion), |
999 | wfc.fn = fn; | 1000 | .fn = fn, |
1000 | wfc.arg = arg; | 1001 | .arg = arg, |
1001 | queue_work_on(cpu, work_on_cpu_wq, &wfc.work); | 1002 | }; |
1002 | flush_work(&wfc.work); | 1003 | |
1003 | 1004 | sub_thread = kthread_create(do_work_for_cpu, &wfc, "work_for_cpu"); | |
1005 | if (IS_ERR(sub_thread)) | ||
1006 | return PTR_ERR(sub_thread); | ||
1007 | kthread_bind(sub_thread, cpu); | ||
1008 | wake_up_process(sub_thread); | ||
1009 | wait_for_completion(&wfc.completion); | ||
1004 | return wfc.ret; | 1010 | return wfc.ret; |
1005 | } | 1011 | } |
1006 | EXPORT_SYMBOL_GPL(work_on_cpu); | 1012 | EXPORT_SYMBOL_GPL(work_on_cpu); |
@@ -1016,8 +1022,4 @@ void __init init_workqueues(void) | |||
1016 | hotcpu_notifier(workqueue_cpu_callback, 0); | 1022 | hotcpu_notifier(workqueue_cpu_callback, 0); |
1017 | keventd_wq = create_workqueue("events"); | 1023 | keventd_wq = create_workqueue("events"); |
1018 | BUG_ON(!keventd_wq); | 1024 | BUG_ON(!keventd_wq); |
1019 | #ifdef CONFIG_SMP | ||
1020 | work_on_cpu_wq = create_workqueue("work_on_cpu"); | ||
1021 | BUG_ON(!work_on_cpu_wq); | ||
1022 | #endif | ||
1023 | } | 1025 | } |