Source-Changes-HG archive

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

[src/trunk]: src/sys/net Create if_slowtimo (if_watchdog) callout for each in...



details:   https://anonhg.NetBSD.org/src/rev/3738a537c3d9
branches:  trunk
changeset: 804151:3738a537c3d9
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Wed Nov 26 07:43:04 2014 +0000

description:
Create if_slowtimo (if_watchdog) callout for each interface

This change is to obviate the need to run if_slowtimo callbacks that
may sleep inside IFNET_FOREACH. And also by this change we can turn
on MPSAFE of callouts individually.

Discussed with uebayasi@ and riastradh@.

diffstat:

 sys/net/if.c |  39 ++++++++++++++++++++++-----------------
 sys/net/if.h |   6 +++++-
 2 files changed, 27 insertions(+), 18 deletions(-)

diffs (123 lines):

diff -r 0ea501985db1 -r 3738a537c3d9 sys/net/if.c
--- a/sys/net/if.c      Wed Nov 26 07:39:52 2014 +0000
+++ b/sys/net/if.c      Wed Nov 26 07:43:04 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.c,v 1.295 2014/11/26 07:22:05 ozaki-r Exp $ */
+/*     $NetBSD: if.c,v 1.296 2014/11/26 07:43:04 ozaki-r Exp $ */
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.295 2014/11/26 07:22:05 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.296 2014/11/26 07:43:04 ozaki-r Exp $");
 
 #include "opt_inet.h"
 
@@ -168,8 +168,6 @@
 
 static struct ifaddr **                ifnet_addrs = NULL;
 
-static callout_t               if_slowtimo_ch;
-
 struct ifnet *lo0ifp;
 int    ifqmaxlen = IFQ_MAXLEN;
 
@@ -236,9 +234,6 @@
        sysctl_net_pktq_setup(NULL, PF_INET6);
 #endif
 
-       callout_init(&if_slowtimo_ch, 0);
-       if_slowtimo(NULL);
-
        if_listener = kauth_listen_scope(KAUTH_SCOPE_NETWORK,
            if_listener_cb, NULL);
 
@@ -638,6 +633,12 @@
 
        /* Announce the interface. */
        rt_ifannouncemsg(ifp, IFAN_ARRIVAL);
+
+       if (ifp->if_slowtimo != NULL) {
+               callout_init(&ifp->if_slowtimo_ch, 0);
+               callout_setfunc(&ifp->if_slowtimo_ch, if_slowtimo, ifp);
+               if_slowtimo(ifp);
+       }
 }
 
 void
@@ -737,6 +738,11 @@
 
        s = splnet();
 
+       if (ifp->if_slowtimo != NULL) {
+               callout_halt(&ifp->if_slowtimo_ch, NULL);
+               callout_destroy(&ifp->if_slowtimo_ch);
+       }
+
        /*
         * Do an if_down() to give protocols a chance to do something.
         */
@@ -1494,24 +1500,23 @@
 }
 
 /*
- * Handle interface slowtimo timer routines.  Called
- * from softclock, we decrement timers (if set) and
+ * Handle interface slowtimo timer routine.  Called
+ * from softclock, we decrement timer (if set) and
  * call the appropriate interface routine on expiration.
  */
 static void
 if_slowtimo(void *arg)
 {
-       struct ifnet *ifp;
+       struct ifnet *ifp = arg;
        int s = splnet();
 
-       IFNET_FOREACH(ifp) {
-               if (ifp->if_timer == 0 || --ifp->if_timer)
-                       continue;
-               if (ifp->if_slowtimo != NULL)
-                       (*ifp->if_slowtimo)(ifp);
-       }
+       KASSERT(ifp->if_slowtimo != NULL);
+
+       if (ifp->if_timer != 0 && --ifp->if_timer == 0)
+               (*ifp->if_slowtimo)(ifp);
+
        splx(s);
-       callout_reset(&if_slowtimo_ch, hz / IFNET_SLOWHZ, if_slowtimo, NULL);
+       callout_schedule(&ifp->if_slowtimo_ch, hz / IFNET_SLOWHZ);
 }
 
 /*
diff -r 0ea501985db1 -r 3738a537c3d9 sys/net/if.h
--- a/sys/net/if.h      Wed Nov 26 07:39:52 2014 +0000
+++ b/sys/net/if.h      Wed Nov 26 07:43:04 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.h,v 1.177 2014/11/26 07:22:05 ozaki-r Exp $ */
+/*     $NetBSD: if.h,v 1.178 2014/11/26 07:43:04 ozaki-r Exp $ */
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -214,6 +214,7 @@
 #ifdef _KERNEL
 #include <sys/condvar.h>
 #include <sys/percpu.h>
+#include <sys/callout.h>
 
 struct ifnet_lock {
        kmutex_t il_lock;       /* Protects the critical section. */
@@ -342,6 +343,9 @@
            const struct sockaddr *);
        int (*if_setflags)(struct ifnet *, const short);
        struct ifnet_lock *if_ioctl_lock;
+#ifdef _KERNEL /* XXX kvm(3) */
+       callout_t if_slowtimo_ch;
+#endif
 } ifnet_t;
  
 #define        if_mtu          if_data.ifi_mtu



Home | Main Index | Thread Index | Old Index