| @@ -124,12 +124,12 @@ void *kthread_data(struct task_struct *task) · 123 unmodified lines |
| 124 | 124 | |
| 125 | 125 | static void __kthread_parkme(struct kthread *self) |
| 126 | 126 | { |
| 127 | | − __set_current_state(TASK_INTERRUPTIBLE); |
| 127 | + __set_current_state(TASK_PARKED); |
| 128 | 128 | while (test_bit(KTHREAD_SHOULD_PARK, &self->flags)) { |
| 129 | 129 | if (!test_and_set_bit(KTHREAD_IS_PARKED, &self->flags)) |
| 130 | 130 | complete(&self->parked); |
| 131 | 131 | schedule(); |
| 132 | | − __set_current_state(TASK_INTERRUPTIBLE); |
| 132 | + __set_current_state(TASK_PARKED); |
| 133 | 133 | } |
| 134 | 134 | clear_bit(KTHREAD_IS_PARKED, &self->flags); |
| 135 | 135 | __set_current_state(TASK_RUNNING); |
| @@ -256,8 +256,13 @@ struct task_struct *kthread_create_on_node(int (*threadfn)(void *data), · 120 unmodified lines |
| 256 | 256 | } |
| 257 | 257 | EXPORT_SYMBOL(kthread_create_on_node); |
| 258 | 258 | |
| 259 | | −static void __kthread_bind(struct task_struct *p, unsigned int cpu) |
| 259 | +static void __kthread_bind(struct task_struct *p, unsigned int cpu, long state) |
| 260 | 260 | { |
| 261 | + /* Must have done schedule() in kthread() before we set_task_cpu */ |
| 262 | + if (!wait_task_inactive(p, state)) { |
| 263 | + WARN_ON(1); |
| 264 | + return; |
| 265 | + } |
| 261 | 266 | /* It's safe because the task is inactive. */ |
| 262 | 267 | do_set_cpus_allowed(p, cpumask_of(cpu)); |
| 263 | 268 | p->flags |= PF_THREAD_BOUND; |
| @@ -274,12 +279,7 @@ static void __kthread_bind(struct task_struct *p, unsigned int cpu) · 10 unmodified lines |
| 274 | 279 | */ |
| 275 | 280 | void kthread_bind(struct task_struct *p, unsigned int cpu) |
| 276 | 281 | { |
| 277 | | − /* Must have done schedule() in kthread() before we set_task_cpu */ |
| 278 | | − if (!wait_task_inactive(p, TASK_UNINTERRUPTIBLE)) { |
| 279 | | − WARN_ON(1); |
| 280 | | − return; |
| 281 | | − } |
| 282 | | − __kthread_bind(p, cpu); |
| 282 | + __kthread_bind(p, cpu, TASK_UNINTERRUPTIBLE); |
| 283 | 283 | } |
| 284 | 284 | EXPORT_SYMBOL(kthread_bind); |
| 285 | 285 | |
| @@ -324,6 +324,22 @@ static struct kthread *task_get_live_kthread(struct task_struct *k) · 38 unmodified lines |
| 324 | 324 | return NULL; |
| 325 | 325 | } |
| 326 | 326 | |
| 327 | +static void __kthread_unpark(struct task_struct *k, struct kthread *kthread) |
| 328 | +{ |
| 329 | + clear_bit(KTHREAD_SHOULD_PARK, &kthread->flags); |
| 330 | + /* |
| 331 | + * We clear the IS_PARKED bit here as we don't wait |
| 332 | + * until the task has left the park code. So if we'd |
| 333 | + * park before that happens we'd see the IS_PARKED bit |
| 334 | + * which might be about to be cleared. |
| 335 | + */ |
| 336 | + if (test_and_clear_bit(KTHREAD_IS_PARKED, &kthread->flags)) { |
| 337 | + if (test_bit(KTHREAD_IS_PER_CPU, &kthread->flags)) |
| 338 | + __kthread_bind(k, kthread->cpu, TASK_PARKED); |
| 339 | + wake_up_state(k, TASK_PARKED); |
| 340 | + } |
| 341 | +} |
| 342 | + |
| 327 | 343 | /** |
| 328 | 344 | * kthread_unpark - unpark a thread created by kthread_create(). |
| 329 | 345 | * @k: thread created by kthread_create(). |
| @@ -336,20 +352,8 @@ void kthread_unpark(struct task_struct *k) · 6 unmodified lines |
| 336 | 352 | { |
| 337 | 353 | struct kthread *kthread = task_get_live_kthread(k); |
| 338 | 354 | |
| 339 | | − if (kthread) { |
| 340 | | − clear_bit(KTHREAD_SHOULD_PARK, &kthread->flags); |
| 341 | | − /* |
| 342 | | − * We clear the IS_PARKED bit here as we don't wait |
| 343 | | − * until the task has left the park code. So if we'd |
| 344 | | − * park before that happens we'd see the IS_PARKED bit |
| 345 | | − * which might be about to be cleared. |
| 346 | | − */ |
| 347 | | − if (test_and_clear_bit(KTHREAD_IS_PARKED, &kthread->flags)) { |
| 348 | | − if (test_bit(KTHREAD_IS_PER_CPU, &kthread->flags)) |
| 349 | | − __kthread_bind(k, kthread->cpu); |
| 350 | | − wake_up_process(k); |
| 351 | | − } |
| 352 | | − } |
| 355 | + if (kthread) |
| 356 | + __kthread_unpark(k, kthread); |
| 353 | 357 | put_task_struct(k); |
| 354 | 358 | } |
| 355 | 359 | |
| @@ -407,7 +411,7 @@ int kthread_stop(struct task_struct *k) · 51 unmodified lines |
| 407 | 411 | trace_sched_kthread_stop(k); |
| 408 | 412 | if (kthread) { |
| 409 | 413 | set_bit(KTHREAD_SHOULD_STOP, &kthread->flags); |
| 410 | | − clear_bit(KTHREAD_SHOULD_PARK, &kthread->flags); |
| 414 | + __kthread_unpark(k, kthread); |
| 411 | 415 | wake_up_process(k); |
| 412 | 416 | wait_for_completion(&kthread->exited); |
| 413 | 417 | } |