From: Stefan Metzmacher <[email protected]>
To: [email protected]
Cc: Stefan Metzmacher <[email protected]>
Subject: [RFC PATCH 09/10] io-wq: add io_wq_worker_comm() helper function for dynamic proc_task_comm() generation
Date: Mon, 15 Mar 2021 18:01:47 +0100 [thread overview]
Message-ID: <9aa08ab77fcaf45b5e2975404da6a6f1e93b809a.1615826736.git.metze@samba.org> (raw)
In-Reply-To: <[email protected]>
Signed-off-by: Stefan Metzmacher <[email protected]>
---
fs/io-wq.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
fs/io-wq.h | 4 +++
2 files changed, 81 insertions(+)
diff --git a/fs/io-wq.c b/fs/io-wq.c
index 5c7d2a8c112e..1267171f6388 100644
--- a/fs/io-wq.c
+++ b/fs/io-wq.c
@@ -559,6 +559,83 @@ void io_wq_worker_sleeping(struct task_struct *tsk)
raw_spin_unlock_irq(&worker->wqe->lock);
}
+/* used to show worker information through /proc/PID/{comm,stat,status} */
+void io_wq_worker_comm(char *buf, size_t size, struct task_struct *tsk)
+{
+ struct io_worker *worker = tsk->pf_io_worker;
+ bool working = false;
+ unsigned flags = 0;
+ unsigned int cpu;
+ int node;
+ int wqe_node = NUMA_NO_NODE;
+ int off;
+
+ BUG_ON(!(tsk->flags & PF_IO_WORKER));
+
+ /* prepend iothread/ to the actual comm */
+ off = scnprintf(buf, size, "iothread/%s", tsk->comm);
+ if (off < 0)
+ return;
+
+ cpu = task_cpu(tsk);
+ node = cpu_to_node(cpu);
+
+ if (worker && io_worker_get(worker)) {
+ spin_lock_irq(&worker->lock);
+ flags = worker->flags;
+ working = worker->cur_work != NULL;
+ wqe_node = worker->wqe->node;
+ spin_unlock_irq(&worker->lock);
+ io_worker_release(worker);
+ }
+
+ /*
+ * It may or may not run on the desired node
+ */
+ if (node == wqe_node)
+ off += scnprintf(buf + off, size - off, "/+numa%u", node);
+ else
+ off += scnprintf(buf + off, size - off, "/-numa%u", node);
+ if (off < 0)
+ return;
+
+ /*
+ * It maybe created via create_io_thread(), but not
+ * via the create_io_worker() wrapper.
+ */
+ if (worker == NULL)
+ return;
+
+ if (!(flags & IO_WORKER_F_UP))
+ off += scnprintf(buf + off, size - off, "-down");
+ else if (flags & IO_WORKER_F_FREE)
+ off += scnprintf(buf + off, size - off, "-free");
+ else if (flags & IO_WORKER_F_RUNNING) {
+ if (working)
+ off += scnprintf(buf + off, size - off, "+working");
+ else
+ off += scnprintf(buf + off, size - off, "+running");
+ if (off < 0)
+ return;
+ }
+ if (off < 0)
+ return;
+
+ if (flags & IO_WORKER_F_BOUND)
+ off += scnprintf(buf + off, size - off, "+bound");
+ else
+ off += scnprintf(buf + off, size - off, "-unbound");
+ if (off < 0)
+ return;
+
+ if (flags & IO_WORKER_F_FIXED)
+ off += scnprintf(buf + off, size - off, "+fixed");
+ if (off < 0)
+ return;
+
+ return;
+}
+
static bool create_io_worker(struct io_wq *wq, struct io_wqe *wqe, int index)
{
struct io_wqe_acct *acct = &wqe->acct[index];
diff --git a/fs/io-wq.h b/fs/io-wq.h
index 80d590564ff9..470f854256d1 100644
--- a/fs/io-wq.h
+++ b/fs/io-wq.h
@@ -140,6 +140,7 @@ enum io_wq_cancel io_wq_cancel_cb(struct io_wq *wq, work_cancel_fn *cancel,
#if defined(CONFIG_IO_WQ)
extern void io_wq_worker_sleeping(struct task_struct *);
extern void io_wq_worker_running(struct task_struct *);
+extern void io_wq_worker_comm(char *buf, size_t size, struct task_struct *tsk);
#else
static inline void io_wq_worker_sleeping(struct task_struct *tsk)
{
@@ -147,6 +148,9 @@ static inline void io_wq_worker_sleeping(struct task_struct *tsk)
static inline void io_wq_worker_running(struct task_struct *tsk)
{
}
+static inline void io_wq_worker_comm(char *buf, size_t size, struct task_struct *tsk)
+{
+}
#endif
static inline bool io_wq_current_is_worker(void)
--
2.25.1
next prev parent reply other threads:[~2021-03-15 17:04 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-19 23:27 Problems with io_threads Stefan Metzmacher
2021-03-15 17:01 ` [RFC PATCH 00/10] Complete setup before calling wake_up_new_task() and improve task->comm Stefan Metzmacher
2021-03-15 17:01 ` [RFC PATCH 01/10] kernel: always initialize task->pf_io_worker to NULL Stefan Metzmacher
2021-03-15 17:01 ` [RFC PATCH 02/10] io_uring: io_sq_thread() no longer needs to reset current->pf_io_worker Stefan Metzmacher
2021-03-15 17:01 ` [RFC PATCH 03/10] io-wq: call set_task_comm() before wake_up_new_task() Stefan Metzmacher
2021-03-15 17:01 ` [RFC PATCH 04/10] io_uring: complete sq_thread setup before calling wake_up_new_task() Stefan Metzmacher
2021-03-15 17:01 ` [RFC PATCH 05/10] io-wq: protect against future set_task_comm() overflows Stefan Metzmacher
2021-03-15 17:01 ` [RFC PATCH 06/10] io_uring: " Stefan Metzmacher
2021-03-15 17:01 ` [RFC PATCH 07/10] fs/proc: hide PF_IO_WORKER in get_task_cmdline() Stefan Metzmacher
2021-03-15 17:01 ` [RFC PATCH 08/10] fs/proc: protect /proc/<pid>/[task/<tid>]/comm for PF_IO_WORKER Stefan Metzmacher
2021-03-15 17:01 ` Stefan Metzmacher [this message]
2021-03-15 17:01 ` [RFC PATCH 10/10] fs/proc: make use of io_wq_worker_comm() for PF_IO_WORKER threads Stefan Metzmacher
2021-03-17 22:42 ` [RFC PATCH 00/10] Complete setup before calling wake_up_new_task() and improve task->comm Jens Axboe
2021-03-17 23:06 ` Stefan Metzmacher
2021-03-17 23:26 ` Jens Axboe
2021-03-20 0:00 ` [PATCH v2 0/5] " Stefan Metzmacher
2021-03-20 0:00 ` [PATCH v2 1/5] kernel: always initialize task->pf_io_worker to NULL Stefan Metzmacher
2021-03-20 0:00 ` [PATCH v2 2/5] io_uring: io_sq_thread() no longer needs to reset current->pf_io_worker Stefan Metzmacher
2021-03-20 0:00 ` [PATCH v2 3/5] io-wq: call set_task_comm() before wake_up_new_task() Stefan Metzmacher
2021-03-20 0:00 ` [PATCH v2 4/5] io_uring: complete sq_thread setup before calling wake_up_new_task() Stefan Metzmacher
2021-03-20 0:00 ` [PATCH v2 5/5] fs/proc: hide PF_IO_WORKER in get_task_cmdline() Stefan Metzmacher
2021-03-20 1:24 ` [PATCH v2 0/5] Complete setup before calling wake_up_new_task() and improve task->comm Jens Axboe
2021-03-20 19:22 ` Stefan Metzmacher
2021-03-20 22:39 ` Jens Axboe
2021-03-19 23:46 ` Problems with io_threads Jens Axboe
2021-03-20 0:25 ` Stefan Metzmacher
2021-03-20 1:20 ` Jens Axboe
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=9aa08ab77fcaf45b5e2975404da6a6f1e93b809a.1615826736.git.metze@samba.org \
[email protected] \
[email protected] \
/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