aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/workqueue.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2010-06-29 04:07:13 -0400
committerTejun Heo <tj@kernel.org>2010-06-29 04:07:13 -0400
commitd302f0178223802a1e496ba90c66193b7721c9c1 (patch)
treed9282d8a6a69b6b5b1db9fbe97301f6338af8752 /kernel/workqueue.c
parent7e11629d0efec829cbf62366143ba1081944a70e (diff)
workqueue: implement worker_{set|clr}_flags()
Implement worker_{set|clr}_flags() to manipulate worker flags. These are currently simple wrappers but logics to track the current worker state and the current level of concurrency will be added. Signed-off-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'kernel/workqueue.c')
-rw-r--r--kernel/workqueue.c48
1 files changed, 40 insertions, 8 deletions
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index e697d6c72daa..4c31fde092c6 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -412,6 +412,38 @@ static void wake_up_worker(struct global_cwq *gcwq)
412} 412}
413 413
414/** 414/**
415 * worker_set_flags - set worker flags
416 * @worker: worker to set flags for
417 * @flags: flags to set
418 * @wakeup: wakeup an idle worker if necessary
419 *
420 * Set @flags in @worker->flags.
421 *
422 * LOCKING:
423 * spin_lock_irq(gcwq->lock).
424 */
425static inline void worker_set_flags(struct worker *worker, unsigned int flags,
426 bool wakeup)
427{
428 worker->flags |= flags;
429}
430
431/**
432 * worker_clr_flags - clear worker flags
433 * @worker: worker to set flags for
434 * @flags: flags to clear
435 *
436 * Clear @flags in @worker->flags.
437 *
438 * LOCKING:
439 * spin_lock_irq(gcwq->lock).
440 */
441static inline void worker_clr_flags(struct worker *worker, unsigned int flags)
442{
443 worker->flags &= ~flags;
444}
445
446/**
415 * busy_worker_head - return the busy hash head for a work 447 * busy_worker_head - return the busy hash head for a work
416 * @gcwq: gcwq of interest 448 * @gcwq: gcwq of interest
417 * @work: work to be hashed 449 * @work: work to be hashed
@@ -776,7 +808,7 @@ static void worker_enter_idle(struct worker *worker)
776 BUG_ON(!list_empty(&worker->entry) && 808 BUG_ON(!list_empty(&worker->entry) &&
777 (worker->hentry.next || worker->hentry.pprev)); 809 (worker->hentry.next || worker->hentry.pprev));
778 810
779 worker->flags |= WORKER_IDLE; 811 worker_set_flags(worker, WORKER_IDLE, false);
780 gcwq->nr_idle++; 812 gcwq->nr_idle++;
781 813
782 /* idle_list is LIFO */ 814 /* idle_list is LIFO */
@@ -800,7 +832,7 @@ static void worker_leave_idle(struct worker *worker)
800 struct global_cwq *gcwq = worker->gcwq; 832 struct global_cwq *gcwq = worker->gcwq;
801 833
802 BUG_ON(!(worker->flags & WORKER_IDLE)); 834 BUG_ON(!(worker->flags & WORKER_IDLE));
803 worker->flags &= ~WORKER_IDLE; 835 worker_clr_flags(worker, WORKER_IDLE);
804 gcwq->nr_idle--; 836 gcwq->nr_idle--;
805 list_del_init(&worker->entry); 837 list_del_init(&worker->entry);
806} 838}
@@ -890,7 +922,7 @@ fail:
890 */ 922 */
891static void start_worker(struct worker *worker) 923static void start_worker(struct worker *worker)
892{ 924{
893 worker->flags |= WORKER_STARTED; 925 worker_set_flags(worker, WORKER_STARTED, false);
894 worker->gcwq->nr_workers++; 926 worker->gcwq->nr_workers++;
895 worker_enter_idle(worker); 927 worker_enter_idle(worker);
896 wake_up_process(worker->task); 928 wake_up_process(worker->task);
@@ -920,7 +952,7 @@ static void destroy_worker(struct worker *worker)
920 gcwq->nr_idle--; 952 gcwq->nr_idle--;
921 953
922 list_del_init(&worker->entry); 954 list_del_init(&worker->entry);
923 worker->flags |= WORKER_DIE; 955 worker_set_flags(worker, WORKER_DIE, false);
924 956
925 spin_unlock_irq(&gcwq->lock); 957 spin_unlock_irq(&gcwq->lock);
926 958
@@ -2214,10 +2246,10 @@ static int __cpuinit trustee_thread(void *__gcwq)
2214 BUG_ON(gcwq->cpu != smp_processor_id()); 2246 BUG_ON(gcwq->cpu != smp_processor_id());
2215 2247
2216 list_for_each_entry(worker, &gcwq->idle_list, entry) 2248 list_for_each_entry(worker, &gcwq->idle_list, entry)
2217 worker->flags |= WORKER_ROGUE; 2249 worker_set_flags(worker, WORKER_ROGUE, false);
2218 2250
2219 for_each_busy_worker(worker, i, pos, gcwq) 2251 for_each_busy_worker(worker, i, pos, gcwq)
2220 worker->flags |= WORKER_ROGUE; 2252 worker_set_flags(worker, WORKER_ROGUE, false);
2221 2253
2222 /* 2254 /*
2223 * We're now in charge. Notify and proceed to drain. We need 2255 * We're now in charge. Notify and proceed to drain. We need
@@ -2324,10 +2356,10 @@ static int __devinit workqueue_cpu_callback(struct notifier_block *nfb,
2324 2356
2325 /* clear ROGUE from all workers */ 2357 /* clear ROGUE from all workers */
2326 list_for_each_entry(worker, &gcwq->idle_list, entry) 2358 list_for_each_entry(worker, &gcwq->idle_list, entry)
2327 worker->flags &= ~WORKER_ROGUE; 2359 worker_clr_flags(worker, WORKER_ROGUE);
2328 2360
2329 for_each_busy_worker(worker, i, pos, gcwq) 2361 for_each_busy_worker(worker, i, pos, gcwq)
2330 worker->flags &= ~WORKER_ROGUE; 2362 worker_clr_flags(worker, WORKER_ROGUE);
2331 break; 2363 break;
2332 } 2364 }
2333 2365