|
66 | 66 | *
|
67 | 67 | * Note that DISASSOCIATED should be flipped only while holding
|
68 | 68 | * attach_mutex to avoid changing binding state while
|
69 |
| - * create_worker() is in progress. |
| 69 | + * worker_attach_to_pool() is in progress. |
70 | 70 | */
|
71 | 71 | POOL_DISASSOCIATED = 1 << 2, /* cpu can't serve workers */
|
72 | 72 | POOL_FREEZING = 1 << 3, /* freeze in progress */
|
@@ -1682,14 +1682,47 @@ static struct worker *alloc_worker(void)
|
1682 | 1682 | return worker;
|
1683 | 1683 | }
|
1684 | 1684 |
|
| 1685 | +/** |
| 1686 | + * worker_attach_to_pool() - attach a worker to a pool |
| 1687 | + * @worker: worker to be attached |
| 1688 | + * @pool: the target pool |
| 1689 | + * |
| 1690 | + * Attach @worker to @pool. Once attached, the %WORKER_UNBOUND flag and |
| 1691 | + * cpu-binding of @worker are kept coordinated with the pool across |
| 1692 | + * cpu-[un]hotplugs. |
| 1693 | + */ |
| 1694 | +static void worker_attach_to_pool(struct worker *worker, |
| 1695 | + struct worker_pool *pool) |
| 1696 | +{ |
| 1697 | + mutex_lock(&pool->attach_mutex); |
| 1698 | + |
| 1699 | + /* |
| 1700 | + * set_cpus_allowed_ptr() will fail if the cpumask doesn't have any |
| 1701 | + * online CPUs. It'll be re-applied when any of the CPUs come up. |
| 1702 | + */ |
| 1703 | + set_cpus_allowed_ptr(worker->task, pool->attrs->cpumask); |
| 1704 | + |
| 1705 | + /* |
| 1706 | + * The pool->attach_mutex ensures %POOL_DISASSOCIATED remains |
| 1707 | + * stable across this function. See the comments above the |
| 1708 | + * flag definition for details. |
| 1709 | + */ |
| 1710 | + if (pool->flags & POOL_DISASSOCIATED) |
| 1711 | + worker->flags |= WORKER_UNBOUND; |
| 1712 | + |
| 1713 | + list_add_tail(&worker->node, &pool->workers); |
| 1714 | + |
| 1715 | + mutex_unlock(&pool->attach_mutex); |
| 1716 | +} |
| 1717 | + |
1685 | 1718 | /**
|
1686 | 1719 | * worker_detach_from_pool() - detach a worker from its pool
|
1687 | 1720 | * @worker: worker which is attached to its pool
|
1688 | 1721 | * @pool: the pool @worker is attached to
|
1689 | 1722 | *
|
1690 |
| - * Undo the attaching which had been done in create_worker(). The caller |
1691 |
| - * worker shouldn't access to the pool after detached except it has other |
1692 |
| - * reference to the pool. |
| 1723 | + * Undo the attaching which had been done in worker_attach_to_pool(). The |
| 1724 | + * caller worker shouldn't access to the pool after detached except it has |
| 1725 | + * other reference to the pool. |
1693 | 1726 | */
|
1694 | 1727 | static void worker_detach_from_pool(struct worker *worker,
|
1695 | 1728 | struct worker_pool *pool)
|
@@ -1753,26 +1786,8 @@ static struct worker *create_worker(struct worker_pool *pool)
|
1753 | 1786 | /* prevent userland from meddling with cpumask of workqueue workers */
|
1754 | 1787 | worker->task->flags |= PF_NO_SETAFFINITY;
|
1755 | 1788 |
|
1756 |
| - mutex_lock(&pool->attach_mutex); |
1757 |
| - |
1758 |
| - /* |
1759 |
| - * set_cpus_allowed_ptr() will fail if the cpumask doesn't have any |
1760 |
| - * online CPUs. It'll be re-applied when any of the CPUs come up. |
1761 |
| - */ |
1762 |
| - set_cpus_allowed_ptr(worker->task, pool->attrs->cpumask); |
1763 |
| - |
1764 |
| - /* |
1765 |
| - * The pool->attach_mutex ensures %POOL_DISASSOCIATED |
1766 |
| - * remains stable across this function. See the comments above the |
1767 |
| - * flag definition for details. |
1768 |
| - */ |
1769 |
| - if (pool->flags & POOL_DISASSOCIATED) |
1770 |
| - worker->flags |= WORKER_UNBOUND; |
1771 |
| - |
1772 | 1789 | /* successful, attach the worker to the pool */
|
1773 |
| - list_add_tail(&worker->node, &pool->workers); |
1774 |
| - |
1775 |
| - mutex_unlock(&pool->attach_mutex); |
| 1790 | + worker_attach_to_pool(worker, pool); |
1776 | 1791 |
|
1777 | 1792 | return worker;
|
1778 | 1793 |
|
|
0 commit comments