Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp2284839pxb; Fri, 25 Mar 2022 14:38:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzefp8O4dn4yQk5j3k4+MTyI0TDfqaO2tQsVYMxCmRE2U+DrsLtZ0cZfWustrPdYxeBKyJ/ X-Received: by 2002:a05:6a00:1490:b0:4fb:1544:bc60 with SMTP id v16-20020a056a00149000b004fb1544bc60mr4700635pfu.73.1648244315130; Fri, 25 Mar 2022 14:38:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1648244315; cv=none; d=google.com; s=arc-20160816; b=py7Vk4EtWu/w2wyWXNKQfHQ3kchGX+J4i8+7dMqZ8gM/S3FDagRfSG364pkv2Hn4dv p/kUqeuaIkVJNHSgfzbiT0sv7KLElXvbzaOkqAwvz9aMs1DaUMmEUAq8DwdvELUXVCPM hybDqML1i/Z1DutSAo539s4p8a2hz74hLJXAp6yR9TCJOy4Bq0bq96rjWsCoEpyi5jMp q7U2qa3dNjF/Qv+9tZS5JZ39UTGmdQZUoNEzn7g8yUES57sVbtDRcdN1LQc7+Obod2uC sJ6vpdYA/cvnLaWf3K26KGtYJXbsBYJEG8Qlig486f47x0b41V1ue0wEoC6xTiYDUPhP pWFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Ocz9INSRRxyO45DVcCGrta8kUKQqY2wTq00b22fkyz4=; b=PmDLix6q96QVd4KcPRWmkIw12Tu7kv9VuUxpQlHYNgOSgOnM+7H3VJ0enXI1sMmUuv j3ZzuwKQ42wEJ3iS0OxZkaSz9l9Aas5KYXnMlHzpjMQ05Nwo/pY+dk9OkL+dOPlLqsYL GJTgci5eKU828KOxqwVWMMJhRERBPH7V6DztZL+Oe6DVVFb15Wp8wytMQIUfu5g1BZnl RYM2paeSg2QTNvdUlloxnOZT2y5DTHuiSJeCEgtXFocMED/h8qM3uoclBwbxq+hMxZVB uKOU2IgSG4ch2LsKt8fWW54uOVWJgski2/Tk1/myskI/w6mBesOgfyYlnhs7y/axQyoC r1og== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=ubs1LDpy; spf=softfail (google.com: domain of transitioning linux-wireless-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id u10-20020a654c0a000000b003816043f064si3490533pgq.601.2022.03.25.14.38.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Mar 2022 14:38:35 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-wireless-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=fail header.i=@nbd.name header.s=20160729 header.b=ubs1LDpy; spf=softfail (google.com: domain of transitioning linux-wireless-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3D37B1FD2D7; Fri, 25 Mar 2022 14:10:48 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233208AbiCYVMT (ORCPT + 70 others); Fri, 25 Mar 2022 17:12:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233254AbiCYVMR (ORCPT ); Fri, 25 Mar 2022 17:12:17 -0400 Received: from nbd.name (nbd.name [IPv6:2a01:4f8:221:3d45::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BDB3A1FE55D for ; Fri, 25 Mar 2022 14:10:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=nbd.name; s=20160729; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Ocz9INSRRxyO45DVcCGrta8kUKQqY2wTq00b22fkyz4=; b=ubs1LDpyqOpe1pke0tVw0xlRQB Nd2yUIEB3HS9I2xNbWFTw1G0I3YddfYV+TfOxy7Wjp7S7h5mDwQXpNI6fXa6xL+R/DMcx5Be4hSpj mgxO9VPEV4UxrY37kaew/l7hCjNfDXWJUvU3XsgrlOF/66xprzAgFR0o9Sv/RV5mI3rc=; Received: from p200300daa70ef200dc11dea3d730df97.dip0.t-ipconnect.de ([2003:da:a70e:f200:dc11:dea3:d730:df97] helo=Maecks.lan) by ds12 with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1nXrCi-0001fW-4K for linux-wireless@vger.kernel.org; Fri, 25 Mar 2022 22:10:40 +0100 From: Felix Fietkau To: linux-wireless@vger.kernel.org Subject: [PATCH 5/8] mt76: dma: reduce lock contention in mt76_dma_tx_cleanup Date: Fri, 25 Mar 2022 22:10:28 +0100 Message-Id: <20220325211031.24171-5-nbd@nbd.name> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220325211031.24171-1-nbd@nbd.name> References: <20220325211031.24171-1-nbd@nbd.name> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Instead of taking q->lock for every single cleaned up frame, batch up to 16 cleaned up frames before taking it. Signed-off-by: Felix Fietkau --- drivers/net/wireless/mediatek/mt76/dma.c | 26 +++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/dma.c b/drivers/net/wireless/mediatek/mt76/dma.c index 09dc37bbf112..07065816262f 100644 --- a/drivers/net/wireless/mediatek/mt76/dma.c +++ b/drivers/net/wireless/mediatek/mt76/dma.c @@ -233,7 +233,9 @@ static void mt76_dma_tx_cleanup(struct mt76_dev *dev, struct mt76_queue *q, bool flush) { struct mt76_queue_entry entry; + int done = 0; int last; + int tail; if (!q || !q->ndesc) return; @@ -244,21 +246,39 @@ mt76_dma_tx_cleanup(struct mt76_dev *dev, struct mt76_queue *q, bool flush) else last = readl(&q->regs->dma_idx); - while (q->queued > 0 && q->tail != last) { + tail = q->tail; + while (q->queued - done > 0 && tail != last) { mt76_dma_tx_cleanup_idx(dev, q, q->tail, &entry); - mt76_queue_tx_complete(dev, q, &entry); + if (entry.skb) + dev->drv->tx_complete_skb(dev, &entry); + tail = (tail + 1) % q->ndesc; + done++; if (entry.txwi) { if (!(dev->drv->drv_flags & MT_DRV_TXWI_NO_FREE)) mt76_put_txwi(dev, entry.txwi); } - if (!flush && q->tail == last) + if (!flush && tail == last) last = readl(&q->regs->dma_idx); + if (done > 16) { + spin_lock_bh(&q->lock); + q->queued -= done; + q->tail = tail; + spin_unlock_bh(&q->lock); + done = 0; + } } spin_unlock_bh(&q->cleanup_lock); + if (done) { + spin_lock_bh(&q->lock); + q->queued -= done; + q->tail = tail; + spin_unlock_bh(&q->lock); + } + if (flush) { spin_lock_bh(&q->lock); mt76_dma_sync_idx(dev, q); -- 2.35.1