On Thu, Dec 25, 2025 at 12:26:02PM +0800, Jason Wang wrote:
> This patch introduces virtqueue ops which is a set of callbacks
> that will be called for different queue layout or features. This would
> help to avoid branches for split/packed and will ease the future
> implementation like in order.
>
> Note that in order to eliminate the indirect calls this patch uses
> global array of const ops to allow compiler to avoid indirect
> branches.
>
> Tested with CONFIG_MITIGATION_RETPOLINE, no performance differences
> were noticed.
>
> Acked-by: Eugenio Pérez <[email protected]>
> Suggested-by: Michael S. Tsirkin <[email protected]>
> Signed-off-by: Jason Wang <[email protected]>
> ---
> drivers/virtio/virtio_ring.c | 173 ++++++++++++++++++++++++++---------
> 1 file changed, 130 insertions(+), 43 deletions(-)
>
> diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> index f804c5c6975a..4e905dc7b6cb 100644
> --- a/drivers/virtio/virtio_ring.c
> +++ b/drivers/virtio/virtio_ring.c
> @@ -67,6 +67,12 @@
> #define LAST_ADD_TIME_INVALID(vq)
> #endif
>
> +enum vq_layout {
> + SPLIT = 0,
> + PACKED,
> + VQ_TYPE_MAX,
> +};
> +
VQ_LAYOUT_SPLIT and VQ_LAYOUT_PACKED would be better.
and VQ_LAYOUT_MAX for consistency.
> struct vring_desc_state_split {
> void *data; /* Data for callback. */
>
> @@ -159,12 +165,29 @@ struct vring_virtqueue_packed {