Notes about VIRTIO_F_EVENT_IDX feature
本文将mark下virtio VIRTIO_F_EVENT_IDX feature相关notes。
Why
In many systems used and available buffer notifications involve significant overhead. To mitigate it, each VQ maintains a flag to indicate when it wants to be notified. Remember that the driver’s one is read-only by the device, and the device’s one is read-only by the driver.
在许多系统中,已使用和可用的缓冲区通知涉及大量开销。为了减少开销,每个 VQ 都会保留一个标志,用于指示何时需要通知。请记住,驱动程序的标志是设备只读的,而设备的标志是驱动程序只读的。
We already know all of this, and its use is pretty straightforward. The only thing you need to take care of is the asynchronous nature of this method: The side of the communication that disables or enables it can’t be sure that the other end is going to know the change, so you can miss notifications or to have more than expected.
这些我们都已经知道了,使用起来也非常简单。唯一需要注意的是该方法的异步性质: 通信的一端禁用或启用它时,无法确定另一端是否会知道这一变化,因此可能会错过通知或出现比预期更多的通知。
A more effective way of notifications toggle is enabled if the VIRTIO_F_EVENT_IDX
feature bit is negotiated by device and driver: Instead of disable them in a binary fashion, driver and device can specify how far the other can progress before a notification is required using an specific descriptor id.
如果通过设备和驱动程序协商VIRTIO_F_EVENT_IDX
功能位,就能启用更有效的通知切换方法: 与二进制禁用方式不同,驱动程序和设备可以使用特定的描述符 id 来指定对方在需要通知之前可以进行到什么程度。
What
Used Buffer Notification Suppression
总结
- driver往avail ring中写flags与used_event
- 当设备写的used_idx >= used_event时,设备MUST发送中断
- 当设备写的used_idx < used_event时,设备SHOULD NOT发送中断
Available Buffer Notification Suppression
总结
- 设备往used ring中写flags与avail_event
- 当driver写的avail_idx >= avail_event时,driver MUST kick
- 当driver写的avail_idx < avail_event时,driver SHOULD NOT kick
参考资料:
- Virtqueues and virtio ring: How the data travels
- virtio 1.3 spec