PERFORCE change 178390 for review

Marko Zec zec at FreeBSD.org
Mon May 17 13:20:16 UTC 2010


http://p4web.freebsd.org/@@178390?ac=10

Change 178390 by zec at zec_nxlab on 2010/05/17 13:20:11

	Virtualize ip_mrouting timers.  The current code couldn't work
	properly because with each vnet it was stomping over same
	global callout handlers.
	
	Eventhandler for ifnet_departure_event must be registered and
	deregistered only once in modevent handler, not once for each
	vnet.

Affected files ...

.. //depot/projects/vimage/src/sys/netinet/ip_mroute.c#37 edit

Differences ...

==== //depot/projects/vimage/src/sys/netinet/ip_mroute.c#37 (text+ko) ====

@@ -191,7 +191,9 @@
 
 static eventhandler_tag if_detach_event_tag = NULL;
 
-static struct callout expire_upcalls_ch;
+static VNET_DEFINE(struct callout, expire_upcalls_ch);
+#define	V_expire_upcalls_ch	VNET(expire_upcalls_ch)
+
 #define		EXPIRE_TIMEOUT	(hz / 4)	/* 4x / second		*/
 #define		UPCALL_EXPIRE	6		/* number of timeouts	*/
 
@@ -206,7 +208,8 @@
 #define	BW_METER_BUCKETS	1024
 static VNET_DEFINE(struct bw_meter*, bw_meter_timers[BW_METER_BUCKETS]);
 #define	V_bw_meter_timers	VNET(bw_meter_timers)
-static struct callout bw_meter_ch;
+static VNET_DEFINE(struct callout, bw_meter_ch);
+#define	V_bw_meter_ch		VNET(bw_meter_ch)
 #define	BW_METER_PERIOD (hz)		/* periodical handling of bw meters */
 
 /*
@@ -217,7 +220,9 @@
 #define	V_bw_upcalls		VNET(bw_upcalls)
 static VNET_DEFINE(u_int, bw_upcalls_n); /* # of pending upcalls */
 #define	V_bw_upcalls_n    	VNET(bw_upcalls_n)
-static struct callout bw_upcalls_ch;
+static VNET_DEFINE(struct callout, bw_upcalls_ch);
+#define	V_bw_upcalls_ch		VNET(bw_upcalls_ch)
+
 #define BW_UPCALLS_PERIOD (hz)		/* periodical flush of bw upcalls */
 
 static VNET_DEFINE(struct pimstat, pimstat);
@@ -605,12 +610,12 @@
     pim_assert_enabled = 0;
     mrt_api_config = 0;
 
-    callout_init(&expire_upcalls_ch, CALLOUT_MPSAFE);
+    callout_init(&V_expire_upcalls_ch, CALLOUT_MPSAFE);
 
     V_bw_upcalls_n = 0;
-    bzero((caddr_t)V_bw_meter_timers, sizeof(V_bw_meter_timers));
-    callout_init(&bw_upcalls_ch, CALLOUT_MPSAFE);
-    callout_init(&bw_meter_ch, CALLOUT_MPSAFE);
+    bzero(V_bw_meter_timers, sizeof(V_bw_meter_timers));
+    callout_init(&V_bw_upcalls_ch, CALLOUT_MPSAFE);
+    callout_init(&V_bw_meter_ch, CALLOUT_MPSAFE);
 }
 
 static void
@@ -686,20 +691,14 @@
 	return EADDRINUSE;
     }
 
-    if_detach_event_tag = EVENTHANDLER_REGISTER(ifnet_departure_event, 
-        if_detached_event, NULL, EVENTHANDLER_PRI_ANY);
-    if (if_detach_event_tag == NULL) {
-	MROUTER_UNLOCK();
-	return (ENOMEM);
-    }
-
     V_mfchashtbl = hashinit_flags(mfchashsize, M_MRTABLE, &V_mfchash, HASH_NOWAIT);
 
-    callout_reset(&expire_upcalls_ch, EXPIRE_TIMEOUT, expire_upcalls, curvnet);
-
-    callout_reset(&bw_upcalls_ch, BW_UPCALLS_PERIOD,
-	expire_bw_upcalls_send, curvnet);
-    callout_reset(&bw_meter_ch, BW_METER_PERIOD, expire_bw_meter_process, curvnet);
+    callout_reset(&V_expire_upcalls_ch, EXPIRE_TIMEOUT, expire_upcalls,
+	curvnet);
+    callout_reset(&V_bw_upcalls_ch, BW_UPCALLS_PERIOD, expire_bw_upcalls_send,
+	curvnet);
+    callout_reset(&V_bw_meter_ch, BW_METER_PERIOD, expire_bw_meter_process,
+	curvnet);
 
     V_ip_mrouter = so;
     ip_mrouter_cnt++;
@@ -760,8 +759,6 @@
 
     VIF_UNLOCK();
 
-    EVENTHANDLER_DEREGISTER(ifnet_departure_event, if_detach_event_tag);
-
     callout_stop(&V_expire_upcalls_ch);
     callout_stop(&V_bw_upcalls_ch);
     callout_stop(&V_bw_meter_ch);
@@ -1496,7 +1493,8 @@
 
     MFC_UNLOCK();
 
-    callout_reset(&expire_upcalls_ch, EXPIRE_TIMEOUT, expire_upcalls, curvnet);
+    callout_reset(&V_expire_upcalls_ch, EXPIRE_TIMEOUT, expire_upcalls,
+	curvnet);
 
     CURVNET_RESTORE();
 }
@@ -2308,8 +2306,8 @@
     bw_upcalls_send();
     MFC_UNLOCK();
 
-    callout_reset(&bw_upcalls_ch, BW_UPCALLS_PERIOD,
-	expire_bw_upcalls_send, curvnet);
+    callout_reset(&V_bw_upcalls_ch, BW_UPCALLS_PERIOD, expire_bw_upcalls_send,
+	curvnet);
     CURVNET_RESTORE();
 }
 
@@ -2325,7 +2323,8 @@
     if (mrt_api_config & MRT_MFC_BW_UPCALL)
 	bw_meter_process();
 
-    callout_reset(&bw_meter_ch, BW_METER_PERIOD, expire_bw_meter_process, curvnet);
+    callout_reset(&V_bw_meter_ch, BW_METER_PERIOD, expire_bw_meter_process,
+	curvnet);
     CURVNET_RESTORE();
 }
 
@@ -2852,6 +2851,15 @@
     switch (type) {
     case MOD_LOAD:
 	MROUTER_LOCK_INIT();
+
+	if_detach_event_tag = EVENTHANDLER_REGISTER(ifnet_departure_event, 
+	    if_detached_event, NULL, EVENTHANDLER_PRI_ANY);
+	if (if_detach_event_tag == NULL) {
+		printf("ip_mroute: unable to ifnet_deperture_even handler\n");
+		MROUTER_LOCK_DESTROY();
+		return (EINVAL);
+	}
+
 	MFC_LOCK_INIT();
 	VIF_LOCK_INIT();
 
@@ -2909,6 +2917,8 @@
 	ip_mrouter_unloading = 1;
 	MROUTER_UNLOCK();
 
+	EVENTHANDLER_DEREGISTER(ifnet_departure_event, if_detach_event_tag);
+
 	if (pim_encap_cookie) {
 	    encap_detach(pim_encap_cookie);
 	    pim_encap_cookie = NULL;


More information about the p4-projects mailing list