reads fine, and works for me in light testing.
OK phessler@
On 2017 Oct 30 (Mon) at 08:36:34 +0100 (+0100), Alexandr Nedvedicky wrote:
:Hello,
:
:patch below adds additional softnet taskq. This will allow certain degree of
:parallelism for packet processing in pf_test(). The current plan is to let
:packets received by even NICs (even ifindex) to be processed by task0, packets
:received by odd NICs (odd ifindex) by task1.
:
:big thanks should go to mpi@, who 'programmed' me to program the patch below.
:
:OK?
:
:thanks and
:regards
:sasha
:
:8<---8<---8<--8<
:diff --git a/sys/net/if.c b/sys/net/if.c
:index e9e9f07add1..d688456b677 100644
:--- a/sys/net/if.c
:+++ b/sys/net/if.c
:@@ -224,7 +224,9 @@ intnet_livelocked(void);
: int ifq_congestion;
:
: intnetisr;
:-struct taskq *softnettq;
:+
:+#define SOFTNET_TASKS 2
:+struct taskq *softnettq[SOFTNET_TASKS];
:
: struct task if_input_task_locked = TASK_INITIALIZER(if_netisr, NULL);
:
:@@ -240,6 +242,8 @@ struct rwlock netlock = RWLOCK_INITIALIZER("netlock");
: void
: ifinit(void)
: {
:+ unsigned inti;
:+
: /*
:* most machines boot with 4 or 5 interfaces, so size the initial map
:* to accomodate this
:@@ -248,9 +252,11 @@ ifinit(void)
:
: timeout_set(&net_tick_to, net_tick, &net_tick_to);
:
:- softnettq = taskq_create("softnet", 1, IPL_NET, TASKQ_MPSAFE);
:- if (softnettq == NULL)
:- panic("unable to create softnet taskq");
:+ for (i = 0; i < SOFTNET_TASKS; i++) {
:+ softnettq[i] = taskq_create("softnet", 1, IPL_NET,
TASKQ_MPSAFE);
:+ if (softnettq[i] == NULL)
:+ panic("unable to create softnet taskq");
:+ }
:
: net_tick(&net_tick_to);
: }
:@@ -725,7 +731,7 @@ if_input(struct ifnet *ifp, struct mbuf_list *ml)
: #endif
:
: if (mq_enlist(&ifp->if_inputqueue, ml) == 0)
:- task_add(softnettq, ifp->if_inputtask);
:+ task_add(net_tq(ifp->if_index), ifp->if_inputtask);
: }
:
: int
:@@ -1025,15 +1031,15 @@ if_detach(struct ifnet *ifp)
: ifp->if_watchdog = NULL;
:
: /* Remove the input task */
:- task_del(softnettq, ifp->if_inputtask);
:+ task_del(net_tq(ifp->if_index), ifp->if_inputtask);
: mq_purge(&ifp->if_inputqueue);
:
: /* Remove the watchdog timeout & task */
: timeout_del(ifp->if_slowtimo);
:- task_del(softnettq, ifp->if_watchdogtask);
:+ task_del(net_tq(ifp->if_index), ifp->if_watchdogtask);
:
: /* Remove the link state task */
:- task_del(softnettq, ifp->if_linkstatetask);
:+ task_del(net_tq(ifp->if_index), ifp->if_linkstatetask);
:
: #if NBPFILTER > 0
: bpfdetach(ifp);
:@@ -1583,7 +1589,7 @@ if_linkstate(struct ifnet *ifp)
: void
: if_link_state_change(struct ifnet *ifp)
: {
:- task_add(softnettq, ifp->if_linkstatetask);
:+ task_add(net_tq(ifp->if_index), ifp->if_linkstatetask);
: }
:
: /*
:@@ -1599,7 +1605,7 @@ if_slowtimo(void *arg)
:
: if (ifp->if_watchdog) {
: if (ifp->if_timer > 0 && --ifp->if_timer == 0)
:- task_add(softnettq, ifp->if_watchdogtask);
:+ task_add(net_tq(ifp->if_index), ifp->if_watchdogtask);
: timeout_add(ifp->if_slowtimo, hz / IFNET_SLOWHZ);
: }
: splx(s);
:@@ -2881,3 +2887,13 @@ unhandled_af(int af)
: {
: panic("unhandled af %d", af);
: }
:+
:+struct taskq *
:+net_tq(unsigned int ifindex)
:+{
:+ struct taskq *t = NULL;
:+
:+ t = softnettq[ifindex % SOFTNET_TASKS];
:+
:+ return (t);
:+}
:diff --git a/sys/net/if.h b/sys/net/if.h
:index 89867eac340..6a0770a8ea0 100644
:--- a/sys/net/if.h
:+++ b/sys/net/if.h
:@@ -489,6 +489,7 @@ void if_congestion(void);
: int if_congested(void);
: __dead void unhandled_af(int);
: int if_setlladdr(struct ifnet *, const uint8_t *);
:+struct taskq * net_tq(unsigned int);
:
: #endif /* _KERNEL */
:
:diff --git a/sys/net/if_loop.c b/sys/net/if_loop.c
:index 277e7f966a2..e9f58a4ee52 100644
:--- a/sys/net/if_loop.c
:+++ b/sys/net/if_loop.c
:@@ -244,7 +244,7 @@ looutput(struct ifnet *ifp, struct mbuf *m, struct
sockaddr *dst,
: m->m_pkthdr.ph_family = dst->sa_family;
: if (mq_enqueue(&ifp->if_inputqueue, m))
: return ENOBUFS;
:- task_add(softnettq, ifp->if_inputtask);
:+ task_add(net_tq(ifp->if_index), ifp->if_inputtask);
:
: return (0);
: }
:diff --git a/sys/net/if_pflow.c b/sys/net/if_pflow.c
:index 38efb02be7e..91a61fe4c15 100644
:--- a/sys/net/if_pflow.c
:+++ b/sys/net/if_pflow.c
:@@ -286,7 +286,7 @@ pflow_clone_destroy(struct ifnet *ifp)
: if (timeout_initialized(&sc->sc_tmo_tmpl))
: timeout_del(&sc->sc_tmo_tmpl);
: pflow_flush(sc);
:- task_del(softnettq, &sc->sc_outputtask);
:+ task_del(net_tq(ifp->if_index), &sc->sc_outputtask);
: mq_purge(&sc->sc_outputqueue);
: