From 4085a40e18d7de2d716ca460dda82ba5245d5c5c Mon Sep 17 00:00:00 2001 From: sf Date: Tue, 30 May 2017 19:28:09 +0000 Subject: [PATCH] More minor virtio tweaks * add some comments about virtio_enqueue_trim * include mutex.h explicitly * make VIRTIO_DEBUG == 1 less verbose in vioblk ok krw@ --- sys/dev/pv/vioblk.c | 27 +++++++++++++-------------- sys/dev/pv/vioscsi.c | 3 ++- sys/dev/pv/virtio.c | 27 +++++++++++++++++++++++++-- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/sys/dev/pv/vioblk.c b/sys/dev/pv/vioblk.c index 82f63ce03f0..64552e3e0ec 100644 --- a/sys/dev/pv/vioblk.c +++ b/sys/dev/pv/vioblk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vioblk.c,v 1.6 2017/05/30 17:47:11 krw Exp $ */ +/* $OpenBSD: vioblk.c,v 1.7 2017/05/30 19:28:09 sf Exp $ */ /* * Copyright (c) 2012 Stefan Fritsch. @@ -54,6 +54,7 @@ #include #include #include +#include #include #include #include @@ -155,11 +156,8 @@ int vioblk_match(struct device *parent, void *match, void *aux) return 0; } -#if VIRTIO_DEBUG > 0 -#define DPRINTF(x...) printf(x) -#else -#define DPRINTF(x...) do {} while (0) -#endif +#define DNPRINTF(n,x...) \ + do { if (VIRTIO_DEBUG >= n) printf(x); } while(0) void vioblk_attach(struct device *parent, struct device *self, void *aux) @@ -247,7 +245,7 @@ vioblk_attach(struct device *parent, struct device *self, void *aux) sc->sc_link.adapter_buswidth = 2; sc->sc_link.luns = 1; sc->sc_link.adapter_target = 2; - DPRINTF("%s: qsize: %d\n", __func__, qsize); + DNPRINTF(1, "%s: qsize: %d\n", __func__, qsize); if (features & VIRTIO_BLK_F_RO) sc->sc_link.flags |= SDEV_READONLY; @@ -285,7 +283,7 @@ vioblk_req_get(void *cookie) SLIST_REMOVE_HEAD(&sc->sc_freelist, vr_list); mtx_leave(&sc->sc_vr_mtx); - DPRINTF("%s: %p\n", __func__, vr); + DNPRINTF(2, "%s: %p\n", __func__, vr); return vr; } @@ -296,7 +294,7 @@ vioblk_req_put(void *cookie, void *io) struct vioblk_softc *sc = cookie; struct virtio_blk_req *vr = io; - DPRINTF("%s: %p\n", __func__, vr); + DNPRINTF(2, "%s: %p\n", __func__, vr); mtx_enter(&sc->sc_vr_mtx); /* @@ -356,7 +354,7 @@ vioblk_vq_done1(struct vioblk_softc *sc, struct virtio_softc *vsc, if (vr->vr_status != VIRTIO_BLK_S_OK) { - DPRINTF("%s: EIO\n", __func__); + DNPRINTF(1, "%s: EIO\n", __func__); xs->error = XS_DRIVER_STUFFUP; xs->resid = xs->datalen; } else { @@ -695,15 +693,16 @@ vioblk_alloc_reqs(struct vioblk_softc *sc, int qsize) */ vd = &vq->vq_desc[slot]; for (r = 0; r < ALLOC_SEGS - 1; r++) { - DPRINTF("%s: vd[%d].next = %d should be %d\n", - __func__, r, vd[r].next, (slot + r + 1)); + DNPRINTF(2, "%s: vd[%d].next = %d should be " + "%d\n", __func__, r, vd[r].next, + (slot + r + 1)); if (vd[r].next != (slot + r + 1)) return i; } if (r == (ALLOC_SEGS -1) && vd[r].next != 0) return i; - DPRINTF("%s: reserved slots are contiguous (good!)\n", - __func__); + DNPRINTF(2, "%s: reserved slots are contiguous " + "(good!)\n", __func__); } vr->vr_qe_index = slot; diff --git a/sys/dev/pv/vioscsi.c b/sys/dev/pv/vioscsi.c index 8e90a73f762..cdd2a5ea3b2 100644 --- a/sys/dev/pv/vioscsi.c +++ b/sys/dev/pv/vioscsi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vioscsi.c,v 1.10 2017/05/30 12:47:47 krw Exp $ */ +/* $OpenBSD: vioscsi.c,v 1.11 2017/05/30 19:28:09 sf Exp $ */ /* * Copyright (c) 2013 Google Inc. * @@ -19,6 +19,7 @@ #include #include #include +#include #include #include diff --git a/sys/dev/pv/virtio.c b/sys/dev/pv/virtio.c index 6dbfb35d2cb..116e1002d09 100644 --- a/sys/dev/pv/virtio.c +++ b/sys/dev/pv/virtio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: virtio.c,v 1.8 2017/05/30 12:47:47 krw Exp $ */ +/* $OpenBSD: virtio.c,v 1.9 2017/05/30 19:28:09 sf Exp $ */ /* $NetBSD: virtio.c,v 1.3 2011/11/02 23:05:52 njoly Exp $ */ /* @@ -462,7 +462,7 @@ vq_free_entry(struct virtqueue *vq, struct vq_entry *qe) * - command blocks (in dmamem) should be pre-allocated and mapped * - dmamaps for command blocks should be pre-allocated and loaded * - dmamaps for payload should be pre-allocated - * r = virtio_enqueue_prep(sc, vq, &slot); // allocate a slot + * r = virtio_enqueue_prep(sc, vq, &slot); // allocate a slot * if (r) // currently 0 or EAGAIN * return r; * r = bus_dmamap_load(dmat, dmamap_payload[slot], data, count, ..); @@ -484,6 +484,26 @@ vq_free_entry(struct virtqueue *vq, struct vq_entry *qe) * virtio_enqueue(sc, vq, slot, dmamap_cmd[slot], 0); * virtio_enqueue(sc, vq, slot, dmamap_payload[slot], iswrite); * virtio_enqueue_commit(sc, vq, slot, 1); + * + * Alternative usage with statically allocated slots: + * + * // while not out of slots, do + * virtio_enqueue_prep(sc, vq, &slot); // allocate a slot + * virtio_enqueue_reserve(sc, vq, slot, max_segs); // reserve all slots + * that may ever be needed + * + * + * // Don't call virtio_enqueue_prep() + * bus_dmamap_load(dmat, dmamap_payload[slot], data, count, ..); + * bus_dmamap_sync(dmat, dmamap_cmd[slot],... BUS_DMASYNC_PREWRITE); + * bus_dmamap_sync(dmat, dmamap_payload[slot],...); + * virtio_enqueue_trim(sc, vq, slot, num_segs_needed); + * virtio_enqueue(sc, vq, slot, dmamap_cmd[slot], 0); + * virtio_enqueue(sc, vq, slot, dmamap_payload[slot], iswrite); + * virtio_enqueue_commit(sc, vq, slot, 1); + * + * + * // don't call virtio_dequeue_commit() */ /* @@ -785,6 +805,9 @@ virtio_dequeue(struct virtio_softc *sc, struct virtqueue *vq, /* * dequeue_commit: complete dequeue; the slot is recycled for future use. * if you forget to call this the slot will be leaked. + * + * Don't call this if you use statically allocated slots + * and virtio_dequeue_trim(). */ int virtio_dequeue_commit(struct virtqueue *vq, int slot) -- 2.20.1