Lines Matching full:wq
50 struct btrfs_fs_info * __pure btrfs_workqueue_owner(const struct btrfs_workqueue *wq) in btrfs_workqueue_owner() argument
52 return wq->fs_info; in btrfs_workqueue_owner()
57 return work->wq->fs_info; in btrfs_work_owner()
60 bool btrfs_workqueue_normal_congested(const struct btrfs_workqueue *wq) in btrfs_workqueue_normal_congested() argument
63 * We could compare wq->pending with num_online_cpus() in btrfs_workqueue_normal_congested()
68 if (wq->thresh == NO_THRESHOLD) in btrfs_workqueue_normal_congested()
71 return atomic_read(&wq->pending) > wq->thresh * 2; in btrfs_workqueue_normal_congested()
74 static void btrfs_init_workqueue(struct btrfs_workqueue *wq, in btrfs_init_workqueue() argument
77 wq->fs_info = fs_info; in btrfs_init_workqueue()
78 atomic_set(&wq->pending, 0); in btrfs_init_workqueue()
79 INIT_LIST_HEAD(&wq->ordered_list); in btrfs_init_workqueue()
80 spin_lock_init(&wq->list_lock); in btrfs_init_workqueue()
81 spin_lock_init(&wq->thres_lock); in btrfs_init_workqueue()
104 * For threshold-able wq, let its concurrency grow on demand. in btrfs_alloc_workqueue()
155 static inline void thresh_queue_hook(struct btrfs_workqueue *wq) in thresh_queue_hook() argument
157 if (wq->thresh == NO_THRESHOLD) in thresh_queue_hook()
159 atomic_inc(&wq->pending); in thresh_queue_hook()
167 static inline void thresh_exec_hook(struct btrfs_workqueue *wq) in thresh_exec_hook() argument
173 if (wq->thresh == NO_THRESHOLD) in thresh_exec_hook()
176 atomic_dec(&wq->pending); in thresh_exec_hook()
177 spin_lock(&wq->thres_lock); in thresh_exec_hook()
179 * Use wq->count to limit the calling frequency of in thresh_exec_hook()
182 wq->count++; in thresh_exec_hook()
183 wq->count %= (wq->thresh / 4); in thresh_exec_hook()
184 if (!wq->count) in thresh_exec_hook()
186 new_current_active = wq->current_active; in thresh_exec_hook()
192 pending = atomic_read(&wq->pending); in thresh_exec_hook()
193 if (pending > wq->thresh) in thresh_exec_hook()
195 if (pending < wq->thresh / 2) in thresh_exec_hook()
197 new_current_active = clamp_val(new_current_active, 1, wq->limit_active); in thresh_exec_hook()
198 if (new_current_active != wq->current_active) { in thresh_exec_hook()
200 wq->current_active = new_current_active; in thresh_exec_hook()
203 spin_unlock(&wq->thres_lock); in thresh_exec_hook()
206 workqueue_set_max_active(wq->normal_wq, wq->current_active); in thresh_exec_hook()
210 static void run_ordered_work(struct btrfs_workqueue *wq, in run_ordered_work() argument
213 struct list_head *list = &wq->ordered_list; in run_ordered_work()
215 spinlock_t *lock = &wq->list_lock; in run_ordered_work()
282 trace_btrfs_all_work_done(wq->fs_info, work); in run_ordered_work()
290 trace_btrfs_all_work_done(wq->fs_info, self); in run_ordered_work()
298 struct btrfs_workqueue *wq = work->wq; in btrfs_work_helper() local
313 thresh_exec_hook(wq); in btrfs_work_helper()
324 run_ordered_work(wq, work); in btrfs_work_helper()
327 trace_btrfs_all_work_done(wq->fs_info, work); in btrfs_work_helper()
341 void btrfs_queue_work(struct btrfs_workqueue *wq, struct btrfs_work *work) in btrfs_queue_work() argument
345 work->wq = wq; in btrfs_queue_work()
346 thresh_queue_hook(wq); in btrfs_queue_work()
348 spin_lock_irqsave(&wq->list_lock, flags); in btrfs_queue_work()
349 list_add_tail(&work->ordered_list, &wq->ordered_list); in btrfs_queue_work()
350 spin_unlock_irqrestore(&wq->list_lock, flags); in btrfs_queue_work()
353 queue_work(wq->normal_wq, &work->normal_work); in btrfs_queue_work()
356 void btrfs_destroy_workqueue(struct btrfs_workqueue *wq) in btrfs_destroy_workqueue() argument
358 if (!wq) in btrfs_destroy_workqueue()
360 destroy_workqueue(wq->normal_wq); in btrfs_destroy_workqueue()
361 trace_btrfs_workqueue_destroy(wq); in btrfs_destroy_workqueue()
362 kfree(wq); in btrfs_destroy_workqueue()
365 void btrfs_workqueue_set_max(struct btrfs_workqueue *wq, int limit_active) in btrfs_workqueue_set_max() argument
367 if (wq) in btrfs_workqueue_set_max()
368 wq->limit_active = limit_active; in btrfs_workqueue_set_max()
371 void btrfs_flush_workqueue(struct btrfs_workqueue *wq) in btrfs_flush_workqueue() argument
373 flush_workqueue(wq->normal_wq); in btrfs_flush_workqueue()