public inbox for [email protected]
 help / color / mirror / Atom feed
* [PATCH] IO_URING: Statistics of the true utilization of sq threads.
       [not found] <CGME20231106074844epcas5p252beb2aa7925de34aea33d5c64d1d72e@epcas5p2.samsung.com>
@ 2023-11-06  7:40 ` Xiaobing Li
  2023-11-06 14:55   ` Jens Axboe
  0 siblings, 1 reply; 2+ messages in thread
From: Xiaobing Li @ 2023-11-06  7:40 UTC (permalink / raw)
  To: axboe, asml.silence
  Cc: linux-kernel, io-uring, kun.dou, peiwei.li, joshi.k, kundan.kumar,
	wenwen.chen, ruyi.zhang, Xiaobing Li

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]>
---
 io_uring/sqpoll.c | 8 ++++++++
 io_uring/sqpoll.h | 2 ++
 2 files changed, 10 insertions(+)

diff --git a/io_uring/sqpoll.c b/io_uring/sqpoll.c
index bd6c2c7959a5..27b01ad42678 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 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..c6b2ecb654fd 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 long work;
+	unsigned long long total;
 	unsigned long		state;
 	struct completion	exited;
 };
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] IO_URING: Statistics of the true utilization of sq threads.
  2023-11-06  7:40 ` [PATCH] IO_URING: Statistics of the true utilization of sq threads Xiaobing Li
@ 2023-11-06 14:55   ` Jens Axboe
  0 siblings, 0 replies; 2+ messages in thread
From: Jens Axboe @ 2023-11-06 14:55 UTC (permalink / raw)
  To: Xiaobing Li, asml.silence
  Cc: linux-kernel, io-uring, kun.dou, peiwei.li, joshi.k, kundan.kumar,
	wenwen.chen, ruyi.zhang

On 11/6/23 12:40 AM, Xiaobing Li wrote:
> 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]>
> ---
>  io_uring/sqpoll.c | 8 ++++++++
>  io_uring/sqpoll.h | 2 ++
>  2 files changed, 10 insertions(+)
> 
> diff --git a/io_uring/sqpoll.c b/io_uring/sqpoll.c
> index bd6c2c7959a5..27b01ad42678 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 long start, begin, end;
>  	DEFINE_WAIT(wait);

These can just be unsigned long, that's the size of jiffies on any
platform. Ditto for struct io_sq_data.

And while this looks fine, nothing is using this accounting. For this to
be an acceptable patch, surely the value needs to be used somehow or at
least you should be able to query it?

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-11-06 14:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CGME20231106074844epcas5p252beb2aa7925de34aea33d5c64d1d72e@epcas5p2.samsung.com>
2023-11-06  7:40 ` [PATCH] IO_URING: Statistics of the true utilization of sq threads Xiaobing Li
2023-11-06 14:55   ` Jens Axboe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox