From owner-dev-commits-src-branches@freebsd.org Mon Aug 23 12:34:32 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id B27C266A694; Mon, 23 Aug 2021 12:34:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4GtWs44D0kz3JhQ; Mon, 23 Aug 2021 12:34:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 74E20145B4; Mon, 23 Aug 2021 12:34:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 17NCYWCo023171; Mon, 23 Aug 2021 12:34:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17NCYWOi023170; Mon, 23 Aug 2021 12:34:32 GMT (envelope-from git) Date: Mon, 23 Aug 2021 12:34:32 GMT Message-Id: <202108231234.17NCYWOi023170@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mateusz Guzik Subject: git: 187ea09fbbdd - stable/13 - uipc: create dedicated lists for fast and slow timeout callbacks MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: mjg X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 187ea09fbbddff0d79d4a154e235a11e251dbad4 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Aug 2021 12:34:32 -0000 The branch stable/13 has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=187ea09fbbddff0d79d4a154e235a11e251dbad4 commit 187ea09fbbddff0d79d4a154e235a11e251dbad4 Author: Mateusz Guzik AuthorDate: 2021-08-15 21:41:47 +0000 Commit: Mateusz Guzik CommitDate: 2021-08-23 12:32:01 +0000 uipc: create dedicated lists for fast and slow timeout callbacks This avoids having to walk all possible protocols only to check if they have one (vast majority does not). Original patch by kevans@. Reviewed by: kevans Sponsored by: Rubicon Communications, LLC ("Netgate") (cherry picked from commit e0a17c3f063fd51430fb2b4f5bc667f79d2967c2) --- sys/kern/uipc_domain.c | 55 ++++++++++++++++++++++++++++++++++++++++---------- sys/sys/protosw.h | 4 ++++ 2 files changed, 48 insertions(+), 11 deletions(-) diff --git a/sys/kern/uipc_domain.c b/sys/kern/uipc_domain.c index 60e30eb1ae00..76c0364f6824 100644 --- a/sys/kern/uipc_domain.c +++ b/sys/kern/uipc_domain.c @@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include @@ -74,6 +75,14 @@ static struct callout pfslow_callout; static void pffasttimo(void *); static void pfslowtimo(void *); +static struct rmlock pftimo_lock; +RM_SYSINIT(pftimo_lock, &pftimo_lock, "pftimo"); + +static LIST_HEAD(, protosw) pffast_list = + LIST_HEAD_INITIALIZER(pffast_list); +static LIST_HEAD(, protosw) pfslow_list = + LIST_HEAD_INITIALIZER(pfslow_list); + struct domain *domains; /* registered protocol domains */ int domain_init_status = 0; static struct mtx dom_mtx; /* domain list lock */ @@ -175,8 +184,16 @@ domain_init(void *arg) if (dp->dom_init) (*dp->dom_init)(); - for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) + for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) { protosw_init(pr); + rm_wlock(&pftimo_lock); + if (pr->pr_fasttimo != NULL) + LIST_INSERT_HEAD(&pffast_list, pr, pr_fasttimos); + if (pr->pr_slowtimo != NULL) + LIST_INSERT_HEAD(&pfslow_list, pr, pr_slowtimos); + rm_wunlock(&pftimo_lock); + } + /* * update global information about maximums */ @@ -381,6 +398,13 @@ pf_proto_register(int family, struct protosw *npr) /* Copy the new struct protosw over the spacer. */ bcopy(npr, fpr, sizeof(*fpr)); + rm_wlock(&pftimo_lock); + if (fpr->pr_fasttimo != NULL) + LIST_INSERT_HEAD(&pffast_list, fpr, pr_fasttimos); + if (fpr->pr_slowtimo != NULL) + LIST_INSERT_HEAD(&pfslow_list, fpr, pr_slowtimos); + rm_wunlock(&pftimo_lock); + /* Job is done, no more protection required. */ mtx_unlock(&dom_mtx); @@ -441,6 +465,13 @@ pf_proto_unregister(int family, int protocol, int type) return (EPROTONOSUPPORT); } + rm_wlock(&pftimo_lock); + if (dpr->pr_fasttimo != NULL) + LIST_REMOVE(dpr, pr_fasttimos); + if (dpr->pr_slowtimo != NULL) + LIST_REMOVE(dpr, pr_slowtimos); + rm_wunlock(&pftimo_lock); + /* De-orbit the protocol and make the slot available again. */ dpr->pr_type = 0; dpr->pr_domain = dp; @@ -477,31 +508,33 @@ pfctlinput(int cmd, struct sockaddr *sa) static void pfslowtimo(void *arg) { + struct rm_priotracker tracker; struct epoch_tracker et; - struct domain *dp; struct protosw *pr; + rm_rlock(&pftimo_lock, &tracker); NET_EPOCH_ENTER(et); - for (dp = domains; dp; dp = dp->dom_next) - for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) - if (pr->pr_slowtimo) - (*pr->pr_slowtimo)(); + LIST_FOREACH(pr, &pfslow_list, pr_slowtimos) { + (*pr->pr_slowtimo)(); + } NET_EPOCH_EXIT(et); + rm_runlock(&pftimo_lock, &tracker); callout_reset(&pfslow_callout, hz/2, pfslowtimo, NULL); } static void pffasttimo(void *arg) { + struct rm_priotracker tracker; struct epoch_tracker et; - struct domain *dp; struct protosw *pr; + rm_rlock(&pftimo_lock, &tracker); NET_EPOCH_ENTER(et); - for (dp = domains; dp; dp = dp->dom_next) - for (pr = dp->dom_protosw; pr < dp->dom_protoswNPROTOSW; pr++) - if (pr->pr_fasttimo) - (*pr->pr_fasttimo)(); + LIST_FOREACH(pr, &pffast_list, pr_fasttimos) { + (*pr->pr_fasttimo)(); + } NET_EPOCH_EXIT(et); + rm_runlock(&pftimo_lock, &tracker); callout_reset(&pffast_callout, hz/5, pffasttimo, NULL); } diff --git a/sys/sys/protosw.h b/sys/sys/protosw.h index 9c3139c866bd..5c876a2052d5 100644 --- a/sys/sys/protosw.h +++ b/sys/sys/protosw.h @@ -35,6 +35,8 @@ #ifndef _SYS_PROTOSW_H_ #define _SYS_PROTOSW_H_ +#include + /* Forward declare these structures referenced from prototypes below. */ struct kaiocb; struct mbuf; @@ -93,6 +95,8 @@ struct protosw { pr_drain_t *pr_drain; /* flush any excess space possible */ struct pr_usrreqs *pr_usrreqs; /* user-protocol hook */ + LIST_ENTRY(protosw) pr_fasttimos; + LIST_ENTRY(protosw) pr_slowtimos; }; /*#endif*/