get_unbound_pool(), workqueue_cpu_up_callback() and init_workqueues() have similar code pieces to create and start the initial worker factor those out into create_and_start_worker(). This patch doesn't introduce any functional changes.
Unified · Split
| @@ -1792,6 +1792,26 @@ static void start_worker(struct worker *worker) · 1791 unmodified lines | ||
| 1792 | 1792 | wake_up_process(worker->task); |
| 1793 | 1793 | } |
| 1794 | 1794 | |
| 1795 | +/** | |
| 1796 | + * create_and_start_worker - create and start a worker for a pool | |
| 1797 | + * @pool: the target pool | |
| 1798 | + * | |
| 1799 | + * Create and start a new worker for @pool. | |
| 1800 | + */ | |
| 1801 | +static int create_and_start_worker(struct worker_pool *pool) | |
| 1802 | +{ | |
| 1803 | + struct worker *worker; | |
| 1804 | + | |
| 1805 | + worker = create_worker(pool); | |
| 1806 | + if (worker) { | |
| 1807 | + spin_lock_irq(&pool->lock); | |
| 1808 | + start_worker(worker); | |
| 1809 | + spin_unlock_irq(&pool->lock); | |
| 1810 | + } | |
| 1811 | + | |
| 1812 | + return worker ? 0 : -ENOMEM; | |
| 1813 | +} | |
| 1814 | + | |
| 1795 | 1815 | /** |
| 1796 | 1816 | * destroy_worker - destroy a workqueue worker |
| 1797 | 1817 | * @worker: worker to be destroyed |
| @@ -3542,7 +3562,6 @@ static struct worker_pool *get_unbound_pool(const struct workqueue_attrs *attrs) · 1744 unmodified lines | ||
| 3542 | 3562 | static DEFINE_MUTEX(create_mutex); |
| 3543 | 3563 | u32 hash = wqattrs_hash(attrs); |
| 3544 | 3564 | struct worker_pool *pool; |
| 3545 | − struct worker *worker; | |
| 3546 | 3565 | |
| 3547 | 3566 | mutex_lock(&create_mutex); |
| 3548 | 3567 | |
| @@ -3568,14 +3587,9 @@ static struct worker_pool *get_unbound_pool(const struct workqueue_attrs *attrs) · 19 unmodified lines | ||
| 3568 | 3587 | goto fail; |
| 3569 | 3588 | |
| 3570 | 3589 | /* create and start the initial worker */ |
| 3571 | − worker = create_worker(pool); | |
| 3572 | − if (!worker) | |
| 3590 | + if (create_and_start_worker(pool) < 0) | |
| 3573 | 3591 | goto fail; |
| 3574 | 3592 | |
| 3575 | − spin_lock_irq(&pool->lock); | |
| 3576 | − start_worker(worker); | |
| 3577 | − spin_unlock_irq(&pool->lock); | |
| 3578 | − | |
| 3579 | 3593 | /* install */ |
| 3580 | 3594 | spin_lock_irq(&workqueue_lock); |
| 3581 | 3595 | hash_add(unbound_pool_hash, &pool->hash_node, hash); |
| @@ -4148,18 +4162,10 @@ static int __cpuinit workqueue_cpu_up_callback(struct notifier_block *nfb, · 566 unmodified lines | ||
| 4148 | 4162 | switch (action & ~CPU_TASKS_FROZEN) { |
| 4149 | 4163 | case CPU_UP_PREPARE: |
| 4150 | 4164 | for_each_cpu_worker_pool(pool, cpu) { |
| 4151 | − struct worker *worker; | |
| 4152 | − | |
| 4153 | 4165 | if (pool->nr_workers) |
| 4154 | 4166 | continue; |
| 4155 | − | |
| 4156 | − worker = create_worker(pool); | |
| 4157 | − if (!worker) | |
| 4167 | + if (create_and_start_worker(pool) < 0) | |
| 4158 | 4168 | return NOTIFY_BAD; |
| 4159 | − | |
| 4160 | − spin_lock_irq(&pool->lock); | |
| 4161 | − start_worker(worker); | |
| 4162 | − spin_unlock_irq(&pool->lock); | |
| 4163 | 4169 | } |
| 4164 | 4170 | break; |
| 4165 | 4171 | |
| @@ -4409,15 +4415,8 @@ static int __init init_workqueues(void) · 243 unmodified lines | ||
| 4409 | 4415 | struct worker_pool *pool; |
| 4410 | 4416 | |
| 4411 | 4417 | for_each_cpu_worker_pool(pool, cpu) { |
| 4412 | − struct worker *worker; | |
| 4413 | − | |
| 4414 | 4418 | pool->flags &= ~POOL_DISASSOCIATED; |
| 4415 | − | |
| 4416 | − worker = create_worker(pool); | |
| 4417 | − BUG_ON(!worker); | |
| 4418 | − spin_lock_irq(&pool->lock); | |
| 4419 | − start_worker(worker); | |
| 4420 | − spin_unlock_irq(&pool->lock); | |
| 4419 | + BUG_ON(create_and_start_worker(pool) < 0); | |
| 4421 | 4420 | } |
| 4422 | 4421 | } |
| 4423 | 4422 | |