async-thread.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  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. ret = -EINVAL;
  422. goto fail_kthread;
  423. }
  424. list_add_tail(&worker->worker_list, &workers->idle_list);
  425. worker->idle = 1;
  426. workers->num_workers++;
  427. workers->num_workers_starting--;
  428. WARN_ON(workers->num_workers_starting < 0);
  429. spin_unlock_irq(&workers->lock);
  430. wake_up_process(worker->task);
  431. return 0;
  432. fail_kthread:
  433. kthread_stop(worker->task);
  434. fail:
  435. kfree(worker);
  436. spin_lock_irq(&workers->lock);
  437. workers->num_workers_starting--;
  438. spin_unlock_irq(&workers->lock);
  439. return ret;
  440. }
  441. int btrfs_start_workers(struct btrfs_workers *workers)
  442. {
  443. spin_lock_irq(&workers->lock);
  444. workers->num_workers_starting++;
  445. spin_unlock_irq(&workers->lock);
  446. return __btrfs_start_workers(workers);
  447. }
  448. /*
  449. * run through the list and find a worker thread that doesn't have a lot
  450. * to do right now. This can return null if we aren't yet at the thread
  451. * count limit and all of the threads are busy.
  452. */
  453. static struct btrfs_worker_thread *next_worker(struct btrfs_workers *workers)
  454. {
  455. struct btrfs_worker_thread *worker;
  456. struct list_head *next;
  457. int enforce_min;
  458. enforce_min = (workers->num_workers + workers->num_workers_starting) <
  459. workers->max_workers;
  460. /*
  461. * if we find an idle thread, don't move it to the end of the
  462. * idle list. This improves the chance that the next submission
  463. * will reuse the same thread, and maybe catch it while it is still
  464. * working
  465. */
  466. if (!list_empty(&workers->idle_list)) {
  467. next = workers->idle_list.next;
  468. worker = list_entry(next, struct btrfs_worker_thread,
  469. worker_list);
  470. return worker;
  471. }
  472. if (enforce_min || list_empty(&workers->worker_list))
  473. return NULL;
  474. /*
  475. * if we pick a busy task, move the task to the end of the list.
  476. * hopefully this will keep things somewhat evenly balanced.
  477. * Do the move in batches based on the sequence number. This groups
  478. * requests submitted at roughly the same time onto the same worker.
  479. */
  480. next = workers->worker_list.next;
  481. worker = list_entry(next, struct btrfs_worker_thread, worker_list);
  482. worker->sequence++;
  483. if (worker->sequence % workers->idle_thresh == 0)
  484. list_move_tail(next, &workers->worker_list);
  485. return worker;
  486. }
  487. /*
  488. * selects a worker thread to take the next job. This will either find
  489. * an idle worker, start a new worker up to the max count, or just return
  490. * one of the existing busy workers.
  491. */
  492. static struct btrfs_worker_thread *find_worker(struct btrfs_workers *workers)
  493. {
  494. struct btrfs_worker_thread *worker;
  495. unsigned long flags;
  496. struct list_head *fallback;
  497. int ret;
  498. spin_lock_irqsave(&workers->lock, flags);
  499. again:
  500. worker = next_worker(workers);
  501. if (!worker) {
  502. if (workers->num_workers + workers->num_workers_starting >=
  503. workers->max_workers) {
  504. goto fallback;
  505. } else if (workers->atomic_worker_start) {
  506. workers->atomic_start_pending = 1;
  507. goto fallback;
  508. } else {
  509. workers->num_workers_starting++;
  510. spin_unlock_irqrestore(&workers->lock, flags);
  511. /* we're below the limit, start another worker */
  512. ret = __btrfs_start_workers(workers);
  513. spin_lock_irqsave(&workers->lock, flags);
  514. if (ret)
  515. goto fallback;
  516. goto again;
  517. }
  518. }
  519. goto found;
  520. fallback:
  521. fallback = NULL;
  522. /*
  523. * we have failed to find any workers, just
  524. * return the first one we can find.
  525. */
  526. if (!list_empty(&workers->worker_list))
  527. fallback = workers->worker_list.next;
  528. if (!list_empty(&workers->idle_list))
  529. fallback = workers->idle_list.next;
  530. BUG_ON(!fallback);
  531. worker = list_entry(fallback,
  532. struct btrfs_worker_thread, worker_list);
  533. found:
  534. /*
  535. * this makes sure the worker doesn't exit before it is placed
  536. * onto a busy/idle list
  537. */
  538. atomic_inc(&worker->num_pending);
  539. spin_unlock_irqrestore(&workers->lock, flags);
  540. return worker;
  541. }
  542. /*
  543. * btrfs_requeue_work just puts the work item back on the tail of the list
  544. * it was taken from. It is intended for use with long running work functions
  545. * that make some progress and want to give the cpu up for others.
  546. */
  547. void btrfs_requeue_work(struct btrfs_work *work)
  548. {
  549. struct btrfs_worker_thread *worker = work->worker;
  550. unsigned long flags;
  551. int wake = 0;
  552. if (test_and_set_bit(WORK_QUEUED_BIT, &work->flags))
  553. return;
  554. spin_lock_irqsave(&worker->lock, flags);
  555. if (test_bit(WORK_HIGH_PRIO_BIT, &work->flags))
  556. list_add_tail(&work->list, &worker->prio_pending);
  557. else
  558. list_add_tail(&work->list, &worker->pending);
  559. atomic_inc(&worker->num_pending);
  560. /* by definition we're busy, take ourselves off the idle
  561. * list
  562. */
  563. if (worker->idle) {
  564. spin_lock(&worker->workers->lock);
  565. worker->idle = 0;
  566. list_move_tail(&worker->worker_list,
  567. &worker->workers->worker_list);
  568. spin_unlock(&worker->workers->lock);
  569. }
  570. if (!worker->working) {
  571. wake = 1;
  572. worker->working = 1;
  573. }
  574. if (wake)
  575. wake_up_process(worker->task);
  576. spin_unlock_irqrestore(&worker->lock, flags);
  577. }
  578. void btrfs_set_work_high_prio(struct btrfs_work *work)
  579. {
  580. set_bit(WORK_HIGH_PRIO_BIT, &work->flags);
  581. }
  582. /*
  583. * places a struct btrfs_work into the pending queue of one of the kthreads
  584. */
  585. void btrfs_queue_worker(struct btrfs_workers *workers, struct btrfs_work *work)
  586. {
  587. struct btrfs_worker_thread *worker;
  588. unsigned long flags;
  589. int wake = 0;
  590. /* don't requeue something already on a list */
  591. if (test_and_set_bit(WORK_QUEUED_BIT, &work->flags))
  592. return;
  593. worker = find_worker(workers);
  594. if (workers->ordered) {
  595. /*
  596. * you're not allowed to do ordered queues from an
  597. * interrupt handler
  598. */
  599. spin_lock(&workers->order_lock);
  600. if (test_bit(WORK_HIGH_PRIO_BIT, &work->flags)) {
  601. list_add_tail(&work->order_list,
  602. &workers->prio_order_list);
  603. } else {
  604. list_add_tail(&work->order_list, &workers->order_list);
  605. }
  606. spin_unlock(&workers->order_lock);
  607. } else {
  608. INIT_LIST_HEAD(&work->order_list);
  609. }
  610. spin_lock_irqsave(&worker->lock, flags);
  611. if (test_bit(WORK_HIGH_PRIO_BIT, &work->flags))
  612. list_add_tail(&work->list, &worker->prio_pending);
  613. else
  614. list_add_tail(&work->list, &worker->pending);
  615. check_busy_worker(worker);
  616. /*
  617. * avoid calling into wake_up_process if this thread has already
  618. * been kicked
  619. */
  620. if (!worker->working)
  621. wake = 1;
  622. worker->working = 1;
  623. if (wake)
  624. wake_up_process(worker->task);
  625. spin_unlock_irqrestore(&worker->lock, flags);
  626. }