Source-Changes-HG archive

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

[src/trunk]: src/sys - Implement pktqueue interface for lockless IP input queue.



details:   https://anonhg.NetBSD.org/src/rev/cb7a6c9d8ab4
branches:  trunk
changeset: 329729:cb7a6c9d8ab4
user:      rmind <rmind%NetBSD.org@localhost>
date:      Thu Jun 05 23:48:16 2014 +0000

description:
- Implement pktqueue interface for lockless IP input queue.
- Replace ipintrq and ip6intrq with the pktqueue mechanism.
- Eliminate kernel-lock from ipintr() and ip6intr().
- Some preparation work to push softnet_lock out of ipintr().

Discussed on tech-net.

diffstat:

 sys/conf/files                                    |    3 +-
 sys/dev/ic/hd64570.c                              |   22 +-
 sys/dev/pci/if_lmc.c                              |   51 +--
 sys/dev/ppbus/if_plip.c                           |   19 +-
 sys/dev/qbus/if_dmc.c                             |   16 +-
 sys/dev/usb/if_upl.c                              |   27 +-
 sys/dev/usb/uhso.c                                |   15 +-
 sys/dist/pf/net/pf.c                              |   22 +-
 sys/dist/pf/net/pfvar.h                           |    4 +-
 sys/external/bsd/ipf/netinet/ip_fil_netbsd.c      |   13 +-
 sys/net/if.c                                      |  107 +++++--
 sys/net/if_arcsubr.c                              |   21 +-
 sys/net/if_atmsubr.c                              |   42 +-
 sys/net/if_ecosubr.c                              |   15 +-
 sys/net/if_ethersubr.c                            |   26 +-
 sys/net/if_faith.c                                |   38 +-
 sys/net/if_fddisubr.c                             |   30 +-
 sys/net/if_gif.c                                  |   40 +-
 sys/net/if_gre.c                                  |   22 +-
 sys/net/if_hippisubr.c                            |   31 +-
 sys/net/if_ieee1394subr.c                         |   18 +-
 sys/net/if_loop.c                                 |   63 +++-
 sys/net/if_mpls.c                                 |   32 +-
 sys/net/if_ppp.c                                  |   30 +-
 sys/net/if_sl.c                                   |   10 +-
 sys/net/if_spppsubr.c                             |   26 +-
 sys/net/if_stf.c                                  |   24 +-
 sys/net/if_strip.c                                |   10 +-
 sys/net/if_tokensubr.c                            |   17 +-
 sys/net/if_tun.c                                  |   22 +-
 sys/net/netisr_dispatch.h                         |    6 +-
 sys/net/pktqueue.c                                |  301 ++++++++++++++++++++++
 sys/net/pktqueue.h                                |   56 ++++
 sys/netinet/in.h                                  |    4 +-
 sys/netinet/in_proto.c                            |   10 +-
 sys/netinet/in_var.h                              |    8 +-
 sys/netinet/ip_input.c                            |  162 ++++++----
 sys/netinet/ip_mroute.c                           |   22 +-
 sys/netinet/ip_var.h                              |    3 +-
 sys/netinet6/in6.h                                |    4 +-
 sys/netinet6/in6_proto.c                          |    6 +-
 sys/netinet6/in6_var.h                            |    8 +-
 sys/netinet6/ip6_input.c                          |   40 +-
 sys/netinet6/ip6_var.h                            |    3 +-
 sys/netipsec/xform_ipip.c                         |   22 +-
 sys/netisdn/i4b_ipr.c                             |   15 +-
 sys/rump/librump/rumpnet/Makefile.rumpnet         |    5 +-
 sys/rump/librump/rumpnet/netisr.c                 |    9 +-
 sys/rump/net/lib/libnetinet/netinet_component.c   |    5 +-
 sys/rump/net/lib/libnetinet6/netinet6_component.c |    6 +-
 50 files changed, 960 insertions(+), 551 deletions(-)

diffs (truncated from 3477 to 300 lines):

diff -r 8354203a533d -r cb7a6c9d8ab4 sys/conf/files
--- a/sys/conf/files    Thu Jun 05 23:43:04 2014 +0000
+++ b/sys/conf/files    Thu Jun 05 23:48:16 2014 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files,v 1.1091 2014/05/19 22:47:54 rmind Exp $
+#      $NetBSD: files,v 1.1092 2014/06/05 23:48:16 rmind Exp $
 #      @(#)files.newconf       7.5 (Berkeley) 5/10/93
 
 version        20100430
@@ -1728,6 +1728,7 @@
 file   net/pfil.c
 file   net/ppp-deflate.c               ppp & ppp_deflate
 file   net/ppp_tty.c                   ppp
+file   net/pktqueue.c
 file   net/net_stats.c
 file   net/radix.c
 file   net/raw_cb.c
diff -r 8354203a533d -r cb7a6c9d8ab4 sys/dev/ic/hd64570.c
--- a/sys/dev/ic/hd64570.c      Thu Jun 05 23:43:04 2014 +0000
+++ b/sys/dev/ic/hd64570.c      Thu Jun 05 23:48:16 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hd64570.c,v 1.46 2014/05/15 09:23:52 msaitoh Exp $     */
+/*     $NetBSD: hd64570.c,v 1.47 2014/06/05 23:48:16 rmind Exp $       */
 
 /*
  * Copyright (c) 1999 Christian E. Hopps
@@ -65,7 +65,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: hd64570.c,v 1.46 2014/05/15 09:23:52 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hd64570.c,v 1.47 2014/06/05 23:48:16 rmind Exp $");
 
 #include "opt_inet.h"
 
@@ -1528,7 +1528,8 @@
 static void
 sca_frame_process(sca_port_t *scp)
 {
-       struct ifqueue *ifq;
+       pktqueue_t *pktq = NULL;
+       struct ifqueue *ifq = NULL;
        struct hdlc_header *hdlc;
        struct cisco_pkt *cisco;
        sca_desc_t *desc;
@@ -1587,8 +1588,7 @@
                m->m_pkthdr.len -= sizeof(struct hdlc_header);
                m->m_data += sizeof(struct hdlc_header);
                m->m_len -= sizeof(struct hdlc_header);
-               ifq = &ipintrq;
-               isr = NETISR_IP;
+               pktq = ip_pktq;
                break;
 #endif /* INET */
 #ifdef INET6
@@ -1598,8 +1598,7 @@
                m->m_pkthdr.len -= sizeof(struct hdlc_header);
                m->m_data += sizeof(struct hdlc_header);
                m->m_len -= sizeof(struct hdlc_header);
-               ifq = &ip6intrq;
-               isr = NETISR_IPV6;
+               pktq = ip6_pktq;
                break;
 #endif /* INET6 */
        case CISCO_KEEPALIVE:
@@ -1689,7 +1688,14 @@
                goto dropit;
        }
 
-       /* queue the packet */
+       /* Queue the packet */
+       if (__predict_true(pktq)) {
+               if (__predict_false(!pktq_enqueue(pktq, m, 0))) {
+                       scp->sp_if.if_iqdrops++;
+                       goto dropit;
+               }
+               return;
+       }
        if (!IF_QFULL(ifq)) {
                IF_ENQUEUE(ifq, m);
                schednetisr(isr);
diff -r 8354203a533d -r cb7a6c9d8ab4 sys/dev/pci/if_lmc.c
--- a/sys/dev/pci/if_lmc.c      Thu Jun 05 23:43:04 2014 +0000
+++ b/sys/dev/pci/if_lmc.c      Thu Jun 05 23:48:16 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_lmc.c,v 1.54 2014/03/29 19:28:25 christos Exp $ */
+/* $NetBSD: if_lmc.c,v 1.55 2014/06/05 23:48:16 rmind Exp $ */
 
 /*-
  * Copyright (c) 2002-2006 David Boggs. <boggs%boggs.palo-alto.ca.us@localhost>
@@ -74,7 +74,7 @@
  */
 
 # include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_lmc.c,v 1.54 2014/03/29 19:28:25 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_lmc.c,v 1.55 2014/06/05 23:48:16 rmind Exp $");
 # include <sys/param.h>        /* OS version */
 # include "opt_inet.h" /* INET6, INET */
 # include "opt_altq_enabled.h" /* ALTQ */
@@ -3319,53 +3319,34 @@
 ifnet_input(struct ifnet *ifp, struct mbuf *mbuf)
   {
   softc_t *sc = IFP2SC(ifp);
-  struct ifqueue *intrq;
-  int isr = 0;
-
-  intrq = NULL; /* surpress compiler warning */
+  pktqueue_t *pktq = NULL;
+
 # if INET
   if (mbuf->m_data[0]>>4 == 4)
-    {
-    isr = NETISR_IP;
-    intrq = &ipintrq;
-    }
+    pktq = ip_pktq;
 # endif /* INET */
 
 # if INET6
   if (mbuf->m_data[0]>>4 == 6)
-    {
-    isr = NETISR_IPV6;
-    intrq = &ip6intrq;
-    }
+    pktq = ip6_pktq;
 # endif /* INET6 */
 
-  if (isr)
-    {
-    if (!IF_QFULL(intrq))
-      {
-      /* ifnet_input() ENQUEUES in a hard interrupt. */
-      /* ip_input() DEQUEUES in a soft interrupt. */
-      /* Some BSD QUEUE routines are not interrupt-safe. */
-      DISABLE_INTR; /* noop in FreeBSD */
-      IF_ENQUEUE(intrq, mbuf);
-      ENABLE_INTR;  /* noop in FreeBSD */
-      schednetisr(isr); /* wake up the network code */
-      }
-    else /* intrq is full */
-      {
-      m_freem(mbuf);
-      sc->status.cntrs.idrops++;
-      if (sc->config.debug)
-        printf("%s: ifnet_input: rx pkt dropped: intrq full\n", NAME_UNIT);
-      }
-    }
-  else /* isr is zero */
+  if (!pktq)
     {
     m_freem(mbuf);
     sc->status.cntrs.idrops++;
     if (sc->config.debug)
       printf("%s: ifnet_input: rx pkt dropped: not IPv4 or IPv6\n", NAME_UNIT);
+    return;
     }
+
+  DISABLE_INTR;
+  if (__predict_false(!pktq_enqueue(pktq, mbuf, 0)))
+    {
+    sc->status.cntrs.idrops++;
+    m_freem(mbuf);
+    }
+  ENABLE_INTR;
   }
 
 /* sppp and p2p replace this with their own proc.
diff -r 8354203a533d -r cb7a6c9d8ab4 sys/dev/ppbus/if_plip.c
--- a/sys/dev/ppbus/if_plip.c   Thu Jun 05 23:43:04 2014 +0000
+++ b/sys/dev/ppbus/if_plip.c   Thu Jun 05 23:48:16 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: if_plip.c,v 1.24 2010/04/05 07:21:47 joerg Exp $ */
+/* $NetBSD: if_plip.c,v 1.25 2014/06/05 23:48:16 rmind Exp $ */
 
 /*-
  * Copyright (c) 1997 Poul-Henning Kamp
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_plip.c,v 1.24 2010/04/05 07:21:47 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_plip.c,v 1.25 2014/06/05 23:48:16 rmind Exp $");
 
 /*
  * Parallel port TCP/IP interfaces added.  I looked at the driver from
@@ -636,17 +636,18 @@
                top = m_devget(sc->sc_ifbuf + LPIPHDRLEN, len, 0, ifp, NULL);
        }
 
-       /* Do nothing if mbuf was not created or the queue is full */
-       if((top == NULL) || (IF_QFULL(&ipintrq))) {
-               IF_DROP(&ipintrq);
+       if (top == NULL) {
                ifp->if_iqdrops++;
-               LP_PRINTF("DROP");
                goto err;
        }
-       if(ifp->if_bpf)
+       if (ifp->if_bpf) {
                lptap(ifp, top);
-       IF_ENQUEUE(&ipintrq, top);
-       schednetisr(NETISR_IP);
+       }
+       if (__predict_false(!pktq_enqueue(ip_pktq, top, 0))) {
+               ifp->if_iqdrops++;
+               m_freem(top);
+               goto err;
+       }
        ifp->if_ipackets++;
        ifp->if_ibytes += len;
        sc->sc_iferrs = 0;
diff -r 8354203a533d -r cb7a6c9d8ab4 sys/dev/qbus/if_dmc.c
--- a/sys/dev/qbus/if_dmc.c     Thu Jun 05 23:43:04 2014 +0000
+++ b/sys/dev/qbus/if_dmc.c     Thu Jun 05 23:48:16 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_dmc.c,v 1.22 2014/05/15 09:23:52 msaitoh Exp $      */
+/*     $NetBSD: if_dmc.c,v 1.23 2014/06/05 23:48:16 rmind Exp $        */
 /*
  * Copyright (c) 1982, 1986 Regents of the University of California.
  * All rights reserved.
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_dmc.c,v 1.22 2014/05/15 09:23:52 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_dmc.c,v 1.23 2014/06/05 23:48:16 rmind Exp $");
 
 #undef DMCDEBUG        /* for base table dump on fatal error */
 
@@ -56,7 +56,6 @@
 #include <sys/device.h>
 
 #include <net/if.h>
-#include <net/netisr.h>
 
 #ifdef INET
 #include <netinet/in.h>
@@ -553,14 +552,12 @@
 
        struct ifnet *ifp;
        struct mbuf *m;
-       struct ifqueue *inq;
        int arg, pkaddr, cmd, len, s;
        struct ifrw *ifrw;
        struct dmcbufs *rp;
        struct ifxmt *ifxp;
        struct dmc_header *dh;
        char buf[64];
-       int isr = 0;
 
        ifp = &sc->sc_if;
 
@@ -625,11 +622,8 @@
                        /* Shave off dmc_header */
                        m_adj(m, sizeof(struct dmc_header));
                        switch (dh->dmc_type) {
-
 #ifdef INET
                        case DMC_IPTYPE:
-                               isr = NETISR_IP;
-                               inq = &ipintrq;
                                break;
 #endif
                        default:
@@ -638,12 +632,8 @@
                        }
 
                        s = splnet();
-                       if (IF_QFULL(inq)) {
-                               IF_DROP(inq);
+                       if (__predict_false(!pktq_enqueue(ip_pktq, m, 0))) {
                                m_freem(m);
-                       } else {
-                               IF_ENQUEUE(inq, m);
-                               schednetisr(isr);
                        }
                        splx(s);
 
diff -r 8354203a533d -r cb7a6c9d8ab4 sys/dev/usb/if_upl.c
--- a/sys/dev/usb/if_upl.c      Thu Jun 05 23:43:04 2014 +0000
+++ b/sys/dev/usb/if_upl.c      Thu Jun 05 23:48:16 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_upl.c,v 1.45 2014/05/15 09:23:52 msaitoh Exp $      */
+/*     $NetBSD: if_upl.c,v 1.46 2014/06/05 23:48:16 rmind Exp $        */
 /*
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_upl.c,v 1.45 2014/05/15 09:23:52 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_upl.c,v 1.46 2014/06/05 23:48:16 rmind Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1033,28 +1033,17 @@
 upl_input(struct ifnet *ifp, struct mbuf *m)
 {
 #ifdef INET



Home | Main Index | Thread Index | Old Index