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/libshmif Use vmem for keeping track of unit...



details:   https://anonhg.NetBSD.org/src/rev/57728efc2951
branches:  trunk
changeset: 758825:57728efc2951
user:      pooka <pooka%NetBSD.org@localhost>
date:      Tue Nov 16 20:08:24 2010 +0000

description:
Use vmem for keeping track of unit numbers so that wildcard allocation
works correctly.

diffstat:

 sys/rump/net/lib/libshmif/component.c |  13 +++++++++----
 sys/rump/net/lib/libshmif/if_shmem.c  |  32 ++++++++++++++++++++++----------
 2 files changed, 31 insertions(+), 14 deletions(-)

diffs (116 lines):

diff -r e9d024decc36 -r 57728efc2951 sys/rump/net/lib/libshmif/component.c
--- a/sys/rump/net/lib/libshmif/component.c     Tue Nov 16 18:25:03 2010 +0000
+++ b/sys/rump/net/lib/libshmif/component.c     Tue Nov 16 20:08:24 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: component.c,v 1.1 2010/11/15 23:51:06 pooka Exp $      */
+/*     $NetBSD: component.c,v 1.2 2010/11/16 20:08:24 pooka Exp $      */
 
 /*
  * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
@@ -26,11 +26,10 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: component.c,v 1.1 2010/11/15 23:51:06 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: component.c,v 1.2 2010/11/16 20:08:24 pooka Exp $");
 
 #include <sys/param.h>
-#include <sys/domain.h>
-#include <sys/protosw.h>
+#include <sys/vmem.h>
 
 #include <net/if.h>
 
@@ -40,6 +39,12 @@
 RUMP_COMPONENT(RUMP_COMPONENT_NET_IF)
 {
        extern struct if_clone shmif_cloner; /* XXX */
+       extern vmem_t *shmif_units; /* XXX */
+
+       shmif_units = vmem_create("shmif", 1, 1<<15, 1, NULL, NULL, NULL, 1, 
+           VM_SLEEP, IPL_NONE);
+       if (shmif_units == NULL)
+               panic("shmif vmem_create failed");
 
        if_clone_attach(&shmif_cloner);
 }
diff -r e9d024decc36 -r 57728efc2951 sys/rump/net/lib/libshmif/if_shmem.c
--- a/sys/rump/net/lib/libshmif/if_shmem.c      Tue Nov 16 18:25:03 2010 +0000
+++ b/sys/rump/net/lib/libshmif/if_shmem.c      Tue Nov 16 20:08:24 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_shmem.c,v 1.30 2010/11/15 23:59:06 pooka Exp $      */
+/*     $NetBSD: if_shmem.c,v 1.31 2010/11/16 20:08:24 pooka Exp $      */
 
 /*
  * Copyright (c) 2009 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.30 2010/11/15 23:59:06 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.31 2010/11/16 20:08:24 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -36,7 +36,7 @@
 #include <sys/kmem.h>
 #include <sys/kthread.h>
 #include <sys/lock.h>
-#include <sys/atomic.h>
+#include <sys/vmem.h>
 
 #include <net/if.h>
 #include <net/if_ether.h>
@@ -93,12 +93,12 @@
 
 static void shmif_rcv(void *);
 
-static uint32_t numif;
-
 #define LOCK_UNLOCKED  0
 #define LOCK_LOCKED    1
 #define LOCK_COOLDOWN  1001
 
+vmem_t *shmif_units;
+
 /*
  * This locking needs work and will misbehave severely if:
  * 1) the backing memory has to be paged in
@@ -252,9 +252,11 @@
        if (memfd == -1)
                return error;
 
-       mynum = atomic_inc_uint_nv(&numif)-1;
+       mynum = vmem_xalloc(shmif_units, 1, 0, 0, 0, 0, 0,
+           VM_INSTANTFIT | VM_SLEEP) - 1;
+
        if ((error = allocif(mynum, &sc)) != 0) {
-               rumpuser_close(memfd, &dummy);
+               rumpuser_close(memfd, NULL);
                return error;
        }
        error = initbackend(sc, memfd);
@@ -277,10 +279,20 @@
 static int
 shmif_clone(struct if_clone *ifc, int unit)
 {
+       int unit2;
 
-       /* not atomic against rump_shmif_create().  so "don't do it". */
-       if (unit >= numif)
-               numif = unit+1;
+       /*
+        * Ok, we know the unit number, but we must still reserve it.
+        * Otherwise the wildcard-side of things might get the same one.
+        * This is slightly offset-happy due to vmem.  First, we offset
+        * the range of unit numbers by +1 since vmem cannot deal with
+        * ranges starting from 0.  Second, since vmem_xalloc() allocates
+        * from [min,max) (half-*open* interval), we need to add one extra
+        * to the one extra we add to maxaddr.  Talk about uuuh.
+        */
+       unit2 = vmem_xalloc(shmif_units, 1, 0, 0, 0, unit+1, unit+3,
+           VM_SLEEP | VM_INSTANTFIT);
+       KASSERT(unit2-1 == unit);
 
        return allocif(unit, NULL);
 }



Home | Main Index | Thread Index | Old Index