繁体   English   中英

为什么 io_uring 的提交队列索引与完成队列不同?

[英]why io_uring's submission queue indexing is different from completion queue?

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();

请参考 Linux 源代码: https://github.com/torvalds/linux/blob/f6eb0fed6a3957c0b93e3a00c1ffaad84ding_22types2h#

     * This indirection could e.g. be used to assign fixed
     * io_uring_sqe entries to operations and only submit them to
     * the queue when needed.

因此,基本上它允许您在提交队列中保留一个条目,并重用它。 此外,它还允许您将提交队列条目的空间分配与条目的实际提交解耦。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM