Sat Aug 9 09:43:49 2014 UTC ()
Count packets in if_shmem

ok @pooka


(ozaki-r)
diff -r1.61 -r1.62 src/sys/rump/net/lib/libshmif/if_shmem.c

cvs diff -r1.61 -r1.62 src/sys/rump/net/lib/libshmif/if_shmem.c (expand / switch to unified diff)

--- src/sys/rump/net/lib/libshmif/if_shmem.c 2014/05/28 20:57:22 1.61
+++ src/sys/rump/net/lib/libshmif/if_shmem.c 2014/08/09 09:43:49 1.62
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: if_shmem.c,v 1.61 2014/05/28 20:57:22 justin Exp $ */ 1/* $NetBSD: if_shmem.c,v 1.62 2014/08/09 09:43:49 ozaki-r Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2009, 2010 Antti Kantee. All Rights Reserved. 4 * Copyright (c) 2009, 2010 Antti Kantee. All Rights Reserved.
5 * 5 *
6 * Development of this software was supported by The Nokia Foundation. 6 * Development of this software was supported by The Nokia Foundation.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -18,27 +18,27 @@ @@ -18,27 +18,27 @@
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE. 27 * SUCH DAMAGE.
28 */ 28 */
29 29
30#include <sys/cdefs.h> 30#include <sys/cdefs.h>
31__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.61 2014/05/28 20:57:22 justin Exp $"); 31__KERNEL_RCSID(0, "$NetBSD: if_shmem.c,v 1.62 2014/08/09 09:43:49 ozaki-r Exp $");
32 32
33#include <sys/param.h> 33#include <sys/param.h>
34#include <sys/atomic.h> 34#include <sys/atomic.h>
35#include <sys/fcntl.h> 35#include <sys/fcntl.h>
36#include <sys/kmem.h> 36#include <sys/kmem.h>
37#include <sys/kthread.h> 37#include <sys/kthread.h>
38#include <sys/lock.h> 38#include <sys/lock.h>
39#include <sys/vmem.h> 39#include <sys/vmem.h>
40#include <sys/cprng.h> 40#include <sys/cprng.h>
41 41
42#include <net/bpf.h> 42#include <net/bpf.h>
43#include <net/if.h> 43#include <net/if.h>
44#include <net/if_dl.h> 44#include <net/if_dl.h>
@@ -556,26 +556,27 @@ shmif_start(struct ifnet *ifp) @@ -556,26 +556,27 @@ shmif_start(struct ifnet *ifp)
556 dataoff = shmif_buswrite(busmem, dataoff, 556 dataoff = shmif_buswrite(busmem, dataoff,
557 mtod(m, void *), m->m_len, &wrap); 557 mtod(m, void *), m->m_len, &wrap);
558 } 558 }
559 KASSERT(pktwrote == pktsize); 559 KASSERT(pktwrote == pktsize);
560 if (wrap) { 560 if (wrap) {
561 busmem->shm_gen++; 561 busmem->shm_gen++;
562 DPRINTF(("bus generation now %" PRIu64 "\n", 562 DPRINTF(("bus generation now %" PRIu64 "\n",
563 busmem->shm_gen)); 563 busmem->shm_gen));
564 } 564 }
565 shmif_unlockbus(busmem); 565 shmif_unlockbus(busmem);
566 566
567 m_freem(m0); 567 m_freem(m0);
568 wrote = true; 568 wrote = true;
 569 ifp->if_opackets++;
569 570
570 DPRINTF(("shmif_start: send %d bytes at off %d\n", 571 DPRINTF(("shmif_start: send %d bytes at off %d\n",
571 pktsize, busmem->shm_last)); 572 pktsize, busmem->shm_last));
572 } 573 }
573 574
574 ifp->if_flags &= ~IFF_OACTIVE; 575 ifp->if_flags &= ~IFF_OACTIVE;
575 576
576 /* wakeup? */ 577 /* wakeup? */
577 if (wrote) { 578 if (wrote) {
578 dowakeup(sc); 579 dowakeup(sc);
579 } 580 }
580} 581}
581 582
@@ -745,26 +746,27 @@ shmif_rcv(void *arg) @@ -745,26 +746,27 @@ shmif_rcv(void *arg)
745 if (memcmp(eth->ether_dhost, CLLADDR(ifp->if_sadl), 746 if (memcmp(eth->ether_dhost, CLLADDR(ifp->if_sadl),
746 ETHER_ADDR_LEN) == 0) { 747 ETHER_ADDR_LEN) == 0) {
747 passup = true; 748 passup = true;
748 } else if (ETHER_IS_MULTICAST(eth->ether_dhost)) { 749 } else if (ETHER_IS_MULTICAST(eth->ether_dhost)) {
749 passup = true; 750 passup = true;
750 } else if (ifp->if_flags & IFF_PROMISC) { 751 } else if (ifp->if_flags & IFF_PROMISC) {
751 m->m_flags |= M_PROMISC; 752 m->m_flags |= M_PROMISC;
752 passup = true; 753 passup = true;
753 } else { 754 } else {
754 passup = false; 755 passup = false;
755 } 756 }
756 757
757 if (passup) { 758 if (passup) {
 759 ifp->if_ipackets++;
758 KERNEL_LOCK(1, NULL); 760 KERNEL_LOCK(1, NULL);
759 bpf_mtap(ifp, m); 761 bpf_mtap(ifp, m);
760 ifp->if_input(ifp, m); 762 ifp->if_input(ifp, m);
761 KERNEL_UNLOCK_ONE(NULL); 763 KERNEL_UNLOCK_ONE(NULL);
762 m = NULL; 764 m = NULL;
763 } 765 }
764 /* else: reuse mbuf for a future packet */ 766 /* else: reuse mbuf for a future packet */
765 } 767 }
766 m_freem(m); 768 m_freem(m);
767 m = NULL; 769 m = NULL;
768 770
769 if (!sc->sc_dying) 771 if (!sc->sc_dying)
770 goto reup; 772 goto reup;