[PATCH 0/3] workqueue: Add telemetry tracepoints for CPU hogs, distress, and BH budget yields

Aaron Tomlin posted 3 patches 3 weeks, 6 days ago
include/trace/events/workqueue.h | 146 +++++++++++++++++++++++++++++++
kernel/workqueue.c               |  24 ++++-
2 files changed, 168 insertions(+), 2 deletions(-)
[PATCH 0/3] workqueue: Add telemetry tracepoints for CPU hogs, distress, and BH budget yields
Posted by Aaron Tomlin 3 weeks, 6 days ago
Hi Tejun, Lai,

While the workqueue subsystem maintains rich internal telemetry via
pwq->stats[], wq_cpu_intensive_thresh_us, and distress mechanisms, several
critical state transitions and execution anomalies currently lack real-time
event notifications.

Across production fleets and low-latency networking workloads, polling
pwq->stats[] or running drgn scripts is impractical for detecting
intermittent stalls. Tail-latency spikes and packet drops often stem from
softirq overruns or latency-critical work items queueing behind CPU-bound
tasks. These event-driven tracepoints allow zero-overhead eBPF tools and
latency profilers to capture stack traces and kernel context at the exact
moment a starvation event or softirq budget exhaustion occurs.

This patch series introduces lightweight tracepoints for these key
operational boundaries:

Patch 1 adds workqueue_cpu_intensive tracepoint. When a concurrency-managed
worker runs for longer than wq_cpu_intensive_thresh_us without sleeping,
wq_worker_tick() marks it as WORKER_CPU_INTENSIVE and kicks the pool to
prevent queue starvation. The tracepoint will capture the offending work
function, workqueue name, CPU, and elapsed duration.

Patch 2 adds workqueue_mayday and workqueue_rescued tracepoints. One when
worker allocation stalls trigger mayday distress, and another when pending
work items are handed off to the rescuer thread to ensure forward progress.

Patch 3 adds workqueue_bh_budget_yield tracepoint. Bottom-Half (BH)
workqueues enforce execution limits in softirq context (BH_WORKER_JIFFIES
and BH_WORKER_RESTARTS). When a BH worker hits these limits while pending
work remains, it yields and re-raises the softirq. The tracepoint can be
used to identify softirq budget saturation and track whether yielding
occurred due to time slice expiration or restart counts.

Aaron Tomlin (3):
  workqueue: Add workqueue_cpu_intensive tracepoint
  workqueue: Add workqueue_mayday and workqueue_rescued tracepoints
  workqueue: Add workqueue_bh_budget_yield tracepoint

 include/trace/events/workqueue.h | 146 +++++++++++++++++++++++++++++++
 kernel/workqueue.c               |  24 ++++-
 2 files changed, 168 insertions(+), 2 deletions(-)

-- 
2.55.0
Re: [PATCH 0/3] workqueue: Add telemetry tracepoints for CPU hogs, distress, and BH budget yields
Posted by Tejun Heo 3 weeks, 4 days ago
Hello, Aaron.

On Sat, Aug 29, 2026 at 07:05:14PM -0400, Aaron Tomlin wrote:
> This patch series introduces lightweight tracepoints for these key
> operational boundaries:

Lai's address was mangled in the cc list. Corrected to
jiangshanlai@gmail.com.

Generally looks fine to me. Some comments:

- As the test robot reported, the open-coded u64 division in the first
  patch breaks 32bit builds. Rather than restructuring the comparison,
  it'd be better to keep it as-is and calculate the duration only after
  the worker is marked CPU_INTENSIVE. That also keeps the division out
  of the every-tick path.

- In the third patch, the timeout flag is determined by re-reading
  jiffies after the loop. If the loop exited because nr_restarts ran
  out, time_before() was never tested and a tick in that window would
  misattribute the yield to timeout. Please derive the reason from the
  condition that actually terminated the loop. Also, BH_WORKER_RESTARTS
  - nr_restarts counts loop iterations, not restarts.

Thanks.

-- 
tejun