Skip to content

Commit

Permalink
ioq: Check for io_uring_register_iowq_max_workers() before using it
Browse files Browse the repository at this point in the history
This allows us to build against liburing as old as version 2.0, which is
apparently shipped by the latest Amazon Linux distribution.

Fixes: #147
  • Loading branch information
tavianator committed Nov 11, 2024
1 parent d09b784 commit dcbcf7f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions build/has/io-uring-max-workers.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright © Tavian Barnes <[email protected]>
// SPDX-License-Identifier: 0BSD

#include <liburing.h>

int main(void) {
struct io_uring ring;
io_uring_queue_init(1, &ring, 0);
unsigned int values[] = {0, 0};
return io_uring_register_iowq_max_workers(&ring, values);
}
1 change: 1 addition & 0 deletions build/header.mk
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ HEADERS := \
gen/has/getmntinfo.h \
gen/has/getprogname-gnu.h \
gen/has/getprogname.h \
gen/has/io-uring-max-workers.h \
gen/has/pipe2.h \
gen/has/posix-getdents.h \
gen/has/posix-spawn-addfchdir-np.h \
Expand Down
3 changes: 3 additions & 0 deletions src/ioq.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,7 @@ static int ioq_ring_init(struct ioq *ioq, struct ioq_thread *thread) {
return -1;
}

#if BFS_HAS_IO_URING_MAX_WORKERS
// Limit the number of io_uring workers
unsigned int values[] = {
ioq->nthreads, // [IO_WQ_BOUND]
Expand All @@ -886,6 +887,8 @@ static int ioq_ring_init(struct ioq *ioq, struct ioq_thread *thread) {
io_uring_register_iowq_max_workers(&thread->ring, values);
#endif

#endif // BFS_WITH_LIBURING

return 0;
}

Expand Down

0 comments on commit dcbcf7f

Please sign in to comment.