From: Tejun Heo <tj@kernel.org>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: LKML <linux-kernel@vger.kernel.org>
Subject: Re: workqueue_set_max_active(wq, 0)?
Date: Thu, 15 Dec 2011 10:35:37 -0800 [thread overview]
Message-ID: <20111215183537.GA32002@google.com> (raw)
In-Reply-To: <1323963492.23550.1.camel@jlt3.sipsolutions.net>
Hello, Johannes.
On Thu, Dec 15, 2011 at 04:38:12PM +0100, Johannes Berg wrote:
> --- a/kernel/workqueue.c 2011-12-10 17:32:26.000000000 +0100
> +++ b/kernel/workqueue.c 2011-12-15 16:36:06.000000000 +0100
> @@ -51,6 +51,7 @@ enum {
> GCWQ_DISASSOCIATED = 1 << 2, /* cpu can't serve workers */
> GCWQ_FREEZING = 1 << 3, /* freeze in progress */
> GCWQ_HIGHPRI_PENDING = 1 << 4, /* highpri works on queue */
> + GCWQ_PAUSING = 1 << 5,
Hmmm... confused. Pausing is per-wq, why is this flag on gcwq?
Shouldn't it be on workqueue_struct?
> +void pause_workqueue(struct workqueue_struct *wq)
> +{
> + unsigned int cpu;
> +
> + for_each_cwq_cpu(cpu, wq) {
> + struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq);
> + struct global_cwq *gcwq = cwq->gcwq;
> +
> + spin_lock_irq(&gcwq->lock);
> +
> + WARN_ON(gcwq->flags & GCWQ_PAUSING);
> + gcwq->flags |= GCWQ_PAUSING;
> +
> + cwq->max_active = 0;
> +
> + spin_unlock_irq(&gcwq->lock);
> + }
> +
> + wait_event(wq->waitq, count_active(wq) == 0);
> +}
> +EXPORT_SYMBOL(pause_workqueue);
What if there are multiple callers of this function on the same wq?
Maybe something like wq->pause_depth and also use it from freeze path?
> +void resume_workqueue(struct workqueue_struct *wq)
> +{
> + unsigned int cpu;
> +
> + for_each_cwq_cpu(cpu, wq) {
> + struct cpu_workqueue_struct *cwq = get_cwq(cpu, wq);
> + struct global_cwq *gcwq = cwq->gcwq;
> +
> + spin_lock_irq(&gcwq->lock);
> +
> + WARN_ON(!(gcwq->flags & GCWQ_PAUSING));
> + gcwq->flags &= ~GCWQ_PAUSING;
> +
> + cwq->max_active = wq->saved_max_active;
> +
> + wake_up_worker(gcwq);
> + spin_unlock_irq(&gcwq->lock);
> + }
> +}
> +EXPORT_SYMBOL(resume_workqueue);
I don't think wake_up_worker() would be sufficient.
cwq_activate_first_delayed() needs to be called to kick the delayed
work items.
I think it would be great if this can be abstracted out so that both
the freezer and explicit pausing use the same facility. They aren't
that different after all.
Thanks.
--
tejun
next prev parent reply other threads:[~2011-12-15 18:35 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-09 9:54 workqueue_set_max_active(wq, 0)? Johannes Berg
2011-12-09 16:57 ` Tejun Heo
2011-12-09 16:59 ` Johannes Berg
2011-12-15 15:38 ` Johannes Berg
2011-12-15 18:35 ` Tejun Heo [this message]
2011-12-15 18:43 ` Johannes Berg
2011-12-15 19:12 ` Tejun Heo
2011-12-15 19:26 ` Johannes Berg
2011-12-15 19:31 ` 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=20111215183537.GA32002@google.com \
--to=tj@kernel.org \
--cc=johannes@sipsolutions.net \
--cc=linux-kernel@vger.kernel.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