From nobody Fri Jan 24 21:07:38 2025 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 4Yfr4B3dnLz5lvf0; Fri, 24 Jan 2025 21:07:38 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Yfr4B2vTjz3g2R; Fri, 24 Jan 2025 21:07:38 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737752858; 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=yJooVuB6/I1GAbSosp99gZnrJNqiugfyGa/sYl0pFFs=; b=UzfW4Cdkav3JcDIEDKRVTxyKaQqJ7tcqVR8rBGIIxNyxZi7PVhCDm10hh61by8m6F3PYf4 3TYlQteTAwLVeSG9ZJMxW/7Hwj6IR3QwOGo2lQ7d+G0lCmg7DZgAf3chEOHjM3fzCAcOhq EJ1gXawwGZehNUjZ2rbaJ470Ulm89Y+zHRKCTpKLVM1GHBOqnjUiuNPswNbFC61hkAttvk m7HaqShS2GR/K97t310VTBo9MZOdnkbqubfIUMN9eTrLB/863gUDX2elUAcamVVukHbH5K XZnGoWUGg1zr0H74sZ1/9g22zdOX1UZsixbn/SfeKdDHRY/HMAJ3Fwvszqwudw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737752858; 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=yJooVuB6/I1GAbSosp99gZnrJNqiugfyGa/sYl0pFFs=; b=dmYyKYyS4tPZJHixe/8dB+TebjGsyqHyz0I/lLulTLWUtb236eghyAPPEJkpD5Oua/Kxbl 0a58UUUKHwAC5/pgnT+RNLJOblEdKhFNDR0e3UKWtpLfUhBrbsskiG/Q38NcJZPnK8oB3s UbEawXEWVk1iUfinscMzHusCOWxp9GNZSNe/0c+DazkOJI8k/VwVbTXkT03rOmJqlca+8p dT26BO37IKprFFm6xTk9mz8wRTh41XXcH7KWs0Xe4CcRfWOohkVKA7unKgdFQteuLgglCh douUtNIeGCGwkmbO7r4Up/L7wFaG5nYN5cKLQD8rr1b4GePmEv2y4gI3UD5J+A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1737752858; a=rsa-sha256; cv=none; b=Mj2AfgP4wnFOKrc9+6L1+f1K2y8rtkoSfDf3wP748OvcKzs8v9708FRmuX0UIB3Bgslt+B q9XPmjkDftbKy++mf8ddN6XRE+PsvKPzlQbj2fgOnDRP5N9ex3BUZkR0ZjMTMFXKRm0R24 /ztEfwiVkP3cnCCTVu6HX86sHd9qb+WJptfB1nqhCg+w+++psS8ftdm8wQaxNFQu3SGU7S JQ0cqXMzUmJDn44344U4X3M9VvtuXmGBZPgezmpo+du/6J+J3YH4pXa5RHGF52HSM5A/pU 8bmxD1aVVrwF7G4FZuE/QvhIdBVA1p9Zk95ETeZrdI48uzhAxHfKMQCwLEUFcA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4Yfr4B2KPzzjDB; Fri, 24 Jan 2025 21:07:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 50OL7cBC039520; Fri, 24 Jan 2025 21:07:38 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50OL7cdA039517; Fri, 24 Jan 2025 21:07:38 GMT (envelope-from git) Date: Fri, 24 Jan 2025 21:07:38 GMT Message-Id: <202501242107.50OL7cdA039517@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: 3ad01642fe9e - main - iflib(4): Replace admin taskqueue group with per-interface taskqueues 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 3ad01642fe9e241124553f2f18fd365ffea5d20b Auto-Submitted: auto-generated The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=3ad01642fe9e241124553f2f18fd365ffea5d20b commit 3ad01642fe9e241124553f2f18fd365ffea5d20b Author: Krzysztof Galazka AuthorDate: 2024-07-05 11:00:13 +0000 Commit: Warner Losh CommitDate: 2025-01-24 21:08:12 +0000 iflib(4): Replace admin taskqueue group with per-interface taskqueues Using one taskqueue group with single thread to execute all admin tasks may lead to unexpected timeouts when long running task (e.g. handling a reset after FW update) for one interface prevents tasks from other interfaces being executed. Taskqueue group API doesn't let to dynamically add threads, and pre-allocating thread for each CPU as it's done for traffic queues would be a waste of resources on systems with small number of interfaces. Replace global taskqueue group for admin tasks with taskqueue allocated for each interface to allow independent execution. Signed-off-by: Krzysztof Galazka Reviewed by: imp, jhb Pull Request: https://github.com/freebsd/freebsd-src/pull/1336 --- sys/dev/bnxt/bnxt_en/bnxt.h | 2 +- sys/dev/bnxt/bnxt_en/if_bnxt.c | 10 +++--- sys/net/iflib.c | 77 ++++++++++++++++++++++-------------------- sys/net/iflib.h | 6 ++-- 4 files changed, 48 insertions(+), 47 deletions(-) diff --git a/sys/dev/bnxt/bnxt_en/bnxt.h b/sys/dev/bnxt/bnxt_en/bnxt.h index c5fadeafa181..e4f866807070 100644 --- a/sys/dev/bnxt/bnxt_en/bnxt.h +++ b/sys/dev/bnxt/bnxt_en/bnxt.h @@ -1091,7 +1091,7 @@ struct bnxt_softc { struct bnxt_cp_ring def_nq_ring; struct iflib_dma_info def_cp_ring_mem; struct iflib_dma_info def_nq_ring_mem; - struct grouptask def_cp_task; + struct task def_cp_task; int db_size; int legacy_db_size; struct bnxt_doorbell_ops db_ops; diff --git a/sys/dev/bnxt/bnxt_en/if_bnxt.c b/sys/dev/bnxt/bnxt_en/if_bnxt.c index 00d37f5e0151..efc467a043f9 100644 --- a/sys/dev/bnxt/bnxt_en/if_bnxt.c +++ b/sys/dev/bnxt/bnxt_en/if_bnxt.c @@ -229,7 +229,7 @@ static void bnxt_clear_ids(struct bnxt_softc *softc); static void inline bnxt_do_enable_intr(struct bnxt_cp_ring *cpr); static void inline bnxt_do_disable_intr(struct bnxt_cp_ring *cpr); static void bnxt_mark_cpr_invalid(struct bnxt_cp_ring *cpr); -static void bnxt_def_cp_task(void *context); +static void bnxt_def_cp_task(void *context, int pending); static void bnxt_handle_async_event(struct bnxt_softc *softc, struct cmpl_base *cmpl); static uint64_t bnxt_get_baudrate(struct bnxt_link_info *link); @@ -2384,8 +2384,7 @@ bnxt_attach_pre(if_ctx_t ctx) &softc->def_cp_ring_mem, 0); softc->def_cp_ring.ring.vaddr = softc->def_cp_ring_mem.idi_vaddr; softc->def_cp_ring.ring.paddr = softc->def_cp_ring_mem.idi_paddr; - iflib_config_gtask_init(ctx, &softc->def_cp_task, bnxt_def_cp_task, - "dflt_cp"); + iflib_config_task_init(ctx, &softc->def_cp_task, bnxt_def_cp_task); rc = bnxt_init_sysctl_ctx(softc); if (rc) @@ -2512,7 +2511,6 @@ bnxt_detach(if_ctx_t ctx) bnxt_free_ctx_mem(softc); bnxt_clear_ids(softc); iflib_irq_free(ctx, &softc->def_cp_ring.irq); - iflib_config_gtask_deinit(&softc->def_cp_task); /* We need to free() these here... */ for (i = softc->nrxqsets-1; i>=0; i--) { if (BNXT_CHIP_P5(softc)) @@ -4348,7 +4346,7 @@ bnxt_handle_def_cp(void *arg) struct bnxt_softc *softc = arg; softc->db_ops.bnxt_db_rx_cq(&softc->def_cp_ring, 0); - GROUPTASK_ENQUEUE(&softc->def_cp_task); + iflib_config_task_enqueue(softc->ctx, &softc->def_cp_task); return FILTER_HANDLED; } @@ -4608,7 +4606,7 @@ async_event_process_exit: } static void -bnxt_def_cp_task(void *context) +bnxt_def_cp_task(void *context, int pending) { if_ctx_t ctx = context; struct bnxt_softc *softc = iflib_get_softc(ctx); diff --git a/sys/net/iflib.c b/sys/net/iflib.c index 6644197f7d5b..1ae2207c9d13 100644 --- a/sys/net/iflib.c +++ b/sys/net/iflib.c @@ -178,8 +178,9 @@ struct iflib_ctx { struct resource *ifc_msix_mem; struct if_irq ifc_legacy_irq; - struct grouptask ifc_admin_task; - struct grouptask ifc_vflr_task; + struct task ifc_admin_task; + struct task ifc_vflr_task; + struct taskqueue *ifc_tq; struct iflib_filter_info ifc_filter_info; struct ifmedia ifc_media; struct ifmedia *ifc_mediap; @@ -1640,7 +1641,7 @@ static int iflib_fast_intr_ctx(void *arg) { iflib_filter_info_t info = arg; - struct grouptask *gtask = info->ifi_task; + if_ctx_t ctx = info->ifi_ctx; int result; DBG_COUNTER_INC(fast_intrs); @@ -1650,8 +1651,7 @@ iflib_fast_intr_ctx(void *arg) return (result); } - if (gtask->gt_taskqueue != NULL) - GROUPTASK_ENQUEUE(gtask); + taskqueue_enqueue(ctx->ifc_tq, &ctx->ifc_admin_task); return (FILTER_HANDLED); } @@ -4176,7 +4176,7 @@ skip_rxeof: } static void -_task_fn_admin(void *context) +_task_fn_admin(void *context, int pending) { if_ctx_t ctx = context; if_softc_ctx_t sctx = &ctx->ifc_softc_ctx; @@ -4227,7 +4227,7 @@ _task_fn_admin(void *context) } static void -_task_fn_iov(void *context) +_task_fn_iov(void *context, int pending) { if_ctx_t ctx = context; @@ -5200,6 +5200,7 @@ iflib_device_register(device_t dev, void *sc, if_shared_ctx_t sctx, if_ctx_t *ct kobj_method_t *kobj_method; int err, msix, rid; int num_txd, num_rxd; + char namebuf[TASKQUEUE_NAMELEN]; ctx = malloc(sizeof(*ctx), M_IFLIB, M_WAITOK | M_ZERO); @@ -5290,10 +5291,25 @@ iflib_device_register(device_t dev, void *sc, if_shared_ctx_t sctx, if_ctx_t *ct scctx->isc_rss_table_size = 64; scctx->isc_rss_table_mask = scctx->isc_rss_table_size - 1; - GROUPTASK_INIT(&ctx->ifc_admin_task, 0, _task_fn_admin, ctx); - /* XXX format name */ - taskqgroup_attach(qgroup_if_config_tqg, &ctx->ifc_admin_task, ctx, - NULL, NULL, "admin"); + /* Create and start admin taskqueue */ + snprintf(namebuf, TASKQUEUE_NAMELEN, "if_%s_tq", device_get_nameunit(dev)); + ctx->ifc_tq = taskqueue_create_fast(namebuf, M_NOWAIT, + taskqueue_thread_enqueue, &ctx->ifc_tq); + if (ctx->ifc_tq == NULL) { + device_printf(dev, "Unable to create admin taskqueue\n"); + return (ENOMEM); + } + + err = taskqueue_start_threads(&ctx->ifc_tq, 1, PI_NET, "%s", namebuf); + if (err) { + device_printf(dev, + "Unable to start admin taskqueue threads error: %d\n", + err); + taskqueue_free(ctx->ifc_tq); + return (err); + } + + TASK_INIT(&ctx->ifc_admin_task, 0, _task_fn_admin, ctx); /* Set up cpu set. If it fails, use the set of all CPUs. */ if (bus_get_cpus(dev, INTR_CPUS, sizeof(ctx->ifc_cpus), &ctx->ifc_cpus) != 0) { @@ -5430,6 +5446,7 @@ iflib_device_register(device_t dev, void *sc, if_shared_ctx_t sctx, if_ctx_t *ct fail_detach: ether_ifdetach(ctx->ifc_ifp); fail_queues: + taskqueue_free(ctx->ifc_tq); iflib_tqg_detach(ctx); iflib_tx_structures_free(ctx); iflib_rx_structures_free(ctx); @@ -5508,6 +5525,9 @@ iflib_device_deregister(if_ctx_t ctx) IFDI_QUEUES_FREE(ctx); CTX_UNLOCK(ctx); + taskqueue_free(ctx->ifc_tq); + ctx->ifc_tq = NULL; + /* ether_ifdetach calls if_qflush - lock must be destroy afterwards*/ iflib_free_intr_mem(ctx); @@ -5545,11 +5565,6 @@ iflib_tqg_detach(if_ctx_t ctx) if (rxq->ifr_task.gt_uniq != NULL) taskqgroup_detach(tqg, &rxq->ifr_task); } - tqg = qgroup_if_config_tqg; - if (ctx->ifc_admin_task.gt_uniq != NULL) - taskqgroup_detach(tqg, &ctx->ifc_admin_task); - if (ctx->ifc_vflr_task.gt_uniq != NULL) - taskqgroup_detach(tqg, &ctx->ifc_vflr_task); } static void @@ -6324,9 +6339,7 @@ iflib_irq_alloc_generic(if_ctx_t ctx, if_irq_t irq, int rid, q = ctx; tqrid = -1; info = &ctx->ifc_filter_info; - gtask = &ctx->ifc_admin_task; - tqg = qgroup_if_config_tqg; - fn = _task_fn_admin; + gtask = NULL; intr_fast = iflib_fast_intr_ctx; break; default: @@ -6388,12 +6401,8 @@ iflib_softirq_alloc_generic(if_ctx_t ctx, if_irq_t irq, iflib_intr_type_t type, NET_GROUPTASK_INIT(gtask, 0, fn, q); break; case IFLIB_INTR_IOV: - q = ctx; - gtask = &ctx->ifc_vflr_task; - tqg = qgroup_if_config_tqg; - fn = _task_fn_iov; - GROUPTASK_INIT(gtask, 0, fn, q); - break; + TASK_INIT(&ctx->ifc_vflr_task, 0, _task_fn_iov, ctx); + return; default: panic("unknown net intr type"); } @@ -6483,15 +6492,14 @@ void iflib_admin_intr_deferred(if_ctx_t ctx) { - MPASS(ctx->ifc_admin_task.gt_taskqueue != NULL); - GROUPTASK_ENQUEUE(&ctx->ifc_admin_task); + taskqueue_enqueue(ctx->ifc_tq, &ctx->ifc_admin_task); } void iflib_iov_intr_deferred(if_ctx_t ctx) { - GROUPTASK_ENQUEUE(&ctx->ifc_vflr_task); + taskqueue_enqueue(ctx->ifc_tq, &ctx->ifc_vflr_task); } void @@ -6503,20 +6511,15 @@ iflib_io_tqg_attach(struct grouptask *gt, void *uniq, int cpu, const char *name) } void -iflib_config_gtask_init(void *ctx, struct grouptask *gtask, gtask_fn_t *fn, - const char *name) +iflib_config_task_init(if_ctx_t ctx, struct task *config_task, task_fn_t *fn) { - - GROUPTASK_INIT(gtask, 0, fn, ctx); - taskqgroup_attach(qgroup_if_config_tqg, gtask, gtask, NULL, NULL, - name); + TASK_INIT(config_task, 0, fn, ctx); } void -iflib_config_gtask_deinit(struct grouptask *gtask) +iflib_config_task_enqueue(if_ctx_t ctx, struct task *config_task) { - - taskqgroup_detach(qgroup_if_config_tqg, gtask); + taskqueue_enqueue(ctx->ifc_tq, config_task); } void diff --git a/sys/net/iflib.h b/sys/net/iflib.h index e3d76fbd3c01..3817445228d0 100644 --- a/sys/net/iflib.h +++ b/sys/net/iflib.h @@ -470,9 +470,9 @@ void iflib_irq_free(if_ctx_t ctx, if_irq_t irq); void iflib_io_tqg_attach(struct grouptask *gt, void *uniq, int cpu, const char *name); -void iflib_config_gtask_init(void *ctx, struct grouptask *gtask, - gtask_fn_t *fn, const char *name); -void iflib_config_gtask_deinit(struct grouptask *gtask); +void iflib_config_task_init(if_ctx_t ctx, struct task *config_task, + task_fn_t *fn); +void iflib_config_task_enqueue(if_ctx_t ctx, struct task *config_task); void iflib_tx_intr_deferred(if_ctx_t ctx, int txqid); void iflib_rx_intr_deferred(if_ctx_t ctx, int rxqid);