lkml.org 
[lkml]   [2022]   [Apr]   [23]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[RFC PATCH 08/16] virtio_ring: packed: extract next_idx()
    Date
    Separate the logic of idx growth of packed into a function. It is
    convenient to share in multiple locations. Subsequent patches will also
    use this logic.

    Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
    ---
    drivers/virtio/virtio_ring.c | 30 +++++++++++++++++-------------
    1 file changed, 17 insertions(+), 13 deletions(-)

    diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
    index fa4270e8c009..e3525d92f646 100644
    --- a/drivers/virtio/virtio_ring.c
    +++ b/drivers/virtio/virtio_ring.c
    @@ -1330,6 +1330,18 @@ static int virtqueue_resize_split(struct virtqueue *_vq, u32 num,
    * Packed ring specific functions - *_packed().
    */

    +static u32 next_idx(struct vring_virtqueue *vq, u32 idx)
    +{
    + if ((unlikely(++idx >= vq->packed.vring.num))) {
    + idx = 0;
    + vq->packed.avail_used_flags ^=
    + 1 << VRING_PACKED_DESC_F_AVAIL |
    + 1 << VRING_PACKED_DESC_F_USED;
    + }
    +
    + return idx;
    +}
    +
    static void vring_unmap_extra_packed(const struct vring_virtqueue *vq,
    struct vring_desc_extra *extra)
    {
    @@ -1465,14 +1477,11 @@ static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,
    vq->vq.num_free -= 1;

    /* Update free pointer */
    - n = head + 1;
    - if (n >= vq->packed.vring.num) {
    - n = 0;
    + n = next_idx(vq, head);
    +
    + if (n < head)
    vq->packed.avail_wrap_counter ^= 1;
    - vq->packed.avail_used_flags ^=
    - 1 << VRING_PACKED_DESC_F_AVAIL |
    - 1 << VRING_PACKED_DESC_F_USED;
    - }
    +
    vq->packed.next_avail_idx = n;
    vq->free_head = vq->packed.desc_extra[id].next;

    @@ -1592,12 +1601,7 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq,
    prev = curr;
    curr = vq->packed.desc_extra[curr].next;

    - if ((unlikely(++i >= vq->packed.vring.num))) {
    - i = 0;
    - vq->packed.avail_used_flags ^=
    - 1 << VRING_PACKED_DESC_F_AVAIL |
    - 1 << VRING_PACKED_DESC_F_USED;
    - }
    + i = next_idx(vq, i);
    }
    }

    --
    2.31.0
    \
     
     \ /
      Last update: 2022-04-24 04:41    [W:8.209 / U:0.040 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site