mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Louis Rilling <Louis.Rilling@kerlabs.com>
To: Tejun Heo <tj@kernel.org>
Cc: linux-kernel@vger.kernel.org, jeff@garzik.org, mingo@elte.hu,
	akpm@linux-foundation.org, jens.axboe@oracle.com,
	rusty@rustcorp.com.au, cl@linux-foundation.org,
	dhowells@redhat.com, arjan@linux.intel.com,
	torvalds@linux-foundation.org, avi@redhat.com,
	peterz@infradead.org, andi@firstfloor.org, fweisbec@gmail.com
Subject: Re: [PATCH 19/21] workqueue: introduce worker
Date: Tue, 17 Nov 2009 12:51:37 +0100	[thread overview]
Message-ID: <20091117115137.GL4379@hawkmoon.kerlabs.com> (raw)
In-Reply-To: <20091117113952.GK4379@hawkmoon.kerlabs.com>

[-- Attachment #1: Type: text/plain, Size: 3259 bytes --]

On 17/11/09 12:39 +0100, Louis Rilling wrote:
> Hi Tejun,
> 
> On 17/11/09  2:15 +0900, Tejun Heo wrote:
> > Separate out worker thread related information to struct worker from
> > struct cpu_workqueue_struct and implement helper functions to deal
> > with the new struct worker.  The only change which is visible outside
> > is that now workqueue worker are all named "kworker/CPUID:WORKERID"
> > where WORKERID is allocated from per-cpu ida.
> > 
> > This is in preparation of concurrency managed workqueue where shared
> > multiple workers would be available per cpu.
> > 
> > Signed-off-by: Tejun Heo <tj@kernel.org>
> > ---
> >  kernel/workqueue.c |  219 +++++++++++++++++++++++++++++++++++++---------------
> >  1 files changed, 157 insertions(+), 62 deletions(-)
> > 
> > diff --git a/kernel/workqueue.c b/kernel/workqueue.c
> > index dce5ad5..6694b3e 100644
> > --- a/kernel/workqueue.c
> > +++ b/kernel/workqueue.c
> 
> [...]
> 
> > @@ -413,6 +426,105 @@ int queue_delayed_work_on(int cpu, struct workqueue_struct *wq,
> >  }
> >  EXPORT_SYMBOL_GPL(queue_delayed_work_on);
> >  
> > +static struct worker *alloc_worker(void)
> > +{
> > +	struct worker *worker;
> > +
> > +	worker = kzalloc(sizeof(*worker), GFP_KERNEL);
> > +	return worker;
> > +}
> > +
> > +/**
> > + * create_worker - create a new workqueue worker
> > + * @cwq: cwq the new worker will belong to
> > + * @bind: whether to set affinity to @cpu or not
> > + *
> > + * Create a new worker which is bound to @cwq.  The returned worker
> > + * can be started by calling start_worker() or destroyed using
> > + * destroy_worker().
> > + *
> > + * CONTEXT:
> > + * Might sleep.  Does GFP_KERNEL allocations.
> > + *
> > + * RETURNS:
> > + * Pointer to the newly created worker.
> > + */
> > +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 ;).

Louis

-- 
Dr Louis Rilling			Kerlabs
Skype: louis.rilling			Batiment Germanium
Phone: (+33|0) 6 80 89 08 23		80 avenue des Buttes de Coesmes
http://www.kerlabs.com/			35700 Rennes

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

  reply	other threads:[~2009-11-17 11:51 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-16 17:15 [PATCHSET] workqueue: prepare for concurrency managed workqueue Tejun Heo
2009-11-16 17:15 ` [PATCH 01/21] workqueue: fix race condition in schedule_on_each_cpu() Tejun Heo
2009-11-16 23:04   ` Frederic Weisbecker
2009-11-17  0:08     ` Tejun Heo
2009-11-17  7:04     ` Avi Kivity
2009-11-17 16:16       ` Tejun Heo
2009-11-16 17:15 ` [PATCH 02/21] sched, kvm: fix race condition involving sched_in_preempt_notifers Tejun Heo
2009-11-16 17:15 ` [PATCH 03/21] workqueue: Add debugobjects support Tejun Heo
2009-11-16 17:15 ` [PATCH 04/21] sched: implement scheduler notifiers Tejun Heo
2009-11-16 18:31   ` Avi Kivity
2009-11-16 18:43     ` Tejun Heo
2009-11-16 18:41   ` Peter Zijlstra
2009-11-16 18:54     ` Tejun Heo
2009-11-16 20:29       ` Peter Zijlstra
2009-11-17 16:16         ` Tejun Heo
2009-11-16 17:15 ` [PATCH 05/21] kvm: convert kvm to use new " Tejun Heo
2009-11-16 17:15 ` [PATCH 06/21] sched: drop preempt notifiers Tejun Heo
2009-11-16 17:15 ` [PATCH 07/21] sched: implement sched_notifier_wake_up_process() Tejun Heo
2009-11-16 17:15 ` [PATCH 08/21] scheduler: implement force_cpus_allowed_ptr() Tejun Heo
2009-11-17  5:14   ` Rusty Russell
2009-11-17  5:19     ` Tejun Heo
2009-11-16 17:15 ` [PATCH 09/21] acpi: use queue_work_on() instead of binding workqueue worker to cpu0 Tejun Heo
2009-11-16 17:15 ` [PATCH 10/21] stop_machine: reimplement without using workqueue Tejun Heo
2009-11-16 17:15 ` [PATCH 11/21] workqueue: misc/cosmetic updates Tejun Heo
2009-11-16 17:15 ` [PATCH 12/21] workqueue: merge feature parametesr into flags Tejun Heo
2009-11-16 17:15 ` [PATCH 13/21] workqueue: update cwq alignement and make one more flag bit available Tejun Heo
2009-11-16 17:15 ` [PATCH 14/21] workqueue: define both bit position and mask for work flags Tejun Heo
2009-11-16 17:15 ` [PATCH 15/21] workqueue: separate out process_one_work() Tejun Heo
2009-11-16 17:15 ` [PATCH 16/21] workqueue: temporarily disable workqueue tracing Tejun Heo
2009-11-16 17:15 ` [PATCH 17/21] workqueue: simple reimplementation of SINGLE_THREAD workqueue Tejun Heo
2009-11-17  0:47   ` Andy Walls
2009-11-17  5:23     ` Tejun Heo
2009-11-17 12:05       ` Andy Walls
2009-11-17 16:21         ` Tejun Heo
2009-11-17 16:26           ` Hi ... I want to introduce myself :) Setiajie &#20313;&#40251;&#26124;
2009-11-17 15:05       ` [PATCH 17/21] workqueue: simple reimplementation of SINGLE_THREAD workqueue Linus Torvalds
2009-11-17 16:12         ` Tejun Heo
2009-11-17 19:01           ` Linus Torvalds
2009-11-17 14:03   ` Johannes Berg
2009-11-17 16:24     ` Tejun Heo
2009-11-16 17:15 ` [PATCH 18/21] workqueue: reimplement workqueue flushing using color coded works Tejun Heo
2009-11-16 17:15 ` [PATCH 19/21] workqueue: introduce worker Tejun Heo
2009-11-17 11:39   ` Louis Rilling
2009-11-17 11:51     ` Louis Rilling [this message]
2009-11-17 16:25       ` Tejun Heo
2009-11-16 17:15 ` [PATCH 20/21] workqueue: reimplement work flushing using linked works Tejun Heo
2009-11-16 17:15 ` [PATCH 21/21] workqueue: reimplement workqueue freeze using cwq->frozen_works queue Tejun Heo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091117115137.GL4379@hawkmoon.kerlabs.com \
    --to=louis.rilling@kerlabs.com \
    --cc=akpm@linux-foundation.org \
    --cc=andi@firstfloor.org \
    --cc=arjan@linux.intel.com \
    --cc=avi@redhat.com \
    --cc=cl@linux-foundation.org \
    --cc=dhowells@redhat.com \
    --cc=fweisbec@gmail.com \
    --cc=jeff@garzik.org \
    --cc=jens.axboe@oracle.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    --cc=rusty@rustcorp.com.au \
    --cc=tj@kernel.org \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®