Skip to contentSkip to conversation

io_uring: show sqthread pid and cpu in fdinfo

PATCH RESEND Applied Joseph Qi 3 participants 3 messages Sep 24, 2020

Subsystems (2)
lore
Share & tools
lore

Joseph Qi

author
#0 lore raw

PATCH RESEND 1/1 io_uring: show sqthread pid and cpu in fdinfo

In most cases we'll specify IORING_SETUP_SQPOLL and run multiple io_uring instances in a host. Since all sqthreads are named "io_uring-sq", it's hard to distinguish the relations between application process and its io_uring sqthread.
With this patch, application can get its corresponding sqthread pid and cpu through show_fdinfo.
Steps:
1. Get io_uring fd first.

$ ls -l /proc/<pid>/fd | grep -w io_uring
2. Then get io_uring instance related info, including corresponding
sqthread pid and cpu.
$ cat /proc/<pid>/fdinfo/<io_uring_fd>

pos: 0
flags: 02000002
mnt_id: 13
SqThread: 6929
SqThreadCpu: 2
UserFiles: 1
0: testfile
UserBufs: 0
PollList:

---
 fs/io_uring.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/io_uring.c +4 -0
index 8b426aa..9c8b3b3 100644
@@ -8415,6 +8415,10 @@ static void __io_uring_show_fdinfo(struct io_ring_ctx *ctx, struct seq_file *m)
 	int i;
 
 	mutex_lock(&ctx->uring_lock);
+	seq_printf(m, "SqThread:\t%d\n", (ctx->flags & IORING_SETUP_SQPOLL) ?
+					 task_pid_nr(ctx->sqo_thread) : -1);
+	seq_printf(m, "SqThreadCpu:\t%d\n", (ctx->flags & IORING_SETUP_SQPOLL) ?
+					    task_cpu(ctx->sqo_thread) : -1);
 	seq_printf(m, "UserFiles:\t%u\n", ctx->nr_user_files);
 	for (i = 0; i < ctx->nr_user_files; i++) {
 		struct fixed_file_table *table;
Signature · 1 line
1.8.3.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 33 lines · Joseph Qi

In most cases we'll specify IORING_SETUP_SQPOLL and run multiple io_uring instances in a host. Since all sqthreads are named "io_uring-sq", it's hard to distinguish the relations between application process and its io_uring sqthread.
With this patch, application can get its corresponding sqthread pid and cpu through show_fdinfo.
Steps:
1. Get io_uring fd first.

$ ls -l /proc/<pid>/fd | grep -w io_uring
2. Then get io_uring instance related info, including corresponding
sqthread pid and cpu.
$ cat /proc/<pid>/fdinfo/<io_uring_fd>

pos: 0
flags: 02000002
mnt_id: 13
SqThread: 6929
SqThreadCpu: 2
UserFiles: 1
0: testfile
UserBufs: 0
PollList:

---
 fs/io_uring.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/io_uring.c +0 -0
index 8b426aa..9c8b3b3 100644

fs/io_uring.c static void __io_uring_show_fdinfo(struct io_ring_ctx *ctx, struct seq_file *m) · line 8419

Quoted 5 lines
fs/io_uring.c +2 -0
@@ -8415,6 +8415,10 @@ static void __io_uring_show_fdinfo(struct io_ring_ctx *ctx, struct seq_file *m)
 	int i;
 
 	mutex_lock(&ctx->uring_lock);
+	seq_printf(m, "SqThread:\t%d\n", (ctx->flags & IORING_SETUP_SQPOLL) ?
+					 task_pid_nr(ctx->sqo_thread) : -1);

What about 'SqThreadPID'?

Quoted 8 lines
fs/io_uring.c +2 -0
+	seq_printf(m, "SqThreadCpu:\t%d\n", (ctx->flags & IORING_SETUP_SQPOLL) ?
+					    task_cpu(ctx->sqo_thread) : -1);
 	seq_printf(m, "UserFiles:\t%u\n", ctx->nr_user_files);
 	for (i = 0; i < ctx->nr_user_files; i++) {
 		struct fixed_file_table *table;
Signature · 1 line
1.8.3.1

With or without that changed, it looks good to me:

Thanks,
Stefano

maintainer Applied
#2 lore raw
In reply to Joseph Qi
Quoted 8 lines · Joseph Qi

In most cases we'll specify IORING_SETUP_SQPOLL and run multiple io_uring instances in a host. Since all sqthreads are named "io_uring-sq", it's hard to distinguish the relations between application process and its io_uring sqthread.
With this patch, application can get its corresponding sqthread pid and cpu through show_fdinfo.
Steps:
1. Get io_uring fd first.

Quoted 4 lines
$ ls -l /proc/<pid>/fd | grep -w io_uring
2. Then get io_uring instance related info, including corresponding
sqthread pid and cpu.
$ cat /proc/<pid>/fdinfo/<io_uring_fd>

Applied, thanks.

Signature · 1 line
Jens Axboe