From owner-svn-src-all@FreeBSD.ORG Sun Dec 14 20:15:31 2008 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 730471065676; Sun, 14 Dec 2008 20:15:31 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 60A478FC19; Sun, 14 Dec 2008 20:15:31 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id mBEKFV5r070479; Sun, 14 Dec 2008 20:15:31 GMT (envelope-from mav@svn.freebsd.org) Received: (from mav@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id mBEKFVjW070478; Sun, 14 Dec 2008 20:15:31 GMT (envelope-from mav@svn.freebsd.org) Message-Id: <200812142015.mBEKFVjW070478@svn.freebsd.org> From: Alexander Motin Date: Sun, 14 Dec 2008 20:15:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r186093 - head/sys/netgraph X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 14 Dec 2008 20:15:31 -0000 Author: mav Date: Sun Dec 14 20:15:30 2008 New Revision: 186093 URL: http://svn.freebsd.org/changeset/base/186093 Log: To avoid one doubtless netgraph SMP scalability limitation point, switch node queues processing from single swi:net thread to several specialized threads. Reviewed by: julian Tested with: Netperf Cluster Modified: head/sys/netgraph/ng_base.c Modified: head/sys/netgraph/ng_base.c ============================================================================== --- head/sys/netgraph/ng_base.c Sun Dec 14 20:05:03 2008 (r186092) +++ head/sys/netgraph/ng_base.c Sun Dec 14 20:15:30 2008 (r186093) @@ -62,6 +62,9 @@ #include #include #include +#include +#include +#include #include #include @@ -211,7 +214,7 @@ static int ng_generic_msg(node_p here, i static ng_ID_t ng_decodeidname(const char *name); static int ngb_mod_event(module_t mod, int event, void *data); static void ng_worklist_add(node_p node); -static void ngintr(void); +static void ngthread(void *); static int ng_apply_item(node_p node, item_p item, int rw); static void ng_flush_input_queue(node_p node); static node_p ng_ID2noderef(ng_ID_t ID); @@ -259,6 +262,10 @@ MALLOC_DEFINE(M_NETGRAPH_MSG, "netgraph_ mtx_lock(&ng_worklist_mtx) #define NG_WORKLIST_UNLOCK() \ mtx_unlock(&ng_worklist_mtx) +#define NG_WORKLIST_SLEEP() \ + mtx_sleep(&ng_worklist, &ng_worklist_mtx, PI_NET, "sleep", 0) +#define NG_WORKLIST_WAKEUP() \ + wakeup_one(&ng_worklist) #ifdef NETGRAPH_DEBUG /*----------------------------------------------*/ /* @@ -2868,9 +2875,13 @@ out: uma_zone_t ng_qzone; uma_zone_t ng_qdzone; +static int numthreads = 0; /* number of queue threads */ static int maxalloc = 4096;/* limit the damage of a leak */ static int maxdata = 512; /* limit the damage of a DoS */ +TUNABLE_INT("net.graph.threads", &numthreads); +SYSCTL_INT(_net_graph, OID_AUTO, threads, CTLFLAG_RDTUN, &numthreads, + 0, "Number of queue processing threads"); TUNABLE_INT("net.graph.maxalloc", &maxalloc); SYSCTL_INT(_net_graph, OID_AUTO, maxalloc, CTLFLAG_RDTUN, &maxalloc, 0, "Maximum number of non-data queue items to allocate"); @@ -3064,7 +3075,9 @@ ng_mod_event(module_t mod, int event, vo static int ngb_mod_event(module_t mod, int event, void *data) { - int error = 0; + struct proc *p; + struct thread *td; + int i, error = 0; switch (event) { case MOD_LOAD: @@ -3091,7 +3104,18 @@ ngb_mod_event(module_t mod, int event, v ng_qdzone = uma_zcreate("NetGraph data items", sizeof(struct ng_item), NULL, NULL, NULL, NULL, UMA_ALIGN_CACHE, 0); uma_zone_set_max(ng_qdzone, maxdata); - netisr_register(NETISR_NETGRAPH, (netisr_t *)ngintr, NULL, 0); + /* Autoconfigure number of threads. */ + if (numthreads <= 0) + numthreads = mp_ncpus; + /* Create threads. */ + p = NULL; /* start with no process */ + for (i = 0; i < numthreads; i++) { + if (kproc_kthread_add(ngthread, NULL, &p, &td, + RFHIGHPID, 0, "ng_queue", "ng_queue%d", i)) { + numthreads = i; + break; + } + } break; case MOD_UNLOAD: /* You can't unload it because an interface may be using it. */ @@ -3246,25 +3270,20 @@ SYSCTL_PROC(_debug, OID_AUTO, ng_dump_it /*********************************************************************** * Worklist routines **********************************************************************/ -/* NETISR thread enters here */ /* * Pick a node off the list of nodes with work, - * try get an item to process off it. - * If there are no more, remove the node from the list. + * try get an item to process off it. Remove the node from the list. */ static void -ngintr(void) +ngthread(void *arg) { for (;;) { node_p node; /* Get node from the worklist. */ NG_WORKLIST_LOCK(); - node = STAILQ_FIRST(&ng_worklist); - if (!node) { - NG_WORKLIST_UNLOCK(); - break; - } + while ((node = STAILQ_FIRST(&ng_worklist)) == NULL) + NG_WORKLIST_SLEEP(); STAILQ_REMOVE_HEAD(&ng_worklist, nd_input_queue.q_work); NG_WORKLIST_UNLOCK(); CTR3(KTR_NET, "%20s: node [%x] (%p) taken off worklist", @@ -3320,9 +3339,9 @@ ng_worklist_add(node_p node) NG_WORKLIST_LOCK(); STAILQ_INSERT_TAIL(&ng_worklist, node, nd_input_queue.q_work); NG_WORKLIST_UNLOCK(); - schednetisr(NETISR_NETGRAPH); CTR3(KTR_NET, "%20s: node [%x] (%p) put on worklist", __func__, node->nd_ID, node); + NG_WORKLIST_WAKEUP(); } else { CTR3(KTR_NET, "%20s: node [%x] (%p) already on worklist", __func__, node->nd_ID, node);