From: Tejun Heo <tj@kernel.org>
To: Aaron Tomlin <atomlin@atomlin.com>
Cc: leitao@debian.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] tools/workqueue/wq_dump.py: Add busy worker inspection and BH pool states
Date: Mon, 31 Aug 2026 10:38:53 -1000 [thread overview]
Message-ID: <7c884196b9a8890efadeb0a8ef9c1f6e@kernel.org> (raw)
In-Reply-To: <20260831181554.117795-3-atomlin@atomlin.com>
Hello, Aaron.
On Mon, Aug 31, 2026 at 02:15:54PM -0400, Aaron Tomlin wrote:
> + if pool.flags & POOL_BH_DRAINING:
> + print(' draining', end='')
> + if pool.flags & POOL_DISASSOCIATED:
> + print(' disassociated', end='')
Note that POOL_DISASSOCIATED is set by init_worker_pool() and cleared only
for per-cpu non-BH pools, so BH and unbound pools carry it for their whole
lifetime. This would print " disassociated" on every one of their lines.
It's only meaningful on a per-cpu non-BH pool whose CPU is offline.
> + if args.busy:
> + for bkt in pool.busy_hash:
> + for worker in hlist_for_each_entry('struct worker', bkt.address_of_(), 'hentry'):
> + wq_name = worker.current_pwq.wq.name.string_().decode()
> + fn_name = prog.symbol(worker.current_func.value_()).name
process_one_work() hashes the worker before setting current_func and
current_pwq, and clears them right after unhashing, all under pool->lock. A
worker caught in either window reads back NULL, so worker.current_pwq.wq
raises and prog.symbol(0) can raise errors and kill the rest of the dump.
Work items can finish at a very high rate, so this wouldn't be difficult to
hit on a busy machine. Maybe catch the exceptions and retry the worker?
> + dur_str = ''
> + if 'jiffies' in prog and worker.current_start.value_():
> + jiffies = prog['jiffies'].value_()
> + dur_s = max(0, (jiffies - worker.current_start.value_()) // hz)
> + dur_str = f' for {dur_s}s'
worker->current_start was added in v7.0 by e8e14ac7cfe4 ("workqueue: Show
in-flight work item duration in stall diagnostics"). The 'jiffies' in prog
test doesn't protect the member access, so on an older kernel or vmcore the
first busy worker aborts the dump, the same failure mode the previous patch
fixes for wq->attrs. Please handle it the same way.
Also, the values are plain Python integers, so on a 32bit kernel the
subtraction goes negative when jiffies wraps (the first wrap is five minutes
after boot due to INITIAL_JIFFIES) and the max() turns the duration into
"for 0s". Mask the difference to the target's word size instead, e.g.:
mask = (1 << (prog['jiffies'].type_.size * 8)) - 1
dur_s = ((jiffies - worker.current_start.value_()) & mask) // hz
Thanks.
--
tejun
prev parent reply other threads:[~2026-08-31 20:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 18:15 [PATCH 0/2] tools/workqueue/wq_dump.py: Backward compatibility and live worker inspection Aaron Tomlin
2026-08-31 18:15 ` [PATCH 1/2] tools/workqueue/wq_dump.py: Support backward compatibility for wq->attrs rename Aaron Tomlin
2026-08-31 20:38 ` Tejun Heo
2026-08-31 18:15 ` [PATCH 2/2] tools/workqueue/wq_dump.py: Add busy worker inspection and BH pool states Aaron Tomlin
2026-08-31 20:38 ` Tejun Heo [this message]
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=7c884196b9a8890efadeb0a8ef9c1f6e@kernel.org \
--to=tj@kernel.org \
--cc=atomlin@atomlin.com \
--cc=leitao@debian.org \
--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
all inboxes | Powered by JetHome®