Linux wireless drivers development
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: linux-wireless@vger.kernel.org,
	Lai Jiangshan <jiangshanlai@gmail.com>,
	Benjamin Berg <benjamin@sipsolutions.net>
Subject: Re: wireless locking simplifications
Date: Fri, 5 May 2023 11:51:57 -1000	[thread overview]
Message-ID: <ZFV6fTH_7umEa5H0@slm.duckdns.org> (raw)
In-Reply-To: <f3471853cd7063a4bd2d783caa14706ee9115748.camel@sipsolutions.net>

Hello, Johannes.

On Fri, May 05, 2023 at 11:05:45PM +0200, Johannes Berg wrote:
...
> The implementation of (2) is a bit ... awkward, @Tejun, @Lai, there's no
> way to "pause" an ordered workqueue, is there? I came up with the below
> patch, but it's a bit ugly and requires a lot of context switches. Just
> flushing isn't enough since then some work might start and hang on
> acquiring the lock.

There isn't currently but workqueue already does something similar for
freezing by temporarily setting max_active to zero, so if you apply a patch
like the following

diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index b8b541caed48..6daf9ee7450d 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -4360,11 +4360,11 @@ static int wq_clamp_max_active(int max_active, unsigned int flags,
 {
 	int lim = flags & WQ_UNBOUND ? WQ_UNBOUND_MAX_ACTIVE : WQ_MAX_ACTIVE;
 
-	if (max_active < 1 || max_active > lim)
+	if (max_active < 0 || max_active > lim)
 		pr_warn("workqueue: max_active %d requested for %s is out of range, clamping between %d and %d\n",
 			max_active, name, 1, lim);
 
-	return clamp_val(max_active, 1, lim);
+	return clamp_val(max_active, 0, lim);
 }
 
 /*
@@ -4625,7 +4625,8 @@ void workqueue_set_max_active(struct workqueue_struct *wq, int max_active)
 	struct pool_workqueue *pwq;
 
 	/* disallow meddling with max_active for ordered workqueues */
-	if (WARN_ON(wq->flags & __WQ_ORDERED_EXPLICIT))
+	if (WARN_ON((wq->flags & __WQ_ORDERED_EXPLICIT) &&
+		    max_active != 0 && max_active != 1))
 		return;
 
 	max_active = wq_clamp_max_active(max_active, wq->flags, wq->name);

and then do set_max_active(wq, 0) followed by flush_workqueue(), it should
be paused until max_active is restored to 1. It probably would be better to
add a separate pause / resume interface which sets a per-wq flag which is
read by pwq_adjust_max_active() tho. Anyways, it's not difficult to
implement at all.

Thanks.

-- 
tejun

  reply	other threads:[~2023-05-05 21:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-05 21:05 wireless locking simplifications Johannes Berg
2023-05-05 21:51 ` Tejun Heo [this message]
2023-05-08 16:06   ` Johannes Berg
2023-05-10 10:58   ` Johannes Berg
2023-05-10 11:11     ` Johannes Berg
2023-05-10 11:25 ` Johannes Berg

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=ZFV6fTH_7umEa5H0@slm.duckdns.org \
    --to=tj@kernel.org \
    --cc=benjamin@sipsolutions.net \
    --cc=jiangshanlai@gmail.com \
    --cc=johannes@sipsolutions.net \
    --cc=linux-wireless@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