簡體   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