简体   繁体   English

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

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

From https://kernel.dk/io_uring.pdf , I noticed submission queue of io_uring requires another indirection of indexing.https://kernel.dk/io_uring.pdf ,我注意到 io_uring 的提交队列需要另一个间接索引。 And the explaination is quite blurry for me.对我来说,解释很模糊。

One important difference is that while the CQ ring is directly indexing the shared array of cqes, the submission side has an indirection array between them.一个重要的区别是,当 CQ 环直接索引 cqes 的共享数组时,提交端在它们之间有一个间接数组。 Hence the submission side ring buffer is an index into this array, which in turn contains the index into the sqes.因此,提交端环形缓冲区是这个数组的索引,而数组又包含了 sqes 的索引。 This might initially seem odd and confusing, but there's some reasoning behind it.这最初可能看起来很奇怪和令人困惑,但它背后有一些原因。 Some applications may embed request units inside internal data structures, and this allows them the flexibility to do so while retaining the ability to submit multiple sqes in one operation.一些应用程序可能会在内部数据结构中嵌入请求单元,这使他们能够灵活地这样做,同时保留在一次操作中提交多个 sqes 的能力。

And here are the code sample for submission queue这是提交队列的代码示例

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

Please refer to Linux source code: https://github.com/torvalds/linux/blob/f6eb0fed6a3957c0b93e3a00c1ffaad84d4ffc31/include/linux/io_uring_types.h#L220-L222请参考 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.

So, basically it allows you to reserve an entry in submission queue, and reuse it.因此,基本上它允许您在提交队列中保留一个条目,并重用它。 Furthermore, It also allows you to decouple the allocation of space for the submission queue entry and the actual submission of the entry.此外,它还允许您将提交队列条目的空间分配与条目的实际提交解耦。

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

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