summaryrefslogtreecommitdiffstats
path: root/sys/dev/virtio/balloon
diff options
context:
space:
mode:
authorbryanv <bryanv@FreeBSD.org>2013-07-04 17:54:46 +0000
committerbryanv <bryanv@FreeBSD.org>2013-07-04 17:54:46 +0000
commit60b31b29f6d6b361213fb63376b8916108560b60 (patch)
tree5764e9795d8c7e30a68e2d314d1bfdaa514f1904 /sys/dev/virtio/balloon
parent2bb83a0bbc6571b7f15c75ada57a13790d861c57 (diff)
downloadFreeBSD-src-60b31b29f6d6b361213fb63376b8916108560b60.zip
FreeBSD-src-60b31b29f6d6b361213fb63376b8916108560b60.tar.gz
Merge virtio_balloon changes from projects/virtio
Contains projects/virtio commits: r245717: virtio_balloon: Make the softc lock a regular mutex r245718: virtio_balloon: Remove two unuseful ASSERTs r245719: virtio_balloon: More verbose ASSERT messages r245720: virtio_balloon: Simplify lowmem handling in vtballoon_inflate() r252530: virtio_balloon: Use just a kthread instead of dedciated kproc r252568: virtio_balloon: Need to use kthread_exit() after r252530 MFC after: 1 month
Diffstat (limited to 'sys/dev/virtio/balloon')
-rw-r--r--sys/dev/virtio/balloon/virtio_balloon.c44
1 files changed, 21 insertions, 23 deletions
diff --git a/sys/dev/virtio/balloon/virtio_balloon.c b/sys/dev/virtio/balloon/virtio_balloon.c
index 224a651..c222032 100644
--- a/sys/dev/virtio/balloon/virtio_balloon.c
+++ b/sys/dev/virtio/balloon/virtio_balloon.c
@@ -70,7 +70,7 @@ struct vtballoon_softc {
uint32_t vtballoon_current_npages;
TAILQ_HEAD(,vm_page) vtballoon_pages;
- struct proc *vtballoon_kproc;
+ struct thread *vtballoon_td;
uint32_t *vtballoon_page_frames;
int vtballoon_timeout;
};
@@ -127,9 +127,9 @@ CTASSERT(VTBALLOON_PAGES_PER_REQUEST * sizeof(uint32_t) <= PAGE_SIZE);
#define VTBALLOON_MTX(_sc) &(_sc)->vtballoon_mtx
#define VTBALLOON_LOCK_INIT(_sc, _name) mtx_init(VTBALLOON_MTX((_sc)), _name, \
- "VirtIO Balloon Lock", MTX_SPIN)
-#define VTBALLOON_LOCK(_sc) mtx_lock_spin(VTBALLOON_MTX((_sc)))
-#define VTBALLOON_UNLOCK(_sc) mtx_unlock_spin(VTBALLOON_MTX((_sc)))
+ "VirtIO Balloon Lock", MTX_DEF)
+#define VTBALLOON_LOCK(_sc) mtx_lock(VTBALLOON_MTX((_sc)))
+#define VTBALLOON_UNLOCK(_sc) mtx_unlock(VTBALLOON_MTX((_sc)))
#define VTBALLOON_LOCK_DESTROY(_sc) mtx_destroy(VTBALLOON_MTX((_sc)))
static device_method_t vtballoon_methods[] = {
@@ -206,10 +206,10 @@ vtballoon_attach(device_t dev)
goto fail;
}
- error = kproc_create(vtballoon_thread, sc, &sc->vtballoon_kproc,
+ error = kthread_add(vtballoon_thread, sc, NULL, &sc->vtballoon_td,
0, 0, "virtio_balloon");
if (error) {
- device_printf(dev, "cannot create balloon kproc\n");
+ device_printf(dev, "cannot create balloon kthread\n");
goto fail;
}
@@ -230,15 +230,14 @@ vtballoon_detach(device_t dev)
sc = device_get_softc(dev);
- if (sc->vtballoon_kproc != NULL) {
+ if (sc->vtballoon_td != NULL) {
VTBALLOON_LOCK(sc);
sc->vtballoon_flags |= VTBALLOON_FLAG_DETACH;
wakeup_one(sc);
- msleep_spin(sc->vtballoon_kproc, VTBALLOON_MTX(sc),
- "vtbdth", 0);
+ msleep(sc->vtballoon_td, VTBALLOON_MTX(sc), 0, "vtbdth", 0);
VTBALLOON_UNLOCK(sc);
- sc->vtballoon_kproc = NULL;
+ sc->vtballoon_td = NULL;
}
if (device_is_attached(dev)) {
@@ -320,28 +319,26 @@ vtballoon_inflate(struct vtballoon_softc *sc, int npages)
int i;
vq = sc->vtballoon_inflate_vq;
- m = NULL;
if (npages > VTBALLOON_PAGES_PER_REQUEST)
npages = VTBALLOON_PAGES_PER_REQUEST;
- KASSERT(npages > 0, ("balloon doesn't need inflating?"));
for (i = 0; i < npages; i++) {
- if ((m = vtballoon_alloc_page(sc)) == NULL)
+ if ((m = vtballoon_alloc_page(sc)) == NULL) {
+ sc->vtballoon_timeout = VTBALLOON_LOWMEM_TIMEOUT;
break;
+ }
sc->vtballoon_page_frames[i] =
VM_PAGE_TO_PHYS(m) >> VIRTIO_BALLOON_PFN_SHIFT;
- KASSERT(m->queue == PQ_NONE, ("allocated page on queue"));
+ KASSERT(m->queue == PQ_NONE,
+ ("%s: allocated page %p on queue", __func__, m));
TAILQ_INSERT_TAIL(&sc->vtballoon_pages, m, pageq);
}
if (i > 0)
vtballoon_send_page_frames(sc, vq, i);
-
- if (m == NULL)
- sc->vtballoon_timeout = VTBALLOON_LOWMEM_TIMEOUT;
}
static void
@@ -357,11 +354,10 @@ vtballoon_deflate(struct vtballoon_softc *sc, int npages)
if (npages > VTBALLOON_PAGES_PER_REQUEST)
npages = VTBALLOON_PAGES_PER_REQUEST;
- KASSERT(npages > 0, ("balloon doesn't need deflating?"));
for (i = 0; i < npages; i++) {
m = TAILQ_FIRST(&sc->vtballoon_pages);
- KASSERT(m != NULL, ("no more pages to deflate"));
+ KASSERT(m != NULL, ("%s: no more pages to deflate", __func__));
sc->vtballoon_page_frames[i] =
VM_PAGE_TO_PHYS(m) >> VIRTIO_BALLOON_PFN_SHIFT;
@@ -383,7 +379,9 @@ vtballoon_deflate(struct vtballoon_softc *sc, int npages)
KASSERT((TAILQ_EMPTY(&sc->vtballoon_pages) &&
sc->vtballoon_current_npages == 0) ||
(!TAILQ_EMPTY(&sc->vtballoon_pages) &&
- sc->vtballoon_current_npages != 0), ("balloon empty?"));
+ sc->vtballoon_current_npages != 0),
+ ("%s: bogus page count %d", __func__,
+ sc->vtballoon_current_npages));
}
static void
@@ -411,7 +409,7 @@ vtballoon_send_page_frames(struct vtballoon_softc *sc, struct virtqueue *vq,
*/
VTBALLOON_LOCK(sc);
while ((c = virtqueue_dequeue(vq, NULL)) == NULL)
- msleep_spin(sc, VTBALLOON_MTX(sc), "vtbspf", 0);
+ msleep(sc, VTBALLOON_MTX(sc), 0, "vtbspf", 0);
VTBALLOON_UNLOCK(sc);
KASSERT(c == vq, ("unexpected balloon operation response"));
@@ -510,7 +508,7 @@ vtballoon_sleep(struct vtballoon_softc *sc)
if (current < desired && timeout == 0)
break;
- msleep_spin(sc, VTBALLOON_MTX(sc), "vtbslp", timeout);
+ msleep(sc, VTBALLOON_MTX(sc), 0, "vtbslp", timeout);
}
VTBALLOON_UNLOCK(sc);
@@ -542,7 +540,7 @@ vtballoon_thread(void *xsc)
}
}
- kproc_exit(0);
+ kthread_exit();
}
static void
OpenPOWER on IntegriCloud