lkml.org 
[lkml]   [2010]   [Jul]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH 27/35] workqueue: implement concurrency managed dynamic worker pool
On Mon, Jun 28, 2010 at 11:04:15PM +0200, Tejun Heo wrote:
> +static bool maybe_create_worker(struct global_cwq *gcwq)
> +{
> + if (!need_to_create_worker(gcwq))
> + return false;
> +restart:
> + /* if we don't make progress in MAYDAY_INITIAL_TIMEOUT, call for help */
> + mod_timer(&gcwq->mayday_timer, jiffies + MAYDAY_INITIAL_TIMEOUT);
> +
> + while (true) {
> + struct worker *worker;
> +
> + spin_unlock_irq(&gcwq->lock);
> +
> + worker = create_worker(gcwq, true);
> + if (worker) {
> + del_timer_sync(&gcwq->mayday_timer);
> + spin_lock_irq(&gcwq->lock);
> + start_worker(worker);
> + BUG_ON(need_to_create_worker(gcwq));
> + return true;
> + }
> +
> + if (!need_to_create_worker(gcwq))
> + break;
> +
> + spin_unlock_irq(&gcwq->lock);
> + __set_current_state(TASK_INTERRUPTIBLE);
> + schedule_timeout(CREATE_COOLDOWN);
> + spin_lock_irq(&gcwq->lock);
> + if (!need_to_create_worker(gcwq))
> + break;
> + }
> +
> + spin_unlock_irq(&gcwq->lock);

A little worried about the lock operation. We may call spin_unlock_irq() twice
under some special situation. Couldn't that happen? Or Am I missing something?

And a rough patch for this issue if needed:
---
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 2eb9fbd..84a9cb9 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -1427,10 +1427,11 @@ restart:
return true;
}

- if (!need_to_create_worker(gcwq))
+ if (!need_to_create_worker(gcwq)) {
+ spin_lock_irq(&gcwq->lock);
break;
+ }

- spin_unlock_irq(&gcwq->lock);
__set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(CREATE_COOLDOWN);
spin_lock_irq(&gcwq->lock);
> + del_timer_sync(&gcwq->mayday_timer);
> + spin_lock_irq(&gcwq->lock);
> + if (need_to_create_worker(gcwq))
> + goto restart;
> + return true;
> +}
> +


\
 
 \ /
  Last update: 2010-07-09 11:17    [W:0.430 / U:0.276 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site