[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250515040523.430181-1-songmuchun@bytedance.com>
Date: Thu, 15 May 2025 12:05:23 +0800
From: Muchun Song <songmuchun@...edance.com>
To: tj@...nel.org,
jiangshanlai@...il.com
Cc: linux-kernel@...r.kernel.org,
muchun.song@...ux.dev,
Muchun Song <songmuchun@...edance.com>
Subject: [PATCH] workqueue: show the latest function name in /proc/PID/{comm,stat,status}
Workqueues, such as system_unbound_wq, are shared across the system,
making it difficult to determine which tasks are being executed by
each worker. This patch improves clarity by displaying the latest
function name associated with each workqueue worker in the
/proc/PID/{comm,stat,status}. For example:
Before:
# ps 64 67 68
PID TTY STAT TIME COMMAND
64 ? I 0:00 [kworker/u34:0-events_unbound]
67 ? I 0:00 [kworker/u33:1-events_unbound]
68 ? I 0:00 [kworker/u33:2-events_unbound]
After:
# ps 64 67 68
PID TTY STAT TIME COMMAND
64 ? I 0:00 [kworker/u34:0-events_unbound:flush_memcg_stats_dwork]
67 ? I 0:00 [kworker/u33:1-events_unbound:flush_to_ldisc]
68 ? I 0:00 [kworker/u33:2-events_unbound:idle_cull_fn]
This change provides a clearer view of the tasks being performed by
each worker, enhancing system monitoring and debugging.
Signed-off-by: Muchun Song <songmuchun@...edance.com>
---
kernel/workqueue.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/kernel/workqueue.c b/kernel/workqueue.c
index 3bef0754cf73..6d4ca373b980 100644
--- a/kernel/workqueue.c
+++ b/kernel/workqueue.c
@@ -6475,9 +6475,12 @@ void wq_worker_comm(char *buf, size_t size, struct task_struct *task)
* current, prepend '+', otherwise '-'.
*/
if (worker->desc[0] != '\0') {
- if (worker->current_work)
- scnprintf(buf + off, size - off, "+%s",
- worker->desc);
+ if (worker->current_func)
+ scnprintf(buf + off, size - off, "+%s:%ps",
+ worker->desc, worker->current_func);
+ else if (worker->last_func)
+ scnprintf(buf + off, size - off, "-%s:%ps",
+ worker->desc, worker->last_func);
else
scnprintf(buf + off, size - off, "-%s",
worker->desc);
--
2.20.1
Powered by blists - more mailing lists