Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/rump/net/lib/libvirtif Pull in the changes from the dpdk...



details:   https://anonhg.NetBSD.org/src/rev/ec625812982a
branches:  trunk
changeset: 327268:ec625812982a
user:      pooka <pooka%NetBSD.org@localhost>
date:      Mon Mar 03 13:56:40 2014 +0000

description:
Pull in the changes from the dpdk, netmap and snabb switch repos.
There are two major changes:

1) All thread context policy is pushed down to the hypercalls.
   This is meant to help performance-mongering implementations be
   able to control packet scheduling better (e.g. pin down packet
   reception to certain physical cores).
2) Generalize linkstr, meaning that the interface can now take an
   arbitrary string which is passed to the create() hypercall.  This can
   be used to map backend device characteristics to the rump kernel
   interface instance.

diffstat:

 sys/rump/net/lib/libvirtif/if_virt.c       |  387 ++++++++++++++++------------
 sys/rump/net/lib/libvirtif/if_virt.h       |    9 +-
 sys/rump/net/lib/libvirtif/rumpcomp_user.c |  181 +++++++++----
 sys/rump/net/lib/libvirtif/rumpcomp_user.h |   10 +-
 4 files changed, 351 insertions(+), 236 deletions(-)

diffs (truncated from 802 to 300 lines):

diff -r fe5aa8c1f835 -r ec625812982a sys/rump/net/lib/libvirtif/if_virt.c
--- a/sys/rump/net/lib/libvirtif/if_virt.c      Mon Mar 03 13:54:43 2014 +0000
+++ b/sys/rump/net/lib/libvirtif/if_virt.c      Mon Mar 03 13:56:40 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_virt.c,v 1.38 2014/02/21 08:33:51 skrll Exp $       */
+/*     $NetBSD: if_virt.c,v 1.39 2014/03/03 13:56:40 pooka Exp $       */
 
 /*
  * Copyright (c) 2008, 2013 Antti Kantee.  All Rights Reserved.
@@ -26,24 +26,17 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_virt.c,v 1.38 2014/02/21 08:33:51 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_virt.c,v 1.39 2014/03/03 13:56:40 pooka Exp $");
 
 #include <sys/param.h>
-#include <sys/condvar.h>
-#include <sys/fcntl.h>
 #include <sys/kernel.h>
 #include <sys/kmem.h>
-#include <sys/kthread.h>
-#include <sys/mutex.h>
-#include <sys/poll.h>
-#include <sys/sockio.h>
-#include <sys/socketvar.h>
 #include <sys/cprng.h>
 
 #include <net/bpf.h>
 #include <net/if.h>
+#include <net/if_dl.h>
 #include <net/if_ether.h>
-#include <net/if_tap.h>
 
 #include <netinet/in.h>
 #include <netinet/in_var.h>
@@ -70,14 +63,11 @@
 struct virtif_sc {
        struct ethercom sc_ec;
        struct virtif_user *sc_viu;
-       bool sc_dying;
-       struct lwp *sc_l_snd, *sc_l_rcv;
-       kmutex_t sc_mtx;
-       kcondvar_t sc_cv;
+
+       int sc_num;
+       char *sc_linkstr;
 };
 
-static void virtif_receiver(void *);
-static void virtif_sender(void *);
 static int  virtif_clone(struct if_clone *, int);
 static int  virtif_unclone(struct ifnet *);
 
@@ -85,60 +75,74 @@
     IF_CLONE_INITIALIZER(VIF_NAME, virtif_clone, virtif_unclone);
 
 static int
+virtif_create(struct ifnet *ifp)
+{
+       uint8_t enaddr[ETHER_ADDR_LEN] = { 0xb2, 0x0a, 0x00, 0x0b, 0x0e, 0x01 };
+       char enaddrstr[3*ETHER_ADDR_LEN];
+       struct virtif_sc *sc = ifp->if_softc;
+       int error;
+
+       if (sc->sc_viu)
+               panic("%s: already created", ifp->if_xname);
+
+       enaddr[2] = cprng_fast32() & 0xff;
+       enaddr[5] = sc->sc_num & 0xff;
+
+       if ((error = VIFHYPER_CREATE(sc->sc_linkstr,
+           sc, enaddr, &sc->sc_viu)) != 0) {
+               printf("VIFHYPER_CREATE failed: %d\n", error);
+               return error;
+       }
+
+       ether_ifattach(ifp, enaddr);
+       ether_snprintf(enaddrstr, sizeof(enaddrstr), enaddr);
+       aprint_normal_ifnet(ifp, "Ethernet address %s\n", enaddrstr);
+
+       IFQ_SET_READY(&ifp->if_snd);
+
+       return 0;
+}
+
+static int
 virtif_clone(struct if_clone *ifc, int num)
 {
        struct virtif_sc *sc;
-       struct virtif_user *viu;
        struct ifnet *ifp;
-       uint8_t enaddr[ETHER_ADDR_LEN] = { 0xb2, 0x0a, 0x00, 0x0b, 0x0e, 0x01 };
        int error = 0;
 
-       if (num >= 0x100)
-               return E2BIG;
-
-       if ((error = VIFHYPER_CREATE(num, &viu)) != 0)
-               return error;
-
-       enaddr[2] = cprng_fast32() & 0xff;
-       enaddr[5] = num;
-
        sc = kmem_zalloc(sizeof(*sc), KM_SLEEP);
-       sc->sc_dying = false;
-       sc->sc_viu = viu;
-
-       mutex_init(&sc->sc_mtx, MUTEX_DEFAULT, IPL_NONE);
-       cv_init(&sc->sc_cv, VIF_NAME "snd");
+       sc->sc_num = num;
        ifp = &sc->sc_ec.ec_if;
        sprintf(ifp->if_xname, "%s%d", VIF_NAME, num);
        ifp->if_softc = sc;
 
-       if (rump_threads) {
-               if ((error = kthread_create(PRI_NONE, KTHREAD_MUSTJOIN, NULL,
-                   virtif_receiver, ifp, &sc->sc_l_rcv, VIF_NAME "ifr")) != 0)
-                       goto out;
-
-               if ((error = kthread_create(PRI_NONE,
-                   KTHREAD_MUSTJOIN | KTHREAD_MPSAFE, NULL,
-                   virtif_sender, ifp, &sc->sc_l_snd, VIF_NAME "ifs")) != 0)
-                       goto out;
-       } else {
-               printf("WARNING: threads not enabled, receive NOT working\n");
-       }
-
        ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
        ifp->if_init = virtif_init;
        ifp->if_ioctl = virtif_ioctl;
        ifp->if_start = virtif_start;
        ifp->if_stop = virtif_stop;
-       IFQ_SET_READY(&ifp->if_snd);
+       ifp->if_mtu = ETHERMTU;
+       ifp->if_dlt = DLT_EN10MB;
 
        if_attach(ifp);
-       ether_ifattach(ifp, enaddr);
 
- out:
+#ifndef RUMP_VIF_LINKSTR
+       /*
+        * if the underlying interface does not expect linkstr, we can
+        * create everything now.  Otherwise, we need to wait for
+        * SIOCSLINKSTR.
+        */
+#define LINKSTRNUMLEN 16
+       sc->sc_linkstr = kmem_alloc(LINKSTRNUMLEN, KM_SLEEP);
+       snprintf(sc->sc_linkstr, LINKSTRNUMLEN, "%d", sc->sc_num);
+#undef LINKSTRNUMLEN
+       error = virtif_create(ifp);
        if (error) {
-               virtif_unclone(ifp);
+               if_detach(ifp);
+               kmem_free(sc, sizeof(*sc));
+               ifp->if_softc = NULL;
        }
+#endif /* !RUMP_VIF_LINKSTR */
 
        return error;
 }
@@ -148,33 +152,16 @@
 {
        struct virtif_sc *sc = ifp->if_softc;
 
-       mutex_enter(&sc->sc_mtx);
-       if (sc->sc_dying) {
-               mutex_exit(&sc->sc_mtx);
-               return EINPROGRESS;
-       }
-       sc->sc_dying = true;
-       cv_broadcast(&sc->sc_cv);
-       mutex_exit(&sc->sc_mtx);
+       if (ifp->if_flags & IFF_UP)
+               return EBUSY;
 
        VIFHYPER_DYING(sc->sc_viu);
 
        virtif_stop(ifp, 1);
        if_down(ifp);
 
-       if (sc->sc_l_snd) {
-               kthread_join(sc->sc_l_snd);
-               sc->sc_l_snd = NULL;
-       }
-       if (sc->sc_l_rcv) {
-               kthread_join(sc->sc_l_rcv);
-               sc->sc_l_rcv = NULL;
-       }
-
        VIFHYPER_DESTROY(sc->sc_viu);
 
-       mutex_destroy(&sc->sc_mtx);
-       cv_destroy(&sc->sc_cv);
        kmem_free(sc, sizeof(*sc));
 
        ether_ifdetach(ifp);
@@ -188,127 +175,125 @@
 {
        struct virtif_sc *sc = ifp->if_softc;
 
-       ifp->if_flags |= IFF_RUNNING;
+       if (sc->sc_viu == NULL)
+               return ENXIO;
 
-       mutex_enter(&sc->sc_mtx);
-       cv_broadcast(&sc->sc_cv);
-       mutex_exit(&sc->sc_mtx);
-       
+       ifp->if_flags |= IFF_RUNNING;
        return 0;
 }
 
 static int
 virtif_ioctl(struct ifnet *ifp, u_long cmd, void *data)
 {
-       int s, rv;
+       struct virtif_sc *sc = ifp->if_softc;
+       int rv;
+
+       switch (cmd) {
+#ifdef RUMP_VIF_LINKSTR
+       struct ifdrv *ifd;
+       size_t linkstrlen;
+
+#ifndef RUMP_VIF_LINKSTRMAX
+#define RUMP_VIF_LINKSTRMAX 4096
+#endif
+
+       case SIOCGLINKSTR:
+               ifd = data;
+
+               if (!sc->sc_linkstr) {
+                       rv = ENOENT;
+                       break;
+               }
+               linkstrlen = strlen(sc->sc_linkstr)+1;
+
+               if (ifd->ifd_cmd == IFLINKSTR_QUERYLEN) {
+                       ifd->ifd_len = linkstrlen;
+                       rv = 0;
+                       break;
+               }
+               if (ifd->ifd_cmd != 0) {
+                       rv = ENOTTY;
+                       break;
+               }
+
+               rv = copyoutstr(sc->sc_linkstr,
+                   ifd->ifd_data, MIN(ifd->ifd_len,linkstrlen), NULL);
+               break;
+       case SIOCSLINKSTR:
+               if (ifp->if_flags & IFF_UP) {
+                       rv = EBUSY;
+                       break;
+               }
+
+               ifd = data;
 
-       s = splnet();
-       rv = ether_ioctl(ifp, cmd, data);
-       if (rv == ENETRESET)
-               rv = 0;
-       splx(s);
+               if (ifd->ifd_cmd == IFLINKSTR_UNSET) {
+                       panic("unset linkstr not implemented");
+               } else if (ifd->ifd_cmd != 0) {
+                       rv = ENOTTY;
+                       break;
+               } else if (sc->sc_linkstr) {
+                       rv = EBUSY;
+                       break;
+               }
+
+               if (ifd->ifd_len > RUMP_VIF_LINKSTRMAX) {
+                       rv = E2BIG;
+                       break;
+               } else if (ifd->ifd_len < 1) {
+                       rv = EINVAL;
+                       break;
+               }
+
+
+               sc->sc_linkstr = kmem_alloc(ifd->ifd_len, KM_SLEEP);
+               rv = copyinstr(ifd->ifd_data, sc->sc_linkstr,
+                   ifd->ifd_len, NULL);
+               if (rv) {
+                       kmem_free(sc->sc_linkstr, ifd->ifd_len);
+                       break;
+               }
+
+               rv = virtif_create(ifp);
+               if (rv) {
+                       kmem_free(sc->sc_linkstr, ifd->ifd_len);
+               }
+               break;
+#endif /* RUMP_VIF_LINKSTR */
+       default:
+               if (!sc->sc_linkstr)



Home | Main Index | Thread Index | Old Index