Source-Changes-HG archive

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

[src/trunk]: src/sys/rump/net/lib/libshmif Include a timestamp in the frame h...



details:   https://anonhg.NetBSD.org/src/rev/b040bdf64e2a
branches:  trunk
changeset: 757069:b040bdf64e2a
user:      pooka <pooka%NetBSD.org@localhost>
date:      Fri Aug 13 10:13:44 2010 +0000

description:
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.

diffstat:

 sys/rump/net/lib/libshmif/dumpbus.c      |  27 +++++++++++++--------------
 sys/rump/net/lib/libshmif/if_shmem.c     |  27 +++++++++++++++++++--------
 sys/rump/net/lib/libshmif/shmif_busops.c |  14 +++++++-------
 sys/rump/net/lib/libshmif/shmifvar.h     |  12 +++++++++---
 4 files changed, 48 insertions(+), 32 deletions(-)

diffs (232 lines):

diff -r b9c7fa36ceb2 -r b040bdf64e2a sys/rump/net/lib/libshmif/dumpbus.c
--- a/sys/rump/net/lib/libshmif/dumpbus.c       Fri Aug 13 05:16:28 2010 +0000
+++ b/sys/rump/net/lib/libshmif/dumpbus.c       Fri Aug 13 10:13:44 2010 +0000
@@ -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;
diff -r b9c7fa36ceb2 -r b040bdf64e2a sys/rump/net/lib/libshmif/if_shmem.c
--- a/sys/rump/net/lib/libshmif/if_shmem.c      Fri Aug 13 05:16:28 2010 +0000
+++ b/sys/rump/net/lib/libshmif/if_shmem.c      Fri Aug 13 10:13:44 2010 +0000
@@ -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 *),
-                   shmif_advance(nextpkt, PKTLEN_SIZE), pktlen, &wrap);
+                   shmif_advance(nextpkt, sizeof(sp)), sp.sp_len, &wrap);
                if (wrap)
                        sc->sc_prevgen = sc->sc_busmem->shm_gen;
 
                DPRINTF(("shmif_rcv: read packet of length %d at %d\n",
-                   pktlen, nextpkt));
+                   sp.sp_len, nextpkt));
 
                sc->sc_nextpacket = shmif_nextpktoff(sc->sc_busmem, nextpkt);
                sc->sc_prevgen = busgen;
                shmif_unlockbus(sc->sc_busmem);
 
-               m->m_len = m->m_pkthdr.len = pktlen;
+               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 */
diff -r b9c7fa36ceb2 -r b040bdf64e2a sys/rump/net/lib/libshmif/shmif_busops.c
--- a/sys/rump/net/lib/libshmif/shmif_busops.c  Fri Aug 13 05:16:28 2010 +0000
+++ b/sys/rump/net/lib/libshmif/shmif_busops.c  Fri Aug 13 10:13:44 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: shmif_busops.c,v 1.1 2010/08/12 21:41:47 pooka Exp $   */
+/*     $NetBSD: shmif_busops.c,v 1.2 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: shmif_busops.c,v 1.1 2010/08/12 21:41:47 pooka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: shmif_busops.c,v 1.2 2010/08/13 10:13:44 pooka Exp $");
 
 #include <sys/param.h>
 #include <sys/atomic.h>
@@ -109,7 +109,7 @@
 shmif_advancefirst(struct shmif_mem *busmem, uint32_t off, size_t len)
 {
 
-       while (off <= busmem->shm_first + PKTLEN_SIZE
+       while (off <= busmem->shm_first + sizeof(struct shmif_pkthdr)
            && off+len > busmem->shm_first) {
                DPRINTF(("advancefirst: old offset %d, ", busmem->shm_first));
                busmem->shm_first = shmif_nextpktoff(busmem, busmem->shm_first);
@@ -155,11 +155,11 @@
 uint32_t
 shmif_nextpktoff(struct shmif_mem *busmem, uint32_t oldoff)
 {
-       uint32_t oldlen;
+       struct shmif_pkthdr sp;
        bool dummy;
 
-       shmif_busread(busmem, &oldlen, oldoff, PKTLEN_SIZE, &dummy);
-       KASSERT(oldlen < BUSMEM_DATASIZE);
+       shmif_busread(busmem, &sp, oldoff, sizeof(sp), &dummy);
+       KASSERT(sp.sp_len < BUSMEM_DATASIZE);
 
-       return shmif_advance(oldoff, PKTLEN_SIZE + oldlen);
+       return shmif_advance(oldoff, sizeof(sp) + sp.sp_len);
 }
diff -r b9c7fa36ceb2 -r b040bdf64e2a sys/rump/net/lib/libshmif/shmifvar.h
--- a/sys/rump/net/lib/libshmif/shmifvar.h      Fri Aug 13 05:16:28 2010 +0000
+++ b/sys/rump/net/lib/libshmif/shmifvar.h      Fri Aug 13 10:13:44 2010 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: shmifvar.h,v 1.3 2010/08/12 21:41:47 pooka Exp $       */
+/*     $NetBSD: shmifvar.h,v 1.4 2010/08/13 10:13:44 pooka Exp $       */
 
 /*-
  * Copyright (c) 2009 Antti Kantee.  All Rights Reserved.
@@ -31,7 +31,7 @@
 #define _RUMP_NET_SHMIFVAR_H_
 
 #define SHMIF_MAGIC 0xca11d054
-#define SHMIF_VERSION 1
+#define SHMIF_VERSION 2
 
 struct shmif_mem {
        uint32_t shm_magic;
@@ -50,7 +50,13 @@
 
 #define IFMEM_DATA     (offsetof(struct shmif_mem, shm_data))
 #define IFMEM_WAKEUP   (offsetof(struct shmif_mem, shm_version))
-#define PKTLEN_SIZE    (sizeof(uint32_t))
+
+struct shmif_pkthdr {
+       uint32_t sp_len;
+
+       uint32_t sp_sec;
+       uint32_t sp_usec;
+};
 
 #define BUSMEM_SIZE (1024*1024)
 #define BUSMEM_DATASIZE (BUSMEM_SIZE - sizeof(struct shmif_mem))



Home | Main Index | Thread Index | Old Index