From nobody Tue Jan 11 10:19:44 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 30A4619420C0; Tue, 11 Jan 2022 10:19:45 +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 4JY6BS65ljz4n8X; Tue, 11 Jan 2022 10:19:44 +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 A95D6171D3; Tue, 11 Jan 2022 10:19:44 +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 20BAJiAH058236; Tue, 11 Jan 2022 10:19:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20BAJi3p058235; Tue, 11 Jan 2022 10:19:44 GMT (envelope-from git) Date: Tue, 11 Jan 2022 10:19:44 GMT Message-Id: <202201111019.20BAJi3p058235@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Wojciech Macek Subject: git: 68f28dd1ccc3 - main - ip_mroute: do not sleep when lock is taken List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: wma X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 68f28dd1ccc33b870bb8c0509694df4ed5e05ee7 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1641896384; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=RrmPE+878gHzpeMVqmUSqOGSnPrOeZsSgshc1AWbiJI=; b=PMdWAJR/80hDhi9m6IIW1VXlmrXF79OMk+HGXr7t3vGORz7a6SdJNHeyRWJWBV/FZpK4Yg CV9K0+Q1pv3eyrN1q8O/ZdOomKQa0Zz+hULIi23pqYsUJHwE+X+vtsWjFRgjExq1hQIAvd GQXGckPMMLMFOW8AfW8SXkDw9FhZWLCM5jRPPXcodRUAuNtUvrxZ1J3vjj10SkXsC1PmUl T8BXOZo1b+JtKSbrhcyA+OdQJleIb2wqXgE3X5OJ/u8vnI4KKywYdlK/WYd4Zn/TZH4dyC aRf5AH+6PwDUH2ssiVwvv82rRX0nqkxo6O/GDrTAuVFuV5E8pinHVEUXaSQGDA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1641896384; a=rsa-sha256; cv=none; b=O81DJJJgO8renlbrnE9C0Om5nQp863YYedd8/CknMqKgQ38LfgiLx3j7EqYa+NQU0+/jiQ rP2LeaoZyplgCblWToVmB6PTDZe307U9xLdoeLOMnDkcKADtRTGHtOnodhD5jSsv49qfop uyaGoNsfsNhZKxg0NIxcNu4tk1ghHiliFXvTSQNC7uKl9L+6lPJARlnf4Tj3nDiS0J/aAc PVlPqYnqSkHq30HJHyLs6Rbo1VBN/Wqrx37sX3MBHAl8+c2jlo266Mko1lb3d++5g7jVrv nHwsqCUWzil3GcdKggkS6L0hX8YWVh/w2JLVZlS8e8+NukJkf1d2VjdaejN1OQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by wma: URL: https://cgit.FreeBSD.org/src/commit/?id=68f28dd1ccc33b870bb8c0509694df4ed5e05ee7 commit 68f28dd1ccc33b870bb8c0509694df4ed5e05ee7 Author: Wojciech Macek AuthorDate: 2022-01-10 07:09:16 +0000 Commit: Wojciech Macek CommitDate: 2022-01-11 10:19:32 +0000 ip_mroute: do not sleep when lock is taken Kthread initialization calls uma_alloc which can sleep. Modify the code to use deferred work instead. --- sys/netinet/ip_mroute.c | 64 ++++++++++++++++++++++--------------------------- 1 file changed, 29 insertions(+), 35 deletions(-) diff --git a/sys/netinet/ip_mroute.c b/sys/netinet/ip_mroute.c index 02738616d56e..a380a9b864b8 100644 --- a/sys/netinet/ip_mroute.c +++ b/sys/netinet/ip_mroute.c @@ -99,6 +99,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -177,6 +178,10 @@ VNET_DEFINE_STATIC(u_char *, nexpire); /* 0..mfchashsize-1 */ #define V_nexpire VNET(nexpire) VNET_DEFINE_STATIC(LIST_HEAD(mfchashhdr, mfc)*, mfchashtbl); #define V_mfchashtbl VNET(mfchashtbl) +VNET_DEFINE_STATIC(struct taskqueue *, task_queue); +#define V_task_queue VNET(task_queue) +VNET_DEFINE_STATIC(struct task, task); +#define V_task VNET(task) VNET_DEFINE_STATIC(vifi_t, numvifs); #define V_numvifs VNET(numvifs) @@ -232,8 +237,6 @@ SYSCTL_ULONG(_net_inet_pim, OID_AUTO, squelch_wholepkt, CTLFLAG_RW, &pim_squelch_wholepkt, 0, "Disable IGMP_WHOLEPKT notifications if rendezvous point is unspecified"); -static volatile int upcall_thread_shutdown = 0; - static const struct encaptab *pim_encap_cookie; static int pim_encapcheck(const struct mbuf *, int, int, void *); static int pim_input(struct mbuf *, int, int, void *); @@ -660,22 +663,15 @@ if_detached_event(void *arg __unused, struct ifnet *ifp) } static void -ip_mrouter_upcall_thread(void *arg) +ip_mrouter_upcall_thread(void *arg, int pending __unused) { CURVNET_SET((struct vnet *) arg); - while (upcall_thread_shutdown == 0) { - /* START: Event loop */ - - /* END: Event loop */ - mtx_lock(&V_upcall_thread_mtx); - cv_timedwait(&V_upcall_thread_cv, &V_upcall_thread_mtx, hz); - mtx_unlock(&V_upcall_thread_mtx); - } + MRW_WLOCK(); + bw_upcalls_send(); + MRW_WUNLOCK(); - upcall_thread_shutdown = 0; CURVNET_RESTORE(); - kthread_exit(); } /* @@ -718,12 +714,9 @@ ip_mrouter_init(struct socket *so, int version) return (ENOMEM); } - /* Create upcall thread */ - upcall_thread_shutdown = 0; - mtx_init(&V_upcall_thread_mtx, "ip_mroute upcall thread mtx", NULL, MTX_DEF); - cv_init(&V_upcall_thread_cv, "ip_mroute upcall cv"); - kthread_add(ip_mrouter_upcall_thread, curvnet, - NULL, NULL, 0, 0, "ip_mroute upcall thread"); + TASK_INIT(&V_task, 0, ip_mrouter_upcall_thread, curvnet); + taskqueue_cancel(V_task_queue, &V_task, NULL); + taskqueue_unblock(V_task_queue); callout_reset(&V_expire_upcalls_ch, EXPIRE_TIMEOUT, expire_upcalls, curvnet); @@ -766,17 +759,14 @@ X_ip_mrouter_done(void) MROUTER_WAIT(); - MRW_WLOCK(); - - upcall_thread_shutdown = 1; - mtx_lock(&V_upcall_thread_mtx); - cv_signal(&V_upcall_thread_cv); - mtx_unlock(&V_upcall_thread_mtx); - - /* Wait for thread shutdown */ - while (upcall_thread_shutdown == 1) {}; + /* Stop and drain task queue */ + taskqueue_block(V_task_queue); + while (taskqueue_cancel(V_task_queue, &V_task, NULL)) { + taskqueue_drain(V_task_queue, &V_task); + } - mtx_destroy(&V_upcall_thread_mtx); + MRW_WLOCK(); + taskqueue_cancel(V_task_queue, &V_task, NULL); /* Destroy upcall ring */ while ((bu = buf_ring_dequeue_mc(V_bw_upcalls_ring)) != NULL) { @@ -1848,9 +1838,7 @@ expire_bw_meter_leq(void *arg) } /* Send all upcalls that are pending delivery */ - mtx_lock(&V_upcall_thread_mtx); - cv_signal(&V_upcall_thread_cv); - mtx_unlock(&V_upcall_thread_mtx); + taskqueue_enqueue(V_task_queue, &V_task); /* Reset counters */ x->bm_start_time = now; @@ -2154,9 +2142,7 @@ bw_meter_prepare_upcall(struct bw_meter *x, struct timeval *nowp) if (buf_ring_enqueue(V_bw_upcalls_ring, u)) log(LOG_WARNING, "bw_meter_prepare_upcall: cannot enqueue upcall\n"); if (buf_ring_count(V_bw_upcalls_ring) > (BW_UPCALLS_MAX / 2)) { - mtx_lock(&V_upcall_thread_mtx); - cv_signal(&V_upcall_thread_cv); - mtx_unlock(&V_upcall_thread_mtx); + taskqueue_enqueue(V_task_queue, &V_task); } } /* @@ -2753,6 +2739,11 @@ vnet_mroute_init(const void *unused __unused) callout_init_rw(&V_expire_upcalls_ch, &mrouter_mtx, 0); callout_init_rw(&V_bw_upcalls_ch, &mrouter_mtx, 0); + + /* Prepare taskqueue */ + V_task_queue = taskqueue_create_fast("ip_mroute_tskq", M_NOWAIT, + taskqueue_thread_enqueue, &V_task_queue); + taskqueue_start_threads(&V_task_queue, 1, PI_NET, "ip_mroute_tskq task"); } VNET_SYSINIT(vnet_mroute_init, SI_SUB_PROTO_MC, SI_ORDER_ANY, vnet_mroute_init, @@ -2762,6 +2753,9 @@ static void vnet_mroute_uninit(const void *unused __unused) { + /* Taskqueue should be cancelled and drained before freeing */ + taskqueue_free(V_task_queue); + free(V_viftable, M_MRTABLE); free(V_nexpire, M_MRTABLE); V_nexpire = NULL;