Currently, the code to attach a new worker to its pool is embedded in create_worker(). Separating this code out will make the codes clearer and will allow rescuers to share the code path later. tj: Description and comment updates.
Showing the changes to kernel/workqueue.c (1 of 1 file). Show all
Unified · Split
| @@ -66,7 +66,7 @@ enum { · 65 unmodified lines | |||
| 66 | * | 66 | * |
| 67 | * Note that DISASSOCIATED should be flipped only while holding | 67 | * Note that DISASSOCIATED should be flipped only while holding |
| 68 | * attach_mutex to avoid changing binding state while | 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 | POOL_DISASSOCIATED = 1 << 2, /* cpu can't serve workers */ | 71 | POOL_DISASSOCIATED = 1 << 2, /* cpu can't serve workers */ |
| 72 | POOL_FREEZING = 1 << 3, /* freeze in progress */ | 72 | POOL_FREEZING = 1 << 3, /* freeze in progress */ |
| @@ -1682,14 +1682,47 @@ static struct worker *alloc_worker(void) · 1609 unmodified lines | |||
| 1682 | return worker; | 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 | * worker_detach_from_pool() - detach a worker from its pool | 1719 | * worker_detach_from_pool() - detach a worker from its pool |
| 1687 | * @worker: worker which is attached to its pool | 1720 | * @worker: worker which is attached to its pool |
| 1688 | * @pool: the pool @worker is attached to | 1721 | * @pool: the pool @worker is attached to |
| 1689 | * | 1722 | * |
| 1690 | * Undo the attaching which had been done in create_worker(). The caller | 1723 | * Undo the attaching which had been done in worker_attach_to_pool(). The |
| 1691 | * worker shouldn't access to the pool after detached except it has other | 1724 | * caller worker shouldn't access to the pool after detached except it has |
| 1692 | * reference to the pool. | 1725 | * other reference to the pool. |
| 1693 | */ | 1726 | */ |
| 1694 | static void worker_detach_from_pool(struct worker *worker, | 1727 | static void worker_detach_from_pool(struct worker *worker, |
| 1695 | struct worker_pool *pool) | 1728 | struct worker_pool *pool) |
| @@ -1753,26 +1786,8 @@ static struct worker *create_worker(struct worker_pool *pool) · 57 unmodified lines | |||
| 1753 | /* prevent userland from meddling with cpumask of workqueue workers */ | 1786 | /* prevent userland from meddling with cpumask of workqueue workers */ |
| 1754 | worker->task->flags |= PF_NO_SETAFFINITY; | 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 | /* successful, attach the worker to the pool */ | 1789 | /* successful, attach the worker to the pool */ |
| 1773 | list_add_tail(&worker->node, &pool->workers); | 1790 | worker_attach_to_pool(worker, pool); |
| 1774 | |||
| 1775 | mutex_unlock(&pool->attach_mutex); | ||
| 1776 | 1791 | ||
| 1777 | return worker; | 1792 | return worker; |
| 1778 | 1793 | ||