Lines Matching refs:wq

201 	struct workqueue_struct *wq;		/* I: the owning workqueue */  member
357 static void workqueue_sysfs_unregister(struct workqueue_struct *wq);
367 #define assert_rcu_or_wq_mutex(wq) \ argument
369 !lockdep_is_held(&wq->mutex), \
372 #define assert_rcu_or_wq_mutex_or_pool_mutex(wq) \ argument
374 !lockdep_is_held(&wq->mutex) && \
427 #define for_each_pwq(pwq, wq) \ argument
428 list_for_each_entry_rcu((pwq), &(wq)->pwqs, pwqs_node) \
429 if (({ assert_rcu_or_wq_mutex(wq); false; })) { } \
563 static struct pool_workqueue *unbound_pwq_by_node(struct workqueue_struct *wq, in unbound_pwq_by_node() argument
566 assert_rcu_or_wq_mutex_or_pool_mutex(wq); in unbound_pwq_by_node()
575 return wq->dfl_pwq; in unbound_pwq_by_node()
577 return rcu_dereference_raw(wq->numa_pwq_tbl[node]); in unbound_pwq_by_node()
1108 if (WARN_ON_ONCE(!(pwq->wq->flags & WQ_UNBOUND))) in put_pwq()
1201 if (atomic_dec_and_test(&pwq->wq->nr_pwqs_to_flush)) in pwq_dec_nr_in_flight()
1202 complete(&pwq->wq->first_flusher->done); in pwq_dec_nr_in_flight()
1349 static bool is_chained_work(struct workqueue_struct *wq) in is_chained_work() argument
1358 return worker && worker->current_pwq->wq == wq; in is_chained_work()
1394 static void __queue_work(int cpu, struct workqueue_struct *wq, in __queue_work() argument
1414 if (unlikely(wq->flags & __WQ_DRAINING) && in __queue_work()
1415 WARN_ON_ONCE(!is_chained_work(wq))) in __queue_work()
1423 if (!(wq->flags & WQ_UNBOUND)) in __queue_work()
1424 pwq = per_cpu_ptr(wq->cpu_pwqs, cpu); in __queue_work()
1426 pwq = unbound_pwq_by_node(wq, cpu_to_node(cpu)); in __queue_work()
1441 if (worker && worker->current_pwq->wq == wq) { in __queue_work()
1461 if (wq->flags & WQ_UNBOUND) { in __queue_work()
1468 wq->name, cpu); in __queue_work()
1509 bool queue_work_on(int cpu, struct workqueue_struct *wq, in queue_work_on() argument
1518 __queue_work(cpu, wq, work); in queue_work_on()
1580 bool queue_work_node(int node, struct workqueue_struct *wq, in queue_work_node() argument
1595 WARN_ON_ONCE(!(wq->flags & WQ_UNBOUND)); in queue_work_node()
1602 __queue_work(cpu, wq, work); in queue_work_node()
1616 __queue_work(dwork->cpu, dwork->wq, &dwork->work); in delayed_work_timer_fn()
1620 static void __queue_delayed_work(int cpu, struct workqueue_struct *wq, in __queue_delayed_work() argument
1626 WARN_ON_ONCE(!wq); in __queue_delayed_work()
1638 __queue_work(cpu, wq, &dwork->work); in __queue_delayed_work()
1642 dwork->wq = wq; in __queue_delayed_work()
1663 bool queue_delayed_work_on(int cpu, struct workqueue_struct *wq, in queue_delayed_work_on() argument
1674 __queue_delayed_work(cpu, wq, dwork, delay); in queue_delayed_work_on()
1701 bool mod_delayed_work_on(int cpu, struct workqueue_struct *wq, in mod_delayed_work_on() argument
1712 __queue_delayed_work(cpu, wq, dwork, delay); in mod_delayed_work_on()
1727 __queue_work(WORK_CPU_UNBOUND, rwork->wq, &rwork->work); in rcu_work_rcufn()
1741 bool queue_rcu_work(struct workqueue_struct *wq, struct rcu_work *rwork) in queue_rcu_work() argument
1746 rwork->wq = wq; in queue_rcu_work()
2014 struct workqueue_struct *wq = pwq->wq; in send_mayday() local
2018 if (!wq->rescuer) in send_mayday()
2029 list_add_tail(&pwq->mayday_node, &wq->maydays); in send_mayday()
2030 wake_up_process(wq->rescuer->task); in send_mayday()
2168 bool cpu_intensive = pwq->wq->flags & WQ_CPU_INTENSIVE; in process_one_work()
2211 strscpy(worker->desc, pwq->wq->name, WORKER_DESC_LEN); in process_one_work()
2244 lock_map_acquire(&pwq->wq->lockdep_map); in process_one_work()
2276 lock_map_release(&pwq->wq->lockdep_map); in process_one_work()
2464 struct workqueue_struct *wq = rescuer->rescue_wq; in rescuer_thread() local
2491 while (!list_empty(&wq->maydays)) { in rescuer_thread()
2492 struct pool_workqueue *pwq = list_first_entry(&wq->maydays, in rescuer_thread()
2536 list_move_tail(&pwq->mayday_node, &wq->maydays); in rescuer_thread()
2601 WARN_ONCE(worker && ((worker->current_pwq->wq->flags & in check_flush_dependency()
2604 worker->current_pwq->wq->name, worker->current_func, in check_flush_dependency()
2715 static bool flush_workqueue_prep_pwqs(struct workqueue_struct *wq, in flush_workqueue_prep_pwqs() argument
2722 WARN_ON_ONCE(atomic_read(&wq->nr_pwqs_to_flush)); in flush_workqueue_prep_pwqs()
2723 atomic_set(&wq->nr_pwqs_to_flush, 1); in flush_workqueue_prep_pwqs()
2726 for_each_pwq(pwq, wq) { in flush_workqueue_prep_pwqs()
2736 atomic_inc(&wq->nr_pwqs_to_flush); in flush_workqueue_prep_pwqs()
2749 if (flush_color >= 0 && atomic_dec_and_test(&wq->nr_pwqs_to_flush)) in flush_workqueue_prep_pwqs()
2750 complete(&wq->first_flusher->done); in flush_workqueue_prep_pwqs()
2762 void flush_workqueue(struct workqueue_struct *wq) in flush_workqueue() argument
2767 .done = COMPLETION_INITIALIZER_ONSTACK_MAP(this_flusher.done, wq->lockdep_map), in flush_workqueue()
2774 lock_map_acquire(&wq->lockdep_map); in flush_workqueue()
2775 lock_map_release(&wq->lockdep_map); in flush_workqueue()
2777 mutex_lock(&wq->mutex); in flush_workqueue()
2782 next_color = work_next_color(wq->work_color); in flush_workqueue()
2784 if (next_color != wq->flush_color) { in flush_workqueue()
2790 WARN_ON_ONCE(!list_empty(&wq->flusher_overflow)); in flush_workqueue()
2791 this_flusher.flush_color = wq->work_color; in flush_workqueue()
2792 wq->work_color = next_color; in flush_workqueue()
2794 if (!wq->first_flusher) { in flush_workqueue()
2796 WARN_ON_ONCE(wq->flush_color != this_flusher.flush_color); in flush_workqueue()
2798 wq->first_flusher = &this_flusher; in flush_workqueue()
2800 if (!flush_workqueue_prep_pwqs(wq, wq->flush_color, in flush_workqueue()
2801 wq->work_color)) { in flush_workqueue()
2803 wq->flush_color = next_color; in flush_workqueue()
2804 wq->first_flusher = NULL; in flush_workqueue()
2809 WARN_ON_ONCE(wq->flush_color == this_flusher.flush_color); in flush_workqueue()
2810 list_add_tail(&this_flusher.list, &wq->flusher_queue); in flush_workqueue()
2811 flush_workqueue_prep_pwqs(wq, -1, wq->work_color); in flush_workqueue()
2819 list_add_tail(&this_flusher.list, &wq->flusher_overflow); in flush_workqueue()
2822 check_flush_dependency(wq, NULL); in flush_workqueue()
2824 mutex_unlock(&wq->mutex); in flush_workqueue()
2834 if (wq->first_flusher != &this_flusher) in flush_workqueue()
2837 mutex_lock(&wq->mutex); in flush_workqueue()
2840 if (wq->first_flusher != &this_flusher) in flush_workqueue()
2843 wq->first_flusher = NULL; in flush_workqueue()
2846 WARN_ON_ONCE(wq->flush_color != this_flusher.flush_color); in flush_workqueue()
2852 list_for_each_entry_safe(next, tmp, &wq->flusher_queue, list) { in flush_workqueue()
2853 if (next->flush_color != wq->flush_color) in flush_workqueue()
2859 WARN_ON_ONCE(!list_empty(&wq->flusher_overflow) && in flush_workqueue()
2860 wq->flush_color != work_next_color(wq->work_color)); in flush_workqueue()
2863 wq->flush_color = work_next_color(wq->flush_color); in flush_workqueue()
2866 if (!list_empty(&wq->flusher_overflow)) { in flush_workqueue()
2873 list_for_each_entry(tmp, &wq->flusher_overflow, list) in flush_workqueue()
2874 tmp->flush_color = wq->work_color; in flush_workqueue()
2876 wq->work_color = work_next_color(wq->work_color); in flush_workqueue()
2878 list_splice_tail_init(&wq->flusher_overflow, in flush_workqueue()
2879 &wq->flusher_queue); in flush_workqueue()
2880 flush_workqueue_prep_pwqs(wq, -1, wq->work_color); in flush_workqueue()
2883 if (list_empty(&wq->flusher_queue)) { in flush_workqueue()
2884 WARN_ON_ONCE(wq->flush_color != wq->work_color); in flush_workqueue()
2892 WARN_ON_ONCE(wq->flush_color == wq->work_color); in flush_workqueue()
2893 WARN_ON_ONCE(wq->flush_color != next->flush_color); in flush_workqueue()
2896 wq->first_flusher = next; in flush_workqueue()
2898 if (flush_workqueue_prep_pwqs(wq, wq->flush_color, -1)) in flush_workqueue()
2905 wq->first_flusher = NULL; in flush_workqueue()
2909 mutex_unlock(&wq->mutex); in flush_workqueue()
2924 void drain_workqueue(struct workqueue_struct *wq) in drain_workqueue() argument
2934 mutex_lock(&wq->mutex); in drain_workqueue()
2935 if (!wq->nr_drainers++) in drain_workqueue()
2936 wq->flags |= __WQ_DRAINING; in drain_workqueue()
2937 mutex_unlock(&wq->mutex); in drain_workqueue()
2939 flush_workqueue(wq); in drain_workqueue()
2941 mutex_lock(&wq->mutex); in drain_workqueue()
2943 for_each_pwq(pwq, wq) { in drain_workqueue()
2956 wq->name, flush_cnt); in drain_workqueue()
2958 mutex_unlock(&wq->mutex); in drain_workqueue()
2962 if (!--wq->nr_drainers) in drain_workqueue()
2963 wq->flags &= ~__WQ_DRAINING; in drain_workqueue()
2964 mutex_unlock(&wq->mutex); in drain_workqueue()
2997 check_flush_dependency(pwq->wq, work); in start_flush_work()
3012 (pwq->wq->saved_max_active == 1 || pwq->wq->rescuer)) { in start_flush_work()
3013 lock_map_acquire(&pwq->wq->lockdep_map); in start_flush_work()
3014 lock_map_release(&pwq->wq->lockdep_map); in start_flush_work()
3183 __queue_work(dwork->cpu, dwork->wq, &dwork->work); in flush_delayed_work()
3440 static void wq_init_lockdep(struct workqueue_struct *wq) in wq_init_lockdep() argument
3444 lockdep_register_key(&wq->key); in wq_init_lockdep()
3445 lock_name = kasprintf(GFP_KERNEL, "%s%s", "(wq_completion)", wq->name); in wq_init_lockdep()
3447 lock_name = wq->name; in wq_init_lockdep()
3449 wq->lock_name = lock_name; in wq_init_lockdep()
3450 lockdep_init_map(&wq->lockdep_map, lock_name, &wq->key, 0); in wq_init_lockdep()
3453 static void wq_unregister_lockdep(struct workqueue_struct *wq) in wq_unregister_lockdep() argument
3455 lockdep_unregister_key(&wq->key); in wq_unregister_lockdep()
3458 static void wq_free_lockdep(struct workqueue_struct *wq) in wq_free_lockdep() argument
3460 if (wq->lock_name != wq->name) in wq_free_lockdep()
3461 kfree(wq->lock_name); in wq_free_lockdep()
3464 static void wq_init_lockdep(struct workqueue_struct *wq) in wq_init_lockdep() argument
3468 static void wq_unregister_lockdep(struct workqueue_struct *wq) in wq_unregister_lockdep() argument
3472 static void wq_free_lockdep(struct workqueue_struct *wq) in wq_free_lockdep() argument
3479 struct workqueue_struct *wq = in rcu_free_wq() local
3482 wq_free_lockdep(wq); in rcu_free_wq()
3484 if (!(wq->flags & WQ_UNBOUND)) in rcu_free_wq()
3485 free_percpu(wq->cpu_pwqs); in rcu_free_wq()
3487 free_workqueue_attrs(wq->unbound_attrs); in rcu_free_wq()
3489 kfree(wq->rescuer); in rcu_free_wq()
3490 kfree(wq); in rcu_free_wq()
3652 struct workqueue_struct *wq = pwq->wq; in pwq_unbound_release_workfn() local
3656 if (WARN_ON_ONCE(!(wq->flags & WQ_UNBOUND))) in pwq_unbound_release_workfn()
3659 mutex_lock(&wq->mutex); in pwq_unbound_release_workfn()
3661 is_last = list_empty(&wq->pwqs); in pwq_unbound_release_workfn()
3662 mutex_unlock(&wq->mutex); in pwq_unbound_release_workfn()
3675 wq_unregister_lockdep(wq); in pwq_unbound_release_workfn()
3676 call_rcu(&wq->rcu, rcu_free_wq); in pwq_unbound_release_workfn()
3690 struct workqueue_struct *wq = pwq->wq; in pwq_adjust_max_active() local
3691 bool freezable = wq->flags & WQ_FREEZABLE; in pwq_adjust_max_active()
3695 lockdep_assert_held(&wq->mutex); in pwq_adjust_max_active()
3698 if (!freezable && pwq->max_active == wq->saved_max_active) in pwq_adjust_max_active()
3710 pwq->max_active = wq->saved_max_active; in pwq_adjust_max_active()
3729 static void init_pwq(struct pool_workqueue *pwq, struct workqueue_struct *wq, in init_pwq() argument
3737 pwq->wq = wq; in init_pwq()
3749 struct workqueue_struct *wq = pwq->wq; in link_pwq() local
3751 lockdep_assert_held(&wq->mutex); in link_pwq()
3758 pwq->work_color = wq->work_color; in link_pwq()
3764 list_add_rcu(&pwq->pwqs_node, &wq->pwqs); in link_pwq()
3768 static struct pool_workqueue *alloc_unbound_pwq(struct workqueue_struct *wq, in alloc_unbound_pwq() argument
3786 init_pwq(pwq, wq, pool); in alloc_unbound_pwq()
3843 static struct pool_workqueue *numa_pwq_tbl_install(struct workqueue_struct *wq, in numa_pwq_tbl_install() argument
3850 lockdep_assert_held(&wq->mutex); in numa_pwq_tbl_install()
3855 old_pwq = rcu_access_pointer(wq->numa_pwq_tbl[node]); in numa_pwq_tbl_install()
3856 rcu_assign_pointer(wq->numa_pwq_tbl[node], pwq); in numa_pwq_tbl_install()
3862 struct workqueue_struct *wq; /* target workqueue */ member
3887 apply_wqattrs_prepare(struct workqueue_struct *wq, in apply_wqattrs_prepare() argument
3925 ctx->dfl_pwq = alloc_unbound_pwq(wq, new_attrs); in apply_wqattrs_prepare()
3931 ctx->pwq_tbl[node] = alloc_unbound_pwq(wq, tmp_attrs); in apply_wqattrs_prepare()
3945 ctx->wq = wq; in apply_wqattrs_prepare()
3962 mutex_lock(&ctx->wq->mutex); in apply_wqattrs_commit()
3964 copy_workqueue_attrs(ctx->wq->unbound_attrs, ctx->attrs); in apply_wqattrs_commit()
3968 ctx->pwq_tbl[node] = numa_pwq_tbl_install(ctx->wq, node, in apply_wqattrs_commit()
3973 swap(ctx->wq->dfl_pwq, ctx->dfl_pwq); in apply_wqattrs_commit()
3975 mutex_unlock(&ctx->wq->mutex); in apply_wqattrs_commit()
3991 static int apply_workqueue_attrs_locked(struct workqueue_struct *wq, in apply_workqueue_attrs_locked() argument
3997 if (WARN_ON(!(wq->flags & WQ_UNBOUND))) in apply_workqueue_attrs_locked()
4001 if (!list_empty(&wq->pwqs)) { in apply_workqueue_attrs_locked()
4002 if (WARN_ON(wq->flags & __WQ_ORDERED_EXPLICIT)) in apply_workqueue_attrs_locked()
4005 wq->flags &= ~__WQ_ORDERED; in apply_workqueue_attrs_locked()
4008 ctx = apply_wqattrs_prepare(wq, attrs); in apply_workqueue_attrs_locked()
4037 int apply_workqueue_attrs(struct workqueue_struct *wq, in apply_workqueue_attrs() argument
4045 ret = apply_workqueue_attrs_locked(wq, attrs); in apply_workqueue_attrs()
4073 static void wq_update_unbound_numa(struct workqueue_struct *wq, int cpu, in wq_update_unbound_numa() argument
4084 if (!wq_numa_enabled || !(wq->flags & WQ_UNBOUND) || in wq_update_unbound_numa()
4085 wq->unbound_attrs->no_numa) in wq_update_unbound_numa()
4096 copy_workqueue_attrs(target_attrs, wq->unbound_attrs); in wq_update_unbound_numa()
4097 pwq = unbound_pwq_by_node(wq, node); in wq_update_unbound_numa()
4105 if (wq_calc_node_cpumask(wq->dfl_pwq->pool->attrs, node, cpu_off, cpumask)) { in wq_update_unbound_numa()
4113 pwq = alloc_unbound_pwq(wq, target_attrs); in wq_update_unbound_numa()
4116 wq->name); in wq_update_unbound_numa()
4121 mutex_lock(&wq->mutex); in wq_update_unbound_numa()
4122 old_pwq = numa_pwq_tbl_install(wq, node, pwq); in wq_update_unbound_numa()
4126 mutex_lock(&wq->mutex); in wq_update_unbound_numa()
4127 spin_lock_irq(&wq->dfl_pwq->pool->lock); in wq_update_unbound_numa()
4128 get_pwq(wq->dfl_pwq); in wq_update_unbound_numa()
4129 spin_unlock_irq(&wq->dfl_pwq->pool->lock); in wq_update_unbound_numa()
4130 old_pwq = numa_pwq_tbl_install(wq, node, wq->dfl_pwq); in wq_update_unbound_numa()
4132 mutex_unlock(&wq->mutex); in wq_update_unbound_numa()
4136 static int alloc_and_link_pwqs(struct workqueue_struct *wq) in alloc_and_link_pwqs() argument
4138 bool highpri = wq->flags & WQ_HIGHPRI; in alloc_and_link_pwqs()
4141 if (!(wq->flags & WQ_UNBOUND)) { in alloc_and_link_pwqs()
4142 wq->cpu_pwqs = alloc_percpu(struct pool_workqueue); in alloc_and_link_pwqs()
4143 if (!wq->cpu_pwqs) in alloc_and_link_pwqs()
4148 per_cpu_ptr(wq->cpu_pwqs, cpu); in alloc_and_link_pwqs()
4152 init_pwq(pwq, wq, &cpu_pools[highpri]); in alloc_and_link_pwqs()
4154 mutex_lock(&wq->mutex); in alloc_and_link_pwqs()
4156 mutex_unlock(&wq->mutex); in alloc_and_link_pwqs()
4162 if (wq->flags & __WQ_ORDERED) { in alloc_and_link_pwqs()
4163 ret = apply_workqueue_attrs(wq, ordered_wq_attrs[highpri]); in alloc_and_link_pwqs()
4165 WARN(!ret && (wq->pwqs.next != &wq->dfl_pwq->pwqs_node || in alloc_and_link_pwqs()
4166 wq->pwqs.prev != &wq->dfl_pwq->pwqs_node), in alloc_and_link_pwqs()
4167 "ordering guarantee broken for workqueue %s\n", wq->name); in alloc_and_link_pwqs()
4169 ret = apply_workqueue_attrs(wq, unbound_std_wq_attrs[highpri]); in alloc_and_link_pwqs()
4192 static int init_rescuer(struct workqueue_struct *wq) in init_rescuer() argument
4197 if (!(wq->flags & WQ_MEM_RECLAIM)) in init_rescuer()
4204 rescuer->rescue_wq = wq; in init_rescuer()
4205 rescuer->task = kthread_create(rescuer_thread, rescuer, "%s", wq->name); in init_rescuer()
4212 wq->rescuer = rescuer; in init_rescuer()
4226 struct workqueue_struct *wq; in alloc_workqueue() local
4245 tbl_size = nr_node_ids * sizeof(wq->numa_pwq_tbl[0]); in alloc_workqueue()
4247 wq = kzalloc(sizeof(*wq) + tbl_size, GFP_KERNEL); in alloc_workqueue()
4248 if (!wq) in alloc_workqueue()
4252 wq->unbound_attrs = alloc_workqueue_attrs(); in alloc_workqueue()
4253 if (!wq->unbound_attrs) in alloc_workqueue()
4258 vsnprintf(wq->name, sizeof(wq->name), fmt, args); in alloc_workqueue()
4262 max_active = wq_clamp_max_active(max_active, flags, wq->name); in alloc_workqueue()
4265 wq->flags = flags; in alloc_workqueue()
4266 wq->saved_max_active = max_active; in alloc_workqueue()
4267 mutex_init(&wq->mutex); in alloc_workqueue()
4268 atomic_set(&wq->nr_pwqs_to_flush, 0); in alloc_workqueue()
4269 INIT_LIST_HEAD(&wq->pwqs); in alloc_workqueue()
4270 INIT_LIST_HEAD(&wq->flusher_queue); in alloc_workqueue()
4271 INIT_LIST_HEAD(&wq->flusher_overflow); in alloc_workqueue()
4272 INIT_LIST_HEAD(&wq->maydays); in alloc_workqueue()
4274 wq_init_lockdep(wq); in alloc_workqueue()
4275 INIT_LIST_HEAD(&wq->list); in alloc_workqueue()
4277 if (alloc_and_link_pwqs(wq) < 0) in alloc_workqueue()
4280 if (wq_online && init_rescuer(wq) < 0) in alloc_workqueue()
4283 if ((wq->flags & WQ_SYSFS) && workqueue_sysfs_register(wq)) in alloc_workqueue()
4293 mutex_lock(&wq->mutex); in alloc_workqueue()
4294 for_each_pwq(pwq, wq) in alloc_workqueue()
4296 mutex_unlock(&wq->mutex); in alloc_workqueue()
4298 list_add_tail_rcu(&wq->list, &workqueues); in alloc_workqueue()
4302 return wq; in alloc_workqueue()
4305 wq_unregister_lockdep(wq); in alloc_workqueue()
4306 wq_free_lockdep(wq); in alloc_workqueue()
4308 free_workqueue_attrs(wq->unbound_attrs); in alloc_workqueue()
4309 kfree(wq); in alloc_workqueue()
4312 destroy_workqueue(wq); in alloc_workqueue()
4323 void destroy_workqueue(struct workqueue_struct *wq) in destroy_workqueue() argument
4329 drain_workqueue(wq); in destroy_workqueue()
4332 mutex_lock(&wq->mutex); in destroy_workqueue()
4333 for_each_pwq(pwq, wq) { in destroy_workqueue()
4338 mutex_unlock(&wq->mutex); in destroy_workqueue()
4344 if (WARN_ON((pwq != wq->dfl_pwq) && (pwq->refcnt > 1)) || in destroy_workqueue()
4347 mutex_unlock(&wq->mutex); in destroy_workqueue()
4352 mutex_unlock(&wq->mutex); in destroy_workqueue()
4359 list_del_rcu(&wq->list); in destroy_workqueue()
4362 workqueue_sysfs_unregister(wq); in destroy_workqueue()
4364 if (wq->rescuer) in destroy_workqueue()
4365 kthread_stop(wq->rescuer->task); in destroy_workqueue()
4367 if (!(wq->flags & WQ_UNBOUND)) { in destroy_workqueue()
4368 wq_unregister_lockdep(wq); in destroy_workqueue()
4373 call_rcu(&wq->rcu, rcu_free_wq); in destroy_workqueue()
4381 pwq = rcu_access_pointer(wq->numa_pwq_tbl[node]); in destroy_workqueue()
4382 RCU_INIT_POINTER(wq->numa_pwq_tbl[node], NULL); in destroy_workqueue()
4390 pwq = wq->dfl_pwq; in destroy_workqueue()
4391 wq->dfl_pwq = NULL; in destroy_workqueue()
4407 void workqueue_set_max_active(struct workqueue_struct *wq, int max_active) in workqueue_set_max_active() argument
4412 if (WARN_ON(wq->flags & __WQ_ORDERED_EXPLICIT)) in workqueue_set_max_active()
4415 max_active = wq_clamp_max_active(max_active, wq->flags, wq->name); in workqueue_set_max_active()
4417 mutex_lock(&wq->mutex); in workqueue_set_max_active()
4419 wq->flags &= ~__WQ_ORDERED; in workqueue_set_max_active()
4420 wq->saved_max_active = max_active; in workqueue_set_max_active()
4422 for_each_pwq(pwq, wq) in workqueue_set_max_active()
4425 mutex_unlock(&wq->mutex); in workqueue_set_max_active()
4478 bool workqueue_congested(int cpu, struct workqueue_struct *wq) in workqueue_congested() argument
4489 if (!(wq->flags & WQ_UNBOUND)) in workqueue_congested()
4490 pwq = per_cpu_ptr(wq->cpu_pwqs, cpu); in workqueue_congested()
4492 pwq = unbound_pwq_by_node(wq, cpu_to_node(cpu)); in workqueue_congested()
4578 struct workqueue_struct *wq = NULL; in print_worker_info() local
4596 probe_kernel_read(&wq, &pwq->wq, sizeof(wq)); in print_worker_info()
4597 probe_kernel_read(name, wq->name, sizeof(name) - 1); in print_worker_info()
4660 worker == pwq->wq->rescuer ? "(RESCUER)" : "", in show_pwq()
4709 struct workqueue_struct *wq; in show_workqueue_state() local
4718 list_for_each_entry_rcu(wq, &workqueues, list) { in show_workqueue_state()
4722 for_each_pwq(pwq, wq) { in show_workqueue_state()
4731 pr_info("workqueue %s: flags=0x%x\n", wq->name, wq->flags); in show_workqueue_state()
4733 for_each_pwq(pwq, wq) { in show_workqueue_state()
5000 struct workqueue_struct *wq; in workqueue_online_cpu() local
5017 list_for_each_entry(wq, &workqueues, list) in workqueue_online_cpu()
5018 wq_update_unbound_numa(wq, cpu, true); in workqueue_online_cpu()
5026 struct workqueue_struct *wq; in workqueue_offline_cpu() local
5036 list_for_each_entry(wq, &workqueues, list) in workqueue_offline_cpu()
5037 wq_update_unbound_numa(wq, cpu, false); in workqueue_offline_cpu()
5118 struct workqueue_struct *wq; in freeze_workqueues_begin() local
5126 list_for_each_entry(wq, &workqueues, list) { in freeze_workqueues_begin()
5127 mutex_lock(&wq->mutex); in freeze_workqueues_begin()
5128 for_each_pwq(pwq, wq) in freeze_workqueues_begin()
5130 mutex_unlock(&wq->mutex); in freeze_workqueues_begin()
5152 struct workqueue_struct *wq; in freeze_workqueues_busy() local
5159 list_for_each_entry(wq, &workqueues, list) { in freeze_workqueues_busy()
5160 if (!(wq->flags & WQ_FREEZABLE)) in freeze_workqueues_busy()
5167 for_each_pwq(pwq, wq) { in freeze_workqueues_busy()
5193 struct workqueue_struct *wq; in thaw_workqueues() local
5204 list_for_each_entry(wq, &workqueues, list) { in thaw_workqueues()
5205 mutex_lock(&wq->mutex); in thaw_workqueues()
5206 for_each_pwq(pwq, wq) in thaw_workqueues()
5208 mutex_unlock(&wq->mutex); in thaw_workqueues()
5220 struct workqueue_struct *wq; in workqueue_apply_unbound_cpumask() local
5225 list_for_each_entry(wq, &workqueues, list) { in workqueue_apply_unbound_cpumask()
5226 if (!(wq->flags & WQ_UNBOUND)) in workqueue_apply_unbound_cpumask()
5229 if (wq->flags & __WQ_ORDERED) in workqueue_apply_unbound_cpumask()
5232 ctx = apply_wqattrs_prepare(wq, wq->unbound_attrs); in workqueue_apply_unbound_cpumask()
5313 struct workqueue_struct *wq; member
5321 return wq_dev->wq; in dev_to_wq()
5327 struct workqueue_struct *wq = dev_to_wq(dev); in per_cpu_show() local
5329 return scnprintf(buf, PAGE_SIZE, "%d\n", (bool)!(wq->flags & WQ_UNBOUND)); in per_cpu_show()
5336 struct workqueue_struct *wq = dev_to_wq(dev); in max_active_show() local
5338 return scnprintf(buf, PAGE_SIZE, "%d\n", wq->saved_max_active); in max_active_show()
5345 struct workqueue_struct *wq = dev_to_wq(dev); in max_active_store() local
5351 workqueue_set_max_active(wq, val); in max_active_store()
5366 struct workqueue_struct *wq = dev_to_wq(dev); in wq_pool_ids_show() local
5375 unbound_pwq_by_node(wq, node)->pool->id); in wq_pool_ids_show()
5388 struct workqueue_struct *wq = dev_to_wq(dev); in wq_nice_show() local
5391 mutex_lock(&wq->mutex); in wq_nice_show()
5392 written = scnprintf(buf, PAGE_SIZE, "%d\n", wq->unbound_attrs->nice); in wq_nice_show()
5393 mutex_unlock(&wq->mutex); in wq_nice_show()
5399 static struct workqueue_attrs *wq_sysfs_prep_attrs(struct workqueue_struct *wq) in wq_sysfs_prep_attrs() argument
5409 copy_workqueue_attrs(attrs, wq->unbound_attrs); in wq_sysfs_prep_attrs()
5416 struct workqueue_struct *wq = dev_to_wq(dev); in wq_nice_store() local
5422 attrs = wq_sysfs_prep_attrs(wq); in wq_nice_store()
5428 ret = apply_workqueue_attrs_locked(wq, attrs); in wq_nice_store()
5441 struct workqueue_struct *wq = dev_to_wq(dev); in wq_cpumask_show() local
5444 mutex_lock(&wq->mutex); in wq_cpumask_show()
5446 cpumask_pr_args(wq->unbound_attrs->cpumask)); in wq_cpumask_show()
5447 mutex_unlock(&wq->mutex); in wq_cpumask_show()
5455 struct workqueue_struct *wq = dev_to_wq(dev); in wq_cpumask_store() local
5461 attrs = wq_sysfs_prep_attrs(wq); in wq_cpumask_store()
5467 ret = apply_workqueue_attrs_locked(wq, attrs); in wq_cpumask_store()
5478 struct workqueue_struct *wq = dev_to_wq(dev); in wq_numa_show() local
5481 mutex_lock(&wq->mutex); in wq_numa_show()
5483 !wq->unbound_attrs->no_numa); in wq_numa_show()
5484 mutex_unlock(&wq->mutex); in wq_numa_show()
5492 struct workqueue_struct *wq = dev_to_wq(dev); in wq_numa_store() local
5498 attrs = wq_sysfs_prep_attrs(wq); in wq_numa_store()
5505 ret = apply_workqueue_attrs_locked(wq, attrs); in wq_numa_store()
5595 int workqueue_sysfs_register(struct workqueue_struct *wq) in workqueue_sysfs_register() argument
5605 if (WARN_ON(wq->flags & __WQ_ORDERED_EXPLICIT)) in workqueue_sysfs_register()
5608 wq->wq_dev = wq_dev = kzalloc(sizeof(*wq_dev), GFP_KERNEL); in workqueue_sysfs_register()
5612 wq_dev->wq = wq; in workqueue_sysfs_register()
5615 dev_set_name(&wq_dev->dev, "%s", wq->name); in workqueue_sysfs_register()
5626 wq->wq_dev = NULL; in workqueue_sysfs_register()
5630 if (wq->flags & WQ_UNBOUND) { in workqueue_sysfs_register()
5637 wq->wq_dev = NULL; in workqueue_sysfs_register()
5654 static void workqueue_sysfs_unregister(struct workqueue_struct *wq) in workqueue_sysfs_unregister() argument
5656 struct wq_device *wq_dev = wq->wq_dev; in workqueue_sysfs_unregister()
5658 if (!wq->wq_dev) in workqueue_sysfs_unregister()
5661 wq->wq_dev = NULL; in workqueue_sysfs_unregister()
5665 static void workqueue_sysfs_unregister(struct workqueue_struct *wq) { } in workqueue_sysfs_unregister() argument
5948 struct workqueue_struct *wq; in workqueue_init() local
5971 list_for_each_entry(wq, &workqueues, list) { in workqueue_init()
5972 wq_update_unbound_numa(wq, smp_processor_id(), true); in workqueue_init()
5973 WARN(init_rescuer(wq), in workqueue_init()
5975 wq->name); in workqueue_init()