From patchwork Thu Dec 10 11:15:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 340987 Delivered-To: patch@linaro.org Received: by 2002:a17:906:4755:0:0:0:0 with SMTP id j21csp5530353ejs; Thu, 10 Dec 2020 03:09:34 -0800 (PST) X-Google-Smtp-Source: ABdhPJzuL764BKSzdO0BKUH82VsInhkmd+ZHaWs2FU2Uo4Er8vYHjyDm5Z/VpiLKSwNUaclbZtNf X-Received: by 2002:a17:906:2499:: with SMTP id e25mr5855266ejb.446.1607598574368; Thu, 10 Dec 2020 03:09:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607598574; cv=none; d=google.com; s=arc-20160816; b=jj1qb+B454XrydRBmJRSqUGOQPgHtB52V9IlWGMpxylcB0C4XN3C3G2deQ0vY3cGA1 +yK8VwR+9Sl1fGhVawP1xo1ie5wYfB5CuCPh/IG9NLqkFUG5Tstff5mUxFGmT9NeOTOj Mi08Pa4yn5Bzmjssr48/ximd14+dEmxOxKhFc+O8x1G+Xe5RVmFlPaZnjwIXW0XTF23V zJT7Iklt91iPR9CWR/hnxtXCIlJOVXRRzn5kZ843VGgXW/ME2Ta0RmYPifYqsHaQydZ8 tMhGxRuF19Vhq3TZIG3nP3sarFSURvfKUX86orZHYRp15j2qzGplHFsuTUcv7kZLC/EH OYvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=VapKC0F7lyscSctbK97hEtuP5mXbtCFlx94A7dqei/c=; b=f9cvN5H3Jgi0svLVLkXZ1qDrJUxH7pvVHYUZVErcaktlRb2bUhzHyLP4x+qCOQ7m4f gYAtNauRKSUeZisTVUZXjh9VX8owFwCUF+DolZG9qzN3HV0VC8xAjhnirBjnLb5ZhPCb fVteB+ZtMysybGKG4nBItKMjt90WuHnvB79M/UDvNhFoHTG2DEmtArkCOjnNTvcRU04y 0XEc5WSY3rywvZwhMURd1Y3rI0fWZlU1cTgM7Z0dDq9ikHLhMHOIlbfWOATl2lu2HVM7 fZTmxgl9TQ5neRn27oq/fHxirqvBajOHYabZEil75KMbYZ9lau0gEDamPxhyBSm8rYxh 0+Cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=thzzgsdX; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k4si2539363eds.355.2020.12.10.03.09.34; Thu, 10 Dec 2020 03:09:34 -0800 (PST) Received-SPF: pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=thzzgsdX; spf=pass (google.com: domain of netdev-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=netdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732998AbgLJLJd (ORCPT + 8 others); Thu, 10 Dec 2020 06:09:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731319AbgLJLJa (ORCPT ); Thu, 10 Dec 2020 06:09:30 -0500 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43C87C061793 for ; Thu, 10 Dec 2020 03:08:50 -0800 (PST) Received: by mail-wm1-x342.google.com with SMTP id g185so4862351wmf.3 for ; Thu, 10 Dec 2020 03:08:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=VapKC0F7lyscSctbK97hEtuP5mXbtCFlx94A7dqei/c=; b=thzzgsdXnMcBCx4HmSmaa1ZwCbajIM4XmNOg9MwjyjmioAJYcIbAJW1meuJwoFDkM3 xW41EHEvBr+b1eGkrtXEamJqtafB91ERnpZ2vfbSHzrAVOOpl6yZKjtGhOvbXU3VDvKI oD5aRb0r7DhYgGnGIQXSNcTDhXuWiv/X5QmfdOT1zTYRrXS1mVhGrdOsWBhJdvrKeQbX 0r7GXEcT4keLDBliAJ8NRpjy/OdW9LOGfR1D77L3M9nbj5bf1Of8QFnd1nUSjSx6cE44 lEtz6iDphnhvFrJb4vSCqRwexayYrCegDf44XZnWB01L1KQlZmxFG1VNBo0gmhtkDmxI T2JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=VapKC0F7lyscSctbK97hEtuP5mXbtCFlx94A7dqei/c=; b=MH3Sku9ZbQTaToWvymyC1Rqq/earG9Lb51wzgs6TTHXZN44h+aurp4zwGQDFbiKD8j t6y/wa/v5d/HyLfjeBLd6t4x4XPPLiq+6Bxz2geTOHHJFoyREvPgo8bSqMijwSS9hpVR TNXyhqWwwGn97a0jJYaFB8D6P1uivntRyEyVGKkROPvp6pl1r/Hrkw4pdfW1K1awLEet vv+uq1kfr1f3d2x5UH1ETad/putWznqHwYcN7+JMCdfyuajOelBPy+NrcG7CkQ6dTbAj qvpEhLrV14q4fCA08pxmie5rUi3xrCzp8D1GNS0WIfmyL1Qk74MmTpQEMojWn1JHGK9G Lkiw== X-Gm-Message-State: AOAM533l6w84yhoDP8SIx42UNuB19Sf5dKacYRz00xsLj6YhUuCTJLU5 D7bg+58Sg8ZOM5NPs/r7pp0IFA== X-Received: by 2002:a1c:6a13:: with SMTP id f19mr7405352wmc.10.1607598528905; Thu, 10 Dec 2020 03:08:48 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:490:8730:4468:1cc2:be0c:233f]) by smtp.gmail.com with ESMTPSA id n123sm8961809wmn.7.2020.12.10.03.08.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Dec 2020 03:08:48 -0800 (PST) From: Loic Poulain To: kuba@kernel.org, davem@davemloft.net Cc: manivannan.sadhasivam@linaro.org, linux-arm-msm@vger.kernel.org, netdev@vger.kernel.org, jhugo@codeaurora.org, Hemant Kumar Subject: [PATCH v2 1/3] bus: mhi: core: Add helper API to return number of free TREs Date: Thu, 10 Dec 2020 12:15:49 +0100 Message-Id: <1607598951-2340-1-git-send-email-loic.poulain@linaro.org> X-Mailer: git-send-email 2.7.4 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Hemant Kumar Introduce mhi_get_free_desc_count() API to return number of TREs available to queue buffer. MHI clients can use this API to know before hand if ring is full without calling queue API. Signed-off-by: Hemant Kumar Reviewed-by: Jeffrey Hugo Reviewed-by: Manivannan Sadhasivam --- v2: no change drivers/bus/mhi/core/main.c | 12 ++++++++++++ include/linux/mhi.h | 9 +++++++++ 2 files changed, 21 insertions(+) -- 2.7.4 diff --git a/drivers/bus/mhi/core/main.c b/drivers/bus/mhi/core/main.c index 54d9c80..a24ba4f 100644 --- a/drivers/bus/mhi/core/main.c +++ b/drivers/bus/mhi/core/main.c @@ -303,6 +303,18 @@ int mhi_destroy_device(struct device *dev, void *data) return 0; } +int mhi_get_free_desc_count(struct mhi_device *mhi_dev, + enum dma_data_direction dir) +{ + struct mhi_controller *mhi_cntrl = mhi_dev->mhi_cntrl; + struct mhi_chan *mhi_chan = (dir == DMA_TO_DEVICE) ? + mhi_dev->ul_chan : mhi_dev->dl_chan; + struct mhi_ring *tre_ring = &mhi_chan->tre_ring; + + return get_nr_avail_ring_elements(mhi_cntrl, tre_ring); +} +EXPORT_SYMBOL_GPL(mhi_get_free_desc_count); + void mhi_notify(struct mhi_device *mhi_dev, enum mhi_callback cb_reason) { struct mhi_driver *mhi_drv; diff --git a/include/linux/mhi.h b/include/linux/mhi.h index 09f786e..25c69a0 100644 --- a/include/linux/mhi.h +++ b/include/linux/mhi.h @@ -616,6 +616,15 @@ void mhi_set_mhi_state(struct mhi_controller *mhi_cntrl, void mhi_notify(struct mhi_device *mhi_dev, enum mhi_callback cb_reason); /** + * mhi_get_free_desc_count - Get transfer ring length + * Get # of TD available to queue buffers + * @mhi_dev: Device associated with the channels + * @dir: Direction of the channel + */ +int mhi_get_free_desc_count(struct mhi_device *mhi_dev, + enum dma_data_direction dir); + +/** * mhi_prepare_for_power_up - Do pre-initialization before power up. * This is optional, call this before power up if * the controller does not want bus framework to From patchwork Thu Dec 10 11:15:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 342681 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5062FC433FE for ; Thu, 10 Dec 2020 11:09:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B9CE23CD4 for ; Thu, 10 Dec 2020 11:09:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733169AbgLJLJk (ORCPT ); Thu, 10 Dec 2020 06:09:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732271AbgLJLJc (ORCPT ); Thu, 10 Dec 2020 06:09:32 -0500 Received: from mail-wm1-x343.google.com (mail-wm1-x343.google.com [IPv6:2a00:1450:4864:20::343]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84EF8C06179C for ; Thu, 10 Dec 2020 03:08:51 -0800 (PST) Received: by mail-wm1-x343.google.com with SMTP id e25so4871223wme.0 for ; Thu, 10 Dec 2020 03:08:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ipm7OLjcu7urJ6wZYaP0vWF1v1t82ROFjhYMYBWsWNE=; b=leqkZDg9rxADeTvThrR9J36plCvo8ZWUw4skR2U66CqZTKOtdzsOaCPnAQGAshozrO MqL0vohkgCYBPrZSpFpltMd/86C+G3Xf9MQHRh4I+YrZ2yM7dXHtx9ECQJ8ntyZaeyWZ DFA9PbwuPuhjoq+RW+xDl1aVEBuas/D55Ql8EzRhh+7Vq893yHPzPXS3TgTkD6gNJwDY DWraVEpoi3jGbS6QJlaSnJZ9j15/ER/9xMOoRG7rFVRQG5N56NN5hrIdjHDw/VdUZjAA 95kkTGcghOU7IzcN75qhBAbSyCApYXGs+n2TWZkxJP2P4QBmasrb1WPCJwyoe5kdkH8e WjSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ipm7OLjcu7urJ6wZYaP0vWF1v1t82ROFjhYMYBWsWNE=; b=Ir7LahRebom3Nz6KVh/eBbzZ0w+dHgoIy3W48QhHMSOTbN5/qIAS0SOr/t2gEZto8F zb5WDhi6Fi5wra+1kutaExNXTivlwhmzNWgJsX32RnW/drxxSLaCm/vQDiFpUtUypHqn H0gbKsNkFhvwzm11NTxO7E/4aIynxgVG8viUbr8iw1CE9L36U2tBhkb16Fqy8DAg7vIm pgv1d8D4go50PKZo1UWO+AAXN8ETqr8fonR3WitT9DLg8U1pM1AHE1hxCQUQbsFUpoKN x3re+2lUmgS/sJrC0ouJwcze/3SFA591Xc8boq0R5vTyBbUCSBv9ZVTinRHZpEElNdUc jCoQ== X-Gm-Message-State: AOAM533yMVE9AYBhKo+V+62IJj8EQGc+Zz6hBfWjZ8oBHhQ1a2PcXDcT uwlrVR29s/ImkhqjLZrYtQynUA== X-Google-Smtp-Source: ABdhPJxhepATf6eciKoYilkXNk66Erurabmb2/fX8Btd2JJ58ELusqrCXzmxH2O2Yfd5QmaaN0o+fQ== X-Received: by 2002:a1c:25c3:: with SMTP id l186mr7304637wml.113.1607598530322; Thu, 10 Dec 2020 03:08:50 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:490:8730:4468:1cc2:be0c:233f]) by smtp.gmail.com with ESMTPSA id n123sm8961809wmn.7.2020.12.10.03.08.49 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Dec 2020 03:08:49 -0800 (PST) From: Loic Poulain To: kuba@kernel.org, davem@davemloft.net Cc: manivannan.sadhasivam@linaro.org, linux-arm-msm@vger.kernel.org, netdev@vger.kernel.org, jhugo@codeaurora.org, Loic Poulain Subject: [PATCH v2 2/3] net: mhi: Get RX queue size from MHI core Date: Thu, 10 Dec 2020 12:15:50 +0100 Message-Id: <1607598951-2340-2-git-send-email-loic.poulain@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1607598951-2340-1-git-send-email-loic.poulain@linaro.org> References: <1607598951-2340-1-git-send-email-loic.poulain@linaro.org> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The RX queue size can be determined at runtime by retrieving the number of available transfer descriptors. Signed-off-by: Loic Poulain --- v2: Fixed commit message typo drivers/net/mhi_net.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/mhi_net.c b/drivers/net/mhi_net.c index 8e72d94..0333e07 100644 --- a/drivers/net/mhi_net.c +++ b/drivers/net/mhi_net.c @@ -256,9 +256,6 @@ static int mhi_net_probe(struct mhi_device *mhi_dev, mhi_netdev->mdev = mhi_dev; SET_NETDEV_DEV(ndev, &mhi_dev->dev); - /* All MHI net channels have 128 ring elements (at least for now) */ - mhi_netdev->rx_queue_sz = 128; - INIT_DELAYED_WORK(&mhi_netdev->rx_refill, mhi_net_rx_refill_work); u64_stats_init(&mhi_netdev->stats.rx_syncp); u64_stats_init(&mhi_netdev->stats.tx_syncp); @@ -268,6 +265,9 @@ static int mhi_net_probe(struct mhi_device *mhi_dev, if (err) goto out_err; + /* Number of transfer descriptors determines size of the queue */ + mhi_netdev->rx_queue_sz = mhi_get_free_desc_count(mhi_dev, DMA_FROM_DEVICE); + err = register_netdev(ndev); if (err) goto out_err; From patchwork Thu Dec 10 11:15:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 341685 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C52BC433FE for ; Thu, 10 Dec 2020 11:10:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E4DC223CD4 for ; Thu, 10 Dec 2020 11:10:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732271AbgLJLKI (ORCPT ); Thu, 10 Dec 2020 06:10:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733031AbgLJLJi (ORCPT ); Thu, 10 Dec 2020 06:09:38 -0500 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30F7EC0617A6 for ; Thu, 10 Dec 2020 03:08:53 -0800 (PST) Received: by mail-wm1-x341.google.com with SMTP id a3so4858201wmb.5 for ; Thu, 10 Dec 2020 03:08:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ItgTeuucSKI7xOPb/cgLQD69gw3sQiixlB2VotUPk5g=; b=TEvsdZohROnaAdJ5/jhdwYd8eOhBsKhXm/k1RudoZ6tCL7rTmhURAa6S/9xJTKlS2E r1ef6LiJiH6th7SwvGo04yV1gkoAjezvYSu7Ntog80GInGG4owGdAjJ28686ROWIpJd1 9YGmuUSZ4y23ykFLhj2pwW5aDkPyT99DSkwC/WxKyB+4T1ESOcJVgK0iaYTyT/Jw5rXT MYdFWE09TWdmI+pxjTGNlZC5hRbMbXI7IBA0A/PO8LEAN2f0gX6gSEUU02zq0nqy/tpu Ut/zZujKEOFizrynGx73NOqQ+hMI7i/yTtkxNqiWEMbV8S0DR1R1cbnjTdxJe4g2CtWD 2/HA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ItgTeuucSKI7xOPb/cgLQD69gw3sQiixlB2VotUPk5g=; b=hAZmvYZDB+K2VhPJaD2dVm0BpchDcK0KOQimcDvGHOkzq8dVSWjhymYNQQM6oAjqTN am9GCA0XrXuY6UGHyvfgWZDXUp3WQ96OPzRtogYo+FGDihmEREaxs2O8V8LmqnY0sKsS tSz++xwRv2BATYMBkmBfLCDWHhI0srCWz2x02amTqVEWwTwxxSNqPJQ9JNHqzy9/qjXF 1Vx6ZM6416OMBxlldrfa88tBnzY1w63clYtdZIUoawnmyniCRlEKO9q7tTniEsJIJ6QI ciIG4nSnUWremVxT5johFwSS5K6+D5cN9yCv9LBXwiqRAZ7L4DFHsoHF+0sU6Zwm+BHw ET8w== X-Gm-Message-State: AOAM530NXMZH6LtVVPw1khLohyKitOcyvua7W6QJpbM1I0WrppeYgU3C pH6kzL06ubBD8BqMMu6oCf/dSA== X-Google-Smtp-Source: ABdhPJw8WjOOZgBLd6ZkveFOdwvNfNdsaML37vwAHz296xZNibxN1eti8URNh3s2lZNYttHsaDDbKw== X-Received: by 2002:a1c:6856:: with SMTP id d83mr7855877wmc.119.1607598531933; Thu, 10 Dec 2020 03:08:51 -0800 (PST) Received: from localhost.localdomain ([2a01:e0a:490:8730:4468:1cc2:be0c:233f]) by smtp.gmail.com with ESMTPSA id n123sm8961809wmn.7.2020.12.10.03.08.51 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Dec 2020 03:08:51 -0800 (PST) From: Loic Poulain To: kuba@kernel.org, davem@davemloft.net Cc: manivannan.sadhasivam@linaro.org, linux-arm-msm@vger.kernel.org, netdev@vger.kernel.org, jhugo@codeaurora.org, Loic Poulain Subject: [PATCH v2 3/3] net: mhi: Add dedicated alloc thread Date: Thu, 10 Dec 2020 12:15:51 +0100 Message-Id: <1607598951-2340-3-git-send-email-loic.poulain@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1607598951-2340-1-git-send-email-loic.poulain@linaro.org> References: <1607598951-2340-1-git-send-email-loic.poulain@linaro.org> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The buffer allocation for RX path is currently done by a work executed in the system workqueue. The work to do is quite simple and consists mostly in allocating and queueing as much as possible buffers to the MHI RX channel. It appears that using a dedicated kthread would be more appropriate to prevent 1. RX allocation latency introduced by the system queue 2. Unbounded work execution, the work only returning when queue is full, it can possibly monopolise the workqueue thread on slower systems. This patch replaces the system work with a simple kthread that loops on buffer allocation and sleeps when queue is full. Moreover it gets rid of the local rx_queued variable (to track buffer count), and instead, relies on the new mhi_get_free_desc_count helper. After pratical testing on a x86_64 machine, this change improves - Peek throughput (slightly, by few mbps) - Throughput stability when concurrent loads are running (stress) - CPU usage, less CPU cycles dedicated to the task Below is the powertop output for RX allocation task before and after this change, when performing UDP download at 6Gbps. Mostly to highlight the improvement in term of CPU usage. older (system workqueue): Usage Events/s Category Description 63,2 ms/s 134,0 kWork mhi_net_rx_refill_work 62,8 ms/s 134,3 kWork mhi_net_rx_refill_work 60,8 ms/s 141,4 kWork mhi_net_rx_refill_work newer (dedicated kthread): Usage Events/s Category Description 20,7 ms/s 155,6 Process [PID 3360] [mhi-net-rx] 22,2 ms/s 169,6 Process [PID 3360] [mhi-net-rx] 22,3 ms/s 150,2 Process [PID 3360] [mhi-net-rx] Signed-off-by: Loic Poulain --- v2: add module parameter for changing RX refill level drivers/net/mhi_net.c | 110 ++++++++++++++++++++++++++++---------------------- 1 file changed, 62 insertions(+), 48 deletions(-) diff --git a/drivers/net/mhi_net.c b/drivers/net/mhi_net.c index 0333e07..bd66d51 100644 --- a/drivers/net/mhi_net.c +++ b/drivers/net/mhi_net.c @@ -5,6 +5,7 @@ */ #include +#include #include #include #include @@ -16,6 +17,11 @@ #define MHI_NET_MAX_MTU 0xffff #define MHI_NET_DEFAULT_MTU 0x4000 +static unsigned int rx_refill_level = 70; +module_param(rx_refill_level, uint, 0600); +MODULE_PARM_DESC(rx_refill_level, + "The minimal RX queue level percentage (0 to 100) under which the RX queue must be refilled"); + struct mhi_net_stats { u64_stats_t rx_packets; u64_stats_t rx_bytes; @@ -25,7 +31,6 @@ struct mhi_net_stats { u64_stats_t tx_bytes; u64_stats_t tx_errors; u64_stats_t tx_dropped; - atomic_t rx_queued; struct u64_stats_sync tx_syncp; struct u64_stats_sync rx_syncp; }; @@ -33,17 +38,66 @@ struct mhi_net_stats { struct mhi_net_dev { struct mhi_device *mdev; struct net_device *ndev; - struct delayed_work rx_refill; + struct task_struct *refill_task; + wait_queue_head_t refill_wq; struct mhi_net_stats stats; u32 rx_queue_sz; + u32 rx_refill_level; }; +static int mhi_net_refill_thread(void *data) +{ + struct mhi_net_dev *mhi_netdev = data; + struct net_device *ndev = mhi_netdev->ndev; + struct mhi_device *mdev = mhi_netdev->mdev; + int size = READ_ONCE(ndev->mtu); + struct sk_buff *skb; + int err; + + while (1) { + err = wait_event_interruptible(mhi_netdev->refill_wq, + !mhi_queue_is_full(mdev, DMA_FROM_DEVICE) + || kthread_should_stop()); + if (err || kthread_should_stop()) + break; + + skb = netdev_alloc_skb(ndev, size); + if (unlikely(!skb)) { + /* No memory, retry later */ + schedule_timeout_interruptible(msecs_to_jiffies(250)); + continue; + } + + err = mhi_queue_skb(mdev, DMA_FROM_DEVICE, skb, size, MHI_EOT); + if (unlikely(err)) { + net_err_ratelimited("%s: Failed to queue RX buf (%d)\n", + ndev->name, err); + kfree_skb(skb); + break; + } + + /* Do not hog the CPU */ + cond_resched(); + } + + return 0; +} + static int mhi_ndo_open(struct net_device *ndev) { struct mhi_net_dev *mhi_netdev = netdev_priv(ndev); + unsigned int qsz = mhi_netdev->rx_queue_sz; - /* Feed the rx buffer pool */ - schedule_delayed_work(&mhi_netdev->rx_refill, 0); + if (rx_refill_level >= 100) + mhi_netdev->rx_refill_level = 1; + else + mhi_netdev->rx_refill_level = qsz - qsz * rx_refill_level / 100; + + mhi_netdev->refill_task = kthread_run(mhi_net_refill_thread, mhi_netdev, + "mhi-net-rx"); + if (IS_ERR(mhi_netdev->refill_task)) { + return PTR_ERR(mhi_netdev->refill_task); + } /* Carrier is established via out-of-band channel (e.g. qmi) */ netif_carrier_on(ndev); @@ -57,9 +111,9 @@ static int mhi_ndo_stop(struct net_device *ndev) { struct mhi_net_dev *mhi_netdev = netdev_priv(ndev); + kthread_stop(mhi_netdev->refill_task); netif_stop_queue(ndev); netif_carrier_off(ndev); - cancel_delayed_work_sync(&mhi_netdev->rx_refill); return 0; } @@ -138,9 +192,6 @@ static void mhi_net_dl_callback(struct mhi_device *mhi_dev, { struct mhi_net_dev *mhi_netdev = dev_get_drvdata(&mhi_dev->dev); struct sk_buff *skb = mhi_res->buf_addr; - int remaining; - - remaining = atomic_dec_return(&mhi_netdev->stats.rx_queued); if (unlikely(mhi_res->transaction_status)) { dev_kfree_skb_any(skb); @@ -163,9 +214,8 @@ static void mhi_net_dl_callback(struct mhi_device *mhi_dev, netif_rx(skb); } - /* Refill if RX buffers queue becomes low */ - if (remaining <= mhi_netdev->rx_queue_sz / 2) - schedule_delayed_work(&mhi_netdev->rx_refill, 0); + if (mhi_get_free_desc_count(mhi_dev, DMA_FROM_DEVICE) >= mhi_netdev->rx_refill_level) + wake_up_interruptible(&mhi_netdev->refill_wq); } static void mhi_net_ul_callback(struct mhi_device *mhi_dev, @@ -200,42 +250,6 @@ static void mhi_net_ul_callback(struct mhi_device *mhi_dev, netif_wake_queue(ndev); } -static void mhi_net_rx_refill_work(struct work_struct *work) -{ - struct mhi_net_dev *mhi_netdev = container_of(work, struct mhi_net_dev, - rx_refill.work); - struct net_device *ndev = mhi_netdev->ndev; - struct mhi_device *mdev = mhi_netdev->mdev; - int size = READ_ONCE(ndev->mtu); - struct sk_buff *skb; - int err; - - while (atomic_read(&mhi_netdev->stats.rx_queued) < mhi_netdev->rx_queue_sz) { - skb = netdev_alloc_skb(ndev, size); - if (unlikely(!skb)) - break; - - err = mhi_queue_skb(mdev, DMA_FROM_DEVICE, skb, size, MHI_EOT); - if (unlikely(err)) { - net_err_ratelimited("%s: Failed to queue RX buf (%d)\n", - ndev->name, err); - kfree_skb(skb); - break; - } - - atomic_inc(&mhi_netdev->stats.rx_queued); - - /* Do not hog the CPU if rx buffers are consumed faster than - * queued (unlikely). - */ - cond_resched(); - } - - /* If we're still starved of rx buffers, reschedule later */ - if (unlikely(!atomic_read(&mhi_netdev->stats.rx_queued))) - schedule_delayed_work(&mhi_netdev->rx_refill, HZ / 2); -} - static int mhi_net_probe(struct mhi_device *mhi_dev, const struct mhi_device_id *id) { @@ -256,7 +270,7 @@ static int mhi_net_probe(struct mhi_device *mhi_dev, mhi_netdev->mdev = mhi_dev; SET_NETDEV_DEV(ndev, &mhi_dev->dev); - INIT_DELAYED_WORK(&mhi_netdev->rx_refill, mhi_net_rx_refill_work); + init_waitqueue_head(&mhi_netdev->refill_wq); u64_stats_init(&mhi_netdev->stats.rx_syncp); u64_stats_init(&mhi_netdev->stats.tx_syncp);