20 #include <linux/slab.h>
21 #include <linux/list.h>
26 #define WORK_QUEUED_BIT 0
27 #define WORK_DONE_BIT 1
28 #define WORK_ORDER_DONE_BIT 2
29 #define WORK_HIGH_PRIO_BIT 3
67 static int __btrfs_start_workers(
struct btrfs_workers *workers);
93 __btrfs_start_workers(start->
queue);
104 worker->
workers->idle_thresh / 2) {
114 spin_unlock_irqrestore(&worker->
workers->lock, flags);
125 worker->
workers->idle_thresh) {
132 &worker->
workers->worker_list);
134 spin_unlock_irqrestore(&worker->
workers->lock, flags);
148 start = kzalloc(
sizeof(*start),
GFP_NOFS);
152 start->
work.func = start_new_worker_func;
153 start->
queue = workers;
165 spin_unlock_irqrestore(&workers->
lock, flags);
171 spin_unlock_irqrestore(&workers->
lock, flags);
188 }
else if (!list_empty(&workers->
order_list)) {
235 spin_lock_irq(&worker->
lock);
236 spin_lock(&worker->
workers->lock);
237 if (worker->
workers->num_workers > 1 &&
242 list_empty(&worker->
pending) &&
246 worker->
workers->num_workers--;
248 spin_unlock(&worker->
workers->lock);
249 spin_unlock_irq(&worker->
lock);
263 if(!list_empty(prio_head))
264 cur = prio_head->
next;
270 if (!list_empty(head))
277 spin_lock_irq(&worker->
lock);
278 list_splice_tail_init(&worker->
prio_pending, prio_head);
279 list_splice_tail_init(&worker->
pending, head);
281 if (!list_empty(prio_head))
282 cur = prio_head->
next;
283 else if (!list_empty(head))
285 spin_unlock_irq(&worker->
lock);
300 static int worker_loop(
void *
arg)
307 INIT_LIST_HEAD(&head);
308 INIT_LIST_HEAD(&prio_head);
315 work = get_next_work(worker, &prio_head, &head);
331 run_ordered_completions(worker->
workers, work);
333 check_pending_worker_creates(worker);
337 spin_lock_irq(&worker->
lock);
338 check_idle_worker(worker);
342 spin_unlock_irq(&worker->
lock);
345 spin_unlock_irq(&worker->
lock);
353 if (!list_empty(&worker->
pending) ||
367 if (!list_empty(&worker->
pending) ||
375 spin_lock_irq(&worker->
lock);
377 if (!list_empty(&worker->
pending) ||
379 spin_unlock_irq(&worker->
lock);
389 spin_unlock_irq(&worker->
lock);
394 try_worker_shutdown(worker)) {
414 spin_lock_irq(&workers->
lock);
429 spin_unlock_irq(&workers->
lock);
432 spin_lock_irq(&workers->
lock);
435 spin_unlock_irq(&workers->
lock);
464 static int __btrfs_start_workers(
struct btrfs_workers *workers)
469 worker = kzalloc(
sizeof(*worker),
GFP_NOFS);
475 INIT_LIST_HEAD(&worker->
pending);
484 "btrfs-%s-%d", workers->
name,
486 if (IS_ERR(worker->
task)) {
487 ret = PTR_ERR(worker->
task);
491 spin_lock_irq(&workers->
lock);
497 spin_unlock_irq(&workers->
lock);
501 spin_lock_irq(&workers->
lock);
503 spin_unlock_irq(&workers->
lock);
509 spin_lock_irq(&workers->
lock);
511 spin_unlock_irq(&workers->
lock);
512 return __btrfs_start_workers(workers);
541 if (enforce_min || list_empty(&workers->
worker_list))
573 worker = next_worker(workers);
584 spin_unlock_irqrestore(&workers->
lock, flags);
586 ret = __btrfs_start_workers(workers);
614 spin_unlock_irqrestore(&workers->
lock, flags);
643 spin_lock(&worker->
workers->lock);
646 &worker->
workers->worker_list);
647 spin_unlock(&worker->
workers->lock);
656 spin_unlock_irqrestore(&worker->
lock, flags);
677 worker = find_worker(workers);
701 check_busy_worker(worker);
713 spin_unlock_irqrestore(&worker->
lock, flags);