From nobody Tue Sep 9 01:17:32 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A4D2EB64DD for ; Mon, 24 Jul 2023 03:41:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230084AbjGXDlm (ORCPT ); Sun, 23 Jul 2023 23:41:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230049AbjGXDlg (ORCPT ); Sun, 23 Jul 2023 23:41:36 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2052.outbound.protection.outlook.com [40.107.244.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 471D1191; Sun, 23 Jul 2023 20:41:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=H+foiyXN3Txa5wpoVTf02QPGJqBYskbG/W6BJC2Sekcm5VydwlEUdHP6n45CIBMZ1bctLN9YBQV4kWeSFXPirKhNhEvHb9r2ZRSQR9pkVnni8sDsX7fWiVf849/7m5MygJffXHJe0YL79ze2eJlbESlZIPmfLQZUUjM50oXlzZqGM6uFKRDg9qHumSEaARA81a1zBAvc4gMjLsuZt2welJ0cLznADq/XhTQtQ8mSGxv6dWNA6RCA81atevDXksORa6Nb2nArStAmxnx5eMZmajW29TopU++flVZFw7rk481LVCqx+jmHR48LjH+bv8+dXuXZO5CYyuZUoXdNvjct5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=KpY16pSmomnFEYpXTws0UaY23QjCR2HG+iPfMc2Mitk=; b=gKUDL0fr61MRN2XhOIA/XSo5TFPPmovxuble9hU+R2ydX1mqcQrThWhT0z4cLVXMLqMNW9CFGU6MHoUqvoC34g0o7NUvm6AMJaAzJssTYPOEzeGDwl50O2Z2VjkK5kVMjYjnmEOCV5mgRwTZQpm2Kr1JNrElyg2JDKAlxXU4tBa5ZOYezYGZbFzoyVVivX9xTxHHZknaelY073uUOeOIqVmS3tgwrEflVw5krrd6amyD0QpJ0bfN7iqIZbRg+qBI587s7tvBmJbXBXpFkVlaXoD0BsTu1KsEkjmO8+dYUqWvypTt2TyPmYp7Hq+4V7+9TYVsQ+A0CYGZUG6BiYIOIA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=redhat.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KpY16pSmomnFEYpXTws0UaY23QjCR2HG+iPfMc2Mitk=; b=cLIlmSLpnnCSThEpP/0/nC/kAVzYSzS0YqIiwq82OkioX7ss9D3kAE21I62TV3pF3ZPhj59A8irXl1vVEYLkqMSdIfnXH5j6BQP2bQYIMZimFoY735GHWywGOzS/4sVwndwm6PJtdzajYr7hwpHUt7Z82yCP+d34YapjpAZU7hmhjjvhntpgYpON/oj87brOtbj2Z2NBtjPmVbkVrgn58ZLVYkvHbJ9NdfOCIOPOpi9mKfWQgENTDcT3FlIMtvdgCRHwF48sdMZTpWGhBjBa7bqdbDHkZd8kDjCZBTvOnqLsXKnR+Np58Fl+xQeUPCzEOihD/+hPTbQQ0Sc35UxVHA== Received: from BN9PR03CA0784.namprd03.prod.outlook.com (2603:10b6:408:13f::9) by MN2PR12MB4223.namprd12.prod.outlook.com (2603:10b6:208:1d3::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.31; Mon, 24 Jul 2023 03:41:33 +0000 Received: from BN8NAM11FT073.eop-nam11.prod.protection.outlook.com (2603:10b6:408:13f:cafe::36) by BN9PR03CA0784.outlook.office365.com (2603:10b6:408:13f::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.28 via Frontend Transport; Mon, 24 Jul 2023 03:41:33 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BN8NAM11FT073.mail.protection.outlook.com (10.13.177.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.24 via Frontend Transport; Mon, 24 Jul 2023 03:41:33 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Sun, 23 Jul 2023 20:41:21 -0700 Received: from nvidia.com (10.126.231.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Sun, 23 Jul 2023 20:41:16 -0700 From: Gavin Li To: , , , , , , , , , , , , CC: , , , , Subject: [PATCH net-next V3 1/4] virtio_net: extract interrupt coalescing settings to a structure Date: Mon, 24 Jul 2023 06:40:45 +0300 Message-ID: <20230724034048.51482-2-gavinl@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230724034048.51482-1-gavinl@nvidia.com> References: <20230724034048.51482-1-gavinl@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT073:EE_|MN2PR12MB4223:EE_ X-MS-Office365-Filtering-Correlation-Id: 2e13de78-6e9c-4aae-b4a2-08db8bf7dff2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sK+KmUpSr7CBooW6yHz78UTFhrElvNDbkfmdJUqhrkQur/h3m+gSDl0wtKL9JW6p2DZyIGhwBxSk7rSYHurWBCnazGXTryL4Hw77TeJFfEMjWuaMtCUqLM8Sy9sCsPOUWZ7YpbD8yXPm6zmbdOV6hjCMyOA4j0lms0MTZc9Cb3yaPjyRjpqm9790TVegdX8sXJ3zsdlIm/MY1MCkW6oLKEygI6MFLiCUgEYaF1lVTbwN5S+Z6GO9mzJ98dfU/O7UXgiNhV/+aUrHJvLZ3CAwMKxik+YSh0xQSJcJf3VC/p80x0auf6gcTdoWnTTE1PTvORMm41szQmAgW1hi7BOFi4m22xpWf25udszeLIB9QNJf0svzoEfznEh4Qwx/uiuWtaxQJnTR9vIUa+e4BA83EpKLMi4/NOGnUXIDdz9tdGiglqji1kbiMT1RgMPh6XsazCiThR5Y0Zb0SZ1H/kXC68GicFB47ApOG8QNTa/Gp4reZjuu+WowWjEhXKyqIsPW8OzYCAx1pkGXotFd+mOFYC4tXdfiMdWVlwp+Gkmhr6k5iqccTNtusYfFexh8q4KXZp/TatFVMr7Ve9gPXcGKNgonYjSMnH1ir4PcJvacFcoOb/QKdaLUgbdpmfDVVXQ1B6jmvYw6ietfNifSF4Q3PFqSPqwA6WXMXsGskez5W/WlQ9poWtZJyYBTYiYKFVujX46B3bP0W8/2iLDIz3RxeGx7aJi30X3CB7Z9UhMEJalF0CB40reXcZXSE/3375N5NZ1dzghtDAySyoAnbaeX6a/WQ/FtPQatLnL2XDF6Bbk2k+N8/MbU9/ANQIYmpwP6 X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(396003)(39860400002)(376002)(136003)(346002)(451199021)(82310400008)(36840700001)(46966006)(40470700004)(16526019)(478600001)(110136005)(6666004)(6286002)(7696005)(1076003)(336012)(186003)(26005)(54906003)(2906002)(8936002)(7416002)(70586007)(70206006)(41300700001)(316002)(6636002)(8676002)(5660300002)(4326008)(7636003)(921005)(36756003)(356005)(86362001)(82740400003)(36860700001)(426003)(2616005)(47076005)(83380400001)(40480700001)(40460700003)(55016003)(83996005)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jul 2023 03:41:33.1590 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2e13de78-6e9c-4aae-b4a2-08db8bf7dff2 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT073.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4223 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Extract interrupt coalescing settings to a structure so that it could be reused in other data structures. Signed-off-by: Gavin Li Reviewed-by: Dragos Tatulea Reviewed-by: Jiri Pirko Acked-by: Jason Wang Acked-by: Michael S. Tsirkin Reviewed-by: Heng Qi --- drivers/net/virtio_net.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 0db14f6b87d3..dd5fec073a27 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -126,6 +126,11 @@ static const struct virtnet_stat_desc virtnet_rq_stats= _desc[] =3D { #define VIRTNET_SQ_STATS_LEN ARRAY_SIZE(virtnet_sq_stats_desc) #define VIRTNET_RQ_STATS_LEN ARRAY_SIZE(virtnet_rq_stats_desc) =20 +struct virtnet_interrupt_coalesce { + u32 max_packets; + u32 max_usecs; +}; + /* Internal representation of a send virtqueue */ struct send_queue { /* Virtqueue associated with this send _queue */ @@ -281,10 +286,8 @@ struct virtnet_info { u32 speed; =20 /* Interrupt coalescing settings */ - u32 tx_usecs; - u32 rx_usecs; - u32 tx_max_packets; - u32 rx_max_packets; + struct virtnet_interrupt_coalesce intr_coal_tx; + struct virtnet_interrupt_coalesce intr_coal_rx; =20 unsigned long guest_offloads; unsigned long guest_offloads_capable; @@ -3056,8 +3059,8 @@ static int virtnet_send_notf_coal_cmds(struct virtnet= _info *vi, return -EINVAL; =20 /* Save parameters */ - vi->tx_usecs =3D ec->tx_coalesce_usecs; - vi->tx_max_packets =3D ec->tx_max_coalesced_frames; + vi->intr_coal_tx.max_usecs =3D ec->tx_coalesce_usecs; + vi->intr_coal_tx.max_packets =3D ec->tx_max_coalesced_frames; =20 vi->ctrl->coal_rx.rx_usecs =3D cpu_to_le32(ec->rx_coalesce_usecs); vi->ctrl->coal_rx.rx_max_packets =3D cpu_to_le32(ec->rx_max_coalesced_fra= mes); @@ -3069,8 +3072,8 @@ static int virtnet_send_notf_coal_cmds(struct virtnet= _info *vi, return -EINVAL; =20 /* Save parameters */ - vi->rx_usecs =3D ec->rx_coalesce_usecs; - vi->rx_max_packets =3D ec->rx_max_coalesced_frames; + vi->intr_coal_rx.max_usecs =3D ec->rx_coalesce_usecs; + vi->intr_coal_rx.max_packets =3D ec->rx_max_coalesced_frames; =20 return 0; } @@ -3132,10 +3135,10 @@ static int virtnet_get_coalesce(struct net_device *= dev, struct virtnet_info *vi =3D netdev_priv(dev); =20 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_NOTF_COAL)) { - ec->rx_coalesce_usecs =3D vi->rx_usecs; - ec->tx_coalesce_usecs =3D vi->tx_usecs; - ec->tx_max_coalesced_frames =3D vi->tx_max_packets; - ec->rx_max_coalesced_frames =3D vi->rx_max_packets; + ec->rx_coalesce_usecs =3D vi->intr_coal_rx.max_usecs; + ec->tx_coalesce_usecs =3D vi->intr_coal_tx.max_usecs; + ec->tx_max_coalesced_frames =3D vi->intr_coal_tx.max_packets; + ec->rx_max_coalesced_frames =3D vi->intr_coal_rx.max_packets; } else { ec->rx_max_coalesced_frames =3D 1; =20 @@ -4119,10 +4122,10 @@ static int virtnet_probe(struct virtio_device *vdev) } =20 if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_NOTF_COAL)) { - vi->rx_usecs =3D 0; - vi->tx_usecs =3D 0; - vi->tx_max_packets =3D 0; - vi->rx_max_packets =3D 0; + vi->intr_coal_rx.max_usecs =3D 0; + vi->intr_coal_tx.max_usecs =3D 0; + vi->intr_coal_tx.max_packets =3D 0; + vi->intr_coal_rx.max_packets =3D 0; } =20 if (virtio_has_feature(vdev, VIRTIO_NET_F_HASH_REPORT)) --=20 2.39.1 From nobody Tue Sep 9 01:17:32 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 578ECC0015E for ; Mon, 24 Jul 2023 03:41:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230118AbjGXDlt (ORCPT ); Sun, 23 Jul 2023 23:41:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230071AbjGXDlk (ORCPT ); Sun, 23 Jul 2023 23:41:40 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2054.outbound.protection.outlook.com [40.107.94.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 813ACE43; Sun, 23 Jul 2023 20:41:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oWSuNhsW02m7Z2b7MFCQ6nJkFSww7fuUnyo5o0XPjP1NHUCZV3sJ7lJkgh3jiccn2WOGuE+o3OUvgrrrq8qBZSkMyOqvWiAj5dF5RH56QpMY1T6bLIzWWqC9omyLji3+X3q3lU38sxjOpHa3mFUI6OxLRpVCgiZ+tzrgNWLyr2S/cyQHLY0udWPopIUh6jmWFqDqfZw5XdxkUdC4Qq+qqIZkoiTguJS5H1ps0puMtKZ9eMRMZdf+JP0SojDyDv9ZIeuP0/YcC8NBRpGOwJ6x85dsR0YxA8ntG+tlG4utDE0cJ+R0/z2/0XiBGUL52Yz8+B6jgeVdOM3gSrRrAj03Ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5HnE17WXvUiKdousTex6K1czsq9mCbCP2v/hVcbXrVo=; b=OPM2kJkA0uNluw4p2A/S/WoJ4xWj4tNCbrH1lPTq0Q7Tg/aegOVq22yuxL1jn4E9IlEPHdHkVELt8vkmbKPMBa3bdNTWsqcOmdMkW7KTlX+UcW2NMIEZvgg8kCYMB3VJj2jzT8Pb5Y01GjuGEecvxFCyAQgJfn2TjN9Ze1nlH5mXymaqgRkTHXhKD3RXBghyBUVNljJw8yOVN4+qPAkOGpCClPsunwcGXOtBRCDEYnG9W9a/ptFkfhOkerOoAO4uWe2zkBCkn9xSLobNjQfnvOj6d8Bs8AIkZZPdmvBETRABLXfMWqINhhK43lDC28Djl3aOkaPyVEXgTnS7Rc71/w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=redhat.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5HnE17WXvUiKdousTex6K1czsq9mCbCP2v/hVcbXrVo=; b=hAB31cwhpHqCDLWO3ExUNQR3s5nDGKuQI/ymaaGlGx5+5C1aT7ENlBBn0MS+skj0rnfEWwDR8pxwb72Gl500gqciLcTNoe/zD0B8zpudo0jKHk3jFa7vV0MIYbb/PB8HFu5sVQ38CvDtiux0uWaUoIjG7QeQT0leFYqiH2Mb0tucuTBMO/tBDlDjXMyDPpab/nyxMUcOv93aNlxcqQtdf14NtQ1X8WaAP6JJQnLh62WjYzwYB7V9dVCoB//dHSSSEqZz53KSC07q5T6lwH03X6CcAnoTHxwiCc5N0RY1GdMnZ9GUqZ19nwljuKzR+PuoWSVwPCYOAWqCJMYmopOFPQ== Received: from BN9PR03CA0123.namprd03.prod.outlook.com (2603:10b6:408:fe::8) by SJ1PR12MB6050.namprd12.prod.outlook.com (2603:10b6:a03:48b::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.32; Mon, 24 Jul 2023 03:41:37 +0000 Received: from BN8NAM11FT099.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fe:cafe::ba) by BN9PR03CA0123.outlook.office365.com (2603:10b6:408:fe::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.28 via Frontend Transport; Mon, 24 Jul 2023 03:41:37 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BN8NAM11FT099.mail.protection.outlook.com (10.13.177.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.24 via Frontend Transport; Mon, 24 Jul 2023 03:41:36 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Sun, 23 Jul 2023 20:41:25 -0700 Received: from nvidia.com (10.126.231.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Sun, 23 Jul 2023 20:41:21 -0700 From: Gavin Li To: , , , , , , , , , , , , CC: , , , , Subject: [PATCH net-next V3 2/4] virtio_net: extract get/set interrupt coalesce to a function Date: Mon, 24 Jul 2023 06:40:46 +0300 Message-ID: <20230724034048.51482-3-gavinl@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230724034048.51482-1-gavinl@nvidia.com> References: <20230724034048.51482-1-gavinl@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT099:EE_|SJ1PR12MB6050:EE_ X-MS-Office365-Filtering-Correlation-Id: 93be3d80-f69e-4fbe-619c-08db8bf7e221 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: F9DgAj4ndXfrcCZd3gR7AwsZnc6wtj8hd0mXQT4oEIrCvRXcNGD1pNkejQaNaiN6C75IVh3F6n25BT/RdACYnpFXiS/WcVQei1PGDIh7BU+lXGFbev+jI8BEJjEAYv2HlIXHDLY1ZafzeE6/JwtKhWS9g1oc/q/aSYydz5Q9GSZ9/jUkAtAEz7im4x2ISi+IN0kEqaEWHSHnELE1Ht6iILYoTzZpAc++uW16tpP1OMYB06DnLWafV96gUB3d6ewa7tBbqcM8iZedYfrBV98i4ngQ8W+uuxLLZ225Im3fpmwWteCUkgFA0yxBFnj2txDyAtHNPNbvqqbpzy3exAu5MDh2OZTQ8/C/TfU/ogqpivAc4v+pCJUVKr9jE6vTa/NGuiTuC/21FDviqYa0W1HsHnSGyT4m2adGaHqm0A1foIZENI4uywfHQNaqKoy6tr+b+bcpvYHMpnBb5mXmehDmNGP3yKY0I6aYtcbDXBeCTn4YTaCoZe4R7j+zeJoudfM2XPLmBxCDBD2ZoeCajh7Fbfl9SjyMaTj7JJdFkvrC8ZIhBc1QqyzFD4Er1SBFkitkc8+wsw8TYsT2MrpkGN9/ZMSSedxeB1l/19n/4Xi+Hq48nNnlPfxVzZY7FPScnRqT8BkpqHZ7+pTvwPz3PVkg8+SXHEXX5C1wdc+zQ8QSr9GEgjorx9YhjCVSx7Pl8Ni/rmYwAkc721TsrC3rDbHgZEedXuRDNPJAYDEAB9pcacRUBEO9TIrxrpEd1eIaXxyRL219WatY5CsabB5uASkPCE8rcNN4T3bqgMrAxmO8+8YV72v9gj+NXu2ePiLf1Ys8 X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(396003)(346002)(376002)(136003)(39860400002)(451199021)(82310400008)(40470700004)(36840700001)(46966006)(40460700003)(86362001)(82740400003)(356005)(921005)(7636003)(40480700001)(55016003)(2906002)(6666004)(7696005)(2616005)(426003)(47076005)(16526019)(1076003)(336012)(186003)(6286002)(26005)(36756003)(5660300002)(41300700001)(70586007)(70206006)(316002)(6636002)(4326008)(478600001)(7416002)(8676002)(8936002)(54906003)(110136005)(83380400001)(36860700001)(83996005)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jul 2023 03:41:36.8047 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 93be3d80-f69e-4fbe-619c-08db8bf7e221 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT099.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ1PR12MB6050 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Extract get/set interrupt coalesce to a function to be reused by global and per queue config. Signed-off-by: Gavin Li Reviewed-by: Dragos Tatulea Reviewed-by: Jiri Pirko Acked-by: Jason Wang Acked-by: Michael S. Tsirkin Reviewed-by: Heng Qi --- drivers/net/virtio_net.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index dd5fec073a27..802ed21453f5 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -3093,10 +3093,8 @@ static int virtnet_coal_params_supported(struct etht= ool_coalesce *ec) return 0; } =20 -static int virtnet_set_coalesce(struct net_device *dev, - struct ethtool_coalesce *ec, - struct kernel_ethtool_coalesce *kernel_coal, - struct netlink_ext_ack *extack) +static int virtnet_set_coalesce_one(struct net_device *dev, + struct ethtool_coalesce *ec) { struct virtnet_info *vi =3D netdev_priv(dev); int ret, i, napi_weight; @@ -3127,10 +3125,16 @@ static int virtnet_set_coalesce(struct net_device *= dev, return ret; } =20 -static int virtnet_get_coalesce(struct net_device *dev, +static int virtnet_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec, struct kernel_ethtool_coalesce *kernel_coal, struct netlink_ext_ack *extack) +{ + return virtnet_set_coalesce_one(dev, ec); +} + +static int virtnet_get_coalesce_one(struct net_device *dev, + struct ethtool_coalesce *ec) { struct virtnet_info *vi =3D netdev_priv(dev); =20 @@ -3149,6 +3153,14 @@ static int virtnet_get_coalesce(struct net_device *d= ev, return 0; } =20 +static int virtnet_get_coalesce(struct net_device *dev, + struct ethtool_coalesce *ec, + struct kernel_ethtool_coalesce *kernel_coal, + struct netlink_ext_ack *extack) +{ + return virtnet_get_coalesce_one(dev, ec); +} + static void virtnet_init_settings(struct net_device *dev) { struct virtnet_info *vi =3D netdev_priv(dev); --=20 2.39.1 From nobody Tue Sep 9 01:17:32 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51A45EB64DD for ; Mon, 24 Jul 2023 03:42:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229925AbjGXDmF (ORCPT ); Sun, 23 Jul 2023 23:42:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230099AbjGXDlx (ORCPT ); Sun, 23 Jul 2023 23:41:53 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2044.outbound.protection.outlook.com [40.107.244.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54898E70; Sun, 23 Jul 2023 20:41:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ky62tRQML8MpDd6PAaOuo+kit/wO3gK6owVgmFeb88NnZIYBlclqg8wq32sokCeSnkq/eAjQOXlhzYRTTN5cu8XzdHQYoUNzbS1KYN3O06+srgVQzFT4At7lV+4YIHbmBa9/KBzJM2L8vDUrQ2i69QSjlRaOzSt3d6RzdpZJvBUbrtIWri9rTCYHuYdhee1kACVDWv/WsLkTfSzSQ99r2Ycj/K1alnCZkeMBjjCEqHrh8uevWNQ0+jgAiSvRhuTG9SMmkNoV1wGXBLvttS8X2SpO/MGpexDORoUUVaxC6+LwpV3vXZy3szVruik64cOGFOKYGXtKOiirnzBg0Mu/4A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=KX5SGpxJxl1oANNUDFL2eDZTz44t12pk7QvPkVGEQSc=; b=L49WFVQRq1RXaqxQwdGaMnGa6OFoNmPZHuhDWmjC2CtFNXCqbjqx93gEpm1L3gcev+LyMnFM29QDfF5KNhvCRDW74LLcpzyIYyNcKUVNZjeHKvxsqANPI5u2aRYgh1Zr3ilhgO4M0NI2pj4NawGaonnSNArb1n5ZxUpiVwmmR964aM03ojEOjyIt6zx9/UQLJ1xgFj2E+t66v7F/huAx1H3LpdC8HT2I3hNyLq1i8LCYRGYSZCEvUj1YZvDDiGkdha83IMwiQLhylWPDrfO7fW7z6aAgZNbYUYncVEr/DzwsXKDTm/6jDt3e6MI8crYzMPgBNC2IFcx/QAa0hJHl8A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.160) smtp.rcpttodomain=redhat.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=KX5SGpxJxl1oANNUDFL2eDZTz44t12pk7QvPkVGEQSc=; b=UmUdIMOhdTEC53JjouB815flmihCuP0xbGaOF17zcjUvB0JSKa1cFFsbPpo0inmDEwDskUSNwA+R+GbIqht+8dgUgFTdF/PTHhKG3XnyK8mPA8QoPfXKkPxk8yy0vWUG1MG/DpbUg+1/CSTDirfk2cn4BazB65f1kWWZPHb9ZpdzVIhjtnXU7CLs+J/gJ9bM/8gBHogsyXucnUARC89u1jiLidQtqdfm7CWFB9FLBDynh+wZNXse39wrI2kSCr5AyPuWefW/BlvKi7jU4CfDMU8FR7mZA9sIVLkFTrEu6Azx8muboqLeFRJ4RJz+OU5rPXRefjEXhA+REtno6YbVpQ== Received: from BN9PR03CA0405.namprd03.prod.outlook.com (2603:10b6:408:111::20) by BL1PR12MB5045.namprd12.prod.outlook.com (2603:10b6:208:310::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.32; Mon, 24 Jul 2023 03:41:43 +0000 Received: from BN8NAM11FT023.eop-nam11.prod.protection.outlook.com (2603:10b6:408:111:cafe::cd) by BN9PR03CA0405.outlook.office365.com (2603:10b6:408:111::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.32 via Frontend Transport; Mon, 24 Jul 2023 03:41:43 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.160) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.160 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.160; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.160) by BN8NAM11FT023.mail.protection.outlook.com (10.13.177.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.24 via Frontend Transport; Mon, 24 Jul 2023 03:41:43 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Sun, 23 Jul 2023 20:41:30 -0700 Received: from nvidia.com (10.126.231.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Sun, 23 Jul 2023 20:41:25 -0700 From: Gavin Li To: , , , , , , , , , , , , CC: , , , , Subject: [PATCH net-next V3 3/4] virtio_net: support per queue interrupt coalesce command Date: Mon, 24 Jul 2023 06:40:47 +0300 Message-ID: <20230724034048.51482-4-gavinl@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230724034048.51482-1-gavinl@nvidia.com> References: <20230724034048.51482-1-gavinl@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BN8NAM11FT023:EE_|BL1PR12MB5045:EE_ X-MS-Office365-Filtering-Correlation-Id: 1ac13ff7-bcc0-49e9-ca1f-08db8bf7e5db X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: F5OHA18IbPW8EoQAPFE+j3KzhRM6iatAmQAMAZhw2KtJKXPjPeOYIg/D/uGZCNWQ98V2PlNkb14RhAMvtOUUprfjFlOYvNUaYiB03SKSBiLU0x3RjB9bKtkiDvsPRZgg1elWJyKZqgB+jSK1VdgTbmpdf17/6lFBXMiYTZopVFThzLJjRjygpXEFRL/IVEQekjXk86c6j+sH9Wj0acK5PO93K8ZugJHTXCl8KkYqmTJ2nXGIWyJQDx2xoNUQIiouc87xECKXtEWj+4ioUpDetMRtmKUY6n7KBreQChoD78qjRyxN6X2O4WaNJuszU5AlX/F6IciUcng5WN9xCpLSGNU42Sn9bxpsZ7hL7itDi/vgjDJytw1/AzaTA6Pi0x6P1SC2+DGZM6UzpbguW6um3Dlp7INlX6lpm8JF7hMtLzR9Er76DceLaTN0UkP5h8TdNgrwhuJ/zQojnOXx/WH2LufRICa9PCGqUSxI/uS1A2Ih0nnjGDclfskHvg9aHLJbzK8/b9/OIEVW+uJKw7w1N0cv0hVDklHzUGy3v9quXDHWZHUICjJiKPAvFjAIdwtrTN8pSw7mFOgzg5jeBlNhxSKzxaLGGmIEraHYGP7tCoMB5SIWqmXm42psCmoghhP6+TzcXYbUehDOk9HckpY6plZWUKaMp3ThY6rtkta9VDaawaNZp/dqaICO8NcTb+R3m7X4iaYXQPsQnneLlfGdq+VE5Jyc1SdKJHuqpBvH+BViSyE4rPoOS/89ZFHzM6yNtnDg94Tfz7ubETtI8IWCa9vOyJlq3V7bZowQ7MrDrgZtyPsnt1ynPyeVMuGKQ57c X-Forefront-Antispam-Report: CIP:216.228.117.160;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge1.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(396003)(136003)(376002)(346002)(39860400002)(451199021)(82310400008)(40470700004)(46966006)(36840700001)(2906002)(55016003)(40480700001)(7636003)(921005)(356005)(82740400003)(83380400001)(426003)(47076005)(16526019)(6286002)(186003)(336012)(2616005)(36860700001)(1076003)(26005)(40460700003)(5660300002)(86362001)(8936002)(8676002)(7416002)(36756003)(6666004)(478600001)(7696005)(4326008)(6636002)(70586007)(70206006)(316002)(110136005)(54906003)(41300700001)(2101003)(83996005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jul 2023 03:41:43.0595 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1ac13ff7-bcc0-49e9-ca1f-08db8bf7e5db X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.160];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT023.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR12MB5045 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add interrupt_coalesce config in send_queue and receive_queue to cache user config. Send per virtqueue interrupt moderation config to underline device in order to have more efficient interrupt moderation and cpu utilization of guest VM. Signed-off-by: Gavin Li Reviewed-by: Dragos Tatulea Reviewed-by: Jiri Pirko Acked-by: Michael S. Tsirkin Reviewed-by: Heng Qi --- drivers/net/virtio_net.c | 120 ++++++++++++++++++++++++++++---- include/uapi/linux/virtio_net.h | 14 ++++ 2 files changed, 122 insertions(+), 12 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 802ed21453f5..0c3ee1e26ece 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -144,6 +144,8 @@ struct send_queue { =20 struct virtnet_sq_stats stats; =20 + struct virtnet_interrupt_coalesce intr_coal; + struct napi_struct napi; =20 /* Record whether sq is in reset state. */ @@ -161,6 +163,8 @@ struct receive_queue { =20 struct virtnet_rq_stats stats; =20 + struct virtnet_interrupt_coalesce intr_coal; + /* Chain pages by the private ptr. */ struct page *pages; =20 @@ -212,6 +216,7 @@ struct control_buf { struct virtio_net_ctrl_rss rss; struct virtio_net_ctrl_coal_tx coal_tx; struct virtio_net_ctrl_coal_rx coal_rx; + struct virtio_net_ctrl_coal_vq coal_vq; }; =20 struct virtnet_info { @@ -3078,6 +3083,55 @@ static int virtnet_send_notf_coal_cmds(struct virtne= t_info *vi, return 0; } =20 +static int virtnet_send_ctrl_coal_vq_cmd(struct virtnet_info *vi, + u16 vqn, u32 max_usecs, u32 max_packets) +{ + struct scatterlist sgs; + + vi->ctrl->coal_vq.vqn =3D cpu_to_le16(vqn); + vi->ctrl->coal_vq.coal.max_usecs =3D cpu_to_le32(max_usecs); + vi->ctrl->coal_vq.coal.max_packets =3D cpu_to_le32(max_packets); + sg_init_one(&sgs, &vi->ctrl->coal_vq, sizeof(vi->ctrl->coal_vq)); + + if (!virtnet_send_command(vi, VIRTIO_NET_CTRL_NOTF_COAL, + VIRTIO_NET_CTRL_NOTF_COAL_VQ_SET, + &sgs)) + return -EINVAL; + + return 0; +} + +static int virtnet_send_notf_coal_vq_cmds(struct virtnet_info *vi, + struct ethtool_coalesce *ec, + u16 queue) +{ + int err; + + if (ec->rx_coalesce_usecs || ec->rx_max_coalesced_frames) { + err =3D virtnet_send_ctrl_coal_vq_cmd(vi, rxq2vq(queue), + ec->rx_coalesce_usecs, + ec->rx_max_coalesced_frames); + if (err) + return err; + /* Save parameters */ + vi->rq[queue].intr_coal.max_usecs =3D ec->rx_coalesce_usecs; + vi->rq[queue].intr_coal.max_packets =3D ec->rx_max_coalesced_frames; + } + + if (ec->tx_coalesce_usecs || ec->tx_max_coalesced_frames) { + err =3D virtnet_send_ctrl_coal_vq_cmd(vi, txq2vq(queue), + ec->tx_coalesce_usecs, + ec->tx_max_coalesced_frames); + if (err) + return err; + /* Save parameters */ + vi->sq[queue].intr_coal.max_usecs =3D ec->tx_coalesce_usecs; + vi->sq[queue].intr_coal.max_packets =3D ec->tx_max_coalesced_frames; + } + + return 0; +} + static int virtnet_coal_params_supported(struct ethtool_coalesce *ec) { /* usecs coalescing is supported only if VIRTIO_NET_F_NOTF_COAL @@ -3094,23 +3148,39 @@ static int virtnet_coal_params_supported(struct eth= tool_coalesce *ec) } =20 static int virtnet_set_coalesce_one(struct net_device *dev, - struct ethtool_coalesce *ec) + struct ethtool_coalesce *ec, + bool per_queue, + u32 queue) { struct virtnet_info *vi =3D netdev_priv(dev); - int ret, i, napi_weight; + int queue_count =3D per_queue ? 1 : vi->max_queue_pairs; + int queue_number =3D per_queue ? queue : 0; bool update_napi =3D false; + int ret, i, napi_weight; + + if (queue >=3D vi->max_queue_pairs) + return -EINVAL; =20 /* Can't change NAPI weight if the link is up */ napi_weight =3D ec->tx_max_coalesced_frames ? NAPI_POLL_WEIGHT : 0; - if (napi_weight ^ vi->sq[0].napi.weight) { - if (dev->flags & IFF_UP) - return -EBUSY; - else + for (i =3D queue_number; i < queue_count; i++) { + if (napi_weight ^ vi->sq[i].napi.weight) { + if (dev->flags & IFF_UP) + return -EBUSY; + update_napi =3D true; + /* All queues that belong to [queue_number, queue_count] will be + * updated for the sake of simplicity, which might not be necessary + */ + queue_number =3D i; + break; + } } =20 - if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_NOTF_COAL)) + if (!per_queue && virtio_has_feature(vi->vdev, VIRTIO_NET_F_NOTF_COAL)) ret =3D virtnet_send_notf_coal_cmds(vi, ec); + else if (per_queue && virtio_has_feature(vi->vdev, VIRTIO_NET_F_VQ_NOTF_C= OAL)) + ret =3D virtnet_send_notf_coal_vq_cmds(vi, ec, queue); else ret =3D virtnet_coal_params_supported(ec); =20 @@ -3118,7 +3188,7 @@ static int virtnet_set_coalesce_one(struct net_device= *dev, return ret; =20 if (update_napi) { - for (i =3D 0; i < vi->max_queue_pairs; i++) + for (i =3D queue_number; i < queue_count; i++) vi->sq[i].napi.weight =3D napi_weight; } =20 @@ -3130,19 +3200,29 @@ static int virtnet_set_coalesce(struct net_device *= dev, struct kernel_ethtool_coalesce *kernel_coal, struct netlink_ext_ack *extack) { - return virtnet_set_coalesce_one(dev, ec); + return virtnet_set_coalesce_one(dev, ec, false, 0); } =20 static int virtnet_get_coalesce_one(struct net_device *dev, - struct ethtool_coalesce *ec) + struct ethtool_coalesce *ec, + bool per_queue, + u32 queue) { struct virtnet_info *vi =3D netdev_priv(dev); =20 - if (virtio_has_feature(vi->vdev, VIRTIO_NET_F_NOTF_COAL)) { + if (queue >=3D vi->max_queue_pairs) + return -EINVAL; + + if (!per_queue && virtio_has_feature(vi->vdev, VIRTIO_NET_F_NOTF_COAL)) { ec->rx_coalesce_usecs =3D vi->intr_coal_rx.max_usecs; ec->tx_coalesce_usecs =3D vi->intr_coal_tx.max_usecs; ec->tx_max_coalesced_frames =3D vi->intr_coal_tx.max_packets; ec->rx_max_coalesced_frames =3D vi->intr_coal_rx.max_packets; + } else if (per_queue && virtio_has_feature(vi->vdev, VIRTIO_NET_F_VQ_NOTF= _COAL)) { + ec->rx_coalesce_usecs =3D vi->rq[queue].intr_coal.max_usecs; + ec->tx_coalesce_usecs =3D vi->sq[queue].intr_coal.max_usecs; + ec->tx_max_coalesced_frames =3D vi->sq[queue].intr_coal.max_packets; + ec->rx_max_coalesced_frames =3D vi->rq[queue].intr_coal.max_packets; } else { ec->rx_max_coalesced_frames =3D 1; =20 @@ -3158,7 +3238,21 @@ static int virtnet_get_coalesce(struct net_device *d= ev, struct kernel_ethtool_coalesce *kernel_coal, struct netlink_ext_ack *extack) { - return virtnet_get_coalesce_one(dev, ec); + return virtnet_get_coalesce_one(dev, ec, false, 0); +} + +static int virtnet_set_per_queue_coalesce(struct net_device *dev, + u32 queue, + struct ethtool_coalesce *ec) +{ + return virtnet_set_coalesce_one(dev, ec, true, queue); +} + +static int virtnet_get_per_queue_coalesce(struct net_device *dev, + u32 queue, + struct ethtool_coalesce *ec) +{ + return virtnet_get_coalesce_one(dev, ec, true, queue); } =20 static void virtnet_init_settings(struct net_device *dev) @@ -3291,6 +3385,8 @@ static const struct ethtool_ops virtnet_ethtool_ops = =3D { .set_link_ksettings =3D virtnet_set_link_ksettings, .set_coalesce =3D virtnet_set_coalesce, .get_coalesce =3D virtnet_get_coalesce, + .set_per_queue_coalesce =3D virtnet_set_per_queue_coalesce, + .get_per_queue_coalesce =3D virtnet_get_per_queue_coalesce, .get_rxfh_key_size =3D virtnet_get_rxfh_key_size, .get_rxfh_indir_size =3D virtnet_get_rxfh_indir_size, .get_rxfh =3D virtnet_get_rxfh, diff --git a/include/uapi/linux/virtio_net.h b/include/uapi/linux/virtio_ne= t.h index 12c1c9699935..cc65ef0f3c3e 100644 --- a/include/uapi/linux/virtio_net.h +++ b/include/uapi/linux/virtio_net.h @@ -56,6 +56,7 @@ #define VIRTIO_NET_F_MQ 22 /* Device supports Receive Flow * Steering */ #define VIRTIO_NET_F_CTRL_MAC_ADDR 23 /* Set MAC address */ +#define VIRTIO_NET_F_VQ_NOTF_COAL 52 /* Device supports virtqueue notifica= tion coalescing */ #define VIRTIO_NET_F_NOTF_COAL 53 /* Device supports notifications coalesc= ing */ #define VIRTIO_NET_F_GUEST_USO4 54 /* Guest can handle USOv4 in. */ #define VIRTIO_NET_F_GUEST_USO6 55 /* Guest can handle USOv6 in. */ @@ -391,5 +392,18 @@ struct virtio_net_ctrl_coal_rx { }; =20 #define VIRTIO_NET_CTRL_NOTF_COAL_RX_SET 1 +#define VIRTIO_NET_CTRL_NOTF_COAL_VQ_SET 2 +#define VIRTIO_NET_CTRL_NOTF_COAL_VQ_GET 3 + +struct virtio_net_ctrl_coal { + __le32 max_packets; + __le32 max_usecs; +}; + +struct virtio_net_ctrl_coal_vq { + __le16 vqn; + __le16 reserved; + struct virtio_net_ctrl_coal coal; +}; =20 #endif /* _UAPI_LINUX_VIRTIO_NET_H */ --=20 2.39.1 From nobody Tue Sep 9 01:17:32 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC950EB64DD for ; Mon, 24 Jul 2023 03:42:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230090AbjGXDmL (ORCPT ); Sun, 23 Jul 2023 23:42:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229645AbjGXDmC (ORCPT ); Sun, 23 Jul 2023 23:42:02 -0400 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2047.outbound.protection.outlook.com [40.107.94.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DE3910C8; Sun, 23 Jul 2023 20:41:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CV0NF+n57gn/kXZ4c+yviS/dLCz08jUcyYkLULs+zWcpgc6cKzVtxb4Cs0INVPAVdCmLuklNzpvd122cSmKr6Cel+YWdlyNDy8pH5gu6QB72k7RZmnkASyefaMWiKmtrKZYRlZ1S+nZleqYOUdLwjkMPzBvgENslxa/LCQ1uaMhv2L/Od/0pxwOgUXPo71I2Wpacdkvs4QYOj85dHveiCcPo4hpmk2QnTBzeSggvNec9a8bwsaFaJvhxBjDXqFs8mlxFevqmDT8ZDjVPfNCMxaCB78TFQghCK0KzttUS3c2j+mHAejksCrM2fuY99jiHm35VryuysLAKxClCIA9QqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=RuBoUM/RIGTCyYd/wQd3oZEgZE1JEa2nvlIobdk6q50=; b=DIAQnovMdpPj9XLg/eiaNt9tYzFaynnik6ymeUPrw50lsb9CA95VqEXTnOJm6aBCLDe29ylKWY/pVhSZ0qFMeqdwq4ZyzajsvZxgqFcmkurv+zXUxp1B10P/lFx0w/oXT6Be/1wprPBofiNG/OvS4FMyQWFG/6n2+d3QG0cll+tfZpNAj9I5051mbNR3txNOEV/72dito7HeOc/9HkTU5IbKFjhcIOt3wnRewm6E4IEBAYhvxwh5W1huH9QhNLrthKewnllotJXLgAPKu94Atqo3QauRTkyOJpxJ//jFgu785+tr86LnYgxYt/IRRrSVIIbeAXBkZDLU9N0Mla60Cg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.117.161) smtp.rcpttodomain=redhat.com smtp.mailfrom=nvidia.com; dmarc=pass (p=reject sp=reject pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=RuBoUM/RIGTCyYd/wQd3oZEgZE1JEa2nvlIobdk6q50=; b=qX+HqzG7IrLSfgNjpNklZ4pfIyryZjH98dICGcQOJDmk5zcI43yoOLce9AeJ5fU4eRJlkNUtGba76CSezyBc3+uyjiP50HQWzHprCWK6XDDPJ5Ru8erhETDObNnG7CuMytkmzrqjbkwgaNW09cp+ELnyLb6xF9t838N69WI9OEDCmwAWf4n8g9qVZjPhayb6o8KXw2ENhmi9BaXvCW077moPxfcDy6BmaXZ+PGV9obFcCa4kh0Y7Cgb4YYWzryi4uhtHKyw2q3AfIKvrLT/xcXuYwGm864RoRZnt3wF2KWE1x/4z2bx8Jst2cVx+MF5gtPC8DHe5XPc1JWvGid47SA== Received: from MW4PR04CA0116.namprd04.prod.outlook.com (2603:10b6:303:83::31) by MW4PR12MB6873.namprd12.prod.outlook.com (2603:10b6:303:20c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.32; Mon, 24 Jul 2023 03:41:46 +0000 Received: from CO1NAM11FT016.eop-nam11.prod.protection.outlook.com (2603:10b6:303:83:cafe::36) by MW4PR04CA0116.outlook.office365.com (2603:10b6:303:83::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.28 via Frontend Transport; Mon, 24 Jul 2023 03:41:45 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.117.161) smtp.mailfrom=nvidia.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.117.161 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.117.161; helo=mail.nvidia.com; pr=C Received: from mail.nvidia.com (216.228.117.161) by CO1NAM11FT016.mail.protection.outlook.com (10.13.175.141) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.24 via Frontend Transport; Mon, 24 Jul 2023 03:41:44 +0000 Received: from rnnvmail201.nvidia.com (10.129.68.8) by mail.nvidia.com (10.129.200.67) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.5; Sun, 23 Jul 2023 20:41:35 -0700 Received: from nvidia.com (10.126.231.35) by rnnvmail201.nvidia.com (10.129.68.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.37; Sun, 23 Jul 2023 20:41:30 -0700 From: Gavin Li To: , , , , , , , , , , , , CC: , , , , Subject: [PATCH net-next V3 4/4] virtio_net: enable per queue interrupt coalesce feature Date: Mon, 24 Jul 2023 06:40:48 +0300 Message-ID: <20230724034048.51482-5-gavinl@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230724034048.51482-1-gavinl@nvidia.com> References: <20230724034048.51482-1-gavinl@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.126.231.35] X-ClientProxiedBy: rnnvmail202.nvidia.com (10.129.68.7) To rnnvmail201.nvidia.com (10.129.68.8) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT016:EE_|MW4PR12MB6873:EE_ X-MS-Office365-Filtering-Correlation-Id: 7ac3734c-8a1a-4369-efc2-08db8bf7e6e3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JX7x/o7TiuM/fzN8t655dQUd1YzlWg6lWcZpgZ1oiM6lK8ecjLXHuZXwWMPm3mCXj8o0Z9tKj2tHZrW2GdPBmVXHJg2ArTx39UflWplyrpKXskbjtANwi57fU+eoaEp8dBT+kk8nOxadAITR+8j99cM3w63CSot1ocNGJhIJc+EZ1Sjer0HjVVKolSN9p4ut+hJHvlcXwXl3k0VfNETUzx9uttBjb2UIL3Qveo92ofkMVhVgVwQ29e9qD7wKYwKRe+x1IjbFqaVTU1c/QHEyfq08xVXfPtAFw8qe7Jw15SS8Vkq0xXr76RF9GpUznvrLGcFEKvo7H1pHSejjBKNq7LxsmYXd27WuHBFvxmYOsp0VYQKBwBm0WFaI+c+OliwXH6gVbCMH4PIMsj35DWbz2tGZaUC2wyFxpBJioFUPtt9BrywRnZccOocdkygq+LqWpY02z+HmVAwUSHD+YSbcDYKG399gkXwys8qOR40ZDL0EWJwEaAxyVdVgRI7FzxsrRrm9t00z9Y+ul727Qv/ybZak5NyGW2HiQgFvf0tVVf6/YEkTL638DF7Y6RCgG6PCBrnmU62TcvDJ2ale/0SeiQT03FRxebrhKaavQZtZleT977drZITbXQscBEObYLP/hs+mNBzvWMqZbCw+2NGYRkDXZtiCqi/HY6XkBRoqyPertKtraZhEJt/M5pJnYlDrvvHjP1gG1sHqGfqB/tHfjrvIE9zk4e+Gs+hJvg/2srmP0ZwckMwvxQA6IaYxAEK0pk4fT3iqX34t9n4jcQWjeeGbkxwexZytHJxqsQYT+8eKn3gs47MEx/NffkUCBQjq X-Forefront-Antispam-Report: CIP:216.228.117.161;CTRY:US;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:mail.nvidia.com;PTR:dc6edge2.nvidia.com;CAT:NONE;SFS:(13230028)(4636009)(376002)(136003)(39860400002)(346002)(396003)(82310400008)(451199021)(36840700001)(46966006)(40470700004)(36860700001)(83380400001)(40480700001)(36756003)(86362001)(82740400003)(40460700003)(7636003)(921005)(356005)(55016003)(54906003)(110136005)(2906002)(478600001)(336012)(186003)(26005)(6286002)(1076003)(7696005)(6666004)(5660300002)(8676002)(7416002)(8936002)(316002)(41300700001)(70586007)(70206006)(6636002)(4326008)(16526019)(47076005)(2616005)(426003)(83996005)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jul 2023 03:41:44.8375 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 7ac3734c-8a1a-4369-efc2-08db8bf7e6e3 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a;Ip=[216.228.117.161];Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT016.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB6873 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Enable per queue interrupt coalesce feature bit in driver and validate its dependency with control queue. Signed-off-by: Gavin Li Reviewed-by: Dragos Tatulea Reviewed-by: Jiri Pirko Acked-by: Michael S. Tsirkin Reviewed-by: Heng Qi --- drivers/net/virtio_net.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 0c3ee1e26ece..a03289da9f51 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -4063,6 +4063,8 @@ static bool virtnet_validate_features(struct virtio_d= evice *vdev) VIRTNET_FAIL_ON(vdev, VIRTIO_NET_F_HASH_REPORT, "VIRTIO_NET_F_CTRL_VQ") || VIRTNET_FAIL_ON(vdev, VIRTIO_NET_F_NOTF_COAL, + "VIRTIO_NET_F_CTRL_VQ") || + VIRTNET_FAIL_ON(vdev, VIRTIO_NET_F_VQ_NOTF_COAL, "VIRTIO_NET_F_CTRL_VQ"))) { return false; } @@ -4487,6 +4489,7 @@ static struct virtio_device_id id_table[] =3D { VIRTIO_NET_F_MTU, VIRTIO_NET_F_CTRL_GUEST_OFFLOADS, \ VIRTIO_NET_F_SPEED_DUPLEX, VIRTIO_NET_F_STANDBY, \ VIRTIO_NET_F_RSS, VIRTIO_NET_F_HASH_REPORT, VIRTIO_NET_F_NOTF_COAL, \ + VIRTIO_NET_F_VQ_NOTF_COAL, \ VIRTIO_NET_F_GUEST_HDRLEN =20 static unsigned int features[] =3D { --=20 2.39.1