Re: [PATCH 19/21] workqueue: introduce worker

Tejun Heo
2009-11-17T16:27:03Z

Hello,

11/17/2009 08:51 PM, Louis Rilling wrote:
>>> +static struct worker *create_worker(struct cpu_workqueue_struct *cwq, bool bind)
>>> +{
>>> + int id = -1;
>>> + struct worker *worker = NULL;
>>> +
>>> + spin_lock(&workqueue_lock);
>>> + while (ida_get_new(&per_cpu(worker_ida, cwq->cpu), &id)) {
>>> + spin_unlock_irq(&workqueue_lock);
>>> + if (!ida_pre_get(&per_cpu(worker_ida, cwq->cpu), GFP_KERNEL))
>>> + goto fail;
>>> + spin_lock(&workqueue_lock);
>>> + }
>>> + spin_unlock_irq(&workqueue_lock);
>>> +
>>> + worker = alloc_worker();
>>> + if (!worker)
>>> + goto fail;
>>> +
>>> + worker->cwq = cwq;
>>> + worker->id = id;
>>> +
>>> + worker->task = kthread_create(worker_thread, worker, "kworker/%u:%d",
>>> + cwq->cpu, id);
>>> + if (IS_ERR(worker->task))
>>> + goto fail;
>>> +
>>> + if (bind)
>>> + kthread_bind(worker->task, cwq->cpu);
>>> +
>>> + return worker;
>>> +fail:
>>> + if (id >= 0) {
>>> + spin_lock(&workqueue_lock);
>>> + ida_remove(&per_cpu(worker_ida, cwq->cpu), id);
>>> + spin_unlock_irq(&workqueue_lock);
>>> + }
>>> + kfree(worker);
>>> + return NULL;
>>> +}
>>
>> AFAIU create_worker() should call spin_lock_irq() instead of spin_lock().
>
> spin_unlock() instead of spin_unlock_irq() looks better in fact ;).

Oooh... right, thanks for spotting that. I'll fix it up.

--
tejun