From: Matthew Wilcox Date: Mon, 18 Feb 2019 14:58:53 +0000 (-0500) Subject: workqueue: Convert to XArray X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=130c39cb978060c8ea4aa95f11e00f090303360f;p=users%2Fwilly%2Fxarray.git workqueue: Convert to XArray Signed-off-by: Matthew Wilcox --- diff --git a/kernel/workqueue.c b/kernel/workqueue.c index 601d61150b65..c3d612e63761 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -327,7 +327,7 @@ module_param_named(debug_force_rr_cpu, wq_debug_force_rr_cpu, bool, 0644); /* the per-cpu worker pools */ static DEFINE_PER_CPU_SHARED_ALIGNED(struct worker_pool [NR_STD_WORKER_POOLS], cpu_worker_pools); -static DEFINE_IDR(worker_pool_idr); /* PR: idr of all pools */ +static DEFINE_XARRAY_ALLOC(worker_pools); /* PR: array of all pools */ /* PL: hash of all unbound pools keyed by pool->attrs */ static DEFINE_HASHTABLE(unbound_pool_hash, UNBOUND_POOL_HASH_ORDER); @@ -393,7 +393,7 @@ static void workqueue_sysfs_unregister(struct workqueue_struct *wq); * ignored. */ #define for_each_pool(pool, pi) \ - idr_for_each_entry(&worker_pool_idr, pool, pi) \ + xa_for_each(&worker_pools, pi, pool) \ if (({ assert_rcu_or_pool_mutex(); false; })) { } \ else @@ -535,17 +535,10 @@ static inline void debug_work_deactivate(struct work_struct *work) { } */ static int worker_pool_assign_id(struct worker_pool *pool) { - int ret; - lockdep_assert_held(&wq_pool_mutex); - ret = idr_alloc(&worker_pool_idr, pool, 0, WORK_OFFQ_POOL_NONE, - GFP_KERNEL); - if (ret >= 0) { - pool->id = ret; - return 0; - } - return ret; + return xa_alloc(&worker_pools, &pool->id, pool, + XA_LIMIT(0, WORK_OFFQ_POOL_NONE - 1), GFP_KERNEL); } /** @@ -722,7 +715,7 @@ static struct worker_pool *get_work_pool(struct work_struct *work) if (pool_id == WORK_OFFQ_POOL_NONE) return NULL; - return idr_find(&worker_pool_idr, pool_id); + return xa_load(&worker_pools, pool_id); } /** @@ -3526,8 +3519,7 @@ static void put_unbound_pool(struct worker_pool *pool) return; /* release id and unhash */ - if (pool->id >= 0) - idr_remove(&worker_pool_idr, pool->id); + xa_erase(&worker_pools, pool->id); hash_del(&pool->hash_node); /* @@ -4700,7 +4692,7 @@ void show_workqueue_state(void) struct workqueue_struct *wq; struct worker_pool *pool; unsigned long flags; - int pi; + unsigned long pi; rcu_read_lock(); @@ -4989,7 +4981,7 @@ int workqueue_online_cpu(unsigned int cpu) { struct worker_pool *pool; struct workqueue_struct *wq; - int pi; + unsigned long pi; mutex_lock(&wq_pool_mutex); @@ -5695,7 +5687,7 @@ static void wq_watchdog_timer_fn(struct timer_list *unused) unsigned long thresh = READ_ONCE(wq_watchdog_thresh) * HZ; bool lockup_detected = false; struct worker_pool *pool; - int pi; + unsigned long pi; if (!thresh) return; @@ -5849,7 +5841,7 @@ static void __init wq_numa_init(void) * * This is the first half of two-staged workqueue subsystem initialization * and invoked as soon as the bare basics - memory allocation, cpumasks and - * idr are up. It sets up all the data structures and system workqueues + * xarray are up. It sets up all the data structures and system workqueues * and allows early boot code to create workqueues and queue/cancel work * items. Actual work item execution starts only after kthreads can be * created and scheduled right before early initcalls.