CVS commit: src/sys/rump/net/lib/libshmif

2021-07-13 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Jul 14 03:16:06 UTC 2021

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
shmif: support ALTQ


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.82 src/sys/rump/net/lib/libshmif/if_shmem.c:1.83
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.82	Wed Jun 16 00:21:19 2021
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Wed Jul 14 03:16:06 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.82 2021/06/16 00:21:19 riastradh Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.83 2021/07/14 03:16:06 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.82 2021/06/16 00:21:19 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.83 2021/07/14 03:16:06 ozaki-r Exp $");
 
 #include 
 #include 
@@ -191,6 +191,7 @@ allocif(int unit, struct shmif_sc **scp)
 	IFCAP_CSUM_UDPv4_Rx	| IFCAP_CSUM_UDPv4_Tx |
 	IFCAP_CSUM_TCPv6_Rx	| IFCAP_CSUM_TCPv6_Tx |
 	IFCAP_CSUM_UDPv6_Rx	| IFCAP_CSUM_UDPv6_Tx;
+	IFQ_SET_READY(>if_snd);
 
 	mutex_init(>sc_mtx, MUTEX_DEFAULT, IPL_NONE);
 	cv_init(>sc_cv, "shmifcv");
@@ -206,6 +207,7 @@ allocif(int unit, struct shmif_sc **scp)
 	}
 #endif
 
+	if_deferred_start_init(ifp, NULL);
 	ether_ifattach(ifp, enaddr);
 	if_register(ifp);
 
@@ -545,7 +547,7 @@ shmif_start(struct ifnet *ifp)
 	ifp->if_flags |= IFF_OACTIVE;
 
 	for (;;) {
-		IF_DEQUEUE(>if_snd, m);
+		IFQ_DEQUEUE(>if_snd, m);
 		if (m == NULL)
 			break;
 



CVS commit: src/sys/rump/net/lib/libshmif

2020-04-03 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Apr  3 13:57:48 UTC 2020

Modified Files:
src/sys/rump/net/lib/libshmif: shmifvar.h

Log Message:
make constant unsigned


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/rump/net/lib/libshmif/shmifvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/shmifvar.h
diff -u src/sys/rump/net/lib/libshmif/shmifvar.h:1.10 src/sys/rump/net/lib/libshmif/shmifvar.h:1.11
--- src/sys/rump/net/lib/libshmif/shmifvar.h:1.10	Wed Sep 17 00:20:58 2014
+++ src/sys/rump/net/lib/libshmif/shmifvar.h	Fri Apr  3 09:57:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: shmifvar.h,v 1.10 2014/09/17 04:20:58 ozaki-r Exp $	*/
+/*	$NetBSD: shmifvar.h,v 1.11 2020/04/03 13:57:48 christos Exp $	*/
 
 /*-
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -60,7 +60,7 @@ struct shmif_pkthdr {
 	uint64_t sp_sender;
 };
 
-#define BUSMEM_SIZE (1024*1024)
+#define BUSMEM_SIZE (1024*1024U)
 #define BUSMEM_DATASIZE (BUSMEM_SIZE - sizeof(struct shmif_mem))
 
 #if 0



CVS commit: src/sys/rump/net/lib/libshmif

2020-02-24 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Feb 25 03:26:18 UTC 2020

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
shmif: reduce the number of calls of cprng(9)


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.80 src/sys/rump/net/lib/libshmif/if_shmem.c:1.81
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.80	Tue Feb 25 03:25:36 2020
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Tue Feb 25 03:26:18 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.80 2020/02/25 03:25:36 ozaki-r Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.81 2020/02/25 03:26:18 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.80 2020/02/25 03:25:36 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.81 2020/02/25 03:26:18 ozaki-r Exp $");
 
 #include 
 #include 
@@ -163,16 +163,16 @@ allocif(int unit, struct shmif_sc **scp)
 	uint8_t enaddr[ETHER_ADDR_LEN] = { 0xb2, 0xa0, 0x00, 0x00, 0x00, 0x00 };
 	struct shmif_sc *sc;
 	struct ifnet *ifp;
-	uint32_t randnum;
+	uint64_t randnum;
 	int error;
 
-	randnum = cprng_strong32();
-	memcpy([2], , sizeof(randnum));
+	randnum = cprng_strong64();
+	memcpy([2], , 4);
 
 	sc = kmem_zalloc(sizeof(*sc), KM_SLEEP);
 	sc->sc_memfd = -1;
 	sc->sc_unit = unit;
-	sc->sc_uid = cprng_strong64();
+	sc->sc_uid = randnum;
 
 	ifp = >sc_ec.ec_if;
 



CVS commit: src/sys/rump/net/lib/libshmif

2020-02-24 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Feb 25 03:25:36 UTC 2020

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
shmif: s/sc_uuid/sc_uid/

It's not UUID :-/


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.79 src/sys/rump/net/lib/libshmif/if_shmem.c:1.80
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.79	Tue Feb 25 03:24:48 2020
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Tue Feb 25 03:25:36 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.79 2020/02/25 03:24:48 ozaki-r Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.80 2020/02/25 03:25:36 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.79 2020/02/25 03:24:48 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.80 2020/02/25 03:25:36 ozaki-r Exp $");
 
 #include 
 #include 
@@ -101,7 +101,7 @@ struct shmif_sc {
 	struct lwp *sc_rcvl;
 	bool sc_dying;
 
-	uint64_t sc_uuid;
+	uint64_t sc_uid;
 };
 
 static void shmif_rcv(void *);
@@ -172,7 +172,7 @@ allocif(int unit, struct shmif_sc **scp)
 	sc = kmem_zalloc(sizeof(*sc), KM_SLEEP);
 	sc->sc_memfd = -1;
 	sc->sc_unit = unit;
-	sc->sc_uuid = cprng_strong64();
+	sc->sc_uid = cprng_strong64();
 
 	ifp = >sc_ec.ec_if;
 
@@ -605,7 +605,7 @@ shmif_snd(struct ifnet *ifp, struct mbuf
 	sp.sp_len = pktsize;
 	sp.sp_sec = tv.tv_sec;
 	sp.sp_usec = tv.tv_usec;
-	sp.sp_sender = sc->sc_uuid;
+	sp.sp_sender = sc->sc_uid;
 
 	bpf_mtap(ifp, m0, BPF_D_OUT);
 
@@ -798,7 +798,7 @@ shmif_rcv(void *arg)
 		 * Test if we want to pass the packet upwards
 		 */
 		eth = mtod(m, struct ether_header *);
-		if (sp.sp_sender == sc->sc_uuid) {
+		if (sp.sp_sender == sc->sc_uid) {
 			passup = false;
 		} else if (memcmp(eth->ether_dhost, CLLADDR(ifp->if_sadl),
 		ETHER_ADDR_LEN) == 0) {



CVS commit: src/sys/rump/net/lib/libshmif

2020-02-24 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Tue Feb 25 03:24:48 UTC 2020

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
shmif: use cprng_strong64 instead of cprng_fast64 to generate a unique ID

shmif uses random bytes generated by cprng(9) as a unique device ID
between rump kernels to identify packets fed by itself and not receive
them.  So if generated bytes are identical between shmif interfaces on
different rump kernels, shmif may drop incoming packets unintentionally.
This is one cause of recent ATF test failures of IPsec.

Fix it by using cprng_strong64 instead of cprng_fast64.  This is a
workaround and we should also investigate why cprng_fast64 starts
failing on rump kernels, although using cprng_strong64 in initialization
itself is feasible.

Fix PR kern/54897


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.78 src/sys/rump/net/lib/libshmif/if_shmem.c:1.79
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.78	Thu Feb 20 08:06:15 2020
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Tue Feb 25 03:24:48 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.78 2020/02/20 08:06:15 ozaki-r Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.79 2020/02/25 03:24:48 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.78 2020/02/20 08:06:15 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.79 2020/02/25 03:24:48 ozaki-r Exp $");
 
 #include 
 #include 
@@ -172,7 +172,7 @@ allocif(int unit, struct shmif_sc **scp)
 	sc = kmem_zalloc(sizeof(*sc), KM_SLEEP);
 	sc->sc_memfd = -1;
 	sc->sc_unit = unit;
-	sc->sc_uuid = cprng_fast64();
+	sc->sc_uuid = cprng_strong64();
 
 	ifp = >sc_ec.ec_if;
 



CVS commit: src/sys/rump/net/lib/libshmif

2020-02-20 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Feb 20 08:06:15 UTC 2020

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
shmif: use cprng_strong32 to generate random bytes for a MAC address

cprng_fast32 sometimes returns indentical bytes, which look
"20:0e:11:33" in a MAC address, on different rump_server instances.
That leads MAC address duplications resulting in a test failure.

Fix it by using cprng_strong32 instead of cprng_fast32.  However
we should rather fix cprng_fast32 (or rump itself) somehow.

The fix mitigates PR kern/54897 but test failures due to other
causes still remain.


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.77 src/sys/rump/net/lib/libshmif/if_shmem.c:1.78
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.77	Sat Feb  1 22:38:31 2020
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Thu Feb 20 08:06:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.77 2020/02/01 22:38:31 thorpej Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.78 2020/02/20 08:06:15 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.77 2020/02/01 22:38:31 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.78 2020/02/20 08:06:15 ozaki-r Exp $");
 
 #include 
 #include 
@@ -166,7 +166,7 @@ allocif(int unit, struct shmif_sc **scp)
 	uint32_t randnum;
 	int error;
 
-	randnum = cprng_fast32();
+	randnum = cprng_strong32();
 	memcpy([2], , sizeof(randnum));
 
 	sc = kmem_zalloc(sizeof(*sc), KM_SLEEP);



CVS commit: src/sys/rump/net/lib/libshmif

2020-02-01 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat Feb  1 22:38:31 UTC 2020

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
Adopt .


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.76 src/sys/rump/net/lib/libshmif/if_shmem.c:1.77
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.76	Wed Dec 12 01:51:32 2018
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Sat Feb  1 22:38:31 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.76 2018/12/12 01:51:32 rin Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.77 2020/02/01 22:38:31 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.76 2018/12/12 01:51:32 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.77 2020/02/01 22:38:31 thorpej Exp $");
 
 #include 
 #include 
@@ -561,7 +561,7 @@ shmif_start(struct ifnet *ifp)
 
 		m = ether_sw_offload_tx(ifp, m);
 		if (m == NULL) {
-			ifp->if_oerrors++;
+			if_statinc(ifp, if_oerrors);
 			break;
 		}
 
@@ -630,7 +630,7 @@ shmif_snd(struct ifnet *ifp, struct mbuf
 	shmif_unlockbus(busmem);
 
 	m_freem(m0);
-	ifp->if_opackets++;
+	if_statinc(ifp, if_opackets);
 
 	DPRINTF(("shmif_start: send %d bytes at off %d\n", pktsize,
 	busmem->shm_last));



CVS commit: src/sys/rump/net/lib/libshmif

2018-12-11 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Dec 12 01:51:32 UTC 2018

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
Add TX/RX offload capabilities to shmif(4). They are emulated in
software by ether_sw_offload_[tr]x().

For rump kernels, if_capabilities for shmemif(4) can be specified
by environmental variable RUMP_SHMIF_CAPENABLE:

 setenv RUMP_SHMIF_CAPENABLE 0x7ff80 (all offload)
 setenv RUMP_SHMIF_CAPENABLE 0x6aa80 (all TX)
 setenv RUMP_SHMIF_CAPENABLE 0x15500 (all RX)

part of PR kern/53562
OK msaitoh


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.75 src/sys/rump/net/lib/libshmif/if_shmem.c:1.76
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.75	Tue Jun 26 06:48:03 2018
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Wed Dec 12 01:51:32 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.75 2018/06/26 06:48:03 msaitoh Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.76 2018/12/12 01:51:32 rin Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.75 2018/06/26 06:48:03 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.76 2018/12/12 01:51:32 rin Exp $");
 
 #include 
 #include 
@@ -43,6 +43,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -76,6 +77,7 @@ struct if_clone shmif_cloner =
 static int	shmif_init(struct ifnet *);
 static int	shmif_ioctl(struct ifnet *, u_long, void *);
 static void	shmif_start(struct ifnet *);
+static void	shmif_snd(struct ifnet *, struct mbuf *);
 static void	shmif_stop(struct ifnet *, int);
 
 #include "shmifvar.h"
@@ -183,6 +185,12 @@ allocif(int unit, struct shmif_sc **scp)
 	ifp->if_stop = shmif_stop;
 	ifp->if_mtu = ETHERMTU;
 	ifp->if_dlt = DLT_EN10MB;
+	ifp->if_capabilities = IFCAP_TSOv4 | IFCAP_TSOv6 |
+	IFCAP_CSUM_IPv4_Rx	| IFCAP_CSUM_IPv4_Tx |
+	IFCAP_CSUM_TCPv4_Rx	| IFCAP_CSUM_TCPv4_Tx |
+	IFCAP_CSUM_UDPv4_Rx	| IFCAP_CSUM_UDPv4_Tx |
+	IFCAP_CSUM_TCPv6_Rx	| IFCAP_CSUM_TCPv6_Tx |
+	IFCAP_CSUM_UDPv6_Rx	| IFCAP_CSUM_UDPv6_Tx;
 
 	mutex_init(>sc_mtx, MUTEX_DEFAULT, IPL_NONE);
 	cv_init(>sc_cv, "shmifcv");
@@ -197,6 +205,16 @@ allocif(int unit, struct shmif_sc **scp)
 
 		return error;
 	}
+#if 1
+	char buf[256];
+
+	if (rumpuser_getparam("RUMP_SHMIF_CAPENABLE", buf, sizeof(buf)) == 0) {
+		uint64_t capen = strtoul(buf, NULL, 0);
+
+		ifp->if_capenable = capen & ifp->if_capabilities;
+	}
+#endif
+
 	ether_ifattach(ifp, enaddr);
 	if_register(ifp);
 
@@ -527,70 +545,33 @@ shmif_ioctl(struct ifnet *ifp, u_long cm
 	return rv;
 }
 
-/* send everything in-context since it's just a matter of mem-to-mem copy */
 static void
 shmif_start(struct ifnet *ifp)
 {
 	struct shmif_sc *sc = ifp->if_softc;
-	struct shmif_mem *busmem = sc->sc_busmem;
-	struct mbuf *m, *m0;
-	uint32_t dataoff;
-	uint32_t pktsize, pktwrote;
+	struct mbuf *m, *n;
 	bool wrote = false;
-	bool wrap;
 
 	ifp->if_flags |= IFF_OACTIVE;
 
 	for (;;) {
-		struct shmif_pkthdr sp;
-		struct timeval tv;
-
-		IF_DEQUEUE(>if_snd, m0);
-		if (m0 == NULL) {
+		IF_DEQUEUE(>if_snd, m);
+		if (m == NULL)
 			break;
-		}
 
-		pktsize = 0;
-		for (m = m0; m != NULL; m = m->m_next) {
-			pktsize += m->m_len;
+		m = ether_sw_offload_tx(ifp, m);
+		if (m == NULL) {
+			ifp->if_oerrors++;
+			break;
 		}
-		KASSERT(pktsize <= ETHERMTU + ETHER_HDR_LEN);
-
-		getmicrouptime();
-		sp.sp_len = pktsize;
-		sp.sp_sec = tv.tv_sec;
-		sp.sp_usec = tv.tv_usec;
-		sp.sp_sender = sc->sc_uuid;
 
-		bpf_mtap(ifp, m0, BPF_D_OUT);
-
-		shmif_lockbus(busmem);
-		KASSERT(busmem->shm_magic == SHMIF_MAGIC);
-		busmem->shm_last = shmif_nextpktoff(busmem, busmem->shm_last);
-
-		wrap = false;
-		dataoff = shmif_buswrite(busmem,
-		busmem->shm_last, , sizeof(sp), );
-		pktwrote = 0;
-		for (m = m0; m != NULL; m = m->m_next) {
-			pktwrote += m->m_len;
-			dataoff = shmif_buswrite(busmem, dataoff,
-			mtod(m, void *), m->m_len, );
-		}
-		KASSERT(pktwrote == pktsize);
-		if (wrap) {
-			busmem->shm_gen++;
-			DPRINTF(("bus generation now %" PRIu64 "\n",
-			busmem->shm_gen));
-		}
-		shmif_unlockbus(busmem);
+		do {
+			n = m->m_nextpkt;
+			shmif_snd(ifp, m);
+			m = n;
+		} while (m != NULL);
 
-		m_freem(m0);
 		wrote = true;
-		ifp->if_opackets++;
-
-		DPRINTF(("shmif_start: send %d bytes at off %d\n",
-		pktsize, busmem->shm_last));
 	}
 
 	ifp->if_flags &= ~IFF_OACTIVE;
@@ -601,6 +582,60 @@ shmif_start(struct ifnet *ifp)
 	}
 }
 
+/* send everything in-context since it's just a matter of mem-to-mem copy */
+static void
+shmif_snd(struct ifnet *ifp, struct mbuf *m0)
+{
+	struct shmif_sc *sc = ifp->if_softc;
+	struct 

CVS commit: src/sys/rump/net/lib/libshmif

2018-04-04 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Wed Apr  4 09:19:33 UTC 2018

Modified Files:
src/sys/rump/net/lib/libshmif: shmif_user.c

Log Message:
Unconditionally include , as we use ftruncate() unconditionally
too.
Reported (with patch) by Antonio Huete Jimenez in PR 53153, slightly
modified by me.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/rump/net/lib/libshmif/shmif_user.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/shmif_user.c
diff -u src/sys/rump/net/lib/libshmif/shmif_user.c:1.1 src/sys/rump/net/lib/libshmif/shmif_user.c:1.2
--- src/sys/rump/net/lib/libshmif/shmif_user.c:1.1	Thu Mar 13 01:42:59 2014
+++ src/sys/rump/net/lib/libshmif/shmif_user.c	Wed Apr  4 09:19:33 2018
@@ -1,4 +1,4 @@
-/*  $NetBSD: shmif_user.c,v 1.1 2014/03/13 01:42:59 pooka Exp $	*/
+/*  $NetBSD: shmif_user.c,v 1.2 2018/04/04 09:19:33 martin Exp $	*/
 
 /*-
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -29,6 +29,7 @@
 #include 
 
 #include 
+#include 
 
 #include 
 
@@ -102,7 +103,6 @@ rumpcomp_shmif_watchwait(int kq)
 
 #include 
 #include 
-#include 
 
 int
 rumpcomp_shmif_watchsetup(int *inotifyp, int fd)
@@ -171,7 +171,6 @@ rumpcomp_shmif_watchwait(int kq)
 
 #else
 #include 
-#include 
 
 /* a polling default implementation */
 int



CVS commit: src/sys/rump/net/lib/libshmif

2017-10-23 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Oct 23 12:55:26 UTC 2017

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
 Fix compile error.


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.73 src/sys/rump/net/lib/libshmif/if_shmem.c:1.74
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.73	Mon Oct 23 09:31:18 2017
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Mon Oct 23 12:55:26 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.73 2017/10/23 09:31:18 msaitoh Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.74 2017/10/23 12:55:26 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.73 2017/10/23 09:31:18 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.74 2017/10/23 12:55:26 msaitoh Exp $");
 
 #include 
 #include 
@@ -189,7 +189,8 @@ allocif(int unit, struct shmif_sc **scp)
 
 	error = if_initialize(ifp);
 	if (error != 0) {
-		aprint_error("shmif%d: if_initialize failed(%d)\n", unit, rv);
+		aprint_error("shmif%d: if_initialize failed(%d)\n", unit,
+		error);
 		cv_destroy(>sc_cv);
 		mutex_destroy(>sc_mtx);
 		kmem_free(sc, sizeof(*sc));



CVS commit: src/sys/rump/net/lib/libshmif

2016-12-22 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Dec 22 12:55:28 UTC 2016

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
Fix that rump.ifconfig shmifN destroy hangs up

rump.ifconfig shmifN destroy sometimes hangs up on closing a file
descriptor of kqueue under heavy load. It seems it happens because of
a race condition between closing a fd and kevent to the same fd on
another kthread for packet Rx. Fix it by executing the close operation
after the kthread left.


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.71 src/sys/rump/net/lib/libshmif/if_shmem.c:1.72
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.71	Thu Dec 22 10:13:09 2016
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Thu Dec 22 12:55:28 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.71 2016/12/22 10:13:09 ozaki-r Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.72 2016/12/22 12:55:28 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.71 2016/12/22 10:13:09 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.72 2016/12/22 12:55:28 ozaki-r Exp $");
 
 #include 
 #include 
@@ -374,7 +374,6 @@ shmif_unclone(struct ifnet *ifp)
 
 	shmif_stop(ifp, 1);
 	if_down(ifp);
-	finibackend(sc);
 
 	mutex_enter(>sc_mtx);
 	sc->sc_dying = true;
@@ -385,6 +384,13 @@ shmif_unclone(struct ifnet *ifp)
 		kthread_join(sc->sc_rcvl);
 	sc->sc_rcvl = NULL;
 
+	/*
+	 * Need to be called after the kthread left, otherwise closing kqueue
+	 * (sc_kq) hangs sometimes perhaps because of a race condition between
+	 * close and kevent in the kthread on the kqueue.
+	 */
+	finibackend(sc);
+
 	vmem_xfree(shmif_units, sc->sc_unit+1, 1);
 
 	ether_ifdetach(ifp);



CVS commit: src/sys/rump/net/lib/libshmif

2016-12-22 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Thu Dec 22 10:13:09 UTC 2016

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
Fix handling return value of rumpcomp_shmif_watchwait


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.70 src/sys/rump/net/lib/libshmif/if_shmem.c:1.71
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.70	Thu Dec 15 09:28:07 2016
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Thu Dec 22 10:13:09 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.70 2016/12/15 09:28:07 ozaki-r Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.71 2016/12/22 10:13:09 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.70 2016/12/15 09:28:07 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.71 2016/12/22 10:13:09 ozaki-r Exp $");
 
 #include 
 #include 
@@ -685,8 +685,7 @@ shmif_rcv(void *arg)
 		shmif_nextpktoff(busmem, busmem->shm_last)
 		 == sc->sc_nextpacket) {
 			shmif_unlockbus(busmem);
-			error = 0;
-			rumpcomp_shmif_watchwait(sc->sc_kq);
+			error = rumpcomp_shmif_watchwait(sc->sc_kq);
 			if (__predict_false(error))
 printf("shmif_rcv: wait failed %d\n", error);
 			membar_consumer();



CVS commit: src/sys/rump/net/lib/libshmif

2014-09-16 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Wed Sep 17 04:20:58 UTC 2014

Modified Files:
src/sys/rump/net/lib/libshmif: shmif_busops.c shmifvar.h

Log Message:
Make shmif buildable when DRPINTF enabled


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/rump/net/lib/libshmif/shmif_busops.c
cvs rdiff -u -r1.9 -r1.10 src/sys/rump/net/lib/libshmif/shmifvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/shmif_busops.c
diff -u src/sys/rump/net/lib/libshmif/shmif_busops.c:1.11 src/sys/rump/net/lib/libshmif/shmif_busops.c:1.12
--- src/sys/rump/net/lib/libshmif/shmif_busops.c:1.11	Fri Dec 20 10:00:59 2013
+++ src/sys/rump/net/lib/libshmif/shmif_busops.c	Wed Sep 17 04:20:58 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: shmif_busops.c,v 1.11 2013/12/20 10:00:59 pooka Exp $	*/
+/*	$NetBSD: shmif_busops.c,v 1.12 2014/09/17 04:20:58 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -29,10 +29,10 @@
 
 #ifdef _KERNEL
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: shmif_busops.c,v 1.11 2013/12/20 10:00:59 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: shmif_busops.c,v 1.12 2014/09/17 04:20:58 ozaki-r Exp $);
 #else
 #include rump/rumpuser_port.h
-__RCSID($NetBSD: shmif_busops.c,v 1.11 2013/12/20 10:00:59 pooka Exp $);
+__RCSID($NetBSD: shmif_busops.c,v 1.12 2014/09/17 04:20:58 ozaki-r Exp $);
 #endif
 
 #include sys/param.h
@@ -111,7 +111,7 @@ shmif_buswrite(struct shmif_mem *busmem,
 
 	memcpy(busmem-shm_data + off, data, chunk);
 
-	DPRINTF((buswrite: wrote %d bytes to %d, chunk, off));
+	DPRINTF((buswrite: wrote %zu bytes to %d, chunk, off));
 
 	if (filledbus) {
 		*wrap = true;
@@ -122,7 +122,7 @@ shmif_buswrite(struct shmif_mem *busmem,
 		return (off + chunk) % BUSMEM_DATASIZE;
 	}
 
-	DPRINTF((, wrapped bytes %d to 0\n, len));
+	DPRINTF((, wrapped bytes %zu to 0\n, len));
 
 	shmif_advancefirst(busmem, 0, len);
 

Index: src/sys/rump/net/lib/libshmif/shmifvar.h
diff -u src/sys/rump/net/lib/libshmif/shmifvar.h:1.9 src/sys/rump/net/lib/libshmif/shmifvar.h:1.10
--- src/sys/rump/net/lib/libshmif/shmifvar.h:1.9	Sat Aug 16 06:18:01 2014
+++ src/sys/rump/net/lib/libshmif/shmifvar.h	Wed Sep 17 04:20:58 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: shmifvar.h,v 1.9 2014/08/16 06:18:01 ozaki-r Exp $	*/
+/*	$NetBSD: shmifvar.h,v 1.10 2014/09/17 04:20:58 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -68,6 +68,7 @@ struct shmif_pkthdr {
 #include rump/rumpuser.h
 #define DPRINTF(x) rumpuser_dprintf x
 #else
+#include stdio.h
 #define DPRINTF(x) printf x
 #endif
 #else



CVS commit: src/sys/rump/net/lib/libshmif

2014-08-16 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Sat Aug 16 06:18:01 UTC 2014

Modified Files:
src/sys/rump/net/lib/libshmif: shmifvar.h

Log Message:
Bump SHMIF_VERSION


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/rump/net/lib/libshmif/shmifvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/shmifvar.h
diff -u src/sys/rump/net/lib/libshmif/shmifvar.h:1.8 src/sys/rump/net/lib/libshmif/shmifvar.h:1.9
--- src/sys/rump/net/lib/libshmif/shmifvar.h:1.8	Fri Aug 15 15:03:03 2014
+++ src/sys/rump/net/lib/libshmif/shmifvar.h	Sat Aug 16 06:18:01 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: shmifvar.h,v 1.8 2014/08/15 15:03:03 ozaki-r Exp $	*/
+/*	$NetBSD: shmifvar.h,v 1.9 2014/08/16 06:18:01 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -31,7 +31,7 @@
 #define _RUMP_NET_SHMIFVAR_H_
 
 #define SHMIF_MAGIC 0xca11d054
-#define SHMIF_VERSION 2
+#define SHMIF_VERSION 3
 
 struct shmif_mem {
 	uint32_t shm_magic;



CVS commit: src/sys/rump/net/lib/libshmif

2014-08-15 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Fri Aug 15 15:03:03 UTC 2014

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c shmifvar.h

Log Message:
Make shmif SIMPLEX

Add a sender field to a packet header on a shmif bus to identify
and ignore packets sent by itself.

This makes shmif work with bridges.

ok pooka@


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/sys/rump/net/lib/libshmif/if_shmem.c
cvs rdiff -u -r1.7 -r1.8 src/sys/rump/net/lib/libshmif/shmifvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.62 src/sys/rump/net/lib/libshmif/if_shmem.c:1.63
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.62	Sat Aug  9 09:43:49 2014
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Fri Aug 15 15:03:03 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.62 2014/08/09 09:43:49 ozaki-r Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.63 2014/08/15 15:03:03 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.62 2014/08/09 09:43:49 ozaki-r Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.63 2014/08/15 15:03:03 ozaki-r Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -97,6 +97,8 @@ struct shmif_sc {
 
 	struct lwp *sc_rcvl;
 	bool sc_dying;
+
+	uint64_t sc_uuid;
 };
 
 static void shmif_rcv(void *);
@@ -167,12 +169,13 @@ allocif(int unit, struct shmif_sc **scp)
 	sc = kmem_zalloc(sizeof(*sc), KM_SLEEP);
 	sc-sc_memfd = -1;
 	sc-sc_unit = unit;
+	sc-sc_uuid = cprng_fast64();
 
 	ifp = sc-sc_ec.ec_if;
 
 	snprintf(ifp-if_xname, sizeof(ifp-if_xname), shmif%d, unit);
 	ifp-if_softc = sc;
-	ifp-if_flags = IFF_BROADCAST | IFF_MULTICAST;
+	ifp-if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
 	ifp-if_init = shmif_init;
 	ifp-if_ioctl = shmif_ioctl;
 	ifp-if_start = shmif_start;
@@ -540,6 +543,7 @@ shmif_start(struct ifnet *ifp)
 		sp.sp_len = pktsize;
 		sp.sp_sec = tv.tv_sec;
 		sp.sp_usec = tv.tv_usec;
+		sp.sp_sender = sc-sc_uuid;
 
 		bpf_mtap(ifp, m0);
 
@@ -743,7 +747,9 @@ shmif_rcv(void *arg)
 		 * Test if we want to pass the packet upwards
 		 */
 		eth = mtod(m, struct ether_header *);
-		if (memcmp(eth-ether_dhost, CLLADDR(ifp-if_sadl),
+		if (sp.sp_sender == sc-sc_uuid) {
+			passup = false;
+		} else if (memcmp(eth-ether_dhost, CLLADDR(ifp-if_sadl),
 		ETHER_ADDR_LEN) == 0) {
 			passup = true;
 		} else if (ETHER_IS_MULTICAST(eth-ether_dhost)) {

Index: src/sys/rump/net/lib/libshmif/shmifvar.h
diff -u src/sys/rump/net/lib/libshmif/shmifvar.h:1.7 src/sys/rump/net/lib/libshmif/shmifvar.h:1.8
--- src/sys/rump/net/lib/libshmif/shmifvar.h:1.7	Fri Dec 20 09:06:35 2013
+++ src/sys/rump/net/lib/libshmif/shmifvar.h	Fri Aug 15 15:03:03 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: shmifvar.h,v 1.7 2013/12/20 09:06:35 pooka Exp $	*/
+/*	$NetBSD: shmifvar.h,v 1.8 2014/08/15 15:03:03 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -56,6 +56,8 @@ struct shmif_pkthdr {
 
 	uint32_t sp_sec;
 	uint32_t sp_usec;
+
+	uint64_t sp_sender;
 };
 
 #define BUSMEM_SIZE (1024*1024)



CVS commit: src/sys/rump/net/lib/libshmif

2014-08-09 Thread Ryota Ozaki
Module Name:src
Committed By:   ozaki-r
Date:   Sat Aug  9 09:43:49 UTC 2014

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
Count packets in if_shmem

ok @pooka


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.61 src/sys/rump/net/lib/libshmif/if_shmem.c:1.62
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.61	Wed May 28 20:57:22 2014
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Sat Aug  9 09:43:49 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.61 2014/05/28 20:57:22 justin Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.62 2014/08/09 09:43:49 ozaki-r Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.61 2014/05/28 20:57:22 justin Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.62 2014/08/09 09:43:49 ozaki-r Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -566,6 +566,7 @@ shmif_start(struct ifnet *ifp)
 
 		m_freem(m0);
 		wrote = true;
+		ifp-if_opackets++;
 
 		DPRINTF((shmif_start: send %d bytes at off %d\n,
 		pktsize, busmem-shm_last));
@@ -755,6 +756,7 @@ shmif_rcv(void *arg)
 		}
 
 		if (passup) {
+			ifp-if_ipackets++;
 			KERNEL_LOCK(1, NULL);
 			bpf_mtap(ifp, m);
 			ifp-if_input(ifp, m);



CVS commit: src/sys/rump/net/lib/libshmif

2014-03-12 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Thu Mar 13 01:42:59 UTC 2014

Modified Files:
src/sys/rump/net/lib/libshmif: Makefile if_shmem.c
Added Files:
src/sys/rump/net/lib/libshmif: shmif_user.c shmif_user.h
Removed Files:
src/sys/rump/net/lib/libshmif: rumpcomp_user.c rumpcomp_user.h

Log Message:
rename rumpcomp_user.* - shmif_user.*


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/rump/net/lib/libshmif/Makefile
cvs rdiff -u -r1.58 -r1.59 src/sys/rump/net/lib/libshmif/if_shmem.c
cvs rdiff -u -r1.14 -r0 src/sys/rump/net/lib/libshmif/rumpcomp_user.c
cvs rdiff -u -r1.4 -r0 src/sys/rump/net/lib/libshmif/rumpcomp_user.h
cvs rdiff -u -r0 -r1.1 src/sys/rump/net/lib/libshmif/shmif_user.c \
src/sys/rump/net/lib/libshmif/shmif_user.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/Makefile
diff -u src/sys/rump/net/lib/libshmif/Makefile:1.4 src/sys/rump/net/lib/libshmif/Makefile:1.5
--- src/sys/rump/net/lib/libshmif/Makefile:1.4	Sun Apr 28 10:43:45 2013
+++ src/sys/rump/net/lib/libshmif/Makefile	Thu Mar 13 01:42:59 2014
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.4 2013/04/28 10:43:45 pooka Exp $
+#	$NetBSD: Makefile,v 1.5 2014/03/13 01:42:59 pooka Exp $
 #
 
 LIB=	rumpnet_shmif
@@ -8,7 +8,7 @@ SRCS+=	component.c
 
 CPPFLAGS+=	-I${.CURDIR}/../../../librump/rumpkern
 
-RUMPCOMP_USER=	# filewatch
+RUMPCOMP_USER_SRCS=	shmif_user.c
 
 .include bsd.lib.mk
 .include bsd.klinks.mk

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.58 src/sys/rump/net/lib/libshmif/if_shmem.c:1.59
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.58	Fri Sep 13 20:38:04 2013
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Thu Mar 13 01:42:59 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.58 2013/09/13 20:38:04 joerg Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.59 2014/03/13 01:42:59 pooka Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.58 2013/09/13 20:38:04 joerg Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.59 2014/03/13 01:42:59 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -52,7 +52,7 @@ __KERNEL_RCSID(0, $NetBSD: if_shmem.c,v
 
 #include rump_private.h
 #include rump_net_private.h
-#include rumpcomp_user.h
+#include shmif_user.h
 
 static int shmif_clone(struct if_clone *, int);
 static int shmif_unclone(struct ifnet *);

Added files:

Index: src/sys/rump/net/lib/libshmif/shmif_user.c
diff -u /dev/null src/sys/rump/net/lib/libshmif/shmif_user.c:1.1
--- /dev/null	Thu Mar 13 01:42:59 2014
+++ src/sys/rump/net/lib/libshmif/shmif_user.c	Thu Mar 13 01:42:59 2014
@@ -0,0 +1,230 @@
+/*  $NetBSD: shmif_user.c,v 1.1 2014/03/13 01:42:59 pooka Exp $	*/
+
+/*-
+ * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#ifndef _KERNEL
+#include sys/types.h
+#include sys/mman.h
+
+#include errno.h
+
+#include rump/rumpuser_component.h
+
+#include shmif_user.h
+
+#define seterr(_v_) if ((_v_) == -1) *error = errno; else *error = 0;
+
+/*
+ * On BSD we use kqueue, on Linux we use inotify.  The underlying
+ * interface requirements aren't quite the same, but we have a very
+ * good chance of doing the fd-path mapping on Linux thanks to dcache,
+ * so just keep the existing interfaces for now.
+ */
+#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) \
+|| defined(__OpenBSD__)
+#include sys/event.h
+
+#include stdlib.h
+
+int
+rumpcomp_shmif_watchsetup(int *kqp, int fd)
+{
+	struct kevent 

CVS commit: src/sys/rump/net/lib/libshmif

2014-03-12 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Thu Mar 13 02:08:04 UTC 2014

Modified Files:
src/sys/rump/net/lib/libshmif: Makefile
Added Files:
src/sys/rump/net/lib/libshmif: shmif_component.c
Removed Files:
src/sys/rump/net/lib/libshmif: component.c

Log Message:
rename component.c - shmif_component.c


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/sys/rump/net/lib/libshmif/Makefile
cvs rdiff -u -r1.2 -r0 src/sys/rump/net/lib/libshmif/component.c
cvs rdiff -u -r0 -r1.1 src/sys/rump/net/lib/libshmif/shmif_component.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/Makefile
diff -u src/sys/rump/net/lib/libshmif/Makefile:1.5 src/sys/rump/net/lib/libshmif/Makefile:1.6
--- src/sys/rump/net/lib/libshmif/Makefile:1.5	Thu Mar 13 01:42:59 2014
+++ src/sys/rump/net/lib/libshmif/Makefile	Thu Mar 13 02:08:04 2014
@@ -1,10 +1,10 @@
-#	$NetBSD: Makefile,v 1.5 2014/03/13 01:42:59 pooka Exp $
+#	$NetBSD: Makefile,v 1.6 2014/03/13 02:08:04 pooka Exp $
 #
 
 LIB=	rumpnet_shmif
 
 SRCS=	if_shmem.c shmif_busops.c
-SRCS+=	component.c
+SRCS+=	shmif_component.c
 
 CPPFLAGS+=	-I${.CURDIR}/../../../librump/rumpkern
 

Added files:

Index: src/sys/rump/net/lib/libshmif/shmif_component.c
diff -u /dev/null src/sys/rump/net/lib/libshmif/shmif_component.c:1.1
--- /dev/null	Thu Mar 13 02:08:04 2014
+++ src/sys/rump/net/lib/libshmif/shmif_component.c	Thu Mar 13 02:08:04 2014
@@ -0,0 +1,50 @@
+/*	$NetBSD: shmif_component.c,v 1.1 2014/03/13 02:08:04 pooka Exp $	*/
+
+/*
+ * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include sys/cdefs.h
+__KERNEL_RCSID(0, $NetBSD: shmif_component.c,v 1.1 2014/03/13 02:08:04 pooka Exp $);
+
+#include sys/param.h
+#include sys/vmem.h
+
+#include net/if.h
+
+#include rump_private.h
+#include rump_net_private.h
+
+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, 115, 1, NULL, NULL, NULL, 1, 
+	VM_SLEEP, IPL_NONE);
+	if (shmif_units == NULL)
+		panic(shmif vmem_create failed);
+
+	if_clone_attach(shmif_cloner);
+}



CVS commit: src/sys/rump/net/lib/libshmif

2014-01-08 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Wed Jan  8 11:06:33 UTC 2014

Modified Files:
src/sys/rump/net/lib/libshmif: rumpcomp_user.c

Log Message:
OpenBSD has kqueue


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/rump/net/lib/libshmif/rumpcomp_user.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/rumpcomp_user.c
diff -u src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.13 src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.14
--- src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.13	Thu Jul  4 17:46:14 2013
+++ src/sys/rump/net/lib/libshmif/rumpcomp_user.c	Wed Jan  8 11:06:33 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpcomp_user.c,v 1.13 2013/07/04 17:46:14 pooka Exp $	*/
+/*  $NetBSD: rumpcomp_user.c,v 1.14 2014/01/08 11:06:33 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -42,7 +42,8 @@
  * good chance of doing the fd-path mapping on Linux thanks to dcache,
  * so just keep the existing interfaces for now.
  */
-#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
+#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) \
+|| defined(__OpenBSD__)
 #include sys/event.h
 
 #include stdlib.h



CVS commit: src/sys/rump/net/lib/libshmif

2013-12-20 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Fri Dec 20 09:06:35 UTC 2013

Modified Files:
src/sys/rump/net/lib/libshmif: shmif_busops.c shmifvar.h

Log Message:
header massage, mostly improves portability


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/rump/net/lib/libshmif/shmif_busops.c
cvs rdiff -u -r1.6 -r1.7 src/sys/rump/net/lib/libshmif/shmifvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/shmif_busops.c
diff -u src/sys/rump/net/lib/libshmif/shmif_busops.c:1.9 src/sys/rump/net/lib/libshmif/shmif_busops.c:1.10
--- src/sys/rump/net/lib/libshmif/shmif_busops.c:1.9	Mon Mar 21 16:41:09 2011
+++ src/sys/rump/net/lib/libshmif/shmif_busops.c	Fri Dec 20 09:06:35 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: shmif_busops.c,v 1.9 2011/03/21 16:41:09 pooka Exp $	*/
+/*	$NetBSD: shmif_busops.c,v 1.10 2013/12/20 09:06:35 pooka Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,19 +28,17 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: shmif_busops.c,v 1.9 2011/03/21 16:41:09 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: shmif_busops.c,v 1.10 2013/12/20 09:06:35 pooka Exp $);
 
 #include sys/param.h
-#include sys/atomic.h
 
 #ifndef _KERNEL
 #include assert.h
+#include inttypes.h
 #include stdbool.h
 #include string.h
 
 #define KASSERT(a) assert(a)
-#else
-#include rump/rumpuser.h
 #endif
 
 #include shmifvar.h

Index: src/sys/rump/net/lib/libshmif/shmifvar.h
diff -u src/sys/rump/net/lib/libshmif/shmifvar.h:1.6 src/sys/rump/net/lib/libshmif/shmifvar.h:1.7
--- src/sys/rump/net/lib/libshmif/shmifvar.h:1.6	Mon Mar 21 16:41:09 2011
+++ src/sys/rump/net/lib/libshmif/shmifvar.h	Fri Dec 20 09:06:35 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: shmifvar.h,v 1.6 2011/03/21 16:41:09 pooka Exp $	*/
+/*	$NetBSD: shmifvar.h,v 1.7 2013/12/20 09:06:35 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -63,6 +63,7 @@ struct shmif_pkthdr {
 
 #if 0
 #ifdef _KERNEL
+#include rump/rumpuser.h
 #define DPRINTF(x) rumpuser_dprintf x
 #else
 #define DPRINTF(x) printf x



CVS commit: src/sys/rump/net/lib/libshmif

2013-12-20 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Fri Dec 20 10:00:59 UTC 2013

Modified Files:
src/sys/rump/net/lib/libshmif: shmif_busops.c

Log Message:
use _KERNEL_RCSID only in _KERNEL, _RCSID elsewhere


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/rump/net/lib/libshmif/shmif_busops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/shmif_busops.c
diff -u src/sys/rump/net/lib/libshmif/shmif_busops.c:1.10 src/sys/rump/net/lib/libshmif/shmif_busops.c:1.11
--- src/sys/rump/net/lib/libshmif/shmif_busops.c:1.10	Fri Dec 20 09:06:35 2013
+++ src/sys/rump/net/lib/libshmif/shmif_busops.c	Fri Dec 20 10:00:59 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: shmif_busops.c,v 1.10 2013/12/20 09:06:35 pooka Exp $	*/
+/*	$NetBSD: shmif_busops.c,v 1.11 2013/12/20 10:00:59 pooka Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -27,8 +27,13 @@
  * SUCH DAMAGE.
  */
 
+#ifdef _KERNEL
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: shmif_busops.c,v 1.10 2013/12/20 09:06:35 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: shmif_busops.c,v 1.11 2013/12/20 10:00:59 pooka Exp $);
+#else
+#include rump/rumpuser_port.h
+__RCSID($NetBSD: shmif_busops.c,v 1.11 2013/12/20 10:00:59 pooka Exp $);
+#endif
 
 #include sys/param.h
 



CVS commit: src/sys/rump/net/lib/libshmif

2013-09-13 Thread Joerg Sonnenberger
Module Name:src
Committed By:   joerg
Date:   Fri Sep 13 20:38:04 UTC 2013

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
Remove busversion.


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.57 src/sys/rump/net/lib/libshmif/if_shmem.c:1.58
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.57	Mon Jul 22 21:12:03 2013
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Fri Sep 13 20:38:04 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.57 2013/07/22 21:12:03 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.58 2013/09/13 20:38:04 joerg Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.57 2013/07/22 21:12:03 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.58 2013/09/13 20:38:04 joerg Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -99,8 +99,6 @@ struct shmif_sc {
 	bool sc_dying;
 };
 
-static const uint32_t busversion = SHMIF_VERSION;
-
 static void shmif_rcv(void *);
 
 #define LOCK_UNLOCKED	0



CVS commit: src/sys/rump/net/lib/libshmif

2013-07-22 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Jul 22 21:12:03 UTC 2013

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
In recv, align data after ether_header at _ALIGN_BYTES.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.56 src/sys/rump/net/lib/libshmif/if_shmem.c:1.57
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.56	Fri Jun 14 05:59:50 2013
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Mon Jul 22 21:12:03 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.56 2013/06/14 05:59:50 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.57 2013/07/22 21:12:03 pooka Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.56 2013/06/14 05:59:50 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.57 2013/07/22 21:12:03 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -647,6 +647,8 @@ shmif_rcv(void *arg)
 	uint32_t nextpkt;
 	bool wrap, passup;
 	int error;
+	const int align
+	= ALIGN(sizeof(struct ether_header)) - sizeof(struct ether_header);
 
  reup:
 	mutex_enter(sc-sc_mtx);
@@ -662,6 +664,7 @@ shmif_rcv(void *arg)
 		if (m == NULL) {
 			m = m_gethdr(M_WAIT, MT_DATA);
 			MCLGET(m, M_WAIT);
+			m-m_data += align;
 		}
 
 		DPRINTF((waiting %d/% PRIu64 \n,



CVS commit: src/sys/rump/net/lib/libshmif

2013-07-04 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Thu Jul  4 17:46:14 UTC 2013

Modified Files:
src/sys/rump/net/lib/libshmif: rumpcomp_user.c

Log Message:
Use kqueue on *BSD, not just NetBSD.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/rump/net/lib/libshmif/rumpcomp_user.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/rumpcomp_user.c
diff -u src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.12 src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.13
--- src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.12	Tue Jun  4 14:54:34 2013
+++ src/sys/rump/net/lib/libshmif/rumpcomp_user.c	Thu Jul  4 17:46:14 2013
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpcomp_user.c,v 1.12 2013/06/04 14:54:34 pooka Exp $	*/
+/*  $NetBSD: rumpcomp_user.c,v 1.13 2013/07/04 17:46:14 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -37,14 +37,16 @@
 #define seterr(_v_) if ((_v_) == -1) *error = errno; else *error = 0;
 
 /*
- * On NetBSD we use kqueue, on Linux we use inotify.  The underlying
+ * On BSD we use kqueue, on Linux we use inotify.  The underlying
  * interface requirements aren't quite the same, but we have a very
  * good chance of doing the fd-path mapping on Linux thanks to dcache,
  * so just keep the existing interfaces for now.
  */
-#if defined(__NetBSD__)
+#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
 #include sys/event.h
 
+#include stdlib.h
+
 int
 rumpcomp_shmif_watchsetup(int *kqp, int fd)
 {



CVS commit: src/sys/rump/net/lib/libshmif

2013-06-14 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Fri Jun 14 05:59:51 UTC 2013

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
sauce previous with a comment


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.55 src/sys/rump/net/lib/libshmif/if_shmem.c:1.56
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.55	Fri Jun 14 05:56:29 2013
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Fri Jun 14 05:59:50 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.55 2013/06/14 05:56:29 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.56 2013/06/14 05:59:50 pooka Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.55 2013/06/14 05:56:29 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.56 2013/06/14 05:59:50 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -724,6 +724,10 @@ shmif_rcv(void *arg)
 			sc, sc-sc_devgen));
 		}
 
+		/*
+		 * Ignore packets too short to possibly be valid.
+		 * This is hit at least for the first frame on a new bus.
+		 */
 		if (__predict_false(sp.sp_len  ETHER_HDR_LEN)) {
 			DPRINTF((shmif read packet len %d  ETHER_HDR_LEN\n,
 			sp.sp_len));



CVS commit: src/sys/rump/net/lib/libshmif

2013-06-13 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Fri Jun 14 05:56:29 UTC 2013

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
Ignore too short packets.  This condition is true especially for the
first packet on a new bus (len == 0).  Everything else in the stack
besides bpf seemed to be able to deal with one, though.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.54 src/sys/rump/net/lib/libshmif/if_shmem.c:1.55
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.54	Wed May  1 06:58:36 2013
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Fri Jun 14 05:56:29 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.54 2013/05/01 06:58:36 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.55 2013/06/14 05:56:29 pooka Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.54 2013/05/01 06:58:36 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.55 2013/06/14 05:56:29 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -724,6 +724,12 @@ shmif_rcv(void *arg)
 			sc, sc-sc_devgen));
 		}
 
+		if (__predict_false(sp.sp_len  ETHER_HDR_LEN)) {
+			DPRINTF((shmif read packet len %d  ETHER_HDR_LEN\n,
+			sp.sp_len));
+			continue;
+		}
+
 		m-m_len = m-m_pkthdr.len = sp.sp_len;
 		m-m_pkthdr.rcvif = ifp;
 



CVS commit: src/sys/rump/net/lib/libshmif

2013-06-04 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Tue Jun  4 14:54:34 UTC 2013

Modified Files:
src/sys/rump/net/lib/libshmif: rumpcomp_user.c

Log Message:
On Linux, pass the inotify descriptor up so that we can correctly read
it in the wait() routine.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/rump/net/lib/libshmif/rumpcomp_user.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/rumpcomp_user.c
diff -u src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.11 src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.12
--- src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.11	Tue May  7 16:18:48 2013
+++ src/sys/rump/net/lib/libshmif/rumpcomp_user.c	Tue Jun  4 14:54:34 2013
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpcomp_user.c,v 1.11 2013/05/07 16:18:48 pooka Exp $	*/
+/*  $NetBSD: rumpcomp_user.c,v 1.12 2013/06/04 14:54:34 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -137,6 +137,7 @@ rumpcomp_shmif_watchsetup(int *inotifyp,
 		goto out;
 	}
 	rv = 0;
+	*inotifyp = inotify;
 
  out:
 	return rumpuser_component_errtrans(rv);



CVS commit: src/sys/rump/net/lib/libshmif

2013-05-07 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Tue May  7 16:18:49 UTC 2013

Modified Files:
src/sys/rump/net/lib/libshmif: rumpcomp_user.c

Log Message:
Include necessary headers on Linux


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/rump/net/lib/libshmif/rumpcomp_user.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/rumpcomp_user.c
diff -u src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.10 src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.11
--- src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.10	Tue Apr 30 12:39:21 2013
+++ src/sys/rump/net/lib/libshmif/rumpcomp_user.c	Tue May  7 16:18:48 2013
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpcomp_user.c,v 1.10 2013/04/30 12:39:21 pooka Exp $	*/
+/*  $NetBSD: rumpcomp_user.c,v 1.11 2013/05/07 16:18:48 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -97,6 +97,10 @@ rumpcomp_shmif_watchwait(int kq)
 #elif defined(__linux__)
 #include sys/inotify.h
 
+#include limits.h
+#include stdio.h
+#include unistd.h
+
 int
 rumpcomp_shmif_watchsetup(int *inotifyp, int fd)
 {



CVS commit: src/sys/rump/net/lib/libshmif

2013-05-01 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Wed May  1 06:58:37 UTC 2013

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
Three cheers for the mighty C type system that doesn't recognize the
difference between an enum and an integer.  Due to wrong parameter order,
the lock backoff routine ended up sleeping 1 million seconds instead
of 1ms.  On the plus side, we got some sort of idea how often the shmif
spinlock backoff routine is hit during a standard test run.


To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.53 src/sys/rump/net/lib/libshmif/if_shmem.c:1.54
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.53	Tue Apr 30 00:03:54 2013
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Wed May  1 06:58:36 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.53 2013/04/30 00:03:54 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.54 2013/05/01 06:58:36 pooka Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.53 2013/04/30 00:03:54 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.54 2013/05/01 06:58:36 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -135,8 +135,8 @@ shmif_lockbus(struct shmif_mem *busmem)
 	LOCK_UNLOCKED, LOCK_LOCKED) == LOCK_LOCKED)) {
 		if (__predict_false(++i  LOCK_COOLDOWN)) {
 			/* wait 1ms */
-			rumpuser_clock_sleep(0, 1000*1000,
-			RUMPUSER_CLOCK_RELWALL);
+			rumpuser_clock_sleep(RUMPUSER_CLOCK_RELWALL,
+			0, 1000*1000);
 			i = 0;
 		}
 		continue;



CVS commit: src/sys/rump/net/lib/libshmif

2013-04-29 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Apr 29 13:17:33 UTC 2013

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c rumpcomp_user.c
rumpcomp_user.h

Log Message:
add a private hypercall to map the bus into memory


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/rump/net/lib/libshmif/if_shmem.c
cvs rdiff -u -r1.5 -r1.6 src/sys/rump/net/lib/libshmif/rumpcomp_user.c
cvs rdiff -u -r1.2 -r1.3 src/sys/rump/net/lib/libshmif/rumpcomp_user.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.50 src/sys/rump/net/lib/libshmif/if_shmem.c:1.51
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.50	Sun Apr 28 13:17:25 2013
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Mon Apr 29 13:17:32 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.50 2013/04/28 13:17:25 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.51 2013/04/29 13:17:32 pooka Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.50 2013/04/28 13:17:25 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.51 2013/04/29 13:17:32 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -205,9 +205,7 @@ initbackend(struct shmif_sc *sc, int mem
 	volatile uint8_t *p;
 	int error;
 
-	sc-sc_busmem = rumpuser_filemmap(memfd, 0, BUSMEM_SIZE,
-	RUMPUSER_FILEMMAP_TRUNCATE | RUMPUSER_FILEMMAP_SHARED
-	| RUMPUSER_FILEMMAP_READ | RUMPUSER_FILEMMAP_WRITE, error);
+	sc-sc_busmem = rumpcomp_shmif_mmap(memfd, BUSMEM_SIZE, error);
 	if (error)
 		return error;
 

Index: src/sys/rump/net/lib/libshmif/rumpcomp_user.c
diff -u src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.5 src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.6
--- src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.5	Sun Apr 28 14:11:43 2013
+++ src/sys/rump/net/lib/libshmif/rumpcomp_user.c	Mon Apr 29 13:17:32 2013
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpcomp_user.c,v 1.5 2013/04/28 14:11:43 pooka Exp $	*/
+/*  $NetBSD: rumpcomp_user.c,v 1.6 2013/04/29 13:17:32 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -26,6 +26,7 @@
  */
 
 #include sys/types.h
+#include sys/mman.h
 
 #include errno.h
 
@@ -176,3 +177,26 @@ rumpcomp_shmif_watchwait(int kq, int *er
 	return 0;
 }
 #endif
+
+void *
+rumpcomp_shmif_mmap(int fd, size_t len, int *error)
+{
+	void *rv;
+
+	*error = 0;
+	if (ftruncate(fd, len) == -1) {
+		*error = errno;
+		return NULL;
+	}
+
+#if defined(__sun__)  !defined(MAP_FILE)
+#define MAP_FILE 0
+#endif
+	
+	rv = mmap(NULL, len, PROT_READ|PROT_WRITE, MAP_FILE|MAP_SHARED, fd, 0);
+	if (rv == MAP_FAILED) {
+		*error = errno;
+	}
+
+	return rv;
+}

Index: src/sys/rump/net/lib/libshmif/rumpcomp_user.h
diff -u src/sys/rump/net/lib/libshmif/rumpcomp_user.h:1.2 src/sys/rump/net/lib/libshmif/rumpcomp_user.h:1.3
--- src/sys/rump/net/lib/libshmif/rumpcomp_user.h:1.2	Sun Apr 28 10:53:22 2013
+++ src/sys/rump/net/lib/libshmif/rumpcomp_user.h	Mon Apr 29 13:17:33 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpcomp_user.h,v 1.2 2013/04/28 10:53:22 pooka Exp $	*/
+/*	$NetBSD: rumpcomp_user.h,v 1.3 2013/04/29 13:17:33 pooka Exp $	*/
 
 /*
  * Copyright (c) 2013 Antti Kantee.  All Rights Reserved.
@@ -27,3 +27,4 @@
 
 int	rumpcomp_shmif_watchsetup(int, int, int *);
 int	rumpcomp_shmif_watchwait(int, int *);
+void	*rumpcomp_shmif_mmap(int, size_t, int *);



CVS commit: src/sys/rump/net/lib/libshmif

2013-04-29 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Tue Apr 30 00:33:16 UTC 2013

Modified Files:
src/sys/rump/net/lib/libshmif: rumpcomp_user.c

Log Message:
fix non-NetBSD implementation


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/rump/net/lib/libshmif/rumpcomp_user.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/rumpcomp_user.c
diff -u src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.8 src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.9
--- src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.8	Tue Apr 30 00:03:54 2013
+++ src/sys/rump/net/lib/libshmif/rumpcomp_user.c	Tue Apr 30 00:33:16 2013
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpcomp_user.c,v 1.8 2013/04/30 00:03:54 pooka Exp $	*/
+/*  $NetBSD: rumpcomp_user.c,v 1.9 2013/04/30 00:33:16 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -167,7 +167,7 @@ rumpcomp_shmif_watchwait(int kq)
 
 /* a polling default implementation */
 int
-rumpcomp_shmif_watchsetup(int inotify, int fd)
+rumpcomp_shmif_watchsetup(int *nono, int fd)
 {
 	static int warned = 0;
 



CVS commit: src/sys/rump/net/lib/libshmif

2013-04-28 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Sun Apr 28 10:53:22 UTC 2013

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c rumpcomp_user.c
rumpcomp_user.h

Log Message:
* remove the unused opaque parameter
* fix some typos in the previous


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/sys/rump/net/lib/libshmif/if_shmem.c
cvs rdiff -u -r1.1 -r1.2 src/sys/rump/net/lib/libshmif/rumpcomp_user.c \
src/sys/rump/net/lib/libshmif/rumpcomp_user.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.48 src/sys/rump/net/lib/libshmif/if_shmem.c:1.49
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.48	Sun Apr 28 10:43:45 2013
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Sun Apr 28 10:53:21 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.48 2013/04/28 10:43:45 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.49 2013/04/28 10:53:21 pooka Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.48 2013/04/28 10:43:45 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.49 2013/04/28 10:53:21 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -251,7 +251,7 @@ initbackend(struct shmif_sc *sc, int mem
 #endif
 	shmif_unlockbus(sc-sc_busmem);
 
-	sc-sc_kq = rumpcomp_shmif_watchsetup(-1, memfd, 0, error);
+	sc-sc_kq = rumpcomp_shmif_watchsetup(-1, memfd, error);
 	if (sc-sc_kq == -1) {
 		rumpuser_unmap(sc-sc_busmem, BUSMEM_SIZE);
 		return error;
@@ -669,7 +669,7 @@ shmif_rcv(void *arg)
 		 == sc-sc_nextpacket) {
 			shmif_unlockbus(busmem);
 			error = 0;
-			rumpcomp_shmif_watchwait(sc-sc_kq, NULL, error);
+			rumpcomp_shmif_watchwait(sc-sc_kq, error);
 			if (__predict_false(error))
 printf(shmif_rcv: wait failed %d\n, error);
 			membar_consumer();

Index: src/sys/rump/net/lib/libshmif/rumpcomp_user.c
diff -u src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.1 src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.2
--- src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.1	Sun Apr 28 10:43:45 2013
+++ src/sys/rump/net/lib/libshmif/rumpcomp_user.c	Sun Apr 28 10:53:22 2013
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpcomp_user.c,v 1.1 2013/04/28 10:43:45 pooka Exp $	*/
+/*  $NetBSD: rumpcomp_user.c,v 1.2 2013/04/28 10:53:22 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -42,7 +42,7 @@
  */
 #if defined(__NetBSD__)
 int
-rumpcomp_shmif_watchsetup(int kq, int fd, intptr_t opaque, int *error)
+rumpcomp_shmif_watchsetup(int kq, int fd, int *error)
 {
 	struct kevent kev;
 	int rv;
@@ -56,14 +56,16 @@ rumpcomp_shmif_watchsetup(int kq, int fd
 	}
 
 	EV_SET(kev, fd, EVFILT_VNODE, EV_ADD|EV_ENABLE|EV_CLEAR,
-	NOTE_WRITE, 0, opaque);
+	NOTE_WRITE, 0, 0);
 	rv = kevent(kq, kev, 1, NULL, 0, NULL);
 	*error = errno;
-	return rv;
+	if (rv == -1)
+		return -1;
+	return kq;
 }
 
 int
-rumpcomp_shmif_watchwait(int kq, intptr_t *opaque, int *error)
+rumpcomp_shmif_watchwait(int kq, int *error)
 {
 	void *cookie;
 	struct kevent kev;
@@ -73,10 +75,8 @@ rumpcomp_shmif_watchwait(int kq, intptr_
 	do {
 		rv = kevent(kq, NULL, 0, kev, 1, NULL);
 	} while (rv == -1  errno == EINTR);
-
 	*error = errno;
-	if (rv != -1  opaque)
-		*opaque = kev.udata;
+
 	rumpuser_component_schedule(cookie);
 	return rv;
 }
@@ -85,7 +85,7 @@ rumpcomp_shmif_watchwait(int kq, intptr_
 #include sys/inotify.h
 
 int
-rumpcomp_shmif_watchsetup(int inotify, int fd, intptr_t notused, int *error)
+rumpcomp_shmif_watchsetup(int inotify, int fd, int *error)
 {
 	char procbuf[PATH_MAX], linkbuf[PATH_MAX];
 	ssize_t nn;
@@ -122,7 +122,7 @@ rumpcomp_shmif_watchsetup(int inotify, i
 }
 
 int
-rumpcomp_shmif_watchwait(int kq, intptr_t *opaque, int *error)
+rumpcomp_shmif_watchwait(int kq, int *error)
 {
 	struct inotify_event iev;
 	void *cookie;
@@ -145,7 +145,7 @@ rumpcomp_shmif_watchwait(int kq, intptr_
 
 /* a polling default implementation */
 int
-rumpcomp_shmif_watchsetup(int inotify, int fd, intptr_t notused, int *error)
+rumpcomp_shmif_watchsetup(int inotify, int fd, int *error)
 {
 	static int warned = 0;
 
@@ -159,7 +159,7 @@ rumpcomp_shmif_watchsetup(int inotify, i
 }
 
 int
-rumpcomp_shmif_watchwait(int kq, intptr_t *opaque, int *error)
+rumpcomp_shmif_watchwait(int kq, int *error)
 {
 	void *cookie;
 
Index: src/sys/rump/net/lib/libshmif/rumpcomp_user.h
diff -u src/sys/rump/net/lib/libshmif/rumpcomp_user.h:1.1 src/sys/rump/net/lib/libshmif/rumpcomp_user.h:1.2
--- src/sys/rump/net/lib/libshmif/rumpcomp_user.h:1.1	Sun Apr 28 10:43:45 2013
+++ src/sys/rump/net/lib/libshmif/rumpcomp_user.h	Sun Apr 28 10:53:22 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpcomp_user.h,v 1.1 2013/04/28 10:43:45 pooka Exp $	*/
+/*	$NetBSD: rumpcomp_user.h,v 1.2 2013/04/28 10:53:22 pooka Exp $	

CVS commit: src/sys/rump/net/lib/libshmif

2013-04-28 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Sun Apr 28 11:03:25 UTC 2013

Modified Files:
src/sys/rump/net/lib/libshmif: rumpcomp_user.c

Log Message:
be a bit less sloppy with errno


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/rump/net/lib/libshmif/rumpcomp_user.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/rumpcomp_user.c
diff -u src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.2 src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.3
--- src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.2	Sun Apr 28 10:53:22 2013
+++ src/sys/rump/net/lib/libshmif/rumpcomp_user.c	Sun Apr 28 11:03:25 2013
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpcomp_user.c,v 1.2 2013/04/28 10:53:22 pooka Exp $	*/
+/*  $NetBSD: rumpcomp_user.c,v 1.3 2013/04/28 11:03:25 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -34,6 +34,8 @@
 
 #include rumpcomp_user.h
 
+#define seterr(_v_) if ((_v_) == -1) *error = errno; else *error = 0;
+
 /*
  * On NetBSD we use kqueue, on Linux we use inotify.  The underlying
  * interface requirements aren't quite the same, but we have a very
@@ -58,7 +60,7 @@ rumpcomp_shmif_watchsetup(int kq, int fd
 	EV_SET(kev, fd, EVFILT_VNODE, EV_ADD|EV_ENABLE|EV_CLEAR,
 	NOTE_WRITE, 0, 0);
 	rv = kevent(kq, kev, 1, NULL, 0, NULL);
-	*error = errno;
+	seterr(rv);
 	if (rv == -1)
 		return -1;
 	return kq;
@@ -75,9 +77,9 @@ rumpcomp_shmif_watchwait(int kq, int *er
 	do {
 		rv = kevent(kq, NULL, 0, kev, 1, NULL);
 	} while (rv == -1  errno == EINTR);
-	*error = errno;
-
+	seterr(rv);
 	rumpuser_component_schedule(cookie);
+
 	return rv;
 }
 
@@ -117,6 +119,7 @@ rumpcomp_shmif_watchsetup(int inotify, i
 		close(inotify);
 		return -1;
 	}
+	*error = 0;
 
 	return inotify;
 }
@@ -132,7 +135,7 @@ rumpcomp_shmif_watchwait(int kq, int *er
 	do {
 		nn = read(kq, iev, sizeof(iev));
 	} while (errno == EINTR);
-	*error = errno;
+	seterr(nn);
 	rumpuser_component_schedule(cookie);
 
 	if (nn == -1) {



CVS commit: src/sys/rump/net/lib/libshmif

2013-04-28 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Sun Apr 28 13:38:35 UTC 2013

Modified Files:
src/sys/rump/net/lib/libshmif: rumpcomp_user.c

Log Message:
include event.h only where used


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/rump/net/lib/libshmif/rumpcomp_user.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/rumpcomp_user.c
diff -u src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.3 src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.4
--- src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.3	Sun Apr 28 11:03:25 2013
+++ src/sys/rump/net/lib/libshmif/rumpcomp_user.c	Sun Apr 28 13:38:35 2013
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpcomp_user.c,v 1.3 2013/04/28 11:03:25 pooka Exp $	*/
+/*  $NetBSD: rumpcomp_user.c,v 1.4 2013/04/28 13:38:35 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -26,7 +26,6 @@
  */
 
 #include sys/types.h
-#include sys/event.h
 
 #include errno.h
 
@@ -43,6 +42,8 @@
  * so just keep the existing interfaces for now.
  */
 #if defined(__NetBSD__)
+#include sys/event.h
+
 int
 rumpcomp_shmif_watchsetup(int kq, int fd, int *error)
 {



CVS commit: src/sys/rump/net/lib/libshmif

2013-04-28 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Sun Apr 28 14:11:44 UTC 2013

Modified Files:
src/sys/rump/net/lib/libshmif: rumpcomp_user.c

Log Message:
some more headers are required by the third implementation


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/rump/net/lib/libshmif/rumpcomp_user.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/rumpcomp_user.c
diff -u src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.4 src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.5
--- src/sys/rump/net/lib/libshmif/rumpcomp_user.c:1.4	Sun Apr 28 13:38:35 2013
+++ src/sys/rump/net/lib/libshmif/rumpcomp_user.c	Sun Apr 28 14:11:43 2013
@@ -1,4 +1,4 @@
-/*  $NetBSD: rumpcomp_user.c,v 1.4 2013/04/28 13:38:35 pooka Exp $	*/
+/*  $NetBSD: rumpcomp_user.c,v 1.5 2013/04/28 14:11:43 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -146,6 +146,8 @@ rumpcomp_shmif_watchwait(int kq, int *er
 }
 
 #else
+#include stdio.h
+#include unistd.h
 
 /* a polling default implementation */
 int



CVS commit: src/sys/rump/net/lib/libshmif

2013-01-14 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Jan 14 20:21:33 UTC 2013

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
fix debug printf formats


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.46 src/sys/rump/net/lib/libshmif/if_shmem.c:1.47
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.46	Thu Oct 11 10:50:45 2012
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Mon Jan 14 20:21:32 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.46 2012/10/11 10:50:45 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.47 2013/01/14 20:21:32 pooka Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.46 2012/10/11 10:50:45 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.47 2013/01/14 20:21:32 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -551,7 +551,8 @@ shmif_start(struct ifnet *ifp)
 		KASSERT(pktwrote == pktsize);
 		if (wrap) {
 			busmem-shm_gen++;
-			DPRINTF((bus generation now %d\n, busmem-shm_gen));
+			DPRINTF((bus generation now % PRIu64 \n,
+			busmem-shm_gen));
 		}
 		shmif_unlockbus(busmem);
 
@@ -653,7 +654,8 @@ shmif_rcv(void *arg)
 			MCLGET(m, M_WAIT);
 		}
 
-		DPRINTF((waiting %d/%d\n, sc-sc_nextpacket, sc-sc_devgen));
+		DPRINTF((waiting %d/% PRIu64 \n,
+		sc-sc_nextpacket, sc-sc_devgen));
 		KASSERT(m-m_flags  M_EXT);
 
 		shmif_lockbus(busmem);
@@ -682,7 +684,7 @@ shmif_rcv(void *arg)
 sc-sc_devgen = busmem-shm_gen - 1;
 			else
 sc-sc_devgen = busmem-shm_gen;
-			DPRINTF((dev %p overrun, new data: %d/%d\n,
+			DPRINTF((dev %p overrun, new data: %d/% PRIu64 \n,
 			sc, nextpkt, sc-sc_devgen));
 		}
 
@@ -708,7 +710,7 @@ shmif_rcv(void *arg)
 
 		if (wrap) {
 			sc-sc_devgen++;
-			DPRINTF((dev %p generation now %d\n,
+			DPRINTF((dev %p generation now % PRIu64 \n,
 			sc, sc-sc_devgen));
 		}
 



CVS commit: src/sys/rump/net/lib/libshmif

2012-10-11 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Thu Oct 11 10:50:46 UTC 2012

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
Pass up all multicast addresses, not just broadcast.  Among other
things, makes IPv6 work over this interface.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.45 src/sys/rump/net/lib/libshmif/if_shmem.c:1.46
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.45	Fri Sep 14 16:29:22 2012
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Thu Oct 11 10:50:45 2012
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.45 2012/09/14 16:29:22 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.46 2012/10/11 10:50:45 pooka Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.45 2012/09/14 16:29:22 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.46 2012/10/11 10:50:45 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -722,8 +722,7 @@ shmif_rcv(void *arg)
 		if (memcmp(eth-ether_dhost, CLLADDR(ifp-if_sadl),
 		ETHER_ADDR_LEN) == 0) {
 			passup = true;
-		} else if (memcmp(eth-ether_dhost, etherbroadcastaddr,
-		ETHER_ADDR_LEN) == 0) {
+		} else if (ETHER_IS_MULTICAST(eth-ether_dhost)) {
 			passup = true;
 		} else if (ifp-if_flags  IFF_PROMISC) {
 			m-m_flags |= M_PROMISC;



CVS commit: src/sys/rump/net/lib/libshmif

2011-08-25 Thread David Young
Module Name:src
Committed By:   dyoung
Date:   Thu Aug 25 15:14:19 UTC 2011

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
Use VMEM_ADDR_MIN and VMEM_ADDR_MAX.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.41 src/sys/rump/net/lib/libshmif/if_shmem.c:1.42
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.41	Tue Aug 23 22:00:57 2011
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Thu Aug 25 15:14:19 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.41 2011/08/23 22:00:57 dyoung Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.42 2011/08/25 15:14:19 dyoung Exp $	*/
 
 /*
  * Copyright (c) 2009, 2010 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.41 2011/08/23 22:00:57 dyoung Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.42 2011/08/25 15:14:19 dyoung Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -293,8 +293,8 @@
 			return error;
 	}
 
-	unit = vmem_xalloc(shmif_units, 1, 0, 0, 0, 0, ~(vmem_addr_t)0,
-	VM_INSTANTFIT | VM_SLEEP) - 1;
+	unit = vmem_xalloc(shmif_units, 1, 0, 0, 0,
+	VMEM_ADDR_MIN, VMEM_ADDR_MAX, VM_INSTANTFIT | VM_SLEEP) - 1;
 
 	if ((error = allocif(unit, sc)) != 0) {
 		if (path)



CVS commit: src/sys/rump/net/lib/libshmif

2011-03-21 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Mar 21 15:47:54 UTC 2011

Removed Files:
src/sys/rump/net/lib/libshmif: dumpbus.c

Log Message:
this was moved to usr.bin ages ago


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r0 src/sys/rump/net/lib/libshmif/dumpbus.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/rump/net/lib/libshmif

2011-03-11 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Fri Mar 11 09:25:59 UTC 2011

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
Don't assume rump kernel PAGE_SIZE and host page size are the same.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.35 src/sys/rump/net/lib/libshmif/if_shmem.c:1.36
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.35	Thu Mar 10 13:27:03 2011
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Fri Mar 11 09:25:59 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.35 2011/03/10 13:27:03 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.36 2011/03/11 09:25:59 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.35 2011/03/10 13:27:03 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.36 2011/03/11 09:25:59 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -219,10 +219,14 @@
 		return ENOEXEC; 
 	}
 
-	/* Prefault in pages to minimize runtime penalty with buslock */
+	/*
+	 * Prefault in pages to minimize runtime penalty with buslock.
+	 * Use 512 instead of PAGE_SIZE to make sure we catch cases where
+	 * rump kernel PAGE_SIZE  host page size.
+	 */
 	for (p = (uint8_t *)sc-sc_busmem;
 	p  (uint8_t *)sc-sc_busmem + BUSMEM_SIZE;
-	p += PAGE_SIZE)
+	p += 512)
 		v = *p;
 
 	shmif_lockbus(sc-sc_busmem);



CVS commit: src/sys/rump/net/lib/libshmif

2011-03-11 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Fri Mar 11 12:10:15 UTC 2011

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
After my change to the interface accepts this packet logic
yesterday the CARP test stopped working, since CARP depends on
IFF_PROMISC (which was previously always accidentally enabled).
While making the interface honor IFF_PROMISC, also make it compare
the received frame's address against ifp-if_sadl instead of a
local enaddr value we cached when the interface was created.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.36 src/sys/rump/net/lib/libshmif/if_shmem.c:1.37
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.36	Fri Mar 11 09:25:59 2011
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Fri Mar 11 12:10:15 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.36 2011/03/11 09:25:59 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.37 2011/03/11 12:10:15 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.36 2011/03/11 09:25:59 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.37 2011/03/11 12:10:15 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -40,6 +40,7 @@
 
 #include net/bpf.h
 #include net/if.h
+#include net/if_dl.h
 #include net/if_ether.h
 
 #include netinet/in.h
@@ -78,7 +79,6 @@
 
 struct shmif_sc {
 	struct ethercom sc_ec;
-	uint8_t sc_myaddr[6];
 	struct shmif_mem *sc_busmem;
 	int sc_memfd;
 	int sc_kq;
@@ -160,7 +160,6 @@
 	sc-sc_unit = unit;
 
 	ifp = sc-sc_ec.ec_if;
-	memcpy(sc-sc_myaddr, enaddr, sizeof(enaddr));
 
 	sprintf(ifp-if_xname, shmif%d, unit);
 	ifp-if_softc = sc;
@@ -170,6 +169,7 @@
 	ifp-if_start = shmif_start;
 	ifp-if_stop = shmif_stop;
 	ifp-if_mtu = ETHERMTU;
+	ifp-if_dlt = DLT_EN10MB;
 
 	mutex_init(sc-sc_mtx, MUTEX_DEFAULT, IPL_NONE);
 	cv_init(sc-sc_cv, shmifcv);
@@ -623,7 +623,7 @@
 	struct mbuf *m = NULL;
 	struct ether_header *eth;
 	uint32_t nextpkt;
-	bool wrap;
+	bool wrap, passup;
 	int error;
 
  reup:
@@ -704,16 +704,30 @@
 		m-m_len = m-m_pkthdr.len = sp.sp_len;
 		m-m_pkthdr.rcvif = ifp;
 
-		/* if it's for us, pass up.  otherwise, reuse storage space */
+		/*
+		 * Test if we want to pass the packet upwards
+		 */
+		passup = false;
 		eth = mtod(m, struct ether_header *);
-		if (memcmp(eth-ether_dhost, sc-sc_myaddr, 6) == 0 ||
-		memcmp(eth-ether_dhost, etherbroadcastaddr, 6) == 0) {
+		if (memcmp(eth-ether_dhost, CLLADDR(ifp-if_sadl),
+		ETHER_ADDR_LEN) == 0) {
+			passup = true;
+		} else if (memcmp(eth-ether_dhost, etherbroadcastaddr,
+		ETHER_ADDR_LEN) == 0) {
+			passup = true;
+		} else if (ifp-if_flags  IFF_PROMISC) {
+			m-m_flags |= M_PROMISC;
+			passup = true;
+		}
+
+		if (passup) {
 			KERNEL_LOCK(1, NULL);
 			bpf_mtap(ifp, m);
 			ifp-if_input(ifp, m);
 			KERNEL_UNLOCK_ONE(NULL);
 			m = NULL;
 		}
+		/* else: reuse mbuf for a future packet */
 	}
 	m_freem(m);
 	m = NULL;



CVS commit: src/sys/rump/net/lib/libshmif

2011-03-11 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Fri Mar 11 12:11:01 UTC 2011

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
make the if-else logic more obvious


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.37 src/sys/rump/net/lib/libshmif/if_shmem.c:1.38
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.37	Fri Mar 11 12:10:15 2011
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Fri Mar 11 12:11:00 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.37 2011/03/11 12:10:15 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.38 2011/03/11 12:11:00 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.37 2011/03/11 12:10:15 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.38 2011/03/11 12:11:00 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -707,7 +707,6 @@
 		/*
 		 * Test if we want to pass the packet upwards
 		 */
-		passup = false;
 		eth = mtod(m, struct ether_header *);
 		if (memcmp(eth-ether_dhost, CLLADDR(ifp-if_sadl),
 		ETHER_ADDR_LEN) == 0) {
@@ -718,6 +717,8 @@
 		} else if (ifp-if_flags  IFF_PROMISC) {
 			m-m_flags |= M_PROMISC;
 			passup = true;
+		} else {
+			passup = false;
 		}
 
 		if (passup) {



CVS commit: src/sys/rump/net/lib/libshmif

2011-03-10 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Thu Mar 10 13:20:54 UTC 2011

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
Pass packet up if it's *for* us, not if it's from someone else.
This fixes a rather curious forwarding/redirect/etc. storm which
happened when there were 2 shmif kernels on the same shmbus with
ip forwarding set on. (at least it stress-tested other code ;)


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.33 src/sys/rump/net/lib/libshmif/if_shmem.c:1.34
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.33	Mon Dec  6 10:48:18 2010
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Thu Mar 10 13:20:54 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.33 2010/12/06 10:48:18 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.34 2011/03/10 13:20:54 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.33 2010/12/06 10:48:18 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.34 2011/03/10 13:20:54 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -697,9 +697,10 @@
 		m-m_len = m-m_pkthdr.len = sp.sp_len;
 		m-m_pkthdr.rcvif = ifp;
 
-		/* if it's from us, don't pass up and reuse storage space */
+		/* if it's for us, pass up.  otherwise, reuse storage space */
 		eth = mtod(m, struct ether_header *);
-		if (memcmp(eth-ether_shost, sc-sc_myaddr, 6) != 0) {
+		if (memcmp(eth-ether_dhost, sc-sc_myaddr, 6) == 0 ||
+		memcmp(eth-ether_dhost, etherbroadcastaddr, 6) == 0) {
 			KERNEL_LOCK(1, NULL);
 			ifp-if_input(ifp, m);
 			KERNEL_UNLOCK_ONE(NULL);



CVS commit: src/sys/rump/net/lib/libshmif

2011-03-10 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Thu Mar 10 13:27:03 UTC 2011

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
Support bpf.  shmif_dumpbus(1) can be used for much the same effect,
but sometimes it's just more convenient to run tcpdump live.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.34 src/sys/rump/net/lib/libshmif/if_shmem.c:1.35
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.34	Thu Mar 10 13:20:54 2011
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Thu Mar 10 13:27:03 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.34 2011/03/10 13:20:54 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.35 2011/03/10 13:27:03 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.34 2011/03/10 13:20:54 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.35 2011/03/10 13:27:03 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -38,6 +38,7 @@
 #include sys/lock.h
 #include sys/vmem.h
 
+#include net/bpf.h
 #include net/if.h
 #include net/if_ether.h
 
@@ -517,6 +518,8 @@
 		sp.sp_sec = tv.tv_sec;
 		sp.sp_usec = tv.tv_usec;
 
+		bpf_mtap(ifp, m0);
+
 		shmif_lockbus(busmem);
 		KASSERT(busmem-shm_magic == SHMIF_MAGIC);
 		busmem-shm_last = shmif_nextpktoff(busmem, busmem-shm_last);
@@ -702,6 +705,7 @@
 		if (memcmp(eth-ether_dhost, sc-sc_myaddr, 6) == 0 ||
 		memcmp(eth-ether_dhost, etherbroadcastaddr, 6) == 0) {
 			KERNEL_LOCK(1, NULL);
+			bpf_mtap(ifp, m);
 			ifp-if_input(ifp, m);
 			KERNEL_UNLOCK_ONE(NULL);
 			m = NULL;



CVS commit: src/sys/rump/net/lib/libshmif

2011-01-12 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Wed Jan 12 16:12:31 UTC 2011

Modified Files:
src/sys/rump/net/lib/libshmif: shmif_busops.c

Log Message:
make this happy to compile standalone


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/rump/net/lib/libshmif/shmif_busops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/shmif_busops.c
diff -u src/sys/rump/net/lib/libshmif/shmif_busops.c:1.7 src/sys/rump/net/lib/libshmif/shmif_busops.c:1.8
--- src/sys/rump/net/lib/libshmif/shmif_busops.c:1.7	Tue Aug 17 12:59:53 2010
+++ src/sys/rump/net/lib/libshmif/shmif_busops.c	Wed Jan 12 16:12:30 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: shmif_busops.c,v 1.7 2010/08/17 12:59:53 pooka Exp $	*/
+/*	$NetBSD: shmif_busops.c,v 1.8 2011/01/12 16:12:30 pooka Exp $	*/
 
 /*
  * Copyright (c) 2009 Antti Kantee.  All Rights Reserved.
@@ -28,20 +28,23 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: shmif_busops.c,v 1.7 2010/08/17 12:59:53 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: shmif_busops.c,v 1.8 2011/01/12 16:12:30 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
 
-#include shmifvar.h
-
 #ifndef _KERNEL
 #include assert.h
+#include stdbool.h
+#include string.h
+
 #define KASSERT(a) assert(a)
 #else
 #include rump/rumpuser.h
 #endif
 
+#include shmifvar.h
+
 uint32_t
 shmif_advance(uint32_t oldoff, uint32_t delta)
 {



CVS commit: src/sys/rump/net/lib/libshmif

2010-12-06 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Dec  6 10:48:19 UTC 2010

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
Allow creation with NULL busname (to be later set with SIOCSLINKSTR).


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.32 src/sys/rump/net/lib/libshmif/if_shmem.c:1.33
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.32	Wed Nov 17 17:51:22 2010
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Mon Dec  6 10:48:18 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.32 2010/11/17 17:51:22 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.33 2010/12/06 10:48:18 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.32 2010/11/17 17:51:22 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.33 2010/12/06 10:48:18 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -279,19 +279,27 @@
 rump_shmif_create(const char *path, int *ifnum)
 {
 	struct shmif_sc *sc;
-	int unit, error, memfd;
+	int unit, error;
+	int memfd = -1; /* XXXgcc */
 
-	memfd = rumpuser_open(path, O_RDWR | O_CREAT, error);
-	if (memfd == -1)
-		return error;
+	if (path) {
+		memfd = rumpuser_open(path, O_RDWR | O_CREAT, error);
+		if (memfd == -1)
+			return error;
+	}
 
 	unit = vmem_xalloc(shmif_units, 1, 0, 0, 0, 0, 0,
 	VM_INSTANTFIT | VM_SLEEP) - 1;
 
 	if ((error = allocif(unit, sc)) != 0) {
-		rumpuser_close(memfd, NULL);
+		if (path)
+			rumpuser_close(memfd, NULL);
 		return error;
 	}
+
+	if (!path)
+		goto out;
+
 	error = initbackend(sc, memfd);
 	if (error) {
 		shmif_unclone(sc-sc_ec.ec_if);
@@ -302,6 +310,7 @@
 	sc-sc_backfile = kmem_alloc(sc-sc_backfilelen, KM_SLEEP);
 	strcpy(sc-sc_backfile, path);
 
+ out:
 	if (ifnum)
 		*ifnum = unit;
 



CVS commit: src/sys/rump/net/lib/libshmif

2010-11-17 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Wed Nov 17 17:51:22 UTC 2010

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
Support destroy in shmif.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.31 src/sys/rump/net/lib/libshmif/if_shmem.c:1.32
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.31	Tue Nov 16 20:08:24 2010
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Wed Nov 17 17:51:22 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.31 2010/11/16 20:08:24 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.32 2010/11/17 17:51:22 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.31 2010/11/16 20:08:24 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.32 2010/11/17 17:51:22 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -81,12 +81,19 @@
 	struct shmif_mem *sc_busmem;
 	int sc_memfd;
 	int sc_kq;
+	int sc_unit;
 
 	char *sc_backfile;
 	size_t sc_backfilelen;
 
 	uint64_t sc_devgen;
 	uint32_t sc_nextpacket;
+
+	kmutex_t sc_mtx;
+	kcondvar_t sc_cv;
+
+	struct lwp *sc_rcvl;
+	bool sc_dying;
 };
 
 static const uint32_t busversion = SHMIF_VERSION;
@@ -142,18 +149,19 @@
 	struct shmif_sc *sc;
 	struct ifnet *ifp;
 	uint32_t randnum;
-	unsigned mynum = unit;
+	int error;
 
 	randnum = arc4random();
 	memcpy(enaddr[2], randnum, sizeof(randnum));
 
 	sc = kmem_zalloc(sizeof(*sc), KM_SLEEP);
 	sc-sc_memfd = -1;
+	sc-sc_unit = unit;
 
 	ifp = sc-sc_ec.ec_if;
 	memcpy(sc-sc_myaddr, enaddr, sizeof(enaddr));
 
-	sprintf(ifp-if_xname, shmif%d, mynum);
+	sprintf(ifp-if_xname, shmif%d, unit);
 	ifp-if_softc = sc;
 	ifp-if_flags = IFF_BROADCAST | IFF_MULTICAST;
 	ifp-if_init = shmif_init;
@@ -162,16 +170,32 @@
 	ifp-if_stop = shmif_stop;
 	ifp-if_mtu = ETHERMTU;
 
+	mutex_init(sc-sc_mtx, MUTEX_DEFAULT, IPL_NONE);
+	cv_init(sc-sc_cv, shmifcv);
+
 	if_attach(ifp);
 	ether_ifattach(ifp, enaddr);
 
 	aprint_verbose(shmif%d: Ethernet address %s\n,
-	mynum, ether_sprintf(enaddr));
+	unit, ether_sprintf(enaddr));
 
 	if (scp)
 		*scp = sc;
 
-	return 0;
+	error = 0;
+	if (rump_threads) {
+		error = kthread_create(PRI_NONE,
+		KTHREAD_MPSAFE | KTHREAD_JOINABLE, NULL,
+		shmif_rcv, ifp, sc-sc_rcvl, shmif);
+	} else {
+		printf(WARNING: threads not enabled, shmif NOT working\n);
+	}
+
+	if (error) {
+		shmif_unclone(ifp);
+	}
+
+	return error;
 }
 
 static int
@@ -221,48 +245,56 @@
 	shmif_unlockbus(sc-sc_busmem);
 
 	sc-sc_kq = rumpuser_writewatchfile_setup(-1, memfd, 0, error);
-	if (sc-sc_kq == -1)
+	if (sc-sc_kq == -1) {
+		rumpuser_unmap(sc-sc_busmem, BUSMEM_SIZE);
 		return error;
+	}
 
 	sc-sc_memfd = memfd;
-	return 0;
+
+	return error;
 }
 
 static void
 finibackend(struct shmif_sc *sc)
 {
-	int dummy;
 
-	kmem_free(sc-sc_backfile, sc-sc_backfilelen);
-	sc-sc_backfile = NULL;
-	sc-sc_backfilelen = 0;
+	if (sc-sc_backfile == NULL)
+		return;
+
+	if (sc-sc_backfile) {
+		kmem_free(sc-sc_backfile, sc-sc_backfilelen);
+		sc-sc_backfile = NULL;
+		sc-sc_backfilelen = 0;
+	}
 
 	rumpuser_unmap(sc-sc_busmem, BUSMEM_SIZE);
-	rumpuser_close(sc-sc_memfd, dummy);
-	rumpuser_close(sc-sc_kq, dummy);
+	rumpuser_close(sc-sc_memfd, NULL);
+	rumpuser_close(sc-sc_kq, NULL);
+
+	sc-sc_memfd = -1;
 }
 
 int
 rump_shmif_create(const char *path, int *ifnum)
 {
 	struct shmif_sc *sc;
-	int mynum, error, memfd, dummy;
+	int unit, error, memfd;
 
 	memfd = rumpuser_open(path, O_RDWR | O_CREAT, error);
 	if (memfd == -1)
 		return error;
 
-	mynum = vmem_xalloc(shmif_units, 1, 0, 0, 0, 0, 0,
+	unit = vmem_xalloc(shmif_units, 1, 0, 0, 0, 0, 0,
 	VM_INSTANTFIT | VM_SLEEP) - 1;
 
-	if ((error = allocif(mynum, sc)) != 0) {
+	if ((error = allocif(unit, sc)) != 0) {
 		rumpuser_close(memfd, NULL);
 		return error;
 	}
 	error = initbackend(sc, memfd);
 	if (error) {
-		rumpuser_close(memfd, dummy);
-		/* XXX: free sc */
+		shmif_unclone(sc-sc_ec.ec_if);
 		return error;
 	}
 
@@ -271,7 +303,7 @@
 	strcpy(sc-sc_backfile, path);
 
 	if (ifnum)
-		*ifnum = mynum;
+		*ifnum = unit;
 
 	return 0;
 }
@@ -300,8 +332,32 @@
 static int
 shmif_unclone(struct ifnet *ifp)
 {
+	struct shmif_sc *sc = ifp-if_softc;
+
+	shmif_stop(ifp, 1);
+	if_down(ifp);
+	finibackend(sc);
+
+	mutex_enter(sc-sc_mtx);
+	sc-sc_dying = true;
+	cv_broadcast(sc-sc_cv);
+	mutex_exit(sc-sc_mtx);
 
-	return EOPNOTSUPP;
+	if (sc-sc_rcvl)
+		kthread_join(sc-sc_rcvl);
+	sc-sc_rcvl = NULL;
+
+	vmem_xfree(shmif_units, sc-sc_unit+1, 1);
+
+	ether_ifdetach(ifp);
+	if_detach(ifp);
+
+	cv_destroy(sc-sc_cv);
+	mutex_destroy(sc-sc_mtx);
+
+	kmem_free(sc, sizeof(*sc));
+
+	return 0;
 }
 
 static int
@@ -312,15 +368,17 @@
 
 	if 

CVS commit: src/sys/rump/net/lib/libshmif

2010-11-15 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Nov 15 22:45:24 UTC 2010

Modified Files:
src/sys/rump/net/lib/libshmif: dumpbus.c

Log Message:
add -h which prints only the bus header info


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/rump/net/lib/libshmif/dumpbus.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/dumpbus.c
diff -u src/sys/rump/net/lib/libshmif/dumpbus.c:1.8 src/sys/rump/net/lib/libshmif/dumpbus.c:1.9
--- src/sys/rump/net/lib/libshmif/dumpbus.c:1.8	Fri Aug 13 11:45:47 2010
+++ src/sys/rump/net/lib/libshmif/dumpbus.c	Mon Nov 15 22:45:23 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: dumpbus.c,v 1.8 2010/08/13 11:45:47 pooka Exp $	*/
+/*	$NetBSD: dumpbus.c,v 1.9 2010/11/15 22:45:23 pooka Exp $	*/
 
 /*
  * Little utility to convert shmif bus traffic to a pcap file
@@ -26,7 +26,7 @@
 usage(void)
 {
 
-	fprintf(stderr, usage: a.out [-p pcapfile]�buspath\n);
+	fprintf(stderr, usage: a.out [-h]�[-p pcapfile]�buspath\n);
 	exit(1);
 }
 
@@ -42,9 +42,13 @@
 	int fd, pfd, i, ch;
 	int bonus;
 	char *buf;
+	bool hflag = false;
 
-	while ((ch = getopt(argc, argv, p:)) != -1) {
+	while ((ch = getopt(argc, argv, hp:)) != -1) {
 		switch (ch) {
+		case 'h':
+			hflag = true;
+			break;
 		case 'p':
 			pcapfile = optarg;
 			break;
@@ -70,11 +74,11 @@
 	if (fstat(fd, sb) == -1)
 		err(1, stat);
 
-	busmem = mmap(NULL, sb.st_size, PROT_READ, MAP_FILE, fd, 0);
+	busmem = mmap(NULL, sb.st_size, PROT_READ, MAP_FILE|MAP_SHARED, fd, 0);
 	if (busmem == MAP_FAILED)
 		err(1, mmap);
-
 	bmem = busmem;
+
 	if (bmem-shm_magic != SHMIF_MAGIC)
 		errx(1, %s not a shmif bus, argv[0]);
 	if (bmem-shm_version != SHMIF_VERSION)
@@ -85,6 +89,9 @@
 	bmem-shm_version, bmem-shm_lock, bmem-shm_gen,
 	bmem-shm_first, bmem-shm_last);
 
+	if (hflag)
+		exit(0);
+
 	if (pcapfile) {
 		struct pcap_file_header phdr;
 



CVS commit: src/sys/rump/net/lib/libshmif

2010-11-15 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Nov 15 22:48:06 UTC 2010

Modified Files:
src/sys/rump/net/lib/libshmif: Makefile if_shmem.c

Log Message:
* make interface a cloner
* use SIOCSLINKSTR for supplying bus filename in case of cloned if

TODO: downing interface, unclone, and some tweaks for robustness


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/rump/net/lib/libshmif/Makefile
cvs rdiff -u -r1.28 -r1.29 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/Makefile
diff -u src/sys/rump/net/lib/libshmif/Makefile:1.2 src/sys/rump/net/lib/libshmif/Makefile:1.3
--- src/sys/rump/net/lib/libshmif/Makefile:1.2	Thu Aug 12 21:41:47 2010
+++ src/sys/rump/net/lib/libshmif/Makefile	Mon Nov 15 22:48:06 2010
@@ -1,9 +1,10 @@
-#	$NetBSD: Makefile,v 1.2 2010/08/12 21:41:47 pooka Exp $
+#	$NetBSD: Makefile,v 1.3 2010/11/15 22:48:06 pooka Exp $
 #
 
 LIB=	rumpnet_shmif
 
 SRCS=	if_shmem.c shmif_busops.c
+SRCS+=	component.c
 
 CPPFLAGS+=	-I${.CURDIR}/../../../librump/rumpkern
 

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.28 src/sys/rump/net/lib/libshmif/if_shmem.c:1.29
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.28	Tue Aug 17 20:42:47 2010
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Mon Nov 15 22:48:06 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.28 2010/08/17 20:42:47 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.29 2010/11/15 22:48:06 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.28 2010/08/17 20:42:47 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.29 2010/11/15 22:48:06 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -50,14 +50,17 @@
 #include rump_private.h
 #include rump_net_private.h
 
+static int shmif_clone(struct if_clone *, int);
+static int shmif_unclone(struct ifnet *);
+
+struct if_clone shmif_cloner =
+IF_CLONE_INITIALIZER(shmif, shmif_clone, shmif_unclone);
+
 /*
  * Do r/w prefault for backend pages when attaching the interface.
- * This works aroud the most likely kernel/ffs/x86pmap bug described
- * in http://mail-index.netbsd.org/tech-kern/2010/08/17/msg008749.html
- *
- * NOTE: read prefaulting is not enough (that's done always)!
+ * At least logically thinking improves performance (although no
+ * mlocking is done, so they might go away).
  */
-
 #define PREFAULT_RW
 
 /*
@@ -79,6 +82,9 @@
 	int sc_memfd;
 	int sc_kq;
 
+	char *sc_backfile;
+	size_t sc_backfilelen;
+
 	uint64_t sc_devgen;
 	uint32_t sc_nextpacket;
 };
@@ -129,38 +135,64 @@
 	KASSERT(old == LOCK_LOCKED);
 }
 
-int
-rump_shmif_create(const char *path, int *ifnum)
+static int
+allocif(int unit, struct shmif_sc **scp)
 {
+	uint8_t enaddr[ETHER_ADDR_LEN] = { 0xb2, 0xa0, 0x00, 0x00, 0x00, 0x00 };
 	struct shmif_sc *sc;
 	struct ifnet *ifp;
-	uint8_t enaddr[ETHER_ADDR_LEN] = { 0xb2, 0xa0, 0x00, 0x00, 0x00, 0x00 };
 	uint32_t randnum;
-	unsigned mynum;
-	volatile uint8_t v;
-	volatile uint8_t *p;
-	int error;
+	unsigned mynum = unit;
 
 	randnum = arc4random();
 	memcpy(enaddr[2], randnum, sizeof(randnum));
-	mynum = atomic_inc_uint_nv(numif)-1;
 
 	sc = kmem_zalloc(sizeof(*sc), KM_SLEEP);
+	sc-sc_memfd = -1;
+
 	ifp = sc-sc_ec.ec_if;
 	memcpy(sc-sc_myaddr, enaddr, sizeof(enaddr));
 
-	sc-sc_memfd = rumpuser_open(path, O_RDWR | O_CREAT, error);
-	if (sc-sc_memfd == -1)
-		goto fail;
-	sc-sc_busmem = rumpuser_filemmap(sc-sc_memfd, 0, BUSMEM_SIZE,
+	sprintf(ifp-if_xname, shmif%d, mynum);
+	ifp-if_softc = sc;
+	ifp-if_flags = IFF_BROADCAST | IFF_MULTICAST;
+	ifp-if_init = shmif_init;
+	ifp-if_ioctl = shmif_ioctl;
+	ifp-if_start = shmif_start;
+	ifp-if_stop = shmif_stop;
+	ifp-if_mtu = ETHERMTU;
+
+	if_attach(ifp);
+	ether_ifattach(ifp, enaddr);
+
+	aprint_verbose(shmif%d: Ethernet address %s\n,
+	mynum, ether_sprintf(enaddr));
+
+	if (scp)
+		*scp = sc;
+
+	return 0;
+}
+
+static int
+initbackend(struct shmif_sc *sc, int memfd)
+{
+	volatile uint8_t v;
+	volatile uint8_t *p;
+	int error;
+
+	sc-sc_busmem = rumpuser_filemmap(memfd, 0, BUSMEM_SIZE,
 	RUMPUSER_FILEMMAP_TRUNCATE | RUMPUSER_FILEMMAP_SHARED
 	| RUMPUSER_FILEMMAP_READ | RUMPUSER_FILEMMAP_WRITE, error);
 	if (error)
-		goto fail;
-
-	if (sc-sc_busmem-shm_magic  sc-sc_busmem-shm_magic != SHMIF_MAGIC)
-		panic(bus is not magical);
+		return error;
 
+	if (sc-sc_busmem-shm_magic
+	 sc-sc_busmem-shm_magic != SHMIF_MAGIC) {
+		printf(bus is not magical);
+		rumpuser_unmap(sc-sc_busmem, BUSMEM_SIZE);
+		return ENOEXEC; 
+	}
 
 	/* Prefault in pages to minimize runtime penalty with buslock */
 	for (p = (uint8_t *)sc-sc_busmem;
@@ -188,39 +220,88 @@
 #endif
 	shmif_unlockbus(sc-sc_busmem);
 
-	sc-sc_kq = rumpuser_writewatchfile_setup(-1, sc-sc_memfd, 0, error);

CVS commit: src/sys/rump/net/lib/libshmif

2010-11-15 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Nov 15 22:49:33 UTC 2010

Modified Files:
src/sys/rump/net/lib/libshmif: dumpbus.c

Log Message:
un-\240


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/rump/net/lib/libshmif/dumpbus.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/dumpbus.c
diff -u src/sys/rump/net/lib/libshmif/dumpbus.c:1.9 src/sys/rump/net/lib/libshmif/dumpbus.c:1.10
--- src/sys/rump/net/lib/libshmif/dumpbus.c:1.9	Mon Nov 15 22:45:23 2010
+++ src/sys/rump/net/lib/libshmif/dumpbus.c	Mon Nov 15 22:49:33 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: dumpbus.c,v 1.9 2010/11/15 22:45:23 pooka Exp $	*/
+/*	$NetBSD: dumpbus.c,v 1.10 2010/11/15 22:49:33 pooka Exp $	*/
 
 /*
  * Little utility to convert shmif bus traffic to a pcap file
@@ -26,7 +26,7 @@
 usage(void)
 {
 
-	fprintf(stderr, usage: a.out [-h]�[-p pcapfile]�buspath\n);
+	fprintf(stderr, usage: a.out [-h] [-p pcapfile] buspath\n);
 	exit(1);
 }
 



CVS commit: src/sys/rump/net/lib/libshmif

2010-11-15 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Nov 15 23:51:07 UTC 2010

Added Files:
src/sys/rump/net/lib/libshmif: component.c

Log Message:
remember to commit this file too


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/rump/net/lib/libshmif/component.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/sys/rump/net/lib/libshmif/component.c
diff -u /dev/null src/sys/rump/net/lib/libshmif/component.c:1.1
--- /dev/null	Mon Nov 15 23:51:07 2010
+++ src/sys/rump/net/lib/libshmif/component.c	Mon Nov 15 23:51:06 2010
@@ -0,0 +1,45 @@
+/*	$NetBSD: component.c,v 1.1 2010/11/15 23:51:06 pooka Exp $	*/
+
+/*
+ * Copyright (c) 2010 Antti Kantee.  All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+ * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include sys/cdefs.h
+__KERNEL_RCSID(0, $NetBSD: component.c,v 1.1 2010/11/15 23:51:06 pooka Exp $);
+
+#include sys/param.h
+#include sys/domain.h
+#include sys/protosw.h
+
+#include net/if.h
+
+#include rump_private.h
+#include rump_net_private.h
+
+RUMP_COMPONENT(RUMP_COMPONENT_NET_IF)
+{
+	extern struct if_clone shmif_cloner; /* XXX */
+
+	if_clone_attach(shmif_cloner);
+}



CVS commit: src/sys/rump/net/lib/libshmif

2010-11-15 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Nov 15 23:59:06 UTC 2010

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
fix completely crackheaded code w/ uninitialized use,
missed as usual by the wonderful -g -O0


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.29 src/sys/rump/net/lib/libshmif/if_shmem.c:1.30
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.29	Mon Nov 15 22:48:06 2010
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Mon Nov 15 23:59:06 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.29 2010/11/15 22:48:06 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.30 2010/11/15 23:59:06 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.29 2010/11/15 22:48:06 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.30 2010/11/15 23:59:06 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -277,11 +277,10 @@
 static int
 shmif_clone(struct if_clone *ifc, int unit)
 {
-	int mynum;
 
 	/* not atomic against rump_shmif_create().  so don't do it. */
-	if (unit = mynum)
-		mynum = unit+1;
+	if (unit = numif)
+		numif = unit+1;
 
 	return allocif(unit, NULL);
 }



CVS commit: src/sys/rump/net/lib/libshmif

2010-08-17 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Tue Aug 17 11:35:24 UTC 2010

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c shmif_busops.c

Log Message:
* fix off-by-wrap case where current datagram aligns exactly with
  the end of the bus
* clarify the can we still use the device's next pointer calculation
  and move it to its own routine
* sprinkle dprintf


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/sys/rump/net/lib/libshmif/if_shmem.c
cvs rdiff -u -r1.5 -r1.6 src/sys/rump/net/lib/libshmif/shmif_busops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.26 src/sys/rump/net/lib/libshmif/if_shmem.c:1.27
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.26	Mon Aug 16 17:33:52 2010
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Tue Aug 17 11:35:23 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.26 2010/08/16 17:33:52 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.27 2010/08/17 11:35:23 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.26 2010/08/16 17:33:52 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.27 2010/08/17 11:35:23 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -267,16 +267,17 @@
 			mtod(m, void *), m-m_len, wrap);
 		}
 		KASSERT(pktwrote == pktsize);
-
-		if (wrap)
+		if (wrap) {
 			busmem-shm_gen++;
+			DPRINTF((bus generation now %d\n, busmem-shm_gen));
+		}
 		shmif_unlockbus(busmem);
 
 		m_freem(m0);
 		wrote = true;
 
 		DPRINTF((shmif_start: send %d bytes at off %d\n,
-		pktsize, npktlenoff));
+		pktsize, busmem-shm_last));
 	}
 
 	ifp-if_flags = ~IFF_OACTIVE;
@@ -294,6 +295,44 @@
 	panic(%s: unimpl, __func__);
 }
 
+
+/*
+ * Check if we have been sleeping too long.  Basically,
+ * our in-sc nextpkt must by first = nextpkt = last+1.
+ * We use the fact that first is guaranteed to never overlap
+ * with the last frame in the ring.
+ */
+static __inline bool
+stillvalid_p(struct shmif_sc *sc)
+{
+	struct shmif_mem *busmem = sc-sc_busmem;
+	unsigned gendiff = busmem-shm_gen - sc-sc_devgen;
+	uint32_t lastoff, devoff;
+
+	KASSERT(busmem-shm_first != busmem-shm_last);
+
+	/* normalize onto a 2x busmem chunk */
+	devoff = sc-sc_nextpacket;
+	lastoff = shmif_nextpktoff(busmem, busmem-shm_last);
+
+	/* trivial case */
+	if (gendiff  1)
+		return false;
+	KASSERT(gendiff = 1);
+
+	/* Normalize onto 2x busmem chunk */
+	if (busmem-shm_first = lastoff) {
+		lastoff += BUSMEM_DATASIZE;
+		if (gendiff == 0)
+			devoff += BUSMEM_DATASIZE;
+	} else {
+		if (gendiff)
+			return false;
+	}
+
+	return devoff = busmem-shm_first  devoff = lastoff;
+}
+
 static void
 shmif_rcv(void *arg)
 {
@@ -302,7 +341,7 @@
 	struct shmif_mem *busmem = sc-sc_busmem;
 	struct mbuf *m = NULL;
 	struct ether_header *eth;
-	uint32_t nextpkt, busgen;
+	uint32_t nextpkt;
 	bool wrap;
 	int error;
 
@@ -318,12 +357,11 @@
 		KASSERT(m-m_flags  M_EXT);
 
 		shmif_lockbus(busmem);
-		busgen = busmem-shm_gen;
 		KASSERT(busmem-shm_magic == SHMIF_MAGIC);
-		KASSERT(busgen = sc-sc_devgen);
+		KASSERT(busmem-shm_gen = sc-sc_devgen);
 
 		/* need more data? */
-		if (sc-sc_devgen == busgen  
+		if (sc-sc_devgen == busmem-shm_gen  
 		shmif_nextpktoff(busmem, busmem-shm_last)
 		 == sc-sc_nextpacket) {
 			shmif_unlockbus(busmem);
@@ -334,23 +372,17 @@
 			continue;
 		}
 
-		/*
-		 * Check if we have been sleeping too long.  There are
-		 * basically two scenarios:
-		 *  1) our next packet is behind the first packet and
-		 * we are a generation behind
-		 *  2) we are over two generations behind
-		 */
-		if ((sc-sc_nextpacket  busmem-shm_first
-		   sc-sc_devgen  busgen) || (sc-sc_devgen+1  busgen)) {
-			KASSERT(busgen  0);
+		if (stillvalid_p(sc)) {
+			nextpkt = sc-sc_nextpacket;
+		} else {
+			KASSERT(busmem-shm_gen  0);
 			nextpkt = busmem-shm_first;
 			if (busmem-shm_first  busmem-shm_last)
-sc-sc_devgen = busgen - 1;
+sc-sc_devgen = busmem-shm_gen - 1;
 			else
-sc-sc_devgen = busgen;
-		} else {
-			nextpkt = sc-sc_nextpacket;
+sc-sc_devgen = busmem-shm_gen;
+			DPRINTF((dev %p overrun, new data: %d/%d\n,
+			sc, nextpkt, sc-sc_devgen));
 		}
 
 		/*
@@ -358,7 +390,7 @@
 		 * generation must be one behind.
 		 */
 		KASSERT(!(nextpkt  busmem-shm_last
-		 sc-sc_devgen == busgen));
+		 sc-sc_devgen == busmem-shm_gen));
 
 		wrap = false;
 		nextpkt = shmif_busread(busmem, sp,
@@ -373,8 +405,11 @@
 		sc-sc_nextpacket = nextpkt;
 		shmif_unlockbus(sc-sc_busmem);
 
-		if (wrap)
+		if (wrap) {
 			sc-sc_devgen++;
+			DPRINTF((dev %p generation now %d\n,
+			sc, sc-sc_devgen));
+		}
 
 		m-m_len = m-m_pkthdr.len = sp.sp_len;
 		m-m_pkthdr.rcvif = ifp;

Index: src/sys/rump/net/lib/libshmif/shmif_busops.c
diff 

CVS commit: src/sys/rump/net/lib/libshmif

2010-08-17 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Tue Aug 17 12:59:53 UTC 2010

Modified Files:
src/sys/rump/net/lib/libshmif: shmif_busops.c

Log Message:
Fix hopefully last off-by-one: if we fill the bus, we must also
advance the first pointer.  This problem triggered only if the
bus was filled in the first round, since the first pointer is at
the end-of-bus only for the bootstrap round.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/rump/net/lib/libshmif/shmif_busops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/shmif_busops.c
diff -u src/sys/rump/net/lib/libshmif/shmif_busops.c:1.6 src/sys/rump/net/lib/libshmif/shmif_busops.c:1.7
--- src/sys/rump/net/lib/libshmif/shmif_busops.c:1.6	Tue Aug 17 11:35:23 2010
+++ src/sys/rump/net/lib/libshmif/shmif_busops.c	Tue Aug 17 12:59:53 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: shmif_busops.c,v 1.6 2010/08/17 11:35:23 pooka Exp $	*/
+/*	$NetBSD: shmif_busops.c,v 1.7 2010/08/17 12:59:53 pooka Exp $	*/
 
 /*
  * Copyright (c) 2009 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: shmif_busops.c,v 1.6 2010/08/17 11:35:23 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: shmif_busops.c,v 1.7 2010/08/17 12:59:53 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -93,20 +93,23 @@
 	bool *wrap)
 {
 	size_t chunk;
+	bool filledbus;
 
 	KASSERT(len  (BUSMEM_DATASIZE/2)  off = BUSMEM_DATASIZE);
 
 	chunk = MIN(len, BUSMEM_DATASIZE - off);
 	len -= chunk;
+	filledbus = (off+chunk == BUSMEM_DATASIZE);
 
-	shmif_advancefirst(busmem, off, chunk + (len ? 1 : 0));
+	shmif_advancefirst(busmem, off, chunk + (filledbus ? 1 : 0));
 
 	memcpy(busmem-shm_data + off, data, chunk);
 
 	DPRINTF((buswrite: wrote %d bytes to %d, chunk, off));
 
-	if (off + chunk == BUSMEM_DATASIZE)
+	if (filledbus) {
 		*wrap = true;
+	}
 
 	if (len == 0) {
 		DPRINTF((\n));



CVS commit: src/sys/rump/net/lib/libshmif

2010-08-17 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Tue Aug 17 20:42:47 UTC 2010

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
Prefault bus pages in driver attachment.  This seems to work around
weird corruption I've been seeing (most likely a host kernel bug).

For more details, see thread at:
http://mail-index.netbsd.org/tech-kern/2010/08/17/msg008749.html


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.27 src/sys/rump/net/lib/libshmif/if_shmem.c:1.28
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.27	Tue Aug 17 11:35:23 2010
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Tue Aug 17 20:42:47 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.27 2010/08/17 11:35:23 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.28 2010/08/17 20:42:47 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.27 2010/08/17 11:35:23 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.28 2010/08/17 20:42:47 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -51,6 +51,16 @@
 #include rump_net_private.h
 
 /*
+ * Do r/w prefault for backend pages when attaching the interface.
+ * This works aroud the most likely kernel/ffs/x86pmap bug described
+ * in http://mail-index.netbsd.org/tech-kern/2010/08/17/msg008749.html
+ *
+ * NOTE: read prefaulting is not enough (that's done always)!
+ */
+
+#define PREFAULT_RW
+
+/*
  * A virtual ethernet interface which uses shared memory from a
  * memory mapped file as the bus.
  */
@@ -127,6 +137,8 @@
 	uint8_t enaddr[ETHER_ADDR_LEN] = { 0xb2, 0xa0, 0x00, 0x00, 0x00, 0x00 };
 	uint32_t randnum;
 	unsigned mynum;
+	volatile uint8_t v;
+	volatile uint8_t *p;
 	int error;
 
 	randnum = arc4random();
@@ -149,6 +161,13 @@
 	if (sc-sc_busmem-shm_magic  sc-sc_busmem-shm_magic != SHMIF_MAGIC)
 		panic(bus is not magical);
 
+
+	/* Prefault in pages to minimize runtime penalty with buslock */
+	for (p = (uint8_t *)sc-sc_busmem;
+	p  (uint8_t *)sc-sc_busmem + BUSMEM_SIZE;
+	p += PAGE_SIZE)
+		v = *p;
+
 	shmif_lockbus(sc-sc_busmem);
 	/* we're first?  initialize bus */
 	if (sc-sc_busmem-shm_magic == 0) {
@@ -158,6 +177,15 @@
 
 	sc-sc_nextpacket = sc-sc_busmem-shm_last;
 	sc-sc_devgen = sc-sc_busmem-shm_gen;
+
+#ifdef PREFAULT_RW
+	for (p = (uint8_t *)sc-sc_busmem;
+	p  (uint8_t *)sc-sc_busmem + BUSMEM_SIZE;
+	p += PAGE_SIZE) {
+		v = *p;
+		*p = v;
+	}
+#endif
 	shmif_unlockbus(sc-sc_busmem);
 
 	sc-sc_kq = rumpuser_writewatchfile_setup(-1, sc-sc_memfd, 0, error);



CVS commit: src/sys/rump/net/lib/libshmif

2010-08-16 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Aug 16 17:33:52 UTC 2010

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c shmif_busops.c

Log Message:
simplify, improve, etc.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/rump/net/lib/libshmif/if_shmem.c
cvs rdiff -u -r1.4 -r1.5 src/sys/rump/net/lib/libshmif/shmif_busops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.25 src/sys/rump/net/lib/libshmif/if_shmem.c:1.26
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.25	Sun Aug 15 21:57:58 2010
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Mon Aug 16 17:33:52 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.25 2010/08/15 21:57:58 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.26 2010/08/16 17:33:52 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.25 2010/08/15 21:57:58 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.26 2010/08/16 17:33:52 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -69,8 +69,8 @@
 	int sc_memfd;
 	int sc_kq;
 
+	uint64_t sc_devgen;
 	uint32_t sc_nextpacket;
-	uint32_t sc_prevgen;
 };
 
 static const uint32_t busversion = SHMIF_VERSION;
@@ -157,7 +157,7 @@
 	}
 
 	sc-sc_nextpacket = sc-sc_busmem-shm_last;
-	sc-sc_prevgen = sc-sc_busmem-shm_gen;
+	sc-sc_devgen = sc-sc_busmem-shm_gen;
 	shmif_unlockbus(sc-sc_busmem);
 
 	sc-sc_kq = rumpuser_writewatchfile_setup(-1, sc-sc_memfd, 0, error);
@@ -171,7 +171,7 @@
 	ifp-if_ioctl = shmif_ioctl;
 	ifp-if_start = shmif_start;
 	ifp-if_stop = shmif_stop;
-	ifp-if_mtu = 1518;
+	ifp-if_mtu = ETHERMTU;
 
 	if_attach(ifp);
 	ether_ifattach(ifp, enaddr);
@@ -223,13 +223,16 @@
 shmif_start(struct ifnet *ifp)
 {
 	struct shmif_sc *sc = ifp-if_softc;
+	struct shmif_mem *busmem = sc-sc_busmem;
 	struct mbuf *m, *m0;
-	uint32_t lastoff, dataoff, npktlenoff;
-	uint32_t pktsize;
+	uint32_t dataoff;
+	uint32_t pktsize, pktwrote;
 	bool wrote = false;
 	bool wrap;
 	int error;
 
+	ifp-if_flags |= IFF_OACTIVE;
+
 	for (;;) {
 		struct shmif_pkthdr sp;
 		struct timeval tv;
@@ -243,29 +246,31 @@
 		for (m = m0; m != NULL; m = m-m_next) {
 			pktsize += m-m_len;
 		}
+		KASSERT(pktsize = ETHERMTU + ETHER_HDR_LEN);
 
 		getmicrouptime(tv);
-
 		sp.sp_len = pktsize;
 		sp.sp_sec = tv.tv_sec;
 		sp.sp_usec = tv.tv_usec;
 
-		shmif_lockbus(sc-sc_busmem);
-		lastoff = sc-sc_busmem-shm_last;
-		npktlenoff = shmif_nextpktoff(sc-sc_busmem, lastoff);
+		shmif_lockbus(busmem);
+		KASSERT(busmem-shm_magic == SHMIF_MAGIC);
+		busmem-shm_last = shmif_nextpktoff(busmem, busmem-shm_last);
 
 		wrap = false;
-		dataoff = shmif_buswrite(sc-sc_busmem,
-		npktlenoff, sp, sizeof(sp), wrap);
+		dataoff = shmif_buswrite(busmem,
+		busmem-shm_last, sp, sizeof(sp), wrap);
+		pktwrote = 0;
 		for (m = m0; m != NULL; m = m-m_next) {
-			dataoff = shmif_buswrite(sc-sc_busmem, dataoff,
+			pktwrote += m-m_len;
+			dataoff = shmif_buswrite(busmem, dataoff,
 			mtod(m, void *), m-m_len, wrap);
 		}
+		KASSERT(pktwrote == pktsize);
 
 		if (wrap)
-			sc-sc_busmem-shm_gen++;
-		sc-sc_busmem-shm_last = npktlenoff;
-		shmif_unlockbus(sc-sc_busmem);
+			busmem-shm_gen++;
+		shmif_unlockbus(busmem);
 
 		m_freem(m0);
 		wrote = true;
@@ -273,6 +278,9 @@
 		DPRINTF((shmif_start: send %d bytes at off %d\n,
 		pktsize, npktlenoff));
 	}
+
+	ifp-if_flags = ~IFF_OACTIVE;
+
 	/* wakeup */
 	if (wrote)
 		rumpuser_pwrite(sc-sc_memfd,
@@ -291,9 +299,10 @@
 {
 	struct ifnet *ifp = arg;
 	struct shmif_sc *sc = ifp-if_softc;
+	struct shmif_mem *busmem = sc-sc_busmem;
 	struct mbuf *m = NULL;
 	struct ether_header *eth;
-	uint32_t nextpkt, lastpkt, busgen, lastnext;
+	uint32_t nextpkt, busgen;
 	bool wrap;
 	int error;
 
@@ -305,26 +314,19 @@
 			MCLGET(m, M_WAIT);
 		}
 
-		DPRINTF((waiting %d/%d\n, sc-sc_nextpacket, sc-sc_prevgen));
-
+		DPRINTF((waiting %d/%d\n, sc-sc_nextpacket, sc-sc_devgen));
 		KASSERT(m-m_flags  M_EXT);
-		shmif_lockbus(sc-sc_busmem);
-		lastpkt = sc-sc_busmem-shm_last;
-		busgen = sc-sc_busmem-shm_gen;
-		lastnext = shmif_nextpktoff(sc-sc_busmem, lastpkt);
-		if ((lastnext  sc-sc_nextpacket  busgen  sc-sc_prevgen)
-		|| (busgen  sc-sc_prevgen+1)) {
-			nextpkt = lastpkt;
-			sc-sc_prevgen = busgen;
-			rumpuser_dprintf(shmif_rcv: generation overrun, 
-			skipping invalid packets\n);
-		} else {
-			nextpkt = sc-sc_nextpacket;
-		}
+
+		shmif_lockbus(busmem);
+		busgen = busmem-shm_gen;
+		KASSERT(busmem-shm_magic == SHMIF_MAGIC);
+		KASSERT(busgen = sc-sc_devgen);
 
 		/* need more data? */
-		if (lastnext == nextpkt  sc-sc_prevgen == busgen){
-			shmif_unlockbus(sc-sc_busmem);
+		if (sc-sc_devgen == busgen  
+		shmif_nextpktoff(busmem, busmem-shm_last)
+		 == sc-sc_nextpacket) {
+			

CVS commit: src/sys/rump/net/lib/libshmif

2010-08-15 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Sun Aug 15 18:40:42 UTC 2010

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
Don't do timestamping with buslock held.  it's the little things ...


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.20 src/sys/rump/net/lib/libshmif/if_shmem.c:1.21
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.20	Fri Aug 13 10:13:44 2010
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Sun Aug 15 18:40:41 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.20 2010/08/13 10:13:44 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.21 2010/08/15 18:40:41 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.20 2010/08/13 10:13:44 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.21 2010/08/15 18:40:41 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -203,16 +203,16 @@
 			pktsize += m-m_len;
 		}
 
-		shmif_lockbus(sc-sc_busmem);
-		lastoff = sc-sc_busmem-shm_last;
-		npktlenoff = shmif_nextpktoff(sc-sc_busmem, lastoff);
-
 		getmicrouptime(tv);
 
 		sp.sp_len = pktsize;
 		sp.sp_sec = tv.tv_sec;
 		sp.sp_usec = tv.tv_usec;
 
+		shmif_lockbus(sc-sc_busmem);
+		lastoff = sc-sc_busmem-shm_last;
+		npktlenoff = shmif_nextpktoff(sc-sc_busmem, lastoff);
+
 		dataoff = shmif_buswrite(sc-sc_busmem,
 		npktlenoff, sp, sizeof(sp), wrap);
 		for (m = m0; m != NULL; m = m-m_next) {



CVS commit: src/sys/rump/net/lib/libshmif

2010-08-15 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Sun Aug 15 18:47:39 UTC 2010

Modified Files:
src/sys/rump/net/lib/libshmif: shmif_busops.c

Log Message:
introduce a sleep to trying to grab the bus


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/rump/net/lib/libshmif/shmif_busops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/shmif_busops.c
diff -u src/sys/rump/net/lib/libshmif/shmif_busops.c:1.2 src/sys/rump/net/lib/libshmif/shmif_busops.c:1.3
--- src/sys/rump/net/lib/libshmif/shmif_busops.c:1.2	Fri Aug 13 10:13:44 2010
+++ src/sys/rump/net/lib/libshmif/shmif_busops.c	Sun Aug 15 18:47:38 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: shmif_busops.c,v 1.2 2010/08/13 10:13:44 pooka Exp $	*/
+/*	$NetBSD: shmif_busops.c,v 1.3 2010/08/15 18:47:38 pooka Exp $	*/
 
 /*
  * Copyright (c) 2009 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: shmif_busops.c,v 1.2 2010/08/13 10:13:44 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: shmif_busops.c,v 1.3 2010/08/15 18:47:38 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -44,6 +44,7 @@
 
 #define LOCK_UNLOCKED	0
 #define LOCK_LOCKED	1
+#define LOCK_COOLDOWN	1001
 
 /*
  * This locking needs work and will misbehave severely if:
@@ -53,10 +54,21 @@
 void
 shmif_lockbus(struct shmif_mem *busmem)
 {
+	int i = 0;
 
-	while (atomic_cas_32(busmem-shm_lock,
-	LOCK_UNLOCKED, LOCK_LOCKED) == LOCK_LOCKED)
+	while (__predict_false(atomic_cas_32(busmem-shm_lock,
+	LOCK_UNLOCKED, LOCK_LOCKED) == LOCK_LOCKED)) {
+		if (__predict_false(++i  LOCK_COOLDOWN)) {
+			uint64_t sec, nsec;
+			int error;
+
+			sec = 0;
+			nsec = 1000*1000; /* 1ms */
+			rumpuser_nanosleep(sec, nsec, error);
+			i = 0;
+		}
 		continue;
+	}
 	membar_enter();
 }
 



CVS commit: src/sys/rump/net/lib/libshmif

2010-08-15 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Sun Aug 15 18:48:39 UTC 2010

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
Take kernel lock before passing data to if_input.  This is in line
with IPL_NET interrupts generally not being MPSAFE.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.21 src/sys/rump/net/lib/libshmif/if_shmem.c:1.22
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.21	Sun Aug 15 18:40:41 2010
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Sun Aug 15 18:48:38 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.21 2010/08/15 18:40:41 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.22 2010/08/15 18:48:38 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.21 2010/08/15 18:40:41 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.22 2010/08/15 18:48:38 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -310,7 +310,9 @@
 		/* if it's from us, don't pass up and reuse storage space */
 		eth = mtod(m, struct ether_header *);
 		if (memcmp(eth-ether_shost, sc-sc_myaddr, 6) != 0) {
+			KERNEL_LOCK(1, NULL);
 			ifp-if_input(ifp, m);
+			KERNEL_UNLOCK_ONE(NULL);
 			m = NULL;
 		}
 	}



CVS commit: src/sys/rump/net/lib/libshmif

2010-08-15 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Sun Aug 15 18:55:03 UTC 2010

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c shmif_busops.c shmifvar.h

Log Message:
Move the lockops together with the interface -- they are needed
only at runtime.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/sys/rump/net/lib/libshmif/if_shmem.c
cvs rdiff -u -r1.3 -r1.4 src/sys/rump/net/lib/libshmif/shmif_busops.c
cvs rdiff -u -r1.4 -r1.5 src/sys/rump/net/lib/libshmif/shmifvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.22 src/sys/rump/net/lib/libshmif/if_shmem.c:1.23
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.22	Sun Aug 15 18:48:38 2010
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Sun Aug 15 18:55:03 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.22 2010/08/15 18:48:38 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.23 2010/08/15 18:55:03 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.22 2010/08/15 18:48:38 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.23 2010/08/15 18:55:03 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -79,6 +79,46 @@
 
 static uint32_t numif;
 
+#define LOCK_UNLOCKED	0
+#define LOCK_LOCKED	1
+#define LOCK_COOLDOWN	1001
+
+/*
+ * This locking needs work and will misbehave severely if:
+ * 1) the backing memory has to be paged in
+ * 2) some lockholder exits while holding the lock
+ */
+static void
+shmif_lockbus(struct shmif_mem *busmem)
+{
+	int i = 0;
+
+	while (__predict_false(atomic_cas_32(busmem-shm_lock,
+	LOCK_UNLOCKED, LOCK_LOCKED) == LOCK_LOCKED)) {
+		if (__predict_false(++i  LOCK_COOLDOWN)) {
+			uint64_t sec, nsec;
+			int error;
+
+			sec = 0;
+			nsec = 1000*1000; /* 1ms */
+			rumpuser_nanosleep(sec, nsec, error);
+			i = 0;
+		}
+		continue;
+	}
+	membar_enter();
+}
+
+static void
+shmif_unlockbus(struct shmif_mem *busmem)
+{
+	unsigned int old;
+
+	membar_exit();
+	old = atomic_swap_32(busmem-shm_lock, LOCK_UNLOCKED);
+	KASSERT(old == LOCK_LOCKED);
+}
+
 int
 rump_shmif_create(const char *path, int *ifnum)
 {

Index: src/sys/rump/net/lib/libshmif/shmif_busops.c
diff -u src/sys/rump/net/lib/libshmif/shmif_busops.c:1.3 src/sys/rump/net/lib/libshmif/shmif_busops.c:1.4
--- src/sys/rump/net/lib/libshmif/shmif_busops.c:1.3	Sun Aug 15 18:47:38 2010
+++ src/sys/rump/net/lib/libshmif/shmif_busops.c	Sun Aug 15 18:55:03 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: shmif_busops.c,v 1.3 2010/08/15 18:47:38 pooka Exp $	*/
+/*	$NetBSD: shmif_busops.c,v 1.4 2010/08/15 18:55:03 pooka Exp $	*/
 
 /*
  * Copyright (c) 2009 Antti Kantee.  All Rights Reserved.
@@ -28,7 +28,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: shmif_busops.c,v 1.3 2010/08/15 18:47:38 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: shmif_busops.c,v 1.4 2010/08/15 18:55:03 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -42,46 +42,6 @@
 #include rump/rumpuser.h
 #endif
 
-#define LOCK_UNLOCKED	0
-#define LOCK_LOCKED	1
-#define LOCK_COOLDOWN	1001
-
-/*
- * This locking needs work and will misbehave severely if:
- * 1) the backing memory has to be paged in
- * 2) some lockholder exits while holding the lock
- */
-void
-shmif_lockbus(struct shmif_mem *busmem)
-{
-	int i = 0;
-
-	while (__predict_false(atomic_cas_32(busmem-shm_lock,
-	LOCK_UNLOCKED, LOCK_LOCKED) == LOCK_LOCKED)) {
-		if (__predict_false(++i  LOCK_COOLDOWN)) {
-			uint64_t sec, nsec;
-			int error;
-
-			sec = 0;
-			nsec = 1000*1000; /* 1ms */
-			rumpuser_nanosleep(sec, nsec, error);
-			i = 0;
-		}
-		continue;
-	}
-	membar_enter();
-}
-
-void
-shmif_unlockbus(struct shmif_mem *busmem)
-{
-	unsigned int old;
-
-	membar_exit();
-	old = atomic_swap_32(busmem-shm_lock, LOCK_UNLOCKED);
-	KASSERT(old == LOCK_LOCKED);
-}
-
 uint32_t
 shmif_advance(uint32_t oldoff, uint32_t delta)
 {

Index: src/sys/rump/net/lib/libshmif/shmifvar.h
diff -u src/sys/rump/net/lib/libshmif/shmifvar.h:1.4 src/sys/rump/net/lib/libshmif/shmifvar.h:1.5
--- src/sys/rump/net/lib/libshmif/shmifvar.h:1.4	Fri Aug 13 10:13:44 2010
+++ src/sys/rump/net/lib/libshmif/shmifvar.h	Sun Aug 15 18:55:03 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: shmifvar.h,v 1.4 2010/08/13 10:13:44 pooka Exp $	*/
+/*	$NetBSD: shmifvar.h,v 1.5 2010/08/15 18:55:03 pooka Exp $	*/
 
 /*-
  * Copyright (c) 2009 Antti Kantee.  All Rights Reserved.
@@ -71,8 +71,6 @@
 #define DPRINTF(x)
 #endif
 
-void		shmif_lockbus(struct shmif_mem *);
-void		shmif_unlockbus(struct shmif_mem *);
 uint32_t	shmif_advance(uint32_t, uint32_t);
 uint32_t	shmif_busread(struct shmif_mem *,
 			  void *, uint32_t, size_t, bool *);



CVS commit: src/sys/rump/net/lib/libshmif

2010-08-15 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Sun Aug 15 21:41:39 UTC 2010

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
reset wrap where necessary


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.23 src/sys/rump/net/lib/libshmif/if_shmem.c:1.24
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.23	Sun Aug 15 18:55:03 2010
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Sun Aug 15 21:41:39 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.23 2010/08/15 18:55:03 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.24 2010/08/15 21:41:39 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.23 2010/08/15 18:55:03 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.24 2010/08/15 21:41:39 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -227,7 +227,7 @@
 	uint32_t lastoff, dataoff, npktlenoff;
 	uint32_t pktsize = 0;
 	bool wrote = false;
-	bool wrap = false;
+	bool wrap;
 	int error;
 
 	for (;;) {
@@ -253,6 +253,7 @@
 		lastoff = sc-sc_busmem-shm_last;
 		npktlenoff = shmif_nextpktoff(sc-sc_busmem, lastoff);
 
+		wrap = false;
 		dataoff = shmif_buswrite(sc-sc_busmem,
 		npktlenoff, sp, sizeof(sp), wrap);
 		for (m = m0; m != NULL; m = m-m_next) {
@@ -292,7 +293,7 @@
 	struct mbuf *m = NULL;
 	struct ether_header *eth;
 	uint32_t nextpkt, lastpkt, busgen, lastnext;
-	bool wrap = false;
+	bool wrap;
 	int error;
 
 	for (;;) {
@@ -330,8 +331,10 @@
 			continue;
 		}
 
+		wrap = false;
 		shmif_busread(sc-sc_busmem,
 		sp, nextpkt, sizeof(sp), wrap);
+		KASSERT(sp.sp_len = MCLBYTES);
 		shmif_busread(sc-sc_busmem, mtod(m, void *),
 		shmif_advance(nextpkt, sizeof(sp)), sp.sp_len, wrap);
 		if (wrap)



CVS commit: src/sys/rump/net/lib/libshmif

2010-08-15 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Sun Aug 15 21:57:58 UTC 2010

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
reset pktsize each loop


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.24 src/sys/rump/net/lib/libshmif/if_shmem.c:1.25
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.24	Sun Aug 15 21:41:39 2010
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Sun Aug 15 21:57:58 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.24 2010/08/15 21:41:39 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.25 2010/08/15 21:57:58 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.24 2010/08/15 21:41:39 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.25 2010/08/15 21:57:58 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -225,7 +225,7 @@
 	struct shmif_sc *sc = ifp-if_softc;
 	struct mbuf *m, *m0;
 	uint32_t lastoff, dataoff, npktlenoff;
-	uint32_t pktsize = 0;
+	uint32_t pktsize;
 	bool wrote = false;
 	bool wrap;
 	int error;
@@ -239,6 +239,7 @@
 			break;
 		}
 
+		pktsize = 0;
 		for (m = m0; m != NULL; m = m-m_next) {
 			pktsize += m-m_len;
 		}



CVS commit: src/sys/rump/net/lib/libshmif

2010-08-13 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Fri Aug 13 10:13:44 UTC 2010

Modified Files:
src/sys/rump/net/lib/libshmif: dumpbus.c if_shmem.c shmif_busops.c
shmifvar.h

Log Message:
Include a timestamp in the frame header.  When converting to pcap,
it can give some idea of when packets were sent.

nb. it's the sending host's timestamp, not an observer timestamp
like in the typical pcap case.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/rump/net/lib/libshmif/dumpbus.c
cvs rdiff -u -r1.19 -r1.20 src/sys/rump/net/lib/libshmif/if_shmem.c
cvs rdiff -u -r1.1 -r1.2 src/sys/rump/net/lib/libshmif/shmif_busops.c
cvs rdiff -u -r1.3 -r1.4 src/sys/rump/net/lib/libshmif/shmifvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/dumpbus.c
diff -u src/sys/rump/net/lib/libshmif/dumpbus.c:1.6 src/sys/rump/net/lib/libshmif/dumpbus.c:1.7
--- src/sys/rump/net/lib/libshmif/dumpbus.c:1.6	Thu Aug 12 21:41:47 2010
+++ src/sys/rump/net/lib/libshmif/dumpbus.c	Fri Aug 13 10:13:44 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: dumpbus.c,v 1.6 2010/08/12 21:41:47 pooka Exp $	*/
+/*	$NetBSD: dumpbus.c,v 1.7 2010/08/13 10:13:44 pooka Exp $	*/
 
 /*
  * Little utility to convert shmif bus traffic to a pcap file
@@ -40,7 +40,6 @@
 	uint32_t curbus, buslast;
 	struct shmif_mem *bmem;
 	int fd, pfd, i, ch;
-	uint32_t pktlen;
 	int bonus;
 	char *buf;
 
@@ -117,42 +116,42 @@
 	if (buslast  curbus)
 		bonus = 1;
 
-	assert(sizeof(pktlen) == PKTLEN_SIZE);
-
 	i = 0;
 	while (curbus = buslast || bonus) {
 		struct pcap_pkthdr packhdr;
+		struct shmif_pkthdr sp;
 		uint32_t oldoff;
 		bool wrap;
 
 		wrap = false;
 		oldoff = curbus;
-		curbus = shmif_busread(bmem,
-		pktlen, oldoff, PKTLEN_SIZE, wrap);
+		curbus = shmif_busread(bmem, sp, oldoff, sizeof(sp), wrap);
 		if (wrap)
 			bonus = 0;
 
-		if (pktlen == 0)
+		if (sp.sp_len == 0)
 			continue;
 
-		printf(packet %d, offset 0x%04x, length 0x%04x\n,
-		i++, curbus, pktlen);
+		printf(packet %d, offset 0x%04x, length 0x%04x, ts %d/%06d\n,
+		i++, curbus, sp.sp_len, sp.sp_sec, sp.sp_usec);
 
-		if (!pcapfile || pktlen == 0) {
+		if (!pcapfile || sp.sp_len == 0) {
 			curbus = shmif_busread(bmem,
-			buf, curbus, pktlen, wrap);
+			buf, curbus, sp.sp_len, wrap);
 			if (wrap)
 bonus = 0;
 			continue;
 		}
 
 		memset(packhdr, 0, sizeof(packhdr));
-		packhdr.caplen = packhdr.len = pktlen;
+		packhdr.caplen = packhdr.len = sp.sp_len;
+		packhdr.ts.tv_sec = sp.sp_sec;
+		packhdr.ts.tv_usec = sp.sp_usec;
 
 		if (write(pfd, packhdr, sizeof(packhdr)) != sizeof(packhdr))
 			err(1, error writing packethdr);
-		curbus = shmif_busread(bmem, buf, curbus, pktlen, wrap);
-		if (write(pfd, buf, pktlen) != pktlen)
+		curbus = shmif_busread(bmem, buf, curbus, sp.sp_len, wrap);
+		if (write(pfd, buf, sp.sp_len) != sp.sp_len)
 			err(1, write packet);
 		if (wrap)
 			bonus = 0;

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.19 src/sys/rump/net/lib/libshmif/if_shmem.c:1.20
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.19	Thu Aug 12 21:41:47 2010
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Fri Aug 13 10:13:44 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.19 2010/08/12 21:41:47 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.20 2010/08/13 10:13:44 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.19 2010/08/12 21:41:47 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.20 2010/08/13 10:13:44 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -191,6 +191,9 @@
 	int error;
 
 	for (;;) {
+		struct shmif_pkthdr sp;
+		struct timeval tv;
+
 		IF_DEQUEUE(ifp-if_snd, m0);
 		if (m0 == NULL) {
 			break;
@@ -204,8 +207,14 @@
 		lastoff = sc-sc_busmem-shm_last;
 		npktlenoff = shmif_nextpktoff(sc-sc_busmem, lastoff);
 
+		getmicrouptime(tv);
+
+		sp.sp_len = pktsize;
+		sp.sp_sec = tv.tv_sec;
+		sp.sp_usec = tv.tv_usec;
+
 		dataoff = shmif_buswrite(sc-sc_busmem,
-		npktlenoff, pktsize, PKTLEN_SIZE, wrap);
+		npktlenoff, sp, sizeof(sp), wrap);
 		for (m = m0; m != NULL; m = m-m_next) {
 			dataoff = shmif_buswrite(sc-sc_busmem, dataoff,
 			mtod(m, void *), m-m_len, wrap);
@@ -242,11 +251,13 @@
 	struct shmif_sc *sc = ifp-if_softc;
 	struct mbuf *m = NULL;
 	struct ether_header *eth;
-	uint32_t nextpkt, pktlen, lastpkt, busgen, lastnext;
+	uint32_t nextpkt, lastpkt, busgen, lastnext;
 	bool wrap = false;
 	int error;
 
 	for (;;) {
+		struct shmif_pkthdr sp;
+
 		if (m == NULL) {
 			m = m_gethdr(M_WAIT, MT_DATA);
 			MCLGET(m, M_WAIT);
@@ -280,20 +291,20 @@
 		}
 
 		shmif_busread(sc-sc_busmem,
-		pktlen, nextpkt, PKTLEN_SIZE, wrap);
+		sp, nextpkt, sizeof(sp), wrap);
 		shmif_busread(sc-sc_busmem, mtod(m, void *),
-		

CVS commit: src/sys/rump/net/lib/libshmif

2010-08-13 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Fri Aug 13 11:45:47 UTC 2010

Modified Files:
src/sys/rump/net/lib/libshmif: dumpbus.c

Log Message:
truncate pcap output file


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/rump/net/lib/libshmif/dumpbus.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/dumpbus.c
diff -u src/sys/rump/net/lib/libshmif/dumpbus.c:1.7 src/sys/rump/net/lib/libshmif/dumpbus.c:1.8
--- src/sys/rump/net/lib/libshmif/dumpbus.c:1.7	Fri Aug 13 10:13:44 2010
+++ src/sys/rump/net/lib/libshmif/dumpbus.c	Fri Aug 13 11:45:47 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: dumpbus.c,v 1.7 2010/08/13 10:13:44 pooka Exp $	*/
+/*	$NetBSD: dumpbus.c,v 1.8 2010/08/13 11:45:47 pooka Exp $	*/
 
 /*
  * Little utility to convert shmif bus traffic to a pcap file
@@ -91,7 +91,7 @@
 		if (strcmp(pcapfile, -) == 0) {
 			pfd = STDOUT_FILENO;
 		} else {
-			pfd = open(pcapfile, O_RDWR | O_CREAT, 0777);
+			pfd = open(pcapfile, O_RDWR | O_CREAT | O_TRUNC, 0777);
 			if (pfd == -1)
 err(1, create pcap dump);
 		}



CVS commit: src/sys/rump/net/lib/libshmif

2010-08-12 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Thu Aug 12 17:00:41 UTC 2010

Modified Files:
src/sys/rump/net/lib/libshmif: dumpbus.c

Log Message:
pass Wall


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/rump/net/lib/libshmif/dumpbus.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/dumpbus.c
diff -u src/sys/rump/net/lib/libshmif/dumpbus.c:1.1 src/sys/rump/net/lib/libshmif/dumpbus.c:1.2
--- src/sys/rump/net/lib/libshmif/dumpbus.c:1.1	Wed Aug 11 12:41:09 2010
+++ src/sys/rump/net/lib/libshmif/dumpbus.c	Thu Aug 12 17:00:41 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: dumpbus.c,v 1.1 2010/08/11 12:41:09 pooka Exp $	*/
+/*	$NetBSD: dumpbus.c,v 1.2 2010/08/12 17:00:41 pooka Exp $	*/
 
 /*
  * Little utility to convert shmif bus traffic to a pcap file
@@ -13,6 +13,8 @@
 #include fcntl.h
 #include pcap.h
 #include stdio.h
+#include stdlib.h
+#include string.h
 #include unistd.h
 
 /* XXX: sync with driver */
@@ -130,4 +132,6 @@
 			err(1, write packet);
 		curbus += pktlen;
 	}
+
+	return 0;
 }



CVS commit: src/sys/rump/net/lib/libshmif

2010-08-12 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Thu Aug 12 17:33:55 UTC 2010

Modified Files:
src/sys/rump/net/lib/libshmif: dumpbus.c if_shmem.c
Added Files:
src/sys/rump/net/lib/libshmif: shmifvar.h

Log Message:
Make shmif memory access slightly more sane.  Create a header which
is shared by the interface and the bus analyzer.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/rump/net/lib/libshmif/dumpbus.c
cvs rdiff -u -r1.15 -r1.16 src/sys/rump/net/lib/libshmif/if_shmem.c
cvs rdiff -u -r0 -r1.1 src/sys/rump/net/lib/libshmif/shmifvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/dumpbus.c
diff -u src/sys/rump/net/lib/libshmif/dumpbus.c:1.2 src/sys/rump/net/lib/libshmif/dumpbus.c:1.3
--- src/sys/rump/net/lib/libshmif/dumpbus.c:1.2	Thu Aug 12 17:00:41 2010
+++ src/sys/rump/net/lib/libshmif/dumpbus.c	Thu Aug 12 17:33:55 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: dumpbus.c,v 1.2 2010/08/12 17:00:41 pooka Exp $	*/
+/*	$NetBSD: dumpbus.c,v 1.3 2010/08/12 17:33:55 pooka Exp $	*/
 
 /*
  * Little utility to convert shmif bus traffic to a pcap file
@@ -9,6 +9,7 @@
 #include sys/mman.h
 #include sys/stat.h
 
+#include assert.h
 #include err.h
 #include fcntl.h
 #include pcap.h
@@ -17,13 +18,7 @@
 #include string.h
 #include unistd.h
 
-/* XXX: sync with driver */
-struct bushdr {
-	uint32_t lock;
-	uint32_t gen;
-	uint32_t last;
-	uint32_t version;
-};
+#include shmifvar.h
 
 static void
 usage(void)
@@ -40,8 +35,9 @@
 	void *busmem;
 	const char *pcapfile = NULL;
 	uint8_t *curbus, *buslast;
-	struct bushdr *bhdr;
+	struct shmif_mem *bmem;
 	int fd, pfd, i, ch;
+	uint32_t pktlen;
 
 	while ((ch = getopt(argc, argv, p:)) != -1) {
 		switch (ch) {
@@ -70,13 +66,13 @@
 	if (busmem == MAP_FAILED)
 		err(1, mmap);
 
-	bhdr = busmem;
-	if (bhdr-version != 1)
-		errx(1, cannot handle bus version %d, bhdr-version);
+	bmem = busmem;
+	if (bmem-shm_version != 1)
+		errx(1, cannot handle bus version %d, bmem-shm_version);
 	printf(bus version %d, lock: %d, generation: %d, lastoff: 0x%x\n,
-	bhdr-version, bhdr-lock, bhdr-gen, bhdr-last);
+	bmem-shm_version, bmem-shm_lock, bmem-shm_gen, bmem-shm_last);
 
-	if (bhdr-gen != 0) {
+	if (bmem-shm_gen != 0) {
 		printf(this dumper can manage only generation 0, sorry\n);
 		exit(0);
 	}
@@ -99,13 +95,12 @@
 			err(1, phdr write);
 	}
 	
-	curbus = busmem;
-	buslast = curbus + bhdr-last;
-	curbus += sizeof(*bhdr);
+	curbus = bmem-shm_data;
+	buslast = bmem-shm_data + bmem-shm_last;
+	assert(sizeof(pktlen) == PKTLEN_SIZE);
 
 	i = 0;
 	while (curbus = buslast) {
-		uint32_t pktlen;
 		struct pcap_pkthdr packhdr;
 
 		pktlen = *(uint32_t *)curbus;
@@ -116,7 +111,7 @@
 			continue;
 
 		printf(packet %d, offset 0x%x, length 0x%x\n,
-		i++, curbus - (uint8_t *)(bhdr + 1), pktlen);
+		i++, curbus - (uint8_t *)(bmem + 1), pktlen);
 
 		if (!pcapfile || pktlen == 0) {
 			curbus += pktlen;

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.15 src/sys/rump/net/lib/libshmif/if_shmem.c:1.16
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.15	Wed Aug 11 12:10:39 2010
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Thu Aug 12 17:33:55 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.15 2010/08/11 12:10:39 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.16 2010/08/12 17:33:55 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.15 2010/08/11 12:10:39 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.16 2010/08/12 17:33:55 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -66,27 +66,20 @@
 static void	shmif_start(struct ifnet *);
 static void	shmif_stop(struct ifnet *, int);
 
+#include shmifvar.h
+
 struct shmif_sc {
 	struct ethercom sc_ec;
 	uint8_t sc_myaddr[6];
-	uint8_t *sc_busmem;
+	struct shmif_mem *sc_busmem;
 	int sc_memfd;
 	int sc_kq;
 
 	uint32_t sc_nextpacket;
 	uint32_t sc_prevgen;
 };
-#define IFMEM_LOCK		(0x00)
-#define IFMEM_GENERATION	(0x04)
-#define IFMEM_LASTPACKET	(0x08)
-#define IFMEM_WAKEUP		(0x0c)
-#define IFMEM_BUSVERSION	IFMEM_WAKEUP
-#define IFMEM_DATA		(0x10)
-
-#define BUSCTRL_ATOFF(sc, off)	((uint32_t *)(sc-sc_busmem+(off)))
 
 #define BUSMEM_SIZE (1024*1024) /* need write throttling? */
-#define PKTLEN_SIZE 4
 
 /* just in case ... */
 static const uint32_t busversion = 1;
@@ -107,7 +100,7 @@
 lockbus(struct shmif_sc *sc)
 {
 
-	while (atomic_cas_32((uint32_t *)sc-sc_busmem,
+	while (atomic_cas_32(sc-sc_busmem-shm_lock,
 	LOCK_UNLOCKED, LOCK_LOCKED) == LOCK_LOCKED)
 		continue;
 	membar_enter();
@@ -119,7 +112,7 @@
 	unsigned int old;
 
 	membar_exit();
-	old = atomic_swap_32((uint32_t *)sc-sc_busmem, LOCK_UNLOCKED);
+	old = atomic_swap_32(sc-sc_busmem-shm_lock, LOCK_UNLOCKED);
 	KASSERT(old == LOCK_LOCKED);
 }
 

CVS commit: src/sys/rump/net/lib/libshmif

2010-08-12 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Thu Aug 12 18:17:23 UTC 2010

Modified Files:
src/sys/rump/net/lib/libshmif: dumpbus.c if_shmem.c shmifvar.h

Log Message:
* include a magic number in the bus format
* simplify offset calculations by making them start from beginning of data


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/sys/rump/net/lib/libshmif/dumpbus.c
cvs rdiff -u -r1.16 -r1.17 src/sys/rump/net/lib/libshmif/if_shmem.c
cvs rdiff -u -r1.1 -r1.2 src/sys/rump/net/lib/libshmif/shmifvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/dumpbus.c
diff -u src/sys/rump/net/lib/libshmif/dumpbus.c:1.3 src/sys/rump/net/lib/libshmif/dumpbus.c:1.4
--- src/sys/rump/net/lib/libshmif/dumpbus.c:1.3	Thu Aug 12 17:33:55 2010
+++ src/sys/rump/net/lib/libshmif/dumpbus.c	Thu Aug 12 18:17:23 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: dumpbus.c,v 1.3 2010/08/12 17:33:55 pooka Exp $	*/
+/*	$NetBSD: dumpbus.c,v 1.4 2010/08/12 18:17:23 pooka Exp $	*/
 
 /*
  * Little utility to convert shmif bus traffic to a pcap file
@@ -67,8 +67,11 @@
 		err(1, mmap);
 
 	bmem = busmem;
-	if (bmem-shm_version != 1)
-		errx(1, cannot handle bus version %d, bmem-shm_version);
+	if (bmem-shm_magic != SHMIF_MAGIC)
+		errx(1, %s not a shmif bus, argv[0]);
+	if (bmem-shm_version != SHMIF_VERSION)
+		errx(1, bus vesrsion %d, program %d,
+		bmem-shm_version, SHMIF_VERSION);
 	printf(bus version %d, lock: %d, generation: %d, lastoff: 0x%x\n,
 	bmem-shm_version, bmem-shm_lock, bmem-shm_gen, bmem-shm_last);
 
@@ -106,12 +109,11 @@
 		pktlen = *(uint32_t *)curbus;
 		curbus += sizeof(pktlen);
 
-		/* quirk */
 		if (pktlen == 0)
 			continue;
 
 		printf(packet %d, offset 0x%x, length 0x%x\n,
-		i++, curbus - (uint8_t *)(bmem + 1), pktlen);
+		i++, curbus - bmem-shm_data, pktlen);
 
 		if (!pcapfile || pktlen == 0) {
 			curbus += pktlen;

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.16 src/sys/rump/net/lib/libshmif/if_shmem.c:1.17
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.16	Thu Aug 12 17:33:55 2010
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Thu Aug 12 18:17:23 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.16 2010/08/12 17:33:55 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.17 2010/08/12 18:17:23 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.16 2010/08/12 17:33:55 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.17 2010/08/12 18:17:23 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -81,8 +81,7 @@
 
 #define BUSMEM_SIZE (1024*1024) /* need write throttling? */
 
-/* just in case ... */
-static const uint32_t busversion = 1;
+static const uint32_t busversion = SHMIF_VERSION;
 
 static void shmif_rcv(void *);
 
@@ -123,18 +122,18 @@
 
 	KASSERT(len  (BUSMEM_SIZE - IFMEM_DATA)  off = BUSMEM_SIZE);
 	chunk = MIN(len, BUSMEM_SIZE - off);
-	memcpy(dest, (uint8_t *)sc-sc_busmem + off, chunk);
+	memcpy(dest, sc-sc_busmem-shm_data + off, chunk);
 	len -= chunk;
 
 	if (len == 0)
 		return off + chunk;
 
 	/* else, wraps around */
-	off = IFMEM_DATA;
+	off = 0;
 	sc-sc_prevgen = sc-sc_busmem-shm_gen;
 
 	/* finish reading */
-	memcpy((uint8_t *)dest + chunk, (uint8_t *)sc-sc_busmem + off, len);
+	memcpy((uint8_t *)dest + chunk, sc-sc_busmem-shm_data + off, len);
 	return off + len;
 }
 
@@ -143,26 +142,25 @@
 {
 	size_t chunk;
 
-	KASSERT(len  (BUSMEM_SIZE - IFMEM_DATA)  off = BUSMEM_SIZE
-	 off = IFMEM_DATA);
+	KASSERT(len  (BUSMEM_SIZE - IFMEM_DATA)  off = BUSMEM_SIZE);
 
 	chunk = MIN(len, BUSMEM_SIZE - off);
-	memcpy((uint8_t *)sc-sc_busmem + off, data, chunk);
+	memcpy(sc-sc_busmem-shm_data + off, data, chunk);
 	len -= chunk;
 
 	if (len == 0)
 		return off + chunk;
 
-	DPRINTF((buswrite wrap: wrote %d bytes to %d, left %d to %d,
-	chunk, off, len, IFMEM_DATA));
+	DPRINTF((buswrite wrap: wrote %d bytes to %d, left %d to 0,
+	chunk, off, len));
 
 	/* else, wraps around */
-	off = IFMEM_DATA;
+	off = 0;
 	sc-sc_prevgen = sc-sc_busmem-shm_gen;
 	sc-sc_busmem-shm_gen++;
 
 	/* finish writing */
-	memcpy((uint8_t *)sc-sc_busmem + off, (uint8_t *)data + chunk, len);
+	memcpy(sc-sc_busmem-shm_data + off, (uint8_t *)data + chunk, len);
 	return off + len;
 }
 
@@ -216,9 +214,11 @@
 	if (error)
 		goto fail;
 
+	if (sc-sc_busmem-shm_magic  sc-sc_busmem-shm_magic != SHMIF_MAGIC)
+		panic(bus is not magical);
+	sc-sc_busmem-shm_magic = SHMIF_MAGIC;
+
 	lockbus(sc);
-	if (sc-sc_busmem-shm_last == 0)
-		sc-sc_busmem-shm_last = IFMEM_DATA;
 	sc-sc_nextpacket = sc-sc_busmem-shm_last;
 	sc-sc_prevgen = sc-sc_busmem-shm_gen;
 	unlockbus(sc);

Index: src/sys/rump/net/lib/libshmif/shmifvar.h
diff -u src/sys/rump/net/lib/libshmif/shmifvar.h:1.1 

CVS commit: src/sys/rump/net/lib/libshmif

2010-08-12 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Thu Aug 12 18:22:40 UTC 2010

Modified Files:
src/sys/rump/net/lib/libshmif: dumpbus.c

Log Message:
Recognize ``-'' for stdout.  allows piping output to tcpdump -r -


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/sys/rump/net/lib/libshmif/dumpbus.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/dumpbus.c
diff -u src/sys/rump/net/lib/libshmif/dumpbus.c:1.4 src/sys/rump/net/lib/libshmif/dumpbus.c:1.5
--- src/sys/rump/net/lib/libshmif/dumpbus.c:1.4	Thu Aug 12 18:17:23 2010
+++ src/sys/rump/net/lib/libshmif/dumpbus.c	Thu Aug 12 18:22:40 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: dumpbus.c,v 1.4 2010/08/12 18:17:23 pooka Exp $	*/
+/*	$NetBSD: dumpbus.c,v 1.5 2010/08/12 18:22:40 pooka Exp $	*/
 
 /*
  * Little utility to convert shmif bus traffic to a pcap file
@@ -83,9 +83,13 @@
 	if (pcapfile) {
 		struct pcap_file_header phdr;
 
-		pfd = open(pcapfile, O_RDWR | O_CREAT, 0777);
-		if (pfd == -1)
-			err(1, create pcap dump);
+		if (strcmp(pcapfile, -) == 0) {
+			pfd = STDOUT_FILENO;
+		} else {
+			pfd = open(pcapfile, O_RDWR | O_CREAT, 0777);
+			if (pfd == -1)
+err(1, create pcap dump);
+		}
 
 		memset(phdr, 0, sizeof(phdr));
 		phdr.magic = 0xa1b2c3d4; /* tcpdump magic */



CVS commit: src/sys/rump/net/lib/libshmif

2010-08-12 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Thu Aug 12 18:39:55 UTC 2010

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
further simplify  fix calculations


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.17 src/sys/rump/net/lib/libshmif/if_shmem.c:1.18
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.17	Thu Aug 12 18:17:23 2010
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Thu Aug 12 18:39:54 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.17 2010/08/12 18:17:23 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.18 2010/08/12 18:39:54 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.17 2010/08/12 18:17:23 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.18 2010/08/12 18:39:54 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -79,7 +79,8 @@
 	uint32_t sc_prevgen;
 };
 
-#define BUSMEM_SIZE (1024*1024) /* need write throttling? */
+#define BUSMEM_SIZE (1024*1024)
+#define BUSMEM_DATASIZE (BUSMEM_SIZE - sizeof(struct shmif_mem))
 
 static const uint32_t busversion = SHMIF_VERSION;
 
@@ -120,8 +121,8 @@
 {
 	size_t chunk;
 
-	KASSERT(len  (BUSMEM_SIZE - IFMEM_DATA)  off = BUSMEM_SIZE);
-	chunk = MIN(len, BUSMEM_SIZE - off);
+	KASSERT(len  (BUSMEM_DATASIZE)  off = BUSMEM_DATASIZE);
+	chunk = MIN(len, BUSMEM_DATASIZE - off);
 	memcpy(dest, sc-sc_busmem-shm_data + off, chunk);
 	len -= chunk;
 
@@ -142,9 +143,9 @@
 {
 	size_t chunk;
 
-	KASSERT(len  (BUSMEM_SIZE - IFMEM_DATA)  off = BUSMEM_SIZE);
+	KASSERT(len  (BUSMEM_DATASIZE)  off = BUSMEM_DATASIZE);
 
-	chunk = MIN(len, BUSMEM_SIZE - off);
+	chunk = MIN(len, BUSMEM_DATASIZE - off);
 	memcpy(sc-sc_busmem-shm_data + off, data, chunk);
 	len -= chunk;
 
@@ -170,8 +171,8 @@
 	uint32_t newoff;
 
 	newoff = oldoff + delta;
-	if (newoff = BUSMEM_SIZE)
-		newoff -= (BUSMEM_SIZE - IFMEM_DATA);
+	if (newoff = BUSMEM_DATASIZE)
+		newoff -= (BUSMEM_DATASIZE);
 	return newoff;
 
 }
@@ -182,7 +183,7 @@
 	uint32_t oldlen;
 
 	busread(sc, oldlen, oldoff, PKTLEN_SIZE);
-	KASSERT(oldlen  BUSMEM_SIZE - IFMEM_DATA);
+	KASSERT(oldlen  BUSMEM_DATASIZE);
 
 	return advance(oldoff, PKTLEN_SIZE + oldlen);
 }



CVS commit: src/sys/rump/net/lib/libshmif

2010-08-12 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Thu Aug 12 21:41:47 UTC 2010

Modified Files:
src/sys/rump/net/lib/libshmif: Makefile dumpbus.c if_shmem.c shmifvar.h
Added Files:
src/sys/rump/net/lib/libshmif: shmif_busops.c

Log Message:
Include a pointer to the beginning of the buffer and add support
to the packet dumper.  This helps in situations where the juicy
details are in a bus multiple generations old.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/rump/net/lib/libshmif/Makefile
cvs rdiff -u -r1.5 -r1.6 src/sys/rump/net/lib/libshmif/dumpbus.c
cvs rdiff -u -r1.18 -r1.19 src/sys/rump/net/lib/libshmif/if_shmem.c
cvs rdiff -u -r0 -r1.1 src/sys/rump/net/lib/libshmif/shmif_busops.c
cvs rdiff -u -r1.2 -r1.3 src/sys/rump/net/lib/libshmif/shmifvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/Makefile
diff -u src/sys/rump/net/lib/libshmif/Makefile:1.1 src/sys/rump/net/lib/libshmif/Makefile:1.2
--- src/sys/rump/net/lib/libshmif/Makefile:1.1	Sat Feb 28 15:28:46 2009
+++ src/sys/rump/net/lib/libshmif/Makefile	Thu Aug 12 21:41:47 2010
@@ -1,9 +1,9 @@
-#	$NetBSD: Makefile,v 1.1 2009/02/28 15:28:46 pooka Exp $
+#	$NetBSD: Makefile,v 1.2 2010/08/12 21:41:47 pooka Exp $
 #
 
 LIB=	rumpnet_shmif
 
-SRCS=	if_shmem.c
+SRCS=	if_shmem.c shmif_busops.c
 
 CPPFLAGS+=	-I${.CURDIR}/../../../librump/rumpkern
 

Index: src/sys/rump/net/lib/libshmif/dumpbus.c
diff -u src/sys/rump/net/lib/libshmif/dumpbus.c:1.5 src/sys/rump/net/lib/libshmif/dumpbus.c:1.6
--- src/sys/rump/net/lib/libshmif/dumpbus.c:1.5	Thu Aug 12 18:22:40 2010
+++ src/sys/rump/net/lib/libshmif/dumpbus.c	Thu Aug 12 21:41:47 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: dumpbus.c,v 1.5 2010/08/12 18:22:40 pooka Exp $	*/
+/*	$NetBSD: dumpbus.c,v 1.6 2010/08/12 21:41:47 pooka Exp $	*/
 
 /*
  * Little utility to convert shmif bus traffic to a pcap file
@@ -13,12 +13,14 @@
 #include err.h
 #include fcntl.h
 #include pcap.h
+#include stdbool.h
 #include stdio.h
 #include stdlib.h
 #include string.h
 #include unistd.h
 
 #include shmifvar.h
+#include shmif_busops.c
 
 static void
 usage(void)
@@ -28,16 +30,19 @@
 	exit(1);
 }
 
+#define BUFSIZE 64*1024
 int
 main(int argc, char *argv[])
 {
 	struct stat sb;
 	void *busmem;
 	const char *pcapfile = NULL;
-	uint8_t *curbus, *buslast;
+	uint32_t curbus, buslast;
 	struct shmif_mem *bmem;
 	int fd, pfd, i, ch;
 	uint32_t pktlen;
+	int bonus;
+	char *buf;
 
 	while ((ch = getopt(argc, argv, p:)) != -1) {
 		switch (ch) {
@@ -55,6 +60,10 @@
 	if (argc != 1)
 		usage();
 
+	buf = malloc(BUFSIZE);
+	if (buf == NULL)
+		err(1, malloc);
+
 	fd = open(argv[0], O_RDONLY);
 	if (fd == -1)
 		err(1, open bus);
@@ -72,13 +81,10 @@
 	if (bmem-shm_version != SHMIF_VERSION)
 		errx(1, bus vesrsion %d, program %d,
 		bmem-shm_version, SHMIF_VERSION);
-	printf(bus version %d, lock: %d, generation: %d, lastoff: 0x%x\n,
-	bmem-shm_version, bmem-shm_lock, bmem-shm_gen, bmem-shm_last);
-
-	if (bmem-shm_gen != 0) {
-		printf(this dumper can manage only generation 0, sorry\n);
-		exit(0);
-	}
+	printf(bus version %d, lock: %d, generation: % PRIu64
+	, firstoff: 0x%04x, lastoff: 0x%04x\n,
+	bmem-shm_version, bmem-shm_lock, bmem-shm_gen,
+	bmem-shm_first, bmem-shm_last);
 
 	if (pcapfile) {
 		struct pcap_file_header phdr;
@@ -102,25 +108,41 @@
 			err(1, phdr write);
 	}
 	
-	curbus = bmem-shm_data;
-	buslast = bmem-shm_data + bmem-shm_last;
+	curbus = bmem-shm_first;
+	buslast = bmem-shm_last;
+	if (curbus == BUSMEM_DATASIZE)
+		curbus = 0;
+
+	bonus = 0;
+	if (buslast  curbus)
+		bonus = 1;
+
 	assert(sizeof(pktlen) == PKTLEN_SIZE);
 
 	i = 0;
-	while (curbus = buslast) {
+	while (curbus = buslast || bonus) {
 		struct pcap_pkthdr packhdr;
+		uint32_t oldoff;
+		bool wrap;
 
-		pktlen = *(uint32_t *)curbus;
-		curbus += sizeof(pktlen);
+		wrap = false;
+		oldoff = curbus;
+		curbus = shmif_busread(bmem,
+		pktlen, oldoff, PKTLEN_SIZE, wrap);
+		if (wrap)
+			bonus = 0;
 
 		if (pktlen == 0)
 			continue;
 
-		printf(packet %d, offset 0x%x, length 0x%x\n,
-		i++, curbus - bmem-shm_data, pktlen);
+		printf(packet %d, offset 0x%04x, length 0x%04x\n,
+		i++, curbus, pktlen);
 
 		if (!pcapfile || pktlen == 0) {
-			curbus += pktlen;
+			curbus = shmif_busread(bmem,
+			buf, curbus, pktlen, wrap);
+			if (wrap)
+bonus = 0;
 			continue;
 		}
 
@@ -129,9 +151,11 @@
 
 		if (write(pfd, packhdr, sizeof(packhdr)) != sizeof(packhdr))
 			err(1, error writing packethdr);
-		if (write(pfd, curbus, pktlen) != pktlen)
+		curbus = shmif_busread(bmem, buf, curbus, pktlen, wrap);
+		if (write(pfd, buf, pktlen) != pktlen)
 			err(1, write packet);
-		curbus += pktlen;
+		if (wrap)
+			bonus = 0;
 	}
 
 	return 0;

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.18 src/sys/rump/net/lib/libshmif/if_shmem.c:1.19
--- 

CVS commit: src/sys/rump/net/lib/libshmif

2010-08-11 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Wed Aug 11 10:30:30 UTC 2010

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
Change bus header a little: reserve only 32bits for the lock and
use 32bit atomic ops to handle it.  Begin data from 0x10 instead
of 0x14.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.13 src/sys/rump/net/lib/libshmif/if_shmem.c:1.14
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.13	Tue Aug 10 18:17:12 2010
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Wed Aug 11 10:30:30 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.13 2010/08/10 18:17:12 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.14 2010/08/11 10:30:30 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.13 2010/08/10 18:17:12 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.14 2010/08/11 10:30:30 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -76,11 +76,11 @@
 	uint32_t sc_nextpacket;
 	uint32_t sc_prevgen;
 };
-#define IFMEM_LOCK		(0)
-#define IFMEM_GENERATION	(8)
-#define IFMEM_LASTPACKET	(12)
-#define IFMEM_WAKEUP		(16)
-#define IFMEM_DATA		(20)
+#define IFMEM_LOCK		(0x00)
+#define IFMEM_GENERATION	(0x04)
+#define IFMEM_LASTPACKET	(0x08)
+#define IFMEM_WAKEUP		(0x0c)
+#define IFMEM_DATA		(0x10)
 
 #define BUSCTRL_ATOFF(sc, off)	((uint32_t *)(sc-sc_busmem+(off)))
 
@@ -102,7 +102,7 @@
 lockbus(struct shmif_sc *sc)
 {
 
-	while (atomic_cas_uint((void *)sc-sc_busmem,
+	while (atomic_cas_32((uint32_t *)sc-sc_busmem,
 	LOCK_UNLOCKED, LOCK_LOCKED) == LOCK_LOCKED)
 		continue;
 	membar_enter();
@@ -114,7 +114,7 @@
 	unsigned int old;
 
 	membar_exit();
-	old = atomic_swap_uint((void *)sc-sc_busmem, LOCK_UNLOCKED);
+	old = atomic_swap_32((uint32_t *)sc-sc_busmem, LOCK_UNLOCKED);
 	KASSERT(old == LOCK_LOCKED);
 }
 



CVS commit: src/sys/rump/net/lib/libshmif

2010-08-11 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Wed Aug 11 12:10:39 UTC 2010

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
* remove some magic numbers from the code
* include bus version number in header just in case we want to examine
  bus traffic at some point in the future


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.14 src/sys/rump/net/lib/libshmif/if_shmem.c:1.15
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.14	Wed Aug 11 10:30:30 2010
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Wed Aug 11 12:10:39 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.14 2010/08/11 10:30:30 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.15 2010/08/11 12:10:39 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.14 2010/08/11 10:30:30 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.15 2010/08/11 12:10:39 pooka Exp $);
 
 #include sys/param.h
 #include sys/atomic.h
@@ -80,11 +80,16 @@
 #define IFMEM_GENERATION	(0x04)
 #define IFMEM_LASTPACKET	(0x08)
 #define IFMEM_WAKEUP		(0x0c)
+#define IFMEM_BUSVERSION	IFMEM_WAKEUP
 #define IFMEM_DATA		(0x10)
 
 #define BUSCTRL_ATOFF(sc, off)	((uint32_t *)(sc-sc_busmem+(off)))
 
 #define BUSMEM_SIZE (1024*1024) /* need write throttling? */
+#define PKTLEN_SIZE 4
+
+/* just in case ... */
+static const uint32_t busversion = 1;
 
 static void shmif_rcv(void *);
 
@@ -185,10 +190,10 @@
 {
 	uint32_t oldlen;
 
-	busread(sc, oldlen, oldoff, 4);
+	busread(sc, oldlen, oldoff, PKTLEN_SIZE);
 	KASSERT(oldlen  BUSMEM_SIZE - IFMEM_DATA);
 
-	return advance(oldoff, 4 + oldlen);
+	return advance(oldoff, PKTLEN_SIZE + oldlen);
 }
 
 int
@@ -202,7 +207,7 @@
 	int error;
 
 	randnum = arc4random();
-	memcpy(enaddr[2], randnum, 4);
+	memcpy(enaddr[2], randnum, sizeof(randnum));
 	mynum = atomic_inc_uint_nv(numif)-1;
 
 	sc = kmem_zalloc(sizeof(*sc), KM_SLEEP);
@@ -304,14 +309,14 @@
 		lastoff = *BUSCTRL_ATOFF(sc, IFMEM_LASTPACKET);
 
 		npktlenoff = nextpktoff(sc, lastoff);
-		dataoff = advance(npktlenoff, 4);
+		dataoff = advance(npktlenoff, PKTLEN_SIZE);
 
 		for (m = m0; m != NULL; m = m-m_next) {
 			pktsize += m-m_len;
 			dataoff = buswrite(sc, dataoff, mtod(m, void *),
 			m-m_len);
 		}
-		buswrite(sc, npktlenoff, pktsize, 4);
+		buswrite(sc, npktlenoff, pktsize, PKTLEN_SIZE);
 		*BUSCTRL_ATOFF(sc, IFMEM_LASTPACKET) = npktlenoff;
 		unlockbus(sc);
 
@@ -323,7 +328,8 @@
 	}
 	/* wakeup */
 	if (wrote)
-		rumpuser_pwrite(sc-sc_memfd, error, 4, IFMEM_WAKEUP, error);
+		rumpuser_pwrite(sc-sc_memfd,
+		busversion, sizeof(busversion), IFMEM_WAKEUP, error);
 }
 
 static void
@@ -376,8 +382,9 @@
 			continue;
 		}
 
-		busread(sc, pktlen, nextpkt, 4);
-		busread(sc, mtod(m, void *), advance(nextpkt, 4), pktlen);
+		busread(sc, pktlen, nextpkt, PKTLEN_SIZE);
+		busread(sc, mtod(m, void *),
+		advance(nextpkt, PKTLEN_SIZE), pktlen);
 
 		DPRINTF((shmif_rcv: read packet of length %d at %d\n,
 		pktlen, nextpkt));



CVS commit: src/sys/rump/net/lib/libshmif

2010-08-11 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Wed Aug 11 12:41:09 UTC 2010

Added Files:
src/sys/rump/net/lib/libshmif: dumpbus.c

Log Message:
Add a little utility to convert shmif bus traffic to a pcap file
which can be then examined with tcpdump -r, wireshark, etc.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/sys/rump/net/lib/libshmif/dumpbus.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/sys/rump/net/lib/libshmif/dumpbus.c
diff -u /dev/null src/sys/rump/net/lib/libshmif/dumpbus.c:1.1
--- /dev/null	Wed Aug 11 12:41:09 2010
+++ src/sys/rump/net/lib/libshmif/dumpbus.c	Wed Aug 11 12:41:09 2010
@@ -0,0 +1,133 @@
+/*	$NetBSD: dumpbus.c,v 1.1 2010/08/11 12:41:09 pooka Exp $	*/
+
+/*
+ * Little utility to convert shmif bus traffic to a pcap file
+ * which can be then examined with tcpdump -r, wireshark, etc.
+ */
+
+#include sys/types.h
+#include sys/mman.h
+#include sys/stat.h
+
+#include err.h
+#include fcntl.h
+#include pcap.h
+#include stdio.h
+#include unistd.h
+
+/* XXX: sync with driver */
+struct bushdr {
+	uint32_t lock;
+	uint32_t gen;
+	uint32_t last;
+	uint32_t version;
+};
+
+static void
+usage(void)
+{
+
+	fprintf(stderr, usage: a.out [-p pcapfile] buspath\n);
+	exit(1);
+}
+
+int
+main(int argc, char *argv[])
+{
+	struct stat sb;
+	void *busmem;
+	const char *pcapfile = NULL;
+	uint8_t *curbus, *buslast;
+	struct bushdr *bhdr;
+	int fd, pfd, i, ch;
+
+	while ((ch = getopt(argc, argv, p:)) != -1) {
+		switch (ch) {
+		case 'p':
+			pcapfile = optarg;
+			break;
+		default:
+			usage();
+		}
+	}
+
+	argc -= optind;
+	argv += optind;
+
+	if (argc != 1)
+		usage();
+
+	fd = open(argv[0], O_RDONLY);
+	if (fd == -1)
+		err(1, open bus);
+
+	if (fstat(fd, sb) == -1)
+		err(1, stat);
+
+	busmem = mmap(NULL, sb.st_size, PROT_READ, MAP_FILE, fd, 0);
+	if (busmem == MAP_FAILED)
+		err(1, mmap);
+
+	bhdr = busmem;
+	if (bhdr-version != 1)
+		errx(1, cannot handle bus version %d, bhdr-version);
+	printf(bus version %d, lock: %d, generation: %d, lastoff: 0x%x\n,
+	bhdr-version, bhdr-lock, bhdr-gen, bhdr-last);
+
+	if (bhdr-gen != 0) {
+		printf(this dumper can manage only generation 0, sorry\n);
+		exit(0);
+	}
+
+	if (pcapfile) {
+		struct pcap_file_header phdr;
+
+		pfd = open(pcapfile, O_RDWR | O_CREAT, 0777);
+		if (pfd == -1)
+			err(1, create pcap dump);
+
+		memset(phdr, 0, sizeof(phdr));
+		phdr.magic = 0xa1b2c3d4; /* tcpdump magic */
+		phdr.version_major = PCAP_VERSION_MAJOR;
+		phdr.version_minor = PCAP_VERSION_MINOR;
+		phdr.snaplen = 1518;
+		phdr.linktype = DLT_EN10MB;
+
+		if (write(pfd, phdr, sizeof(phdr)) != sizeof(phdr))
+			err(1, phdr write);
+	}
+	
+	curbus = busmem;
+	buslast = curbus + bhdr-last;
+	curbus += sizeof(*bhdr);
+
+	i = 0;
+	while (curbus = buslast) {
+		uint32_t pktlen;
+		struct pcap_pkthdr packhdr;
+
+		pktlen = *(uint32_t *)curbus;
+		curbus += sizeof(pktlen);
+
+		/* quirk */
+		if (pktlen == 0)
+			continue;
+
+		printf(packet %d, offset 0x%x, length 0x%x\n,
+		i++, curbus - (uint8_t *)(bhdr + 1), pktlen);
+
+		if (!pcapfile || pktlen == 0) {
+			curbus += pktlen;
+			continue;
+		}
+
+		memset(packhdr, 0, sizeof(packhdr));
+		packhdr.caplen = packhdr.len = pktlen;
+
+		if (write(pfd, packhdr, sizeof(packhdr)) != sizeof(packhdr))
+			err(1, error writing packethdr);
+		if (write(pfd, curbus, pktlen) != pktlen)
+			err(1, write packet);
+		curbus += pktlen;
+	}
+}



CVS commit: src/sys/rump/net/lib/libshmif

2010-08-10 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Tue Aug 10 18:17:12 UTC 2010

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
* use atomic ops instead of __cpu_simple_luck
* this interface is un-IFF_SIMPLEX


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.12 src/sys/rump/net/lib/libshmif/if_shmem.c:1.13
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.12	Thu Jul 29 22:48:11 2010
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Tue Aug 10 18:17:12 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.12 2010/07/29 22:48:11 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.13 2010/08/10 18:17:12 pooka Exp $	*/
 
 /*
  * Copyright (c) 2009 Antti Kantee.  All Rights Reserved.
@@ -28,9 +28,10 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.12 2010/07/29 22:48:11 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.13 2010/08/10 18:17:12 pooka Exp $);
 
 #include sys/param.h
+#include sys/atomic.h
 #include sys/fcntl.h
 #include sys/kmem.h
 #include sys/kthread.h
@@ -89,6 +90,9 @@
 
 static uint32_t numif;
 
+#define LOCK_UNLOCKED	0
+#define LOCK_LOCKED	1
+
 /*
  * This locking needs work and will misbehave severely if:
  * 1) the backing memory has to be paged in
@@ -98,14 +102,20 @@
 lockbus(struct shmif_sc *sc)
 {
 
-	__cpu_simple_lock((__cpu_simple_lock_t *)sc-sc_busmem);
+	while (atomic_cas_uint((void *)sc-sc_busmem,
+	LOCK_UNLOCKED, LOCK_LOCKED) == LOCK_LOCKED)
+		continue;
+	membar_enter();
 }
 
 static void
 unlockbus(struct shmif_sc *sc)
 {
+	unsigned int old;
 
-	__cpu_simple_unlock((__cpu_simple_lock_t *)sc-sc_busmem);
+	membar_exit();
+	old = atomic_swap_uint((void *)sc-sc_busmem, LOCK_UNLOCKED);
+	KASSERT(old == LOCK_LOCKED);
 }
 
 static uint32_t
@@ -221,7 +231,7 @@
 
 	sprintf(ifp-if_xname, shmif%d, mynum);
 	ifp-if_softc = sc;
-	ifp-if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
+	ifp-if_flags = IFF_BROADCAST | IFF_MULTICAST;
 	ifp-if_init = shmif_init;
 	ifp-if_ioctl = shmif_ioctl;
 	ifp-if_start = shmif_start;



CVS commit: src/sys/rump/net/lib/libshmif

2010-07-29 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Thu Jul 29 22:48:11 UTC 2010

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
* print interface number, backend path and ethernet address for dmesg
* make kassert more demanding


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.11 src/sys/rump/net/lib/libshmif/if_shmem.c:1.12
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.11	Thu Jul 29 18:30:39 2010
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Thu Jul 29 22:48:11 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.11 2010/07/29 18:30:39 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.12 2010/07/29 22:48:11 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.11 2010/07/29 18:30:39 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.12 2010/07/29 22:48:11 pooka Exp $);
 
 #include sys/param.h
 #include sys/fcntl.h
@@ -135,7 +135,8 @@
 {
 	size_t chunk;
 
-	KASSERT(len  (BUSMEM_SIZE - IFMEM_DATA)  off = BUSMEM_SIZE);
+	KASSERT(len  (BUSMEM_SIZE - IFMEM_DATA)  off = BUSMEM_SIZE
+	 off = IFMEM_DATA);
 
 	chunk = MIN(len, BUSMEM_SIZE - off);
 	memcpy(sc-sc_busmem + off, data, chunk);
@@ -230,6 +231,10 @@
 	if_attach(ifp);
 	ether_ifattach(ifp, enaddr);
 
+	aprint_verbose(shmif%d: bus %s\n, mynum, path);
+	aprint_verbose(shmif%d: Ethernet address %s\n,
+	mynum, ether_sprintf(enaddr));
+
 	if (ifnum)
 		*ifnum = mynum;
 	return 0;



CVS commit: src/sys/rump/net/lib/libshmif

2009-11-30 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Mon Nov 30 11:14:58 UTC 2009

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
fix comment


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.9 src/sys/rump/net/lib/libshmif/if_shmem.c:1.10
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.9	Tue Oct 20 23:29:57 2009
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Mon Nov 30 11:14:58 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.9 2009/10/20 23:29:57 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.10 2009/11/30 11:14:58 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.9 2009/10/20 23:29:57 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.10 2009/11/30 11:14:58 pooka Exp $);
 
 #include sys/param.h
 #include sys/fcntl.h
@@ -373,7 +373,7 @@
 		m-m_len = m-m_pkthdr.len = pktlen;
 		m-m_pkthdr.rcvif = ifp;
 
-		/* if it's to us, don't pass up and reuse storage space */
+		/* if it's from us, don't pass up and reuse storage space */
 		eth = mtod(m, struct ether_header *);
 		if (memcmp(eth-ether_shost, sc-sc_myaddr, 6) != 0) {
 			ifp-if_input(ifp, m);



CVS commit: src/sys/rump/net/lib/libshmif

2009-10-20 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Tue Oct 20 23:21:54 UTC 2009

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
printf - rumpuser_dprintf
(can't use printf while holding spinlock)


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.7 src/sys/rump/net/lib/libshmif/if_shmem.c:1.8
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.7	Tue May 26 19:03:05 2009
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Tue Oct 20 23:21:53 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.7 2009/05/26 19:03:05 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.8 2009/10/20 23:21:53 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.7 2009/05/26 19:03:05 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.8 2009/10/20 23:21:53 pooka Exp $);
 
 #include sys/param.h
 #include sys/fcntl.h
@@ -49,7 +49,7 @@
 #include rump_private.h
 
 #if 0
-#define DPRINTF(x) printf x
+#define DPRINTF(x) rumpuser_dprintf x
 #else
 #define DPRINTF(x)
 #endif
@@ -346,7 +346,7 @@
 		|| (busgen  sc-sc_prevgen+1)) {
 			nextpkt = lastpkt;
 			sc-sc_prevgen = busgen;
-			printf(DROPPING\n);
+			rumpuser_dprintf(DROPPING\n);
 		} else {
 			nextpkt = sc-sc_nextpacket;
 		}



CVS commit: src/sys/rump/net/lib/libshmif

2009-10-20 Thread Antti Kantee
Module Name:src
Committed By:   pooka
Date:   Tue Oct 20 23:29:57 UTC 2009

Modified Files:
src/sys/rump/net/lib/libshmif: if_shmem.c

Log Message:
use autogenerated prototype


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/rump/net/lib/libshmif/if_shmem.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/rump/net/lib/libshmif/if_shmem.c
diff -u src/sys/rump/net/lib/libshmif/if_shmem.c:1.8 src/sys/rump/net/lib/libshmif/if_shmem.c:1.9
--- src/sys/rump/net/lib/libshmif/if_shmem.c:1.8	Tue Oct 20 23:21:53 2009
+++ src/sys/rump/net/lib/libshmif/if_shmem.c	Tue Oct 20 23:29:57 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_shmem.c,v 1.8 2009/10/20 23:21:53 pooka Exp $	*/
+/*	$NetBSD: if_shmem.c,v 1.9 2009/10/20 23:29:57 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.8 2009/10/20 23:21:53 pooka Exp $);
+__KERNEL_RCSID(0, $NetBSD: if_shmem.c,v 1.9 2009/10/20 23:29:57 pooka Exp $);
 
 #include sys/param.h
 #include sys/fcntl.h
@@ -47,6 +47,7 @@
 #include rump/rumpuser.h
 
 #include rump_private.h
+#include rump_net_private.h
 
 #if 0
 #define DPRINTF(x) rumpuser_dprintf x
@@ -179,8 +180,6 @@
 	return advance(oldoff, 4 + oldlen);
 }
 
-int rump_shmif_create(const char *, int *); /* XXX */
-
 int
 rump_shmif_create(const char *path, int *ifnum)
 {