From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4DA254499B3 for ; Fri, 31 Jul 2026 15:49:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785512968; cv=none; b=LavAL2M78taCNbb32QrdisQPjTSRBmhW9K9ay4np2hrK78U+swGHLVAatf5zZFAHH9J9S13MtfCpF6WpBejyhUzfjjq/yP3lxv3oMG5DCLoeHOWhCSLax/RoKe7+sxrpabZHIlPKp6DFkEwbbatRU0ssdOtc3dj67AEn1nUHoW8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785512968; c=relaxed/simple; bh=bo6GZs5cRhfR+4h6zHzYZY0ne9OWftzWzsm3xWEM+bs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=G3O6e2WhwDi6QWdknbVRG7G9FsZTiYujRoQ56EUPcvFYrbUyVeK4vIw7KmaX+OiAXdUV0Qtg54OfuddxEd2f5eka5XMjWkQnKj3VLLBGHSCqJSIwJTSZRV4Yrnl9Bt8+cjtU8j6IkAbj2+f3h2yFcaoexFlMHtpadPW8gaFBG3Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=khfBC/8q; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="khfBC/8q" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2cf110997efso1823485ad.2 for ; Fri, 31 Jul 2026 08:49:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785512965; x=1786117765; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=cjsOjYk7yuXBgbYLc3ZTyWopMFfcMdSI35CR9dqHg6w=; b=khfBC/8qgCqymQftNSjQzWzpxk5yfkqVg1IrQrWbzVcwuc/Fxjzr3nhFmMrJ/Tn0X9 pUjodzYaCngKP443ZPt9tu/MX7P4CmaJhxyemYtNjLu7cPyuhbQ2ybs0Npqzr5/WJ/Ba ch4tggiBLnEQAnnzOMeYa/4thPQo+ySuCyp7Q1LIxa6rtk1mgbXJZk4U/3zuqvYwSeZu ahKC/hwzs7sVimOMYZM62gjlsbZLhtD8eWuGuNjx2Xp9Z4+KdkhQ2aLv4JqVYAr0lEaF GC4fdMNNvlexJsDD5W0mT1l9p/Q4XB4ofFi4tjhNXPe6DqFYMucyb9Nk6TGNuEgCjKMF UTow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785512965; x=1786117765; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=cjsOjYk7yuXBgbYLc3ZTyWopMFfcMdSI35CR9dqHg6w=; b=CnRgnsMRyv97ta2dwPHIqrdyo7d5hEANFjGXrfD+b0A5ruZaLAWwZZ4cyiKPnxb7vV KbMaWc2eKu/W+PuE+l0uDIAlEqPubVQbemhl/hgBWcPFY3xKiEqUofPzr+aHV4T+P8/4 seLnTrac8Czk9UP+ncynAgTGsr6YaUGFyan2cscGUV+66ML/Pr8HazyRyIvzD4LTDv32 5g6CCXipRb61LkSF9ZGV4h14bnGinDXjLWOTs7OID50ECPDuNbFnKz7+FrM4H4KRsQbG XLiMTIdbkSHSx1pSDsTcC/7G5yeOaQSnFW6NpZSliYJ9F+NkQZzPj5aZ9CjCH5jA8DeX I8jQ== X-Forwarded-Encrypted: i=1; AHgh+Rq7EEmshNmMvy0Yitg5tagMnK5QaqpGHYtAmEo9+kG5o0jEsc0O5KKKpsE3osXKpmbn6t7pa9S3Q21P6iQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwtKSIQO2iMkOupyNnA/IUO8HpGu8TQFnZymz2kF26M/w3ArPDd kIQtCkY2ioV/QfExaPfFM9NxCbVtQIu0C1r/MtRQ2LHRbdwqLO6zUa6J X-Gm-Gg: AR+sD12uoajTacoqJ9k6r2RHjbebUtOyHb8AvUFLpclN1c4Nzgx9HOSZ1W0BlGYA34y cLvZy4DhA7buf794WjUPouSyCAcYiZN7T36ANUhT0pAAf1PMBUkk0vJrJL8lDP4QdnqdumLSLGB dSWOlwcLpdXtc4/DLeLnsq/ep+tBpjfAoHADyvq/VyGvaz4w0dh8Ho/l0Su1wAgCHOKI6n1MZKO 52MsV6+EAQnoPeNNe5s4QDwNeERgTrlr3yht6M06xdjIWMlAx0ydfM0ifqI4uS/RDznX52ArdR1 jQbwXCDMOxBflddlDUaV2n54VqDcLokdnl4ujgDCRj9YB597RnCaN3dz4mbc8TCodJ/Sy0yCWK1 FYtkOST3CZjammmon1NIqiyw2hjX2o2oZthmbUCaJ74WedFgToab/xM050uWB8fdBM8jq760geb iQlv8j8e0WEAB+4uIOZl6wTdCS2ZS4v6ryR3dFRXhRQNxEWigymLfPSUs6iwqts1XgLJKzhihIt dU= X-Received: by 2002:a17:903:3c23:b0:2d0:2741:f31b with SMTP id d9443c01a7336-2d0523fc4ecmr7602255ad.4.1785512965351; Fri, 31 Jul 2026 08:49:25 -0700 (PDT) Received: from Potato.tail66a299.ts.net ([171.76.83.76]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3153e045016sm11852510eec.19.2026.07.31.08.49.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 Jul 2026 08:49:25 -0700 (PDT) From: Shivesh X-Google-Original-From: Shivesh To: arend.vanspriel@broadcom.com Cc: linux-wireless@vger.kernel.org, brcm80211@lists.linux.dev, brcm80211-dev-list.pdl@broadcom.com, linux-kernel@vger.kernel.org, Shivesh Subject: [PATCH v3 5/8] wifi: brcmfmac: msgbuf: tune thresholds and optimize sleep latency Date: Fri, 31 Jul 2026 15:48:37 +0000 Message-ID: <20260731154901.1822-6-shivesh@example.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260731154901.1822-1-shivesh@example.com> References: <20260731154901.1822-1-shivesh@example.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Shivesh Increases tx pktids and tune flush thresholds. Fixes a silent tx stall under high load by correctly using test_and_set_bit. Optimizes initialization polling latency from msleep(10) to usleep_range. Signed-off-by: Shivesh --- .../broadcom/brcm80211/brcmfmac/msgbuf.c | 69 ++++++++++++++++--- 1 file changed, 61 insertions(+), 8 deletions(-) diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c index ba1ce1552e0f..8db6167072da 100644 --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/msgbuf.c @@ -48,7 +48,19 @@ #define MSGBUF_TYPE_LPBK_DMAXFER 0x13 #define MSGBUF_TYPE_LPBK_DMAXFER_CMPLT 0x14 -#define NR_TX_PKTIDS 2048 +/* + * NR_TX_PKTIDS: number of simultaneously in-flight TX packet IDs. + * Each outstanding TX frame consumes one ID until the dongle returns + * a TX-status completion. The original 2048-entry pool exhausted under + * ≥4 concurrent iperf3 streams on Wi-Fi 5/6 (802.11ac/ax) devices, + * causing "No PKTID available" drops and TCP retransmits. 4096 gives + * headroom for high-aggregation scenarios while still fitting in a + * modest amount of host memory (~48 KB for the pktid table entries). + * + * NR_RX_PKTIDS: RX post buffers pre-allocated to the dongle. 1024 is + * sufficient for current hardware RX ring depths; leave unchanged. + */ +#define NR_TX_PKTIDS 4096 #define NR_RX_PKTIDS 1024 #define BRCMF_IOCTL_REQ_PKTID 0xFFFE @@ -64,8 +76,29 @@ #define BRCMF_MSGBUF_PKT_FLAGS_FRAME_MASK 0x07 #define BRCMF_MSGBUF_PKT_FLAGS_PRIO_SHIFT 5 -#define BRCMF_MSGBUF_TX_FLUSH_CNT1 32 -#define BRCMF_MSGBUF_TX_FLUSH_CNT2 96 +/* + * TX flush / doorbell-ring thresholds. + * + * CNT1 is the minimum number of frames to accumulate in the commonring + * before the first intermediate write_complete() (doorbell ring) is + * issued mid-batch. CNT2 is the hard flush interval: after this many + * frames have been written since the last flush, we unconditionally + * ring the bell and reset the counter. + * + * Raising both from the original 32/96 to 64/128 doubles the average + * number of TX descriptors committed per MMIO write, halving the PCIe + * doorbell rate on sustained throughput workloads. The tradeoff is a + * marginally higher worst-case latency for the last frames in a burst, + * which in practice is hidden by the time the dongle DMA engine drains + * the previous batch. + * + * TRICKLE_TXWORKER_THRS governs how often brcmf_msgbuf_tx_queue_data() + * forces a workqueue schedule when the queue depth is not a multiple of + * this value. Keeping it at half of CNT1 (32) preserves responsiveness + * for low-rate flows (e.g. VoIP, ICMP) that never accumulate 64 frames. + */ +#define BRCMF_MSGBUF_TX_FLUSH_CNT1 64 +#define BRCMF_MSGBUF_TX_FLUSH_CNT2 128 #define BRCMF_MSGBUF_DELAY_TXWORKER_THRS 96 #define BRCMF_MSGBUF_TRICKLE_TXWORKER_THRS 32 @@ -787,10 +820,30 @@ static int brcmf_msgbuf_schedule_txdata(struct brcmf_msgbuf *msgbuf, u32 flowid, { struct brcmf_commonring *commonring; - set_bit(flowid, msgbuf->flow_map); + /* + * If the bit was already set, a txflow_work item is already + * queued or running for this ring. In that case the existing + * worker will drain our freshly enqueued frame when it runs, + * so we only need to schedule another work item when the + * force flag is set or the ring is below the delay threshold. + * + * If the bit was NOT set (test_and_set_bit returns false), no + * worker is pending for this ring at all. We MUST schedule + * one unconditionally, otherwise the frame we just enqueued + * will sit in the flowring unsent until some unrelated event + * triggers the workqueue — causing silent TX stalls under + * high load when outstanding_tx >= DELAY_TXWORKER_THRS. + */ + if (!test_and_set_bit(flowid, msgbuf->flow_map)) { + /* Bit was clear: no worker pending, always schedule. */ + queue_work(msgbuf->txflow_wq, &msgbuf->txflow_work); + return 0; + } + + /* Bit was already set: worker pending, apply coalescing heuristic. */ commonring = msgbuf->flowrings[flowid]; - if ((force) || (atomic_read(&commonring->outstanding_tx) < - BRCMF_MSGBUF_DELAY_TXWORKER_THRS)) + if (force || (atomic_read(&commonring->outstanding_tx) < + BRCMF_MSGBUF_DELAY_TXWORKER_THRS)) queue_work(msgbuf->txflow_wq, &msgbuf->txflow_work); return 0; @@ -1621,11 +1674,11 @@ int brcmf_proto_msgbuf_attach(struct brcmf_pub *drvr) do { brcmf_msgbuf_rxbuf_data_fill(msgbuf); if (msgbuf->max_rxbufpost != msgbuf->rxbufpost) - msleep(10); + usleep_range(1000, 2000); else break; count++; - } while (count < 10); + } while (count < 100); brcmf_msgbuf_rxbuf_event_post(msgbuf); brcmf_msgbuf_rxbuf_ioctlresp_post(msgbuf); -- 2.53.0