From cf707a04dc7469fdb7a4037ad0e56f6c5a9295a0 Mon Sep 17 00:00:00 2001 From: krw Date: Wed, 31 May 2017 08:10:24 +0000 Subject: [PATCH] Optimize virtio_enqueue_trim() a bit by nuking unneeded re-initializations of statically set fields. Move a common chunk out of both clauses of if/else. No intentional functional change. ok sf@ --- sys/dev/pv/virtio.c | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/sys/dev/pv/virtio.c b/sys/dev/pv/virtio.c index 116e1002d09..3107ee8c9ac 100644 --- a/sys/dev/pv/virtio.c +++ b/sys/dev/pv/virtio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: virtio.c,v 1.9 2017/05/30 19:28:09 sf Exp $ */ +/* $OpenBSD: virtio.c,v 1.10 2017/05/31 08:10:24 krw Exp $ */ /* $NetBSD: virtio.c,v 1.3 2011/11/02 23:05:52 njoly Exp $ */ /* @@ -735,37 +735,27 @@ virtio_enqueue_trim(struct virtqueue *vq, int slot, int nsegs) { struct vq_entry *qe1 = &vq->vq_entries[slot]; struct vring_desc *vd = &vq->vq_desc[0]; - struct vq_entry *qe; - int i, s; + int i; if ((vd[slot].flags & VRING_DESC_F_INDIRECT) == 0) { - qe1->qe_indirect = 0; - qe1->qe_desc_base = vd; qe1->qe_next = qe1->qe_index; - /* * N.B.: the vq_entries are ASSUMED to be a contiguous * block with slot being the index to the first one. */ - s = slot; - for (i = 0; i < nsegs - 1; i++) { - qe = &vq->vq_entries[s+1]; - vd[s].flags = VRING_DESC_F_NEXT; - vd[s].next = qe->qe_index; - s = qe->qe_index; - } - vd[s].flags = 0; } else { + qe1->qe_next = 0; vd = &vq->vq_desc[qe1->qe_index]; vd->len = sizeof(struct vring_desc) * nsegs; vd = qe1->qe_desc_base; - for (i = 0; i < nsegs; i++) { - vd[i].flags = VRING_DESC_F_NEXT; - if (i == (nsegs - 1)) - vd[i].flags = 0; - } - qe1->qe_next = 0; + slot = 0; + } + + for (i = 0; i < nsegs -1 ; i++) { + vd[slot].flags = VRING_DESC_F_NEXT; + slot++; } + vd[slot].flags = 0; } /* -- 2.20.1