From nobody Sun Feb 8 21:26:40 2026 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 CE017EB64D9 for ; Mon, 10 Jul 2023 09:21:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230450AbjGJJVN (ORCPT ); Mon, 10 Jul 2023 05:21:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229522AbjGJJVL (ORCPT ); Mon, 10 Jul 2023 05:21:11 -0400 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2057.outbound.protection.outlook.com [40.107.244.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 297318E; Mon, 10 Jul 2023 02:21:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G6y/Y/d/q73UlUiSAUGzoy2RzcYa/2e16E4pNgDBhG+P8bmXsQLR7FBCbhQGH/xfshuglYWMCOT60ZED08BW8OxuQ9eIwr1DSq/6+L0L3tuLuFSRvG+xDp/v9ZMbLQSRqWWn+Kl8ps8WSyP2zt4mi7qX/MFQTP099thjvy6DprdykwJZuQ0GWQfSXb2k/qbZ0bOBZxKBzqtvJoFGGrUQyjAT/2GStpNCEC7dTkzkR5BFvYQ739qCSAOCk0cLPyEv8W9TSOGz8R3RVQFLubU5t5pqgYRkQ6/ch41BmcOMmOSVhqTB6+qU2hWvqC+M0HJlrxQCZEFGZoYYCzaKMpSqvA== 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=9T7xFue66UabcZ5Lt5gTbUtfirJ4UZ7HQaMClC0DXU0=; b=LDWhAEtfYeCfJ1+AEGgspsBuooHnkUY2kxVIg2hAkU4YWmbH3jbYL9VXh+FlxK/LqAoKH36tcOcfo5zOZiewYYwp4P6m95MYtud0JVU1mkrsk8rOFgV8eVL1QaeaDgadrgJInfkdnYc20dRWMSv9SRDspqwacdTjn7Q1Xbm70hFoiu+/zsc88mDnKLhK5KS2plXd9zTRU8YwhnUTI/N0hUeUEJDArOvlFNmgldHSLMFS0n5MWjdAdu5R+thW5u09J/3p9atQY2cu2LXi8VnIfklcdCDzwky8hxpCLsyeuMtVi3GYclFwCbEzR5BvxsoAhRyyuOGmv0D88zuztDOhQQ== 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=9T7xFue66UabcZ5Lt5gTbUtfirJ4UZ7HQaMClC0DXU0=; b=qZPJoZUHVBuklFy+TI9Q6wfqSNB2lu2iR9oiSLSH6ggKROdByzX+WsBuTuQmyraSABOKWGZZ+I56Iy12JbQUf0atrgZaeDZMPOUg4xI037/PlTllEhAd6tOXjZZvKJPPsv6apoLo/blN/3pJ+6JhnBQXek6Wo8N/1+MsqW3D7pjdWSs4ruXsOysgcXh9Ta/Bg4hkXp9kYekksJlCUhQ4uK6lRxvhv+6bCsVr24pFGloDxsKxEFMSbu88PQ2s1wEsCjP0BjEI9Z8eGBaOywgGslWSdZ4VBZuG+hgSmVgZHb91zTKlH/l8IzQ/rw0oohYjFVvMkRR8ee+vaMxX4Mu74Q== Received: from MW4P221CA0015.NAMP221.PROD.OUTLOOK.COM (2603:10b6:303:8b::20) by SJ0PR12MB6734.namprd12.prod.outlook.com (2603:10b6:a03:478::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.30; Mon, 10 Jul 2023 09:21:01 +0000 Received: from CO1NAM11FT037.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8b:cafe::24) by MW4P221CA0015.outlook.office365.com (2603:10b6:303:8b::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.31 via Frontend Transport; Mon, 10 Jul 2023 09:21:01 +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 CO1NAM11FT037.mail.protection.outlook.com (10.13.174.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6521.44 via Frontend Transport; Mon, 10 Jul 2023 09:21:01 +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; Mon, 10 Jul 2023 02:20:53 -0700 Received: from nvidia.com (10.126.230.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; Mon, 10 Jul 2023 02:20:48 -0700 From: Gavin Li To: , , , , , , , , , , , , CC: , , , Subject: [PATCH net-next V1 1/4] virtio_net: extract interrupt coalescing settings to a structure Date: Mon, 10 Jul 2023 12:20:02 +0300 Message-ID: <20230710092005.5062-2-gavinl@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230710092005.5062-1-gavinl@nvidia.com> References: <20230710092005.5062-1-gavinl@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.126.230.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: CO1NAM11FT037:EE_|SJ0PR12MB6734:EE_ X-MS-Office365-Filtering-Correlation-Id: 90d1cd04-fa29-4ffe-9840-08db8126fa60 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XT9WnnlzTMj3qE/5owCKt2GquHRU96qeZJE1ZR4jv32g8kw8gvJLKoo17MMsNWzC/UoENQpoOEPxhoLoAQIyfWLRFzGU/Uhvjwsh/CjapxvQUPXwK2WYxvxX8iICXiwxdXVpy4rpODC3OaQxT3bFQ9Ge1EQDNAW8oWPsMtZ/kKez2wHCwvWh75wCPuOcqyuJ7Kao2vrqUB070fFyvn94/OPx6Jm509Oed9+63XYtIyrFH++dsnbYtR18NmZC07kWRpUQnTlIwdASBOd+Y8Bk+VXE8/RogsIgY2YtsbqFVv3e21xlak8kq+bYkuyGHImB88+WOOPTgPTAa9GhMblLVjQ7Viy9A1pLJ4QigWrKxW4Jv7ysJ5c84dTw27ME8TZ9U6cqX4x5Iro4Jie/FOC/4sv0Nbphl+puEKrlErjVPSZszv/1ycqiFZ9E3RSIn+xvEvXxqUDtmfC9ug1m9o6Z5tkrRLwaZ3HGAmG1W25HRq7WWi1/B4LtPFjzznPJq1BKomrVcYvQKUPa4lSZdU+Q/1JC8WbLbCChYTcNmf8Jj7woBf7kqia4IpDa99ijKQ1733z/pMDc5R+bG9BS7gvEgadAuNWOzryGBYi1x0UkRqmp3txG3wXvseqxvQmVo5Q0MgRSoBcU/tZfvVQLEVkRr19grO9CZ4pdOAkb3MBFQbhoW3m66Db6g08NQnUVCqVdsnRroqFR2wClsIj2LJeqzvCLbQDi8lrlbRDy+cLC/DoVflMZe/muWXTjUYPkEqkxalHBB2ByeL633XRhloHkq2VHV+cXfavBKhnu0yvz51mRtmohsCcpXFyg26Aydi+D 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)(346002)(136003)(39860400002)(396003)(376002)(451199021)(40470700004)(36840700001)(46966006)(6666004)(7696005)(478600001)(110136005)(54906003)(6286002)(1076003)(26005)(186003)(36756003)(16526019)(2906002)(82310400005)(70586007)(70206006)(41300700001)(6636002)(4326008)(5660300002)(7416002)(8936002)(316002)(921005)(82740400003)(8676002)(7636003)(356005)(2616005)(40460700003)(86362001)(36860700001)(83380400001)(47076005)(336012)(426003)(40480700001)(55016003)(2101003)(83996005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jul 2023 09:21:01.1338 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 90d1cd04-fa29-4ffe-9840-08db8126fa60 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: CO1NAM11FT037.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR12MB6734 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: Michael S. Tsirkin --- 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 Sun Feb 8 21:26:40 2026 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 C5716EB64DA for ; Mon, 10 Jul 2023 09:21:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229792AbjGJJV1 (ORCPT ); Mon, 10 Jul 2023 05:21:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231702AbjGJJVV (ORCPT ); Mon, 10 Jul 2023 05:21:21 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2081.outbound.protection.outlook.com [40.107.243.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 420D0EB; Mon, 10 Jul 2023 02:21:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dGx1Cy3B+fvFSE0xF0Ufukj+ggkmMOJ1Vv3iNJ5G82FqeYHzOGO9wuh4Or5T8J9rB9jw/Usv15XsnGSwuFZ0JRGHpnFHNoamXP3tOL17ryKhrC6pYJf2HxaZE8b81UcnH/vi7aGhoCz9DmacCNs4XfZaZjWcZrZLA99yFcSohC9fhttyYlQLYNeKbOtzdYv5d6L2CqIGmhlbwgW2slphGV8rJwLYtflXX/+U365cuBKaZ8t52DH1DEJ6Hx5FCC4Lz4AQtwzy8gJbF4YEp/eI140f3XF+KGPWOKItP1THxyDVvIAVBX/B9cOfsPnf9aa8F+83h3GxFX31J3yQu66kpA== 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=tnwAzz5ZvOGHhKN+xXy7unvd0kcKuNmiauGFOL0S3gM=; b=mQN+GCbh7cadxSkPypvX1OzvkOeKP69vwYb6gfl14TDjnXd4iocXAL5h+kgkdQOlQrtUEk/RCXkRwRjvHEA7VO79B+v/ENbAE4VsEwnaNAoV6YzPJ2dlo0QaTDUXWZXGZbvzwspEhsWvuTYvu0jA5vA8rZmNQ1HNp98UEU59YeKo5aJZGpE7n1ZHTdAhLnGqG1s6AjvsOR+MZG7Qe/BuiyoylsE6BsDfppebT3KFG/Uy2dypeSg/aa2r6mnPruryy68bnvQbzbhLLdLIAOP9JcBNebR8SJw6b9wQwOe1jlMBZqTNYckbrciWh7PZxQzzSpy/dBp0bJa4i43fkWGQiA== 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=tnwAzz5ZvOGHhKN+xXy7unvd0kcKuNmiauGFOL0S3gM=; b=RrQA/FJMPiQ2rBUaDtDB6gxLNUiqTm6k+tDHuVkRmPsINXFxhCqvqryTU5X+qAQLJ/t8gq5maWGz9aXfh3tgerb6LV4eWm2+/aKAon9VeXKVLDbD+GOMU+NVwPzAGd8UMUCGk0jCRIWDPSUmFkTKcjMHUkYippg3oIEk8S4wi8zcgvtLX/n79pnEslA6j4T7JyAgLVeFq3AfMl4oI3Hu4jA/WpBGKjrPYOxQJbm7ZkjwJQkgatVbOx2NC6/q9qeht0szxDH/d3sABGULU1nLUYSLPv4OX1C0SkHWe5Sg8DGeTVFRybYEIuldzTK5v9FZfZU+Y7hpIB8pjd8O8+e+hw== Received: from BN8PR15CA0065.namprd15.prod.outlook.com (2603:10b6:408:80::42) by CH3PR12MB9077.namprd12.prod.outlook.com (2603:10b6:610:1a2::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.31; Mon, 10 Jul 2023 09:21:18 +0000 Received: from BN8NAM11FT089.eop-nam11.prod.protection.outlook.com (2603:10b6:408:80:cafe::a2) by BN8PR15CA0065.outlook.office365.com (2603:10b6:408:80::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.31 via Frontend Transport; Mon, 10 Jul 2023 09:21:18 +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 BN8NAM11FT089.mail.protection.outlook.com (10.13.176.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.18 via Frontend Transport; Mon, 10 Jul 2023 09:21:18 +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; Mon, 10 Jul 2023 02:20:57 -0700 Received: from nvidia.com (10.126.230.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; Mon, 10 Jul 2023 02:20:53 -0700 From: Gavin Li To: , , , , , , , , , , , , CC: , , , Subject: [PATCH net-next V1 2/4] virtio_net: extract get/set interrupt coalesce to a function Date: Mon, 10 Jul 2023 12:20:03 +0300 Message-ID: <20230710092005.5062-3-gavinl@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230710092005.5062-1-gavinl@nvidia.com> References: <20230710092005.5062-1-gavinl@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.126.230.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: BN8NAM11FT089:EE_|CH3PR12MB9077:EE_ X-MS-Office365-Filtering-Correlation-Id: 8e69d6d0-4de7-4d6a-35d8-08db812704a5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vFUX1LGVEG1e4KgJ1fKiU4gEzUMjaRvqr6qDbSydAZkcisDG8EWi2BPKU7C7p92X5pCEztVm1sF+zDlKDVbcUpeHFekOL8VggLoS25HtDY8NdUv5vtn/0Hd1ljYlwWoZ1a4TXOVc5eBGDKPAJOisZrrHzpFbVpD4lRBlS+Z4ohrNOczIi6uLMO2FSqGk0RzgFH18nfyWetbJhuRki2X3Oq6x1Tfb2pRHE4RH8TIH+MrSc6G3MdCFhjXnMFT6AgUiA/L+Lv8TYE0am+H1uCWhJXCdKSkTG6u6V1X2hS9MXYM10er4jAz5ulhMAt+mEuYmsPpy4/euVVF4nQIRuvnb6Snv7ceXDYebJdyuM8OzWsAy9gcv40q/HdmAxDkHSQ6HGAMwVCUs9+k8p0BUxfrfYXY37iOgPK5xHCQUUA+PAOUcMxL33c0gYAA0U+4MKgrJ/B/UhkkstUwgRzj3HXGQEV+JVQ/8GilbWgKBoOEVndTkGlO0igwf/PESHmfooq5o4uAw9jMq9FOPtTR8sIy+CXH9G0RwjJLJbcjlmhBKnP5Tc6IiiXzYmbBTZiDF+JHpjELapaWx4ynzDfCgeC+Qa3LrmSwn+CG0VyIJBEultnum4NMRaIE4+EboX1Jeh3v2KUYmfD2txV/E9I/ztrshJvx1jXaUzIxI0gYsIeRsS2VYYpDcteKYERHrVjGEpYemMfVj52KVGw9u2Q9SDlntQ3KS5mLPcxh9Ot+KKZj0ftePHDhV9rAvD68Wr5vUMam87za3pulgcxOuOJitWmfdP5LAAjSSmTDZyv7BWGrqd4eGa/d/L9+IkacpDgEFVYu4 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)(136003)(346002)(39860400002)(376002)(396003)(451199021)(36840700001)(40470700004)(46966006)(36860700001)(82310400005)(36756003)(86362001)(40480700001)(55016003)(40460700003)(921005)(356005)(7636003)(82740400003)(478600001)(110136005)(6666004)(54906003)(7696005)(8936002)(8676002)(5660300002)(7416002)(316002)(2906002)(6636002)(4326008)(70586007)(70206006)(41300700001)(2616005)(336012)(426003)(26005)(47076005)(1076003)(186003)(16526019)(83380400001)(6286002)(83996005)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jul 2023 09:21:18.2669 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8e69d6d0-4de7-4d6a-35d8-08db812704a5 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: BN8NAM11FT089.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB9077 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: Michael S. Tsirkin --- 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 Sun Feb 8 21:26:40 2026 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 DAFC5EB64DA for ; Mon, 10 Jul 2023 09:21:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230477AbjGJJVo (ORCPT ); Mon, 10 Jul 2023 05:21:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232049AbjGJJVi (ORCPT ); Mon, 10 Jul 2023 05:21:38 -0400 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on20628.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e88::628]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 015818E; Mon, 10 Jul 2023 02:21:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jxndD8bttaTnbolfHJq4coRzXkMEyGcRu0ba5r6vrO7bvu/jWKA27KYgyWtCUTMLGvzyVB7jIPK33dFsw7rFY5wZf0KM6k3OA9ps0Ayp+acRa8TAZrL3L33yfLNHuHPFoplk0DuzDp2/YSprxSb7DMw1DnRLFLDKYOojOUjQFh5y5UF0iY0MdqCpSP+79X5S9jOp2/GqUGr4ZoEQmDd/0/yt2eHLJAIXwCO81Ms4717AmFO4b2uy1dpoQqg8Buxcpcu5gnQikC02aCOBh0x/4nClJEANAC6AoyAkk1KFRa09VKdULfQxMtRPkcpGUYpRNIUrQniXFJ0ttL0Rgt32hw== 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=4SWmaZkssxm/63HkKMMcLHDwl31FnbHnufrPN+g/VQ0=; b=I9oNrPMYnJ32My6mF5uVZYQuNa+yCz5MBxy39e0UNBEN05IZZS2FHmz3cHSZWsglCg+MzNVmN8dB6W8y8fi1edCmj9eHqvO0Dx6sEE+2TqxTAWuzqlx8eAcZdpSYopISvWQ2lTkRgmCTjUkP908FjSELGjJgmT++xl+gQbujRc3V71+JRwRrF5md8q2HUi2jYpjMg2XpLv5zQaq44kKp9b1dJmmSpxi9g0VZysTADOuXbaE1Fl/BEQq0kkc/ZStLi4w9l5XCEagApBZFulH/yZXhQHtiivAwuA/yUjPUsJaiHjRpQTFTCjjSyv5iN8ocKJn2AQu7jvuC5FJxMNCmHQ== 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=4SWmaZkssxm/63HkKMMcLHDwl31FnbHnufrPN+g/VQ0=; b=JRhT99n2pfeR64O9iN/FAAZjtiLqAUxqfScMcgeTsU/YPiBrA6l5/6CmBtQD59lfyg1dCqcocKu5T7nkqxcH+9cumLXQfLjXSHTy0bYVIbg3Rk2io4ejl7Sk0Cv19DHps6a9AOgAS2M+hHD7iZgCHOKCCXDCYBHB2NLdS85WfhLuZCxpJdoTU7YP950H88u3BBXoVhQJ3GqU0d2/aFNWXO8ttVPk5CEYEDYJ2ah3wv73fcNhvaswSYmFuYbLhqQ3XZkAN5bGeCkLz1I1EtjBXrt1XHIN++6fmhj7GWGwPko2SIwOWFQnxHQ8xFGiL9XoSniSUwCMTy6NEgQLI0qaqw== Received: from BN0PR03CA0034.namprd03.prod.outlook.com (2603:10b6:408:e7::9) by MW6PR12MB8661.namprd12.prod.outlook.com (2603:10b6:303:23f::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.26; Mon, 10 Jul 2023 09:21:22 +0000 Received: from BN8NAM11FT019.eop-nam11.prod.protection.outlook.com (2603:10b6:408:e7:cafe::94) by BN0PR03CA0034.outlook.office365.com (2603:10b6:408:e7::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.30 via Frontend Transport; Mon, 10 Jul 2023 09:21:22 +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 BN8NAM11FT019.mail.protection.outlook.com (10.13.176.158) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.19 via Frontend Transport; Mon, 10 Jul 2023 09:21:22 +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; Mon, 10 Jul 2023 02:21:02 -0700 Received: from nvidia.com (10.126.230.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; Mon, 10 Jul 2023 02:20:57 -0700 From: Gavin Li To: , , , , , , , , , , , , CC: , , , Subject: [PATCH net-next V1 3/4] virtio_net: support per queue interrupt coalesce command Date: Mon, 10 Jul 2023 12:20:04 +0300 Message-ID: <20230710092005.5062-4-gavinl@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230710092005.5062-1-gavinl@nvidia.com> References: <20230710092005.5062-1-gavinl@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.126.230.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: BN8NAM11FT019:EE_|MW6PR12MB8661:EE_ X-MS-Office365-Filtering-Correlation-Id: 8aae8c8b-4f67-4639-aef6-08db8127071b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OALTX+Ne+i6ZhZUj1MpGw7DveHmmuTGo+5QATLUNqkcAenhbaj82dL5eI0EAw4ycVKfy83V0Fqx3Wl4fFKQwyZK+WhwuZjfcMf83BqrBSibeWrzvpzNwMrf7DzY029UMgHVIGhmAz7kaqJ0EpwDe7c6gQNGBxEe73+PgLtVzfha+RjY1BQgq78+CcWAABX1zPXesqM6tTXF7z3jO9A+nPzhNI1RpnzFlo+SIKOSysd2xpk9SYR1M+FoLDAcD6Ho7xNxyELcVeoD8i5sit6H9YqKmKyhnhriX83Kv3ArpiUucl9ZrG3vlaK/1DW1MtaIzajZ+qGAvL7khU8x1gOydGNuL1Ms93avr9FAXT2wiqqmFZv3Cs6qKZm/YGga9rNSXmyUiEiMxCj1FXRzGG14Nt1L23qsMok3Ezm9HCPe/zzoEhR1r4T1WLfvnadMCgvXQBjRLqJwbRIFjb7dyGm9sQBOpJGmhWln25hNcrXAqdnV2QL58MZCEwrkZSSwzEVD7egJpNce4d3n2KkmjCTEea2/8YtUZ0knGr49GEeLBGOamPXqL/TbW+rga+eku3KLecGIu2kJQuCKhhmQJ6yZWcqllUb+m8cHGpXNjOViFMlXUFJ0OgWFIg0yaICg65cIJACxn8EzeMAREaayGLtSfhYke0vGpYeIfCR2KzCQhg8Rartm79Gx8NAJ9xM8fSVc0BtB+6jTWolKScbg19X9Py28kWSSQY2XYOTZ3cCytJakb6c7KXnyBtYqjLMapITGuUF06+/FM/XrD5G8AUo2TTdlzCosac8OeGbMlIwKd7Fc= 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)(396003)(136003)(39860400002)(346002)(451199021)(46966006)(40470700004)(36840700001)(7696005)(478600001)(110136005)(54906003)(6666004)(6286002)(1076003)(16526019)(26005)(186003)(2906002)(70586007)(82310400005)(5660300002)(316002)(41300700001)(8936002)(4326008)(8676002)(70206006)(7416002)(356005)(82740400003)(6636002)(921005)(7636003)(40460700003)(36756003)(86362001)(2616005)(83380400001)(47076005)(426003)(336012)(40480700001)(55016003)(36860700001)(2101003)(83996005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jul 2023 09:21:22.3832 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8aae8c8b-4f67-4639-aef6-08db8127071b 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: BN8NAM11FT019.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8661 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 --- drivers/net/virtio_net.c | 117 ++++++++++++++++++++++++++++---- include/uapi/linux/virtio_net.h | 14 ++++ 2 files changed, 119 insertions(+), 12 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 802ed21453f5..333a38e1941f 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 @@ -3078,6 +3082,56 @@ 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 virtio_net_ctrl_coal_vq coal_vq =3D {}; + struct scatterlist sgs; + + coal_vq.vqn =3D cpu_to_le16(vqn); + coal_vq.coal.max_usecs =3D cpu_to_le32(max_usecs); + coal_vq.coal.max_packets =3D cpu_to_le32(max_packets); + sg_init_one(&sgs, &coal_vq, sizeof(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,36 @@ 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; + 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 +3185,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 +3197,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 +3235,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 +3382,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 Sun Feb 8 21:26:40 2026 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 1FD8DEB64DA for ; Mon, 10 Jul 2023 09:21:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231770AbjGJJVs (ORCPT ); Mon, 10 Jul 2023 05:21:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231207AbjGJJVn (ORCPT ); Mon, 10 Jul 2023 05:21:43 -0400 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2046.outbound.protection.outlook.com [40.107.237.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DE361BC; Mon, 10 Jul 2023 02:21:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SRWwe0QtcoXVOsnUrmqW912M25HtnD3aTMZvCoh1SfQiTE+2JUq8x1Ci5O2NIkKnZkye+yIaab7dEXTrKuWdEm2QO9rF1EGRex+kHjj9CCjEQVvZ8IIC1DvzpZq9egszcfDLLcVETyR6SgPTT6N77OBzGj5imHAUVOCxaMdJBleTHgkjF+iIc+5cXxizvEyVzZkHFeyJ3eXFuCXco98+J+hptJQwo9q2QNXzRgh1ru1zRG1SAm5dqj2SO6lkBc5iTn11HWgc/Qf7fQBMyfZwkYkQiP1UnGQzIW8PWUOyUlN4kqxnx64Kfw0kMdp1ckCsFGeH8ZR6m9k0HstuAJgS/w== 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=d0oHsOuXgvTMjpbxKtqjrGPAMf2I/9i3elpw5czoUwE=; b=VgYvskPBO2078y3YSk9TxGGwZ6ucVIOVBk7QQSnheYuIOcs++RZCpMFgH1oKZupLV2vSt/Lh9nWwxD0fXDWJupHaURv+fojIy0hLvJOKJ+1+AxEuYJohKyqfp227lhGQuvvK6wQD5GZsN0Bdy7N0y+c7gcI7MxACWM4l2gCFCaAIrN8lPVwpplwIVpH6VrlJCtkGKNrcjgrw8/ACqnO4fom5rNPSZQmi/Eon0oeLeLXXu3OVopsA9T3YqF4aj7vX/3JrcnDNfUZ2her+4nIOFrUhl3mbu09DxBWYk2ZUB0FstJ5bhohzQnXPzSUGK8OXmBuL5X79EbPFaSNtvrLFnA== 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=d0oHsOuXgvTMjpbxKtqjrGPAMf2I/9i3elpw5czoUwE=; b=srruZDNAVPwx1u6hT3wkhYO3rJwG0UXtmUtKPfnB/kyxu9pfzwXqunn0JbUQzdspbaq9YbOezbAj6ToNee59zaGg5YvY/x8UMjnad/HWB8O3QzeH8wvpa3tPepYt8JPjRlWIYWNYaIF9M/qbjkJtwHOf6JWlmfY44LQagBE0tSGp1YGBiMX/LJmdn5rXU341u5kF/acKtc2RsNymOq4bKE8l92ufZ0c8KF0E5dHA8HYGUKOhPC5Ym7A9gi0kvoVQ3dcZ2cQ/23mqmIcvW+eLFweyqY6+sFQBDHuOKHSpFYrwNAfM/9yLoCFkID6DjJkpUiLqpq75XKFPX16KO39EEw== Received: from BN9PR03CA0136.namprd03.prod.outlook.com (2603:10b6:408:fe::21) by LV3PR12MB9439.namprd12.prod.outlook.com (2603:10b6:408:20e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.30; Mon, 10 Jul 2023 09:21:29 +0000 Received: from BN8NAM11FT026.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fe:cafe::f8) by BN9PR03CA0136.outlook.office365.com (2603:10b6:408:fe::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.30 via Frontend Transport; Mon, 10 Jul 2023 09:21:29 +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 BN8NAM11FT026.mail.protection.outlook.com (10.13.177.51) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.18 via Frontend Transport; Mon, 10 Jul 2023 09:21:29 +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; Mon, 10 Jul 2023 02:21:06 -0700 Received: from nvidia.com (10.126.230.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; Mon, 10 Jul 2023 02:21:02 -0700 From: Gavin Li To: , , , , , , , , , , , , CC: , , , Subject: [PATCH net-next V1 4/4] virtio_net: enable per queue interrupt coalesce feature Date: Mon, 10 Jul 2023 12:20:05 +0300 Message-ID: <20230710092005.5062-5-gavinl@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230710092005.5062-1-gavinl@nvidia.com> References: <20230710092005.5062-1-gavinl@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.126.230.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: BN8NAM11FT026:EE_|LV3PR12MB9439:EE_ X-MS-Office365-Filtering-Correlation-Id: 30fcdad7-4be5-422b-f98d-08db81270b37 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fUl7dZ8hA6EviDSbySZZ43UlqYQkOzDbTdgX4n7Xk37fkwBe8xbXfpLOQ+gqQC2V4QiJYqNYgxqfwDuc82HubbuKsK59vkvVvk3I9ueJOct9j4ip7BqfD8mdgQWxnM/HMwksGWNuIAvjOrkessgSmtqvFT0uTbMJeIczqWJIv2M+BO+n4ipqaL+AvCNSMr0+gd6G9LhGlhVgwKNqSFwt1GEEHX+pxy8jFCjEloFjUH0ePuX+j4zta2gPZXfCNUAa11Hpn9Fn5lJmt3H5fSt5nzhzmr5PlIGRIW37RlIqa8FdRfe0GrzTfmD/QVs0emA7V+G2gV/WHYZ4PmYvrA8lpUqbhESN3PfdeZFA2S6jT4lfbUjNgD/330f9800vGhaT5Evm6VDJu6KERqDHLQwmsopqyl3LRlipAD+PdOfoZXhaOtWjOtEUTg7X3nZ2B6ZtJIaG90tIR11sTTqtwI3iw3xx57aSMvz/FUbfQSQ5yQdeHojBrTJL3qx2BY8MO5oxiKkqPg0TCi5RbMWAumohzIY11/LOAN99XzkifCwVIWXMhSKCasLKO4TVuaDJ0kqnjDVK1JXvMwI6r6V+N5ii+gVO7JxGjO1HKcrjNlvt/+dCJcNIBPSxh5JQBdXI4IhgPcdjQdrml7D16ND98IEkagVMO0OJCBhgaufMp6aH1wB56EUCH/KMAxYvaNBZJ3DloN1cr7NVLd61BTgEnF9wxj8ESLovxUki4oiK9aoLoxXGOPb50teLdFFxk7AqPNVs/iVpt7aaZ7Iy+nKzaqamXwd7jxdEJYbGXJbz7RXpnuBPpWKe5AuJF5NvVYEtaxzg 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)(346002)(396003)(39860400002)(376002)(136003)(451199021)(40470700004)(46966006)(36840700001)(86362001)(82310400005)(82740400003)(40460700003)(40480700001)(36756003)(55016003)(7696005)(110136005)(54906003)(70206006)(70586007)(356005)(921005)(7636003)(36860700001)(6286002)(16526019)(26005)(186003)(1076003)(2616005)(7416002)(5660300002)(2906002)(316002)(478600001)(8936002)(8676002)(47076005)(336012)(83380400001)(426003)(4326008)(6636002)(41300700001)(83996005)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jul 2023 09:21:29.2795 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 30fcdad7-4be5-422b-f98d-08db81270b37 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: BN8NAM11FT026.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: LV3PR12MB9439 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 --- 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 333a38e1941f..81bac3597a2b 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -4060,6 +4060,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; } @@ -4484,6 +4486,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