Skip to content

Commit

Permalink
test: add test cases for hybrid iopoll
Browse files Browse the repository at this point in the history
Add a test file for hybrid iopoll to make sure it works safe.Test case
include basic read/write tests, and run in normal iopoll mode and
passthrough mode respectively.

--
changes since v1:
- remove iopoll-hybridpoll.c
- test hybrid poll with exsiting iopoll and io_uring_passthrough
- add a misconfiguration check

changes since v2:
- modify description of man doc

Signed-off-by: hexue <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
xue01-he authored and axboe committed Nov 16, 2024
1 parent a27cad8 commit d20600d
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
10 changes: 9 additions & 1 deletion man/io_uring_setup.2
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,15 @@ in question. For NVMe devices, the nvme driver must be loaded with the
parameter set to the desired number of polling queues. The polling queues
will be shared appropriately between the CPUs in the system, if the number
is less than the number of online CPU threads.

.TP
.B IORING_SETUP_HYBRID_IOPOLL
This flag must be used with
.B IORING_SETUP_IOPOLL
flag. Hybrid io polling is a feature based on iopoll, it differs from strict
polling in that it will delay a bit before doing completion side polling, to
avoid wasting too much CPU resources. Like
.B IOPOLL
, it requires that devices support polling.
.TP
.B IORING_SETUP_SQPOLL
When this flag is specified, a kernel thread is created to perform
Expand Down
3 changes: 3 additions & 0 deletions src/include/liburing/io_uring.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ enum io_uring_sqe_flags_bit {
*/
#define IORING_SETUP_NO_SQARRAY (1U << 16)

/* Use hybrid poll in iopoll process */
#define IORING_SETUP_HYBRID_IOPOLL (1U << 17)

enum io_uring_op {
IORING_OP_NOP,
IORING_OP_READV,
Expand Down
14 changes: 9 additions & 5 deletions test/io_uring_passthrough.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ static int __test_io(const char *file, struct io_uring *ring, int tc, int read,
}

static int test_io(const char *file, int tc, int read, int sqthread,
int fixed, int nonvec)
int fixed, int nonvec, int hybrid)
{
struct io_uring ring;
int ret, ring_flags = 0;
Expand All @@ -265,6 +265,9 @@ static int test_io(const char *file, int tc, int read, int sqthread,
if (sqthread)
ring_flags |= IORING_SETUP_SQPOLL;

if (hybrid)
ring_flags |= IORING_SETUP_IOPOLL | IORING_SETUP_HYBRID_IOPOLL;

ret = t_create_ring(64, &ring, ring_flags);
if (ret == T_SETUP_SKIP)
return 0;
Expand Down Expand Up @@ -449,18 +452,19 @@ int main(int argc, char *argv[])

vecs = t_create_buffers(BUFFERS, BS);

for (i = 0; i < 16; i++) {
for (i = 0; i < 32; i++) {
int read = (i & 1) != 0;
int sqthread = (i & 2) != 0;
int fixed = (i & 4) != 0;
int nonvec = (i & 8) != 0;
int hybrid = (i & 16) != 0;

ret = test_io(fname, i, read, sqthread, fixed, nonvec);
ret = test_io(fname, i, read, sqthread, fixed, nonvec, hybrid);
if (no_pt)
break;
if (ret) {
fprintf(stderr, "test_io failed %d/%d/%d/%d\n",
read, sqthread, fixed, nonvec);
fprintf(stderr, "test_io failed %d/%d/%d/%d/%d\n",
read, sqthread, fixed, nonvec, hybrid);
goto err;
}
}
Expand Down
22 changes: 13 additions & 9 deletions test/iopoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ static int test_io_uring_submit_enters(const char *file)
}

static int test_io(const char *file, int write, int sqthread, int fixed,
int buf_select, int defer)
int hybrid, int buf_select, int defer)
{
struct io_uring ring;
int ret, ring_flags = IORING_SETUP_IOPOLL;
Expand All @@ -363,6 +363,9 @@ static int test_io(const char *file, int write, int sqthread, int fixed,
ring_flags |= IORING_SETUP_SINGLE_ISSUER |
IORING_SETUP_DEFER_TASKRUN;

if (hybrid)
ring_flags |= IORING_SETUP_HYBRID_IOPOLL;

ret = t_create_ring(64, &ring, ring_flags);
if (ret == T_SETUP_SKIP)
return 0;
Expand Down Expand Up @@ -418,22 +421,23 @@ int main(int argc, char *argv[])

vecs = t_create_buffers(BUFFERS, BS);

nr = 32;
nr = 64;
if (no_buf_select)
nr = 8;
else if (!t_probe_defer_taskrun())
nr = 16;
else if (!t_probe_defer_taskrun())
nr = 32;
for (i = 0; i < nr; i++) {
int write = (i & 1) != 0;
int sqthread = (i & 2) != 0;
int fixed = (i & 4) != 0;
int buf_select = (i & 8) != 0;
int defer = (i & 16) != 0;
int hybrid = (i & 8) != 0;
int buf_select = (i & 16) != 0;
int defer = (i & 32) != 0;

ret = test_io(fname, write, sqthread, fixed, buf_select, defer);
ret = test_io(fname, write, sqthread, fixed, hybrid, buf_select, defer);
if (ret) {
fprintf(stderr, "test_io failed %d/%d/%d/%d/%d\n",
write, sqthread, fixed, buf_select, defer);
fprintf(stderr, "test_io failed %d/%d/%d/%d/%d/%d\n",
write, sqthread, fixed, hybrid, buf_select, defer);
goto err;
}
if (no_iopoll)
Expand Down

0 comments on commit d20600d

Please sign in to comment.