netisr: Add priority for netisr "rollup" functions
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Tue, 18 Dec 2012 13:47:39 +0000 (21:47 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Tue, 18 Dec 2012 13:47:39 +0000 (21:47 +0800)
Higher priority "rollup" will be run first.  This mechanism auguments
the original "rollup" functionality which now could be used to implement
things like transmission packets aggregation and software TCP LRO.

sys/net/if.c
sys/net/netisr.c
sys/net/netisr.h
sys/netinet/tcp_subr.c

index b0f880c..d29571e 100644 (file)
@@ -2656,6 +2656,14 @@ ifnet_service_loop(void *arg __unused)
        }
 }
 
+#ifdef notyet
+static void
+if_start_rollup(void)
+{
+       /* TODO */
+}
+#endif
+
 static void
 ifnetinit(void *dummy __unused)
 {
@@ -2670,6 +2678,9 @@ ifnetinit(void *dummy __unused)
                netmsg_service_port_init(&thr->td_msgport);
                lwkt_schedule(thr);
        }
+#ifdef notyet
+       netisr_register_rollup(if_start_rollup, NETISR_ROLLUP_PRIO_IFSTART);
+#endif
 }
 
 struct ifnet *
index a2c5b9b..0d9a9bf 100644 (file)
@@ -69,6 +69,7 @@ struct netmsg_port_registration {
 struct netmsg_rollup {
        TAILQ_ENTRY(netmsg_rollup) ru_entry;
        netisr_ru_t     ru_func;
+       int             ru_prio;
 };
 
 struct netmsg_barrier {
@@ -503,13 +504,24 @@ netisr_register_hashcheck(int num, netisr_hashck_t hashck)
 }
 
 void
-netisr_register_rollup(netisr_ru_t ru_func)
+netisr_register_rollup(netisr_ru_t ru_func, int prio)
 {
-       struct netmsg_rollup *ru;
+       struct netmsg_rollup *new_ru, *ru;
+
+       new_ru = kmalloc(sizeof(*new_ru), M_TEMP, M_WAITOK|M_ZERO);
+       new_ru->ru_func = ru_func;
+       new_ru->ru_prio = prio;
 
-       ru = kmalloc(sizeof(*ru), M_TEMP, M_WAITOK|M_ZERO);
-       ru->ru_func = ru_func;
-       TAILQ_INSERT_TAIL(&netrulist, ru, ru_entry);
+       /*
+        * Higher priority "rollup" appears first
+        */
+       TAILQ_FOREACH(ru, &netrulist, ru_entry) {
+               if (ru->ru_prio < new_ru->ru_prio) {
+                       TAILQ_INSERT_BEFORE(ru, new_ru, ru_entry);
+                       return;
+               }
+       }
+       TAILQ_INSERT_TAIL(&netrulist, new_ru, ru_entry);
 }
 
 /*
index 52aa968..2e1584b 100644 (file)
@@ -159,6 +159,9 @@ struct netisr {
 #define NETMSG_SERVICE_ADAPTIVE        1
 #define NETMSG_SERVICE_MPSAFE  2
 
+#define NETISR_ROLLUP_PRIO_TCP         200
+#define NETISR_ROLLUP_PRIO_IFSTART     50
+
 extern lwkt_port netisr_adone_rport;
 extern lwkt_port netisr_afree_rport;
 extern lwkt_port netisr_afree_free_so_rport;
@@ -170,7 +173,7 @@ lwkt_port_t cur_netport(void);
 
 void           netisr_register(int, netisr_fn_t, netisr_cpufn_t);
 void           netisr_register_hashcheck(int, netisr_hashck_t);
-void           netisr_register_rollup(netisr_ru_t ru_func);
+void           netisr_register_rollup(netisr_ru_t ru_func, int ru_prio);
 
 void           netisr_characterize(int num, struct mbuf **mp, int hoff);
 void           netisr_hashcheck(int num, struct mbuf *m,
index fdfff6b..7c04e5e 100644 (file)
@@ -411,7 +411,7 @@ tcp_init(void)
        }
 
        syncache_init();
-       netisr_register_rollup(tcp_willblock);
+       netisr_register_rollup(tcp_willblock, NETISR_ROLLUP_PRIO_TCP);
 }
 
 static void