async-thread.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. /*
  2. * Copyright (C) 2007 Oracle. All rights reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public
  6. * License v2 as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. * General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public
  14. * License along with this program; if not, write to the
  15. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16. * Boston, MA 021110-1307, USA.
  17. */
  18. #include <linux/kthread.h>
  19. #include <linux/slab.h>
  20. #include <linux/list.h>
  21. #include <linux/spinlock.h>
  22. #include <linux/freezer.h>
  23. #include "async-thread.h"
  24. #define WORK_QUEUED_BIT 0
  25. #define WORK_DONE_BIT 1
  26. #define WORK_ORDER_DONE_BIT 2
  27. #define WORK_HIGH_PRIO_BIT 3
  28. /*
  29. * container for the kthread task pointer and the list of pending work
  30. * One of these is allocated per thread.
  31. */
  32. struct btrfs_worker_thread {
  33. /* pool we belong to */
  34. struct btrfs_workers *workers;
  35. /* list of struct btrfs_work that are waiting for service */
  36. struct list_head pending;
  37. struct list_head prio_pending;
  38. /* list of worker threads from struct btrfs_workers */
  39. struct list_head worker_list;
  40. /* kthread */
  41. struct task_struct *task;
  42. /* number of things on the pending list */
  43. atomic_t num_pending;
  44. /* reference counter for this struct */
  45. atomic_t refs;
  46. unsigned long sequence;
  47. /* protects the pending list. */
  48. spinlock_t lock;
  49. /* set to non-zero when this thread is already awake and kicking */
  50. int working;
  51. /* are we currently idle */
  52. int idle;
  53. };
  54. static int __btrfs_start_workers(struct btrfs_workers *workers);
  55. /*
  56. * btrfs_start_workers uses kthread_run, which can block waiting for memory
  57. * for a very long time. It will actually throttle on page writeback,
  58. * and so it may not make progress until after our btrfs worker threads
  59. * process all of the pending work structs in their queue
  60. *
  61. * This means we can't use btrfs_start_workers from inside a btrfs worker
  62. * thread that is used as part of cleaning dirty memory, which pretty much
  63. * involves all of the worker threads.
  64. *
  65. * Instead we have a helper queue who never has more than one thread
  66. * where we scheduler thread start operations. This worker_start struct
  67. * is used to contain the work and hold a pointer to the queue that needs
  68. * another worker.
  69. */
  70. struct worker_start {
  71. struct btrfs_work work;
  72. struct btrfs_workers *queue;
  73. };
  74. static void start_new_worker_func(struct btrfs_work *work)
  75. {
  76. struct worker_start *start;
  77. start = container_of(work, struct worker_start, work);
  78. __btrfs_start_workers(start->queue);
  79. kfree(start);
  80. }
  81. /*
  82. * helper function to move a thread onto the idle list after it
  83. * has finished some requests.
  84. */
  85. static void check_idle_worker(struct btrfs_worker_thread *worker)
  86. {
  87. if (!worker->idle && atomic_read(&worker->num_pending) <
  88. worker->workers->idle_thresh / 2) {
  89. unsigned long flags;
  90. spin_lock_irqsave(&worker->workers->lock, flags);
  91. worker->idle = 1;
  92. /* the list may be empty if the worker is just starting */
  93. if (!list_empty(&worker->worker_list) &&
  94. !worker->workers->stopping) {
  95. list_move(&worker->worker_list,
  96. &worker->workers->idle_list);
  97. }
  98. spin_unlock_irqrestore(&worker->workers->lock, flags);
  99. }
  100. }
  101. /*
  102. * helper function to move a thread off the idle list after new
  103. * pending work is added.
  104. */
  105. static void check_busy_worker(struct btrfs_worker_thread *worker)
  106. {
  107. if (worker->idle && atomic_read(&worker->num_pending) >=
  108. worker->workers->idle_thresh) {
  109. unsigned long flags;
  110. spin_lock_irqsave(&worker->workers->lock, flags);
  111. worker->idle = 0;
  112. if (!list_empty(&worker->worker_list) &&
  113. !worker->workers->stopping) {
  114. list_move_tail(&worker->worker_list,
  115. &worker->workers->worker_list);
  116. }
  117. spin_unlock_irqrestore(&worker->workers->lock, flags);
  118. }
  119. }
  120. static void check_pending_worker_creates(struct btrfs_worker_thread *worker)
  121. {
  122. struct btrfs_workers *workers = worker->workers;
  123. struct worker_start *start;
  124. unsigned long flags;
  125. rmb();
  126. if (!workers->atomic_start_pending)
  127. return;
  128. start = kzalloc(sizeof(*start), GFP_NOFS);
  129. if (!start)
  130. return;
  131. start->work.func = start_new_worker_func;
  132. start->queue = workers;
  133. spin_lock_irqsave(&workers->lock, flags);
  134. if (!workers->atomic_start_pending)
  135. goto out;
  136. workers->atomic_start_pending = 0;
  137. if (workers->num_workers + workers->num_workers_starting >=
  138. workers->max_workers)
  139. goto out;
  140. workers->num_workers_starting += 1;
  141. spin_unlock_irqrestore(&workers->lock, flags);
  142. btrfs_queue_worker(workers->atomic_worker_start, &start->work);
  143. return;
  144. out:
  145. kfree(start);
  146. spin_unlock_irqrestore(&workers->lock, flags);
  147. }
  148. static noinline void run_ordered_completions(struct btrfs_workers *workers,
  149. struct btrfs_work *work)
  150. {
  151. if (!workers->ordered)
  152. return;
  153. set_bit(WORK_DONE_BIT, &work->flags);
  154. spin_lock(&workers->order_lock);
  155. while (1) {
  156. if (!list_empty(&workers->prio_order_list)) {
  157. work = list_entry(workers->prio_order_list.next,
  158. struct btrfs_work, order_list);
  159. } else if (!list_empty(&workers->order_list)) {
  160. work = list_entry(workers->order_list.next,
  161. struct btrfs_work, order_list);
  162. } else {
  163. break;
  164. }
  165. if (!test_bit(WORK_DONE_BIT, &work->flags))
  166. break;
  167. /* we are going to call the ordered done function, but
  168. * we leave the work item on the list as a barrier so
  169. * that later work items that are done don't have their
  170. * functions called before this one returns
  171. */
  172. if (test_and_set_bit(WORK_ORDER_DONE_BIT, &work->flags))
  173. break;
  174. spin_unlock(&workers->order_lock);
  175. work->ordered_func(work);
  176. /* now take the lock again and drop our item from the list */
  177. spin_lock(&workers->order_lock);
  178. list_del(&work->order_list);
  179. spin_unlock(&workers->order_lock);
  180. /*
  181. * we don't want to call the ordered free functions
  182. * with the lock held though
  183. */
  184. work->ordered_free(work);
  185. spin_lock(&workers->order_lock);
  186. }
  187. spin_unlock(&workers->order_lock);
  188. }
  189. static void put_worker(struct btrfs_worker_thread *worker)
  190. {
  191. if (atomic_dec_and_test(&worker->refs))
  192. kfree(worker);
  193. }
  194. static int try_worker_shutdown(struct btrfs_worker_thread *worker)
  195. {
  196. int freeit = 0;
  197. spin_lock_irq(&worker->lock);
  198. spin_lock(&worker->workers->lock);
  199. if (worker->workers->num_workers > 1 &&
  200. worker->idle &&
  201. !worker->working &&
  202. !list_empty(&worker->worker_list) &&
  203. list_empty(&worker->prio_pending) &&
  204. list_empty(&worker->pending) &&
  205. atomic_read(&worker->num_pending) == 0) {
  206. freeit = 1;
  207. list_del_init(&worker->worker_list);
  208. worker->workers->num_workers--;
  209. }
  210. spin_unlock(&worker->workers->lock);
  211. spin_unlock_irq(&worker->lock);
  212. if (freeit)
  213. put_worker(worker);
  214. return freeit;
  215. }
  216. static struct btrfs_work *get_next_work(struct btrfs_worker_thread *worker,
  217. struct list_head *prio_head,
  218. struct list_head *head)
  219. {
  220. struct btrfs_work *work = NULL;
  221. struct list_head *cur = NULL;
  222. if(!list_empty(prio_head))
  223. cur = prio_head->next;
  224. smp_mb();
  225. if (!list_empty(&worker->prio_pending))
  226. goto refill;
  227. if (!list_empty(head))
  228. cur = head->next;
  229. if (cur)
  230. goto out;
  231. refill:
  232. spin_lock_irq(&worker->lock);
  233. list_splice_tail_init(&worker->prio_pending, prio_head);
  234. list_splice_tail_init(&worker->pending, head);
  235. if (!list_empty(prio_head))
  236. cur = prio_head->next;
  237. else if (!list_empty(head))
  238. cur = head->next;
  239. spin_unlock_irq(&worker->lock);
  240. if (!cur)
  241. goto out_fail;
  242. out:
  243. work = list_entry(cur, struct btrfs_work, list);
  244. out_fail:
  245. return work;
  246. }
  247. /*
  248. * main loop for servicing work items
  249. */
  250. static int worker_loop(void *arg)
  251. {
  252. struct btrfs_worker_thread *worker = arg;
  253. struct list_head head;
  254. struct list_head prio_head;
  255. struct btrfs_work *work;
  256. INIT_LIST_HEAD(&head);
  257. INIT_LIST_HEAD(&prio_head);
  258. do {
  259. again:
  260. while (1) {
  261. work = get_next_work(worker, &prio_head, &head);
  262. if (!work)
  263. break;
  264. list_del(&work->list);
  265. clear_bit(WORK_QUEUED_BIT, &work->flags);
  266. work->worker = worker;
  267. work->func(work);
  268. atomic_dec(&worker->num_pending);
  269. /*
  270. * unless this is an ordered work queue,
  271. * 'work' was probably freed by func above.
  272. */
  273. run_ordered_completions(worker->workers, work);
  274. check_pending_worker_creates(worker);
  275. cond_resched();
  276. }
  277. spin_lock_irq(&worker->lock);
  278. check_idle_worker(worker);
  279. if (freezing(current)) {
  280. worker->working = 0;
  281. spin_unlock_irq(&worker->lock);
  282. try_to_freeze();
  283. } else {
  284. spin_unlock_irq(&worker->lock);
  285. if (!kthread_should_stop()) {
  286. cpu_relax();
  287. /*
  288. * we've dropped the lock, did someone else
  289. * jump_in?
  290. */
  291. smp_mb();
  292. if (!list_empty(&worker->pending) ||
  293. !list_empty(&worker->prio_pending))
  294. continue;
  295. /*
  296. * this short schedule allows more work to
  297. * come in without the queue functions
  298. * needing to go through wake_up_process()
  299. *
  300. * worker->working is still 1, so nobody
  301. * is going to try and wake us up
  302. */
  303. schedule_timeout(1);
  304. smp_mb();
  305. if (!list_empty(&worker->pending) ||
  306. !list_empty(&worker->prio_pending))
  307. continue;
  308. if (kthread_should_stop())
  309. break;
  310. /* still no more work?, sleep for real */
  311. spin_lock_irq(&worker->lock);
  312. set_current_state(TASK_INTERRUPTIBLE);
  313. if (!list_empty(&worker->pending) ||
  314. !list_empty(&worker->prio_pending)) {
  315. spin_unlock_irq(&worker->lock);
  316. set_current_state(TASK_RUNNING);
  317. goto again;
  318. }
  319. /*
  320. * this makes sure we get a wakeup when someone
  321. * adds something new to the queue
  322. */
  323. worker->working = 0;
  324. spin_unlock_irq(&worker->lock);
  325. if (!kthread_should_stop()) {
  326. schedule_timeout(HZ * 120);
  327. if (!worker->working &&
  328. try_worker_shutdown(worker)) {
  329. return 0;
  330. }
  331. }
  332. }
  333. __set_current_state(TASK_RUNNING);
  334. }
  335. } while (!kthread_should_stop());
  336. return 0;
  337. }
  338. /*
  339. * this will wait for all the worker threads to shutdown
  340. */
  341. void btrfs_stop_workers(struct btrfs_workers *workers)
  342. {
  343. struct list_head *cur;
  344. struct btrfs_worker_thread *worker;
  345. int can_stop;
  346. spin_lock_irq(&workers->lock);
  347. workers->stopping = 1;
  348. list_splice_init(&workers->idle_list, &workers->worker_list);
  349. while (!list_empty(&workers->worker_list)) {
  350. cur = workers->worker_list.next;
  351. worker = list_entry(cur, struct btrfs_worker_thread,
  352. worker_list);
  353. atomic_inc(&worker->refs);
  354. workers->num_workers -= 1;
  355. if (!list_empty(&worker->worker_list)) {
  356. list_del_init(&worker->worker_list);
  357. put_worker(worker);
  358. can_stop = 1;
  359. } else
  360. can_stop = 0;
  361. spin_unlock_irq(&workers->lock);
  362. if (can_stop)
  363. kthread_stop(worker->task);
  364. spin_lock_irq(&workers->lock);
  365. put_worker(worker);
  366. }
  367. spin_unlock_irq(&workers->lock);
  368. }
  369. /*
  370. * simple init on struct btrfs_workers
  371. */
  372. void btrfs_init_workers(struct btrfs_workers *workers, char *name, int max,
  373. struct btrfs_workers *async_helper)
  374. {
  375. workers->num_workers = 0;
  376. workers->num_workers_starting = 0;
  377. INIT_LIST_HEAD(&workers->worker_list);
  378. INIT_LIST_HEAD(&workers->idle_list);
  379. INIT_LIST_HEAD(&workers->order_list);
  380. INIT_LIST_HEAD(&workers->prio_order_list);
  381. spin_lock_init(&workers->lock);
  382. spin_lock_init(&workers->order_lock);
  383. workers->max_workers = max;
  384. workers->idle_thresh = 32;
  385. workers->name = name;
  386. workers->ordered = 0;
  387. workers->atomic_start_pending = 0;
  388. workers->atomic_worker_start = async_helper;
  389. workers->stopping = 0;
  390. }
  391. /*
  392. * starts new worker threads. This does not enforce the max worker
  393. * count in case you need to temporarily go past it.
  394. */
  395. static int __btrfs_start_workers(struct btrfs_workers *workers)
  396. {
  397. struct btrfs_worker_thread *worker;
  398. int ret = 0;
  399. worker = kzalloc(sizeof(*worker), GFP_NOFS);
  400. if (!worker) {
  401. ret = -ENOMEM;
  402. goto fail;
  403. }
  404. INIT_LIST_HEAD(&worker->pending);
  405. INIT_LIST_HEAD(&worker->prio_pending);
  406. INIT_LIST_HEAD(&worker->worker_list);
  407. spin_lock_init(&worker->lock);
  408. atomic_set(&worker->num_pending, 0);
  409. atomic_set(&worker->refs, 1);
  410. worker->workers = workers;
  411. worker->task = kthread_create(worker_loop, worker,
  412. "btrfs-%s-%d", workers->name,
  413. workers->num_workers + 1);
  414. if (IS_ERR(worker->task)) {
  415. ret = PTR_ERR(worker->task);
  416. goto fail;
  417. }
  418. spin_lock_irq(&workers->lock);
  419. if (workers->stopping) {
  420. spin_unlock_irq(&workers->lock);
  421. goto fail_kthread;
  422. }
  423. list_add_tail(&worker->worker_list, &workers->idle_list);
  424. worker->idle = 1;
  425. workers->num_workers++;
  426. workers->num_workers_starting--;
  427. WARN_ON(workers->num_workers_starting < 0);
  428. spin_unlock_irq(&workers->lock);
  429. wake_up_process(worker->task);
  430. return 0;
  431. fail_kthread:
  432. kthread_stop(worker->task);
  433. fail:
  434. kfree(worker);
  435. spin_lock_irq(&workers->lock);
  436. workers->num_workers_starting--;
  437. spin_unlock_irq(&workers->lock);
  438. return ret;
  439. }
  440. int btrfs_start_workers(struct btrfs_workers *workers)
  441. {
  442. spin_lock_irq(&workers->lock);
  443. workers->num_workers_starting++;
  444. spin_unlock_irq(&workers->lock);
  445. return __btrfs_start_workers(workers);
  446. }
  447. /*
  448. * run through the list and find a worker thread that doesn't have a lot
  449. * to do right now. This can return null if we aren't yet at the thread
  450. * count limit and all of the threads are busy.
  451. */
  452. static struct btrfs_worker_thread *next_worker(struct btrfs_workers *workers)
  453. {
  454. struct btrfs_worker_thread *worker;
  455. struct list_head *next;
  456. int enforce_min;
  457. enforce_min = (workers->num_workers + workers->num_workers_starting) <
  458. workers->max_workers;
  459. /*
  460. * if we find an idle thread, don't move it to the end of the
  461. * idle list. This improves the chance that the next submission
  462. * will reuse the same thread, and maybe catch it while it is still
  463. * working
  464. */
  465. if (!list_empty(&workers->idle_list)) {
  466. next = workers->idle_list.next;
  467. worker = list_entry(next, struct btrfs_worker_thread,
  468. worker_list);
  469. return worker;
  470. }
  471. if (enforce_min || list_empty(&workers->worker_list))
  472. return NULL;
  473. /*
  474. * if we pick a busy task, move the task to the end of the list.
  475. * hopefully this will keep things somewhat evenly balanced.
  476. * Do the move in batches based on the sequence number. This groups
  477. * requests submitted at roughly the same time onto the same worker.
  478. */
  479. next = workers->worker_list.next;
  480. worker = list_entry(next, struct btrfs_worker_thread, worker_list);
  481. worker->sequence++;
  482. if (worker->sequence % workers->idle_thresh == 0)
  483. list_move_tail(next, &workers->worker_list);
  484. return worker;
  485. }
  486. /*
  487. * selects a worker thread to take the next job. This will either find
  488. * an idle worker, start a new worker up to the max count, or just return
  489. * one of the existing busy workers.
  490. */
  491. static struct btrfs_worker_thread *find_worker(struct btrfs_workers *workers)
  492. {
  493. struct btrfs_worker_thread *worker;
  494. unsigned long flags;
  495. struct list_head *fallback;
  496. int ret;
  497. spin_lock_irqsave(&workers->lock, flags);
  498. again:
  499. worker = next_worker(workers);
  500. if (!worker) {
  501. if (workers->num_workers + workers->num_workers_starting >=
  502. workers->max_workers) {
  503. goto fallback;
  504. } else if (workers->atomic_worker_start) {
  505. workers->atomic_start_pending = 1;
  506. goto fallback;
  507. } else {
  508. workers->num_workers_starting++;
  509. spin_unlock_irqrestore(&workers->lock, flags);
  510. /* we're below the limit, start another worker */
  511. ret = __btrfs_start_workers(workers);
  512. spin_lock_irqsave(&workers->lock, flags);
  513. if (ret)
  514. goto fallback;
  515. goto again;
  516. }
  517. }
  518. goto found;
  519. fallback:
  520. fallback = NULL;
  521. /*
  522. * we have failed to find any workers, just
  523. * return the first one we can find.
  524. */
  525. if (!list_empty(&workers->worker_list))
  526. fallback = workers->worker_list.next;
  527. if (!list_empty(&workers->idle_list))
  528. fallback = workers->idle_list.next;
  529. BUG_ON(!fallback);
  530. worker = list_entry(fallback,
  531. struct btrfs_worker_thread, worker_list);
  532. found:
  533. /*
  534. * this makes sure the worker doesn't exit before it is placed
  535. * onto a busy/idle list
  536. */
  537. atomic_inc(&worker->num_pending);
  538. spin_unlock_irqrestore(&workers->lock, flags);
  539. return worker;
  540. }
  541. /*
  542. * btrfs_requeue_work just puts the work item back on the tail of the list
  543. * it was taken from. It is intended for use with long running work functions
  544. * that make some progress and want to give the cpu up for others.
  545. */
  546. void btrfs_requeue_work(struct btrfs_work *work)
  547. {
  548. struct btrfs_worker_thread *worker = work->worker;
  549. unsigned long flags;
  550. int wake = 0;
  551. if (test_and_set_bit(WORK_QUEUED_BIT, &work->flags))
  552. return;
  553. spin_lock_irqsave(&worker->lock, flags);
  554. if (test_bit(WORK_HIGH_PRIO_BIT, &work->flags))
  555. list_add_tail(&work->list, &worker->prio_pending);
  556. else
  557. list_add_tail(&work->list, &worker->pending);
  558. atomic_inc(&worker->num_pending);
  559. /* by definition we're busy, take ourselves off the idle
  560. * list
  561. */
  562. if (worker->idle) {
  563. spin_lock(&worker->workers->lock);
  564. worker->idle = 0;
  565. list_move_tail(&worker->worker_list,
  566. &worker->workers->worker_list);
  567. spin_unlock(&worker->workers->lock);
  568. }
  569. if (!worker->working) {
  570. wake = 1;
  571. worker->working = 1;
  572. }
  573. if (wake)
  574. wake_up_process(worker->task);
  575. spin_unlock_irqrestore(&worker->lock, flags);
  576. }
  577. void btrfs_set_work_high_prio(struct btrfs_work *work)
  578. {
  579. set_bit(WORK_HIGH_PRIO_BIT, &work->flags);
  580. }
  581. /*
  582. * places a struct btrfs_work into the pending queue of one of the kthreads
  583. */
  584. void btrfs_queue_worker(struct btrfs_workers *workers, struct btrfs_work *work)
  585. {
  586. struct btrfs_worker_thread *worker;
  587. unsigned long flags;
  588. int wake = 0;
  589. /* don't requeue something already on a list */
  590. if (test_and_set_bit(WORK_QUEUED_BIT, &work->flags))
  591. return;
  592. worker = find_worker(workers);
  593. if (workers->ordered) {
  594. /*
  595. * you're not allowed to do ordered queues from an
  596. * interrupt handler
  597. */
  598. spin_lock(&workers->order_lock);
  599. if (test_bit(WORK_HIGH_PRIO_BIT, &work->flags)) {
  600. list_add_tail(&work->order_list,
  601. &workers->prio_order_list);
  602. } else {
  603. list_add_tail(&work->order_list, &workers->order_list);
  604. }
  605. spin_unlock(&workers->order_lock);
  606. } else {
  607. INIT_LIST_HEAD(&work->order_list);
  608. }
  609. spin_lock_irqsave(&worker->lock, flags);
  610. if (test_bit(WORK_HIGH_PRIO_BIT, &work->flags))
  611. list_add_tail(&work->list, &worker->prio_pending);
  612. else
  613. list_add_tail(&work->list, &worker->pending);
  614. check_busy_worker(worker);
  615. /*
  616. * avoid calling into wake_up_process if this thread has already
  617. * been kicked
  618. */
  619. if (!worker->working)
  620. wake = 1;
  621. worker->working = 1;
  622. if (wake)
  623. wake_up_process(worker->task);
  624. spin_unlock_irqrestore(&worker->lock, flags);
  625. }