async-thread.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  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. goto out;
  225. }
  226. smp_mb();
  227. if (!list_empty(&worker->prio_pending))
  228. goto refill;
  229. if (!list_empty(head)) {
  230. cur = head->next;
  231. goto out;
  232. }
  233. refill:
  234. spin_lock_irq(&worker->lock);
  235. list_splice_tail_init(&worker->prio_pending, prio_head);
  236. list_splice_tail_init(&worker->pending, head);
  237. if (!list_empty(prio_head))
  238. cur = prio_head->next;
  239. else if (!list_empty(head))
  240. cur = head->next;
  241. spin_unlock_irq(&worker->lock);
  242. if (!cur)
  243. goto out_fail;
  244. out:
  245. work = list_entry(cur, struct btrfs_work, list);
  246. out_fail:
  247. return work;
  248. }
  249. /*
  250. * main loop for servicing work items
  251. */
  252. static int worker_loop(void *arg)
  253. {
  254. struct btrfs_worker_thread *worker = arg;
  255. struct list_head head;
  256. struct list_head prio_head;
  257. struct btrfs_work *work;
  258. INIT_LIST_HEAD(&head);
  259. INIT_LIST_HEAD(&prio_head);
  260. do {
  261. again:
  262. while (1) {
  263. work = get_next_work(worker, &prio_head, &head);
  264. if (!work)
  265. break;
  266. list_del(&work->list);
  267. clear_bit(WORK_QUEUED_BIT, &work->flags);
  268. work->worker = worker;
  269. work->func(work);
  270. atomic_dec(&worker->num_pending);
  271. /*
  272. * unless this is an ordered work queue,
  273. * 'work' was probably freed by func above.
  274. */
  275. run_ordered_completions(worker->workers, work);
  276. check_pending_worker_creates(worker);
  277. cond_resched();
  278. }
  279. spin_lock_irq(&worker->lock);
  280. check_idle_worker(worker);
  281. if (freezing(current)) {
  282. worker->working = 0;
  283. spin_unlock_irq(&worker->lock);
  284. try_to_freeze();
  285. } else {
  286. spin_unlock_irq(&worker->lock);
  287. if (!kthread_should_stop()) {
  288. cpu_relax();
  289. /*
  290. * we've dropped the lock, did someone else
  291. * jump_in?
  292. */
  293. smp_mb();
  294. if (!list_empty(&worker->pending) ||
  295. !list_empty(&worker->prio_pending))
  296. continue;
  297. /*
  298. * this short schedule allows more work to
  299. * come in without the queue functions
  300. * needing to go through wake_up_process()
  301. *
  302. * worker->working is still 1, so nobody
  303. * is going to try and wake us up
  304. */
  305. schedule_timeout(1);
  306. smp_mb();
  307. if (!list_empty(&worker->pending) ||
  308. !list_empty(&worker->prio_pending))
  309. continue;
  310. if (kthread_should_stop())
  311. break;
  312. /* still no more work?, sleep for real */
  313. spin_lock_irq(&worker->lock);
  314. set_current_state(TASK_INTERRUPTIBLE);
  315. if (!list_empty(&worker->pending) ||
  316. !list_empty(&worker->prio_pending)) {
  317. spin_unlock_irq(&worker->lock);
  318. set_current_state(TASK_RUNNING);
  319. goto again;
  320. }
  321. /*
  322. * this makes sure we get a wakeup when someone
  323. * adds something new to the queue
  324. */
  325. worker->working = 0;
  326. spin_unlock_irq(&worker->lock);
  327. if (!kthread_should_stop()) {
  328. schedule_timeout(HZ * 120);
  329. if (!worker->working &&
  330. try_worker_shutdown(worker)) {
  331. return 0;
  332. }
  333. }
  334. }
  335. __set_current_state(TASK_RUNNING);
  336. }
  337. } while (!kthread_should_stop());
  338. return 0;
  339. }
  340. /*
  341. * this will wait for all the worker threads to shutdown
  342. */
  343. void btrfs_stop_workers(struct btrfs_workers *workers)
  344. {
  345. struct list_head *cur;
  346. struct btrfs_worker_thread *worker;
  347. int can_stop;
  348. spin_lock_irq(&workers->lock);
  349. workers->stopping = 1;
  350. list_splice_init(&workers->idle_list, &workers->worker_list);
  351. while (!list_empty(&workers->worker_list)) {
  352. cur = workers->worker_list.next;
  353. worker = list_entry(cur, struct btrfs_worker_thread,
  354. worker_list);
  355. atomic_inc(&worker->refs);
  356. workers->num_workers -= 1;
  357. if (!list_empty(&worker->worker_list)) {
  358. list_del_init(&worker->worker_list);
  359. put_worker(worker);
  360. can_stop = 1;
  361. } else
  362. can_stop = 0;
  363. spin_unlock_irq(&workers->lock);
  364. if (can_stop)
  365. kthread_stop(worker->task);
  366. spin_lock_irq(&workers->lock);
  367. put_worker(worker);
  368. }
  369. spin_unlock_irq(&workers->lock);
  370. }
  371. /*
  372. * simple init on struct btrfs_workers
  373. */
  374. void btrfs_init_workers(struct btrfs_workers *workers, char *name, int max,
  375. struct btrfs_workers *async_helper)
  376. {
  377. workers->num_workers = 0;
  378. workers->num_workers_starting = 0;
  379. INIT_LIST_HEAD(&workers->worker_list);
  380. INIT_LIST_HEAD(&workers->idle_list);
  381. INIT_LIST_HEAD(&workers->order_list);
  382. INIT_LIST_HEAD(&workers->prio_order_list);
  383. spin_lock_init(&workers->lock);
  384. spin_lock_init(&workers->order_lock);
  385. workers->max_workers = max;
  386. workers->idle_thresh = 32;
  387. workers->name = name;
  388. workers->ordered = 0;
  389. workers->atomic_start_pending = 0;
  390. workers->atomic_worker_start = async_helper;
  391. workers->stopping = 0;
  392. }
  393. /*
  394. * starts new worker threads. This does not enforce the max worker
  395. * count in case you need to temporarily go past it.
  396. */
  397. static int __btrfs_start_workers(struct btrfs_workers *workers)
  398. {
  399. struct btrfs_worker_thread *worker;
  400. int ret = 0;
  401. worker = kzalloc(sizeof(*worker), GFP_NOFS);
  402. if (!worker) {
  403. ret = -ENOMEM;
  404. goto fail;
  405. }
  406. INIT_LIST_HEAD(&worker->pending);
  407. INIT_LIST_HEAD(&worker->prio_pending);
  408. INIT_LIST_HEAD(&worker->worker_list);
  409. spin_lock_init(&worker->lock);
  410. atomic_set(&worker->num_pending, 0);
  411. atomic_set(&worker->refs, 1);
  412. worker->workers = workers;
  413. worker->task = kthread_create(worker_loop, worker,
  414. "btrfs-%s-%d", workers->name,
  415. workers->num_workers + 1);
  416. if (IS_ERR(worker->task)) {
  417. ret = PTR_ERR(worker->task);
  418. goto fail;
  419. }
  420. spin_lock_irq(&workers->lock);
  421. if (workers->stopping) {
  422. spin_unlock_irq(&workers->lock);
  423. ret = -EINVAL;
  424. goto fail_kthread;
  425. }
  426. list_add_tail(&worker->worker_list, &workers->idle_list);
  427. worker->idle = 1;
  428. workers->num_workers++;
  429. workers->num_workers_starting--;
  430. WARN_ON(workers->num_workers_starting < 0);
  431. spin_unlock_irq(&workers->lock);
  432. wake_up_process(worker->task);
  433. return 0;
  434. fail_kthread:
  435. kthread_stop(worker->task);
  436. fail:
  437. kfree(worker);
  438. spin_lock_irq(&workers->lock);
  439. workers->num_workers_starting--;
  440. spin_unlock_irq(&workers->lock);
  441. return ret;
  442. }
  443. int btrfs_start_workers(struct btrfs_workers *workers)
  444. {
  445. spin_lock_irq(&workers->lock);
  446. workers->num_workers_starting++;
  447. spin_unlock_irq(&workers->lock);
  448. return __btrfs_start_workers(workers);
  449. }
  450. /*
  451. * run through the list and find a worker thread that doesn't have a lot
  452. * to do right now. This can return null if we aren't yet at the thread
  453. * count limit and all of the threads are busy.
  454. */
  455. static struct btrfs_worker_thread *next_worker(struct btrfs_workers *workers)
  456. {
  457. struct btrfs_worker_thread *worker;
  458. struct list_head *next;
  459. int enforce_min;
  460. enforce_min = (workers->num_workers + workers->num_workers_starting) <
  461. workers->max_workers;
  462. /*
  463. * if we find an idle thread, don't move it to the end of the
  464. * idle list. This improves the chance that the next submission
  465. * will reuse the same thread, and maybe catch it while it is still
  466. * working
  467. */
  468. if (!list_empty(&workers->idle_list)) {
  469. next = workers->idle_list.next;
  470. worker = list_entry(next, struct btrfs_worker_thread,
  471. worker_list);
  472. return worker;
  473. }
  474. if (enforce_min || list_empty(&workers->worker_list))
  475. return NULL;
  476. /*
  477. * if we pick a busy task, move the task to the end of the list.
  478. * hopefully this will keep things somewhat evenly balanced.
  479. * Do the move in batches based on the sequence number. This groups
  480. * requests submitted at roughly the same time onto the same worker.
  481. */
  482. next = workers->worker_list.next;
  483. worker = list_entry(next, struct btrfs_worker_thread, worker_list);
  484. worker->sequence++;
  485. if (worker->sequence % workers->idle_thresh == 0)
  486. list_move_tail(next, &workers->worker_list);
  487. return worker;
  488. }
  489. /*
  490. * selects a worker thread to take the next job. This will either find
  491. * an idle worker, start a new worker up to the max count, or just return
  492. * one of the existing busy workers.
  493. */
  494. static struct btrfs_worker_thread *find_worker(struct btrfs_workers *workers)
  495. {
  496. struct btrfs_worker_thread *worker;
  497. unsigned long flags;
  498. struct list_head *fallback;
  499. int ret;
  500. spin_lock_irqsave(&workers->lock, flags);
  501. again:
  502. worker = next_worker(workers);
  503. if (!worker) {
  504. if (workers->num_workers + workers->num_workers_starting >=
  505. workers->max_workers) {
  506. goto fallback;
  507. } else if (workers->atomic_worker_start) {
  508. workers->atomic_start_pending = 1;
  509. goto fallback;
  510. } else {
  511. workers->num_workers_starting++;
  512. spin_unlock_irqrestore(&workers->lock, flags);
  513. /* we're below the limit, start another worker */
  514. ret = __btrfs_start_workers(workers);
  515. spin_lock_irqsave(&workers->lock, flags);
  516. if (ret)
  517. goto fallback;
  518. goto again;
  519. }
  520. }
  521. goto found;
  522. fallback:
  523. fallback = NULL;
  524. /*
  525. * we have failed to find any workers, just
  526. * return the first one we can find.
  527. */
  528. if (!list_empty(&workers->worker_list))
  529. fallback = workers->worker_list.next;
  530. if (!list_empty(&workers->idle_list))
  531. fallback = workers->idle_list.next;
  532. BUG_ON(!fallback);
  533. worker = list_entry(fallback,
  534. struct btrfs_worker_thread, worker_list);
  535. found:
  536. /*
  537. * this makes sure the worker doesn't exit before it is placed
  538. * onto a busy/idle list
  539. */
  540. atomic_inc(&worker->num_pending);
  541. spin_unlock_irqrestore(&workers->lock, flags);
  542. return worker;
  543. }
  544. /*
  545. * btrfs_requeue_work just puts the work item back on the tail of the list
  546. * it was taken from. It is intended for use with long running work functions
  547. * that make some progress and want to give the cpu up for others.
  548. */
  549. void btrfs_requeue_work(struct btrfs_work *work)
  550. {
  551. struct btrfs_worker_thread *worker = work->worker;
  552. unsigned long flags;
  553. int wake = 0;
  554. if (test_and_set_bit(WORK_QUEUED_BIT, &work->flags))
  555. return;
  556. spin_lock_irqsave(&worker->lock, flags);
  557. if (test_bit(WORK_HIGH_PRIO_BIT, &work->flags))
  558. list_add_tail(&work->list, &worker->prio_pending);
  559. else
  560. list_add_tail(&work->list, &worker->pending);
  561. atomic_inc(&worker->num_pending);
  562. /* by definition we're busy, take ourselves off the idle
  563. * list
  564. */
  565. if (worker->idle) {
  566. spin_lock(&worker->workers->lock);
  567. worker->idle = 0;
  568. list_move_tail(&worker->worker_list,
  569. &worker->workers->worker_list);
  570. spin_unlock(&worker->workers->lock);
  571. }
  572. if (!worker->working) {
  573. wake = 1;
  574. worker->working = 1;
  575. }
  576. if (wake)
  577. wake_up_process(worker->task);
  578. spin_unlock_irqrestore(&worker->lock, flags);
  579. }
  580. void btrfs_set_work_high_prio(struct btrfs_work *work)
  581. {
  582. set_bit(WORK_HIGH_PRIO_BIT, &work->flags);
  583. }
  584. /*
  585. * places a struct btrfs_work into the pending queue of one of the kthreads
  586. */
  587. void btrfs_queue_worker(struct btrfs_workers *workers, struct btrfs_work *work)
  588. {
  589. struct btrfs_worker_thread *worker;
  590. unsigned long flags;
  591. int wake = 0;
  592. /* don't requeue something already on a list */
  593. if (test_and_set_bit(WORK_QUEUED_BIT, &work->flags))
  594. return;
  595. worker = find_worker(workers);
  596. if (workers->ordered) {
  597. /*
  598. * you're not allowed to do ordered queues from an
  599. * interrupt handler
  600. */
  601. spin_lock(&workers->order_lock);
  602. if (test_bit(WORK_HIGH_PRIO_BIT, &work->flags)) {
  603. list_add_tail(&work->order_list,
  604. &workers->prio_order_list);
  605. } else {
  606. list_add_tail(&work->order_list, &workers->order_list);
  607. }
  608. spin_unlock(&workers->order_lock);
  609. } else {
  610. INIT_LIST_HEAD(&work->order_list);
  611. }
  612. spin_lock_irqsave(&worker->lock, flags);
  613. if (test_bit(WORK_HIGH_PRIO_BIT, &work->flags))
  614. list_add_tail(&work->list, &worker->prio_pending);
  615. else
  616. list_add_tail(&work->list, &worker->pending);
  617. check_busy_worker(worker);
  618. /*
  619. * avoid calling into wake_up_process if this thread has already
  620. * been kicked
  621. */
  622. if (!worker->working)
  623. wake = 1;
  624. worker->working = 1;
  625. if (wake)
  626. wake_up_process(worker->task);
  627. spin_unlock_irqrestore(&worker->lock, flags);
  628. }