From: Xiaobing Li <[email protected]>
To: [email protected], [email protected]
Cc: [email protected], [email protected],
[email protected], [email protected], [email protected],
[email protected], [email protected],
[email protected], Xiaobing Li <[email protected]>
Subject: [PATCH v2] io_uring: Statistics of the true utilization of sq threads.
Date: Wed, 8 Nov 2023 16:07:32 +0800 [thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: CGME20231108081516epcas5p442a11004e3b4e6339972fd6da4c6692b@epcas5p4.samsung.com
Since the sq thread has a while(1) structure, during this process, there
may be a lot of time that is not processing IO but does not exceed the
timeout period, therefore, the sqpoll thread will keep running and will
keep occupying the CPU. Obviously, the CPU is wasted at this time;Our
goal is to count the part of the time that the sqpoll thread actually
processes IO, so as to reflect the part of the CPU it uses to process
IO, which can be used to help improve the actual utilization of the CPU
in the future.
Signed-off-by: Xiaobing Li <[email protected]>
v1 -> v2: Added method to query data.
The test results are as follows:
cat /proc/11440/fdinfo/6
pos: 0
flags: 02000002
mnt_id: 16
ino: 94449
SqMask: 0xf
SqHead: 1845170
SqTail: 1845170
CachedSqHead: 1845170
CqMask: 0xf
CqHead: 1845154
CqTail: 1845154
CachedCqTail: 1845154
SQEs: 0
CQEs: 0
SqThread: -1
SqThreadCpu: -1
UserFiles: 1
UserBufs: 0
PollList:
CqOverflowList:
PID: 11440
work: 18794
total: 19123
---
io_uring/fdinfo.c | 6 ++++++
io_uring/sqpoll.c | 8 ++++++++
io_uring/sqpoll.h | 2 ++
3 files changed, 16 insertions(+)
diff --git a/io_uring/fdinfo.c b/io_uring/fdinfo.c
index f04a43044d91..f0b79c533062 100644
--- a/io_uring/fdinfo.c
+++ b/io_uring/fdinfo.c
@@ -213,6 +213,12 @@ __cold void io_uring_show_fdinfo(struct seq_file *m, struct file *f)
}
+ if (ctx->sq_data) {
+ seq_printf(m, "PID:\t%d\n", task_pid_nr(ctx->sq_data->thread));
+ seq_printf(m, "work:\t%lu\n", ctx->sq_data->work);
+ seq_printf(m, "total:\t%lu\n", ctx->sq_data->total);
+ }
+
spin_unlock(&ctx->completion_lock);
}
#endif
diff --git a/io_uring/sqpoll.c b/io_uring/sqpoll.c
index bd6c2c7959a5..c821273406bd 100644
--- a/io_uring/sqpoll.c
+++ b/io_uring/sqpoll.c
@@ -224,6 +224,7 @@ static int io_sq_thread(void *data)
struct io_ring_ctx *ctx;
unsigned long timeout = 0;
char buf[TASK_COMM_LEN];
+ unsigned long start, begin, end;
DEFINE_WAIT(wait);
snprintf(buf, sizeof(buf), "iou-sqp-%d", sqd->task_pid);
@@ -235,6 +236,7 @@ static int io_sq_thread(void *data)
set_cpus_allowed_ptr(current, cpu_online_mask);
mutex_lock(&sqd->lock);
+ start = jiffies;
while (1) {
bool cap_entries, sqt_spin = false;
@@ -245,12 +247,18 @@ static int io_sq_thread(void *data)
}
cap_entries = !list_is_singular(&sqd->ctx_list);
+ begin = jiffies;
list_for_each_entry(ctx, &sqd->ctx_list, sqd_list) {
int ret = __io_sq_thread(ctx, cap_entries);
if (!sqt_spin && (ret > 0 || !wq_list_empty(&ctx->iopoll_list)))
sqt_spin = true;
}
+ end = jiffies;
+ sqd->total = end - start;
+ if (sqt_spin == true)
+ sqd->work += end - begin;
+
if (io_run_task_work())
sqt_spin = true;
diff --git a/io_uring/sqpoll.h b/io_uring/sqpoll.h
index 8df37e8c9149..0aa4e2efa4db 100644
--- a/io_uring/sqpoll.h
+++ b/io_uring/sqpoll.h
@@ -16,6 +16,8 @@ struct io_sq_data {
pid_t task_pid;
pid_t task_tgid;
+ unsigned long work;
+ unsigned long total;
unsigned long state;
struct completion exited;
};
--
2.34.1
next parent reply other threads:[~2023-11-08 8:15 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CGME20231108081516epcas5p442a11004e3b4e6339972fd6da4c6692b@epcas5p4.samsung.com>
2023-11-08 8:07 ` Xiaobing Li [this message]
2023-11-08 15:26 ` [PATCH v2] io_uring: Statistics of the true utilization of sq threads Jens Axboe
[not found] ` <CGME20231113031827epcas5p2e6e858292a3cd4b9e03b4615d972b22d@epcas5p2.samsung.com>
2023-11-13 3:10 ` Xiaobing Li
2023-11-13 16:38 ` Jens Axboe
2023-11-08 16:23 ` Gabriel Krisman Bertazi
2023-11-09 16:14 ` Pavel Begunkov
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 \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[email protected] \
[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