Author: bryanv
Date: Thu Jul  4 17:54:46 2013
New Revision: 252704
URL: http://svnweb.freebsd.org/changeset/base/252704

Log:
  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

Modified:
  head/sys/dev/virtio/balloon/virtio_balloon.c

Modified: head/sys/dev/virtio/balloon/virtio_balloon.c
==============================================================================
--- head/sys/dev/virtio/balloon/virtio_balloon.c        Thu Jul  4 17:53:02 
2013        (r252703)
+++ head/sys/dev/virtio/balloon/virtio_balloon.c        Thu Jul  4 17:54:46 
2013        (r252704)
@@ -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 * s
 
 #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
        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
 
        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
        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 vtball
         */
        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 *
                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
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to