0

https://kernel.dk/io_uring.pdf,我注意到 io_uring 的提交队列需要另一个间接索引。对我来说,解释很模糊。

一个重要的区别是,当 CQ 环直接索引 cqes 的共享数组时,提交方在它们之间有一个间接数组。因此,提交端环形缓冲区是这个数组的索引,而数组又包含了 sqes 的索引。这最初可能看起来很奇怪和令人困惑,但它背后有一些原因。一些应用程序可能会在内部数据结构中嵌入请求单元,这使他们能够灵活地这样做,同时保留在一次操作中提交多个 sqes 的能力。

这是提交队列的代码示例

struct io_uring_sqe *sqe;
unsigned tail, index;
tail = sqring→tail;
index = tail & (*sqring→ring_mask);
sqe = &sqring→sqes[index];
/* this call fills in the sqe entries for this IO */
init_io(sqe);
/* fill the sqe index into the SQ ring array */
sqring→array[index] = index; // the completion queue wont need this extra indexing
tail++;
write_barrier();
sqring→tail = tail;
write_barrier();
4

0 回答 0