Comments (9)
If multiple threads are waiting on the same cq ring, then they would both get woken up if an event is posted. They then have to ensure mutual exclusivity for reading the events and ring, of course.
from liburing.
We do return the number submitted, so if the function returns 0, nothing was submitted and we didn't wait for anything. I agree that's a bug in the application, but the return value is pretty clear.
Not quite sure I see the issue here, to be honest.
from liburing.
We do return the number submitted, so if the function returns 0, nothing was submitted and we didn't wait for anything.
I was talking about io_uring_wait_cqe
instead of io_uring_submit_and_wait
#include <stdio.h>
#include "liburing.h"
int main()
{
struct io_uring ring;
struct io_uring_cqe *cqe;
int ret;
ret = io_uring_queue_init(8, &ring, 0);
if (ret) {
printf("ring setup failed\n");
return 1;
}
return io_uring_wait_cqe(&ring, &cqe); // dead lock
}
from liburing.
Sorry my bad, my eyes were tired. I don't think it's a given that doing io_uring_wait_cqe() on an empty queue is a bug. It could be that the application has multiple threads sharing that ring, and someone else will queue IO on it. The scenario you outline isn't a deadlock, it's interruptible sleep. So you can wake the application, if you need/want to.
from liburing.
Is liburing thread safe? Ok I see.
So can we have io_uring_pending_requests
that get the number of unhandled (running and in cqe) requests?
from liburing.
The kernel side has the protection it needs, if you want multiple threads filling in and updating the SQ ring, then you need to have your own synchronization in userspace. But it's doable.
It's not possible to implement io_uring_pending_requests() without adding additional tracking on the kernel side. SQEs are consumed before the IO is complete, so we'd need an additional counter to do that. Nothing tracks the count of requests that are inflight, but haven't yet completed and produced a CQE.
from liburing.
Ok. Thanks for your explaination. I wonder what will happen if multiple threads are waiting the same ring though.
from liburing.
@axboe I notice you said
It could be that the application has multiple threads sharing that ring, and someone else will queue IO on it.
Is that means if I already call io_uring_wait_cqe
and is blocked because there is no available cqe
, I can submit a new sqe
on another thread, and if it done, the io_uring_wait_cqe
will return the cqe
about the new sqe
from liburing.
@axboe I notice you said
我注意到你说
It could be that the application has multiple threads sharing that ring, and someone else will queue IO on it.这可能是因为应用程序有多个线程共享该环,而其他线程将在其上对 IO 进行排队。
Is that means if I already call
io_uring_wait_cqe
and is blocked because there is no availablecqe
, I can submit a newsqe
on another thread, and if it done, theio_uring_wait_cqe
will return thecqe
about the newsqe
这是否意味着如果我已经调用 io uring wait cqe 并且因为没有可用的 cqe 而被阻塞,我可以在另一个线程上提交一个新的 sqe,如果这样做了,io uring wait cqe 将返回关于新 sqe 的 cqe
@axboe I notice you said
It could be that the application has multiple threads sharing that ring, and someone else will queue IO on it.
Is that means if I already call
io_uring_wait_cqe
and is blocked because there is no availablecqe
, I can submit a newsqe
on another thread, and if it done, theio_uring_wait_cqe
will return thecqe
about the newsqe
I have the same doubts,I tested this and it works on one machine, but not on another.
from liburing.
Related Issues (20)
- What's the proper way to read all the PID stat files "/proc/[pid]/stat" in a io_uring friendly way? HOT 11
- EAGAINs impacting the performance of io_uring HOT 8
- SPDX license expressions
- SOCKET_URING_OP_GETSOCKOPT hangs HOT 13
- `io_uring_prep_recv` does not return `0`? HOT 2
- Question: will io_uring block in this scenario in the same way as libaio? HOT 7
- io_uring read multishot fails when trying to read a tty HOT 8
- Is there a way to synchronously wait for a completion of a submitted write for a particular FD HOT 2
- redefinition of 'struct in6_pktinfo' when building on ubi7 with gcc/g++ 9.5.0 HOT 5
- Can we know how many bytes we have read by using io_uring_prep_readv method? HOT 1
- RCU calls made by the NAPI busy poll code generates context switches occupying 50% of the time of the CPU hosting the sqp thread HOT 92
- Per-iovec zero-copy and fixed buffer settings for writev/sendmsg HOT 5
- possible socket leakage with direct file descriptors HOT 21
- Ordering guarantees between accept and close? HOT 11
- SYSCHK(syscall(__NR_io_uring_setup, 10, ¶ms)): Invalid argument HOT 3
- io_uring openat non-existing file, cqe->res returns -2, outside of specification HOT 2
- io_uring_prep_recv with IORING_RECVSEND_BUNDLE always fills only one buffer at a time HOT 13
- io_uring_prep_send_bundle should not have len argument HOT 5
- Wrong number of arguments in io_uring_prep_fixed_fd_install man
- test buf-ring-nommap.t failed with -12 (-ENOMEM) in ppc64le arch.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from liburing.