axboe / liburing

Library providing helpers for the Linux kernel io_uring support
MIT License
2.7k stars 394 forks source link

How to understand the error code when setting worker thread binding CPU to io_uring-register_iowq-aff failed? #1147

Closed wwwwxxxxhhhh closed 1 month ago

wwwwxxxxhhhh commented 1 month ago

Hi, I want to call the interface io_uring-register_iowq-aff to bind the worker thread to CPU1, but the result returns Unknown error -22, and the collected error is displayed as Success.Error result, please check the docx file.

The actual worker thread did not successfully bind to the specified CPU. What should I do to correctly specify the corresponding CPU? error_result.docx Thanks.

wwwwxxxxhhhh commented 1 month ago

Sorry, put the file here. [Uploading error_result.docx…]()

axboe commented 1 month ago

Please just paste your code and the errors into the GitHub issue, I really don't want to download random word documents for something that should just be readily readable in here. Include what kernel you are using as well.

wwwwxxxxhhhh commented 1 month ago

Hi, I directly simplified the wq aff. c program for testing, and the program is as follows: ##################################################################### / SPDX-License-Identifier: MIT / /*

define IOWQ_CPU 0

define SQPOLL_CPU 1

static int test(int sqpoll) { struct io_uring_params p = { }; struct io_uring ring; struct io_uring_sqe *sqe; char buf[64]; int fds[2], ret; cpu_set_t set;

if (sqpoll) {
    p.flags = IORING_SETUP_SQPOLL | IORING_SETUP_SQ_AFF;
    p.sq_thread_cpu = SQPOLL_CPU;
}

io_uring_queue_init_params(8, &ring, &p);

CPU_ZERO(&set);
CPU_SET(IOWQ_CPU, &set);

ret = io_uring_register_iowq_aff(&ring, sizeof(set), &set);
if (ret) {
    fprintf(stderr, "register aff: %d\n", ret);
}

if (pipe(fds) < 0) {
    perror("pipe");
}

sqe = io_uring_get_sqe(&ring);
io_uring_prep_read(sqe, fds[0], buf, sizeof(buf), 0);
sqe->flags |= IOSQE_ASYNC;
io_uring_submit(&ring);
usleep(10000);
io_uring_queue_exit(&ring);
return ret;

}

int main(int argc, char *argv[]) { int ret; ret = test(1); return 0; }

wwwwxxxxhhhh commented 1 month ago

Hi, The test results are as follows: [root@localhost wxh]# ./wxh_iouring io_uring.conf register aff: -22 [root@localhost wxh]# ./wxh_iouring register aff: -22

wwwwxxxxhhhh commented 1 month ago

Hi, The kernel version I tested is as follows: 5.10.0-136.12.0.86.oe2203sp1.x86_64

axboe commented 1 month ago

I don't know what version of kernel that is, but if you get -EINVAL, then it's too old to support WQ_AFF. The current 5.10-stable trees do support it, but older ones do not.