Skip to content

Commit e8e14ac

Browse files
leitaohtejun
authored andcommitted
workqueue: Show in-flight work item duration in stall diagnostics
When diagnosing workqueue stalls, knowing how long each in-flight work item has been executing is valuable. Add a current_start timestamp (jiffies) to struct worker, set it when a work item begins execution in process_one_work(), and print the elapsed wall-clock time in show_pwq(). Unlike current_at (which tracks CPU runtime and resets on wakeup for CPU-intensive detection), current_start is never reset because the diagnostic cares about total wall-clock time including sleeps. Before: in-flight: 165:stall_work_fn [wq_stall] After: in-flight: 165:stall_work_fn [wq_stall] for 100s Signed-off-by: Breno Leitao <leitao@debian.org> Acked-by: Song Liu <song@kernel.org> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 6037160 commit e8e14ac

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

kernel/workqueue.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3204,6 +3204,7 @@ __acquires(&pool->lock)
32043204
worker->current_pwq = pwq;
32053205
if (worker->task)
32063206
worker->current_at = worker->task->se.sum_exec_runtime;
3207+
worker->current_start = jiffies;
32073208
work_data = *work_data_bits(work);
32083209
worker->current_color = get_work_color(work_data);
32093210

@@ -6359,6 +6360,8 @@ static void show_pwq(struct pool_workqueue *pwq)
63596360
pr_cont(" %s", comma ? "," : "");
63606361
pr_cont_worker_id(worker);
63616362
pr_cont(":%ps", worker->current_func);
6363+
pr_cont(" for %us",
6364+
jiffies_to_msecs(jiffies - worker->current_start) / 1000);
63626365
list_for_each_entry(work, &worker->scheduled, entry)
63636366
pr_cont_work(false, work, &pcws);
63646367
pr_cont_work_flush(comma, (work_func_t)-1L, &pcws);

kernel/workqueue_internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ struct worker {
3232
work_func_t current_func; /* K: function */
3333
struct pool_workqueue *current_pwq; /* K: pwq */
3434
u64 current_at; /* K: runtime at start or last wakeup */
35+
unsigned long current_start; /* K: start time of current work item */
3536
unsigned int current_color; /* K: color */
3637

3738
int sleeping; /* S: is worker sleeping? */

0 commit comments

Comments
 (0)