Skip to content

Commit 9773709

Browse files
ps-ushankaraxboe
authored andcommitted
selftests: ublk: kublk: tie sqe allocation to io instead of queue
We currently have a helper ublk_queue_alloc_sqes which the ublk targets use to allocate SQEs for their own operations. However, as we move towards decoupled ublk_queues and ublk server threads, this helper does not make sense anymore. SQEs are allocated from rings, and we will have one ring per thread to avoid locking. Change the SQE allocation helper to ublk_io_alloc_sqes. Currently this still allocates SQEs from the io's queue's ring, but when we fully decouple threads and queues, it will allocate from the io's thread's ring instead. Signed-off-by: Uday Shankar <[email protected]> Reviewed-by: Ming Lei <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent bf098d7 commit 9773709

File tree

6 files changed

+21
-13
lines changed

6 files changed

+21
-13
lines changed

tools/testing/selftests/ublk/fault_inject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static int ublk_fault_inject_queue_io(struct ublk_queue *q, int tag)
4646
.tv_nsec = (long long)q->dev->private_data,
4747
};
4848

49-
ublk_queue_alloc_sqes(q, &sqe, 1);
49+
ublk_io_alloc_sqes(ublk_get_io(q, tag), &sqe, 1);
5050
io_uring_prep_timeout(sqe, &ts, 1, 0);
5151
sqe->user_data = build_user_data(tag, ublksrv_get_op(iod), 0, q->q_id, 1);
5252

tools/testing/selftests/ublk/file_backed.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static int loop_queue_flush_io(struct ublk_queue *q, const struct ublksrv_io_des
1818
unsigned ublk_op = ublksrv_get_op(iod);
1919
struct io_uring_sqe *sqe[1];
2020

21-
ublk_queue_alloc_sqes(q, sqe, 1);
21+
ublk_io_alloc_sqes(ublk_get_io(q, tag), sqe, 1);
2222
io_uring_prep_fsync(sqe[0], 1 /*fds[1]*/, IORING_FSYNC_DATASYNC);
2323
io_uring_sqe_set_flags(sqe[0], IOSQE_FIXED_FILE);
2424
/* bit63 marks us as tgt io */
@@ -36,7 +36,7 @@ static int loop_queue_tgt_rw_io(struct ublk_queue *q, const struct ublksrv_io_de
3636
void *addr = (zc | auto_zc) ? NULL : (void *)iod->addr;
3737

3838
if (!zc || auto_zc) {
39-
ublk_queue_alloc_sqes(q, sqe, 1);
39+
ublk_io_alloc_sqes(ublk_get_io(q, tag), sqe, 1);
4040
if (!sqe[0])
4141
return -ENOMEM;
4242

@@ -52,7 +52,7 @@ static int loop_queue_tgt_rw_io(struct ublk_queue *q, const struct ublksrv_io_de
5252
return 1;
5353
}
5454

55-
ublk_queue_alloc_sqes(q, sqe, 3);
55+
ublk_io_alloc_sqes(ublk_get_io(q, tag), sqe, 3);
5656

5757
io_uring_prep_buf_register(sqe[0], 0, tag, q->q_id, tag);
5858
sqe[0]->flags |= IOSQE_CQE_SKIP_SUCCESS | IOSQE_IO_HARDLINK;

tools/testing/selftests/ublk/kublk.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ int ublk_queue_io_cmd(struct ublk_queue *q, struct ublk_io *io, unsigned tag)
599599
if (io_uring_sq_space_left(&q->ring) < 1)
600600
io_uring_submit(&q->ring);
601601

602-
ublk_queue_alloc_sqes(q, sqe, 1);
602+
ublk_io_alloc_sqes(ublk_get_io(q, tag), sqe, 1);
603603
if (!sqe[0]) {
604604
ublk_err("%s: run out of sqe %d, tag %d\n",
605605
__func__, q->q_id, tag);

tools/testing/selftests/ublk/kublk.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ struct ublk_io {
124124
unsigned short flags;
125125
unsigned short refs; /* used by target code only */
126126

127+
int tag;
128+
127129
int result;
128130

129131
unsigned short tgt_ios;
@@ -289,17 +291,23 @@ static inline void ublk_dbg(int level, const char *fmt, ...)
289291
}
290292
}
291293

292-
static inline int ublk_queue_alloc_sqes(struct ublk_queue *q,
294+
static inline struct ublk_queue *ublk_io_to_queue(const struct ublk_io *io)
295+
{
296+
return container_of(io, struct ublk_queue, ios[io->tag]);
297+
}
298+
299+
static inline int ublk_io_alloc_sqes(struct ublk_io *io,
293300
struct io_uring_sqe *sqes[], int nr_sqes)
294301
{
295-
unsigned left = io_uring_sq_space_left(&q->ring);
302+
struct io_uring *ring = &ublk_io_to_queue(io)->ring;
303+
unsigned left = io_uring_sq_space_left(ring);
296304
int i;
297305

298306
if (left < nr_sqes)
299-
io_uring_submit(&q->ring);
307+
io_uring_submit(ring);
300308

301309
for (i = 0; i < nr_sqes; i++) {
302-
sqes[i] = io_uring_get_sqe(&q->ring);
310+
sqes[i] = io_uring_get_sqe(ring);
303311
if (!sqes[i])
304312
return i;
305313
}

tools/testing/selftests/ublk/null.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static int null_queue_zc_io(struct ublk_queue *q, int tag)
6060
const struct ublksrv_io_desc *iod = ublk_get_iod(q, tag);
6161
struct io_uring_sqe *sqe[3];
6262

63-
ublk_queue_alloc_sqes(q, sqe, 3);
63+
ublk_io_alloc_sqes(ublk_get_io(q, tag), sqe, 3);
6464

6565
io_uring_prep_buf_register(sqe[0], 0, tag, q->q_id, tag);
6666
sqe[0]->user_data = build_user_data(tag,
@@ -82,7 +82,7 @@ static int null_queue_auto_zc_io(struct ublk_queue *q, int tag)
8282
const struct ublksrv_io_desc *iod = ublk_get_iod(q, tag);
8383
struct io_uring_sqe *sqe[1];
8484

85-
ublk_queue_alloc_sqes(q, sqe, 1);
85+
ublk_io_alloc_sqes(ublk_get_io(q, tag), sqe, 1);
8686
__setup_nop_io(tag, iod, sqe[0], q->q_id);
8787
return 1;
8888
}

tools/testing/selftests/ublk/stripe.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static int stripe_queue_tgt_rw_io(struct ublk_queue *q, const struct ublksrv_io_
138138
io->private_data = s;
139139
calculate_stripe_array(conf, iod, s, base);
140140

141-
ublk_queue_alloc_sqes(q, sqe, s->nr + extra);
141+
ublk_io_alloc_sqes(ublk_get_io(q, tag), sqe, s->nr + extra);
142142

143143
if (zc) {
144144
io_uring_prep_buf_register(sqe[0], 0, tag, q->q_id, tag);
@@ -182,7 +182,7 @@ static int handle_flush(struct ublk_queue *q, const struct ublksrv_io_desc *iod,
182182
struct io_uring_sqe *sqe[NR_STRIPE];
183183
int i;
184184

185-
ublk_queue_alloc_sqes(q, sqe, conf->nr_files);
185+
ublk_io_alloc_sqes(ublk_get_io(q, tag), sqe, conf->nr_files);
186186
for (i = 0; i < conf->nr_files; i++) {
187187
io_uring_prep_fsync(sqe[i], i + 1, IORING_FSYNC_DATASYNC);
188188
io_uring_sqe_set_flags(sqe[i], IOSQE_FIXED_FILE);

0 commit comments

Comments
 (0)