From nobody Sat Feb 7 17:55:52 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 4CB16EB64DC for ; Mon, 17 Jul 2023 14:31:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231669AbjGQObo (ORCPT ); Mon, 17 Jul 2023 10:31:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231440AbjGQObe (ORCPT ); Mon, 17 Jul 2023 10:31:34 -0400 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2072.outbound.protection.outlook.com [40.107.243.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B777C10D8; Mon, 17 Jul 2023 07:31:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=I6IGdTxa9k+wSz30PGkI7ZBGHKTVQACykVWh0d1BAKPrQgaRRDQ7OrhofLLpvTy1M64vY9ZXmWGkC4v1QGgwnVKL0l5DOcN0/ZFQ/beHtZ4ul8DszNH6trj694YwJPkljMpKd58KFh1SlAkCUiKclJJwfZ1w0V9lmBD6hW2RHNVsYKFEHBQlrHd89+RX1EB5XRETOr3spo9/cYdjUgAVjHE1yIi+K61oMH+WWYri/kdZqSthdGAbrZDYS7SqYZGIJFNaaak4cBXwSK7k3UZCRnWRDjZU/7Q9Q3Vrv2kl4QQV0/9+2QV9L+pn9c9GJzWdHIVdFxxQD7KZiFPOnzhlPQ== 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=lmaMgTEr2DxCw7JpV3t1WatyVff7Pt2/kf5GHbUzd8qwWRR6ockHYVrwsUPbQm7mCosWcmc0lSRdSd9jiyDjrnbv4NwHG1KNY0e5qs4BSuuE9Ab3PLIwYlYyjkoHpex1Msavh2v5ki0ybyRNj3Z1jV+LebA5RpSu8bFh3m/NegbRTfRx5RdWFN34/IZxgLlDIftj9zucYzIV6ppHpZYQV/oxrYGX25rkZybwj90jYub43RZ/ENUQGuW1Jj48v1zMhDaNoYI4KFMluU3J+VebxQiiHRaHslbk3SKW/G3H2f3CMVaz29ioJ2PJqvPYeGx8q3w1dej+aTGFPEXeGfRWlQ== 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=KpY16pSmomnFEYpXTws0UaY23QjCR2HG+iPfMc2Mitk=; b=jx5xTrRY/50/Ml+qy99qRUeKpx2fhuWsDsOi7xsXQ7iRxPa0cNNh1YGGvA7QRyaXMKifyp9E3221bp36u1txsKP2mOLCVDpag2u60RBT8wXdtxNVFv601vxCi+zUe4EL/2OIh4UBZU/ojl3XaypV4GDpmS07MM8hEwkP0jbYAcIPKyIFkY9Kj+n3y68DgnXj2LxUX2aUv63KkVqsW0+YW53XHaJD3WpImdJ0N0N+TrIgjBZwXBuc4UZsrtTjKnDgutVTuMybY5e+Nrh86GwiCAxdOw4i4sXWOa5WU6Ky6Pnx3jd1qBPMOApkOw/wjsoSu6e6ml48+YcJ/MVELSddXQ== Received: from BN9PR03CA0582.namprd03.prod.outlook.com (2603:10b6:408:10d::17) by CH2PR12MB4183.namprd12.prod.outlook.com (2603:10b6:610:7a::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.32; Mon, 17 Jul 2023 14:31:30 +0000 Received: from BN8NAM11FT083.eop-nam11.prod.protection.outlook.com (2603:10b6:408:10d:cafe::c2) by BN9PR03CA0582.outlook.office365.com (2603:10b6:408:10d::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.32 via Frontend Transport; Mon, 17 Jul 2023 14:31:30 +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 BN8NAM11FT083.mail.protection.outlook.com (10.13.177.75) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.33 via Frontend Transport; Mon, 17 Jul 2023 14:31:30 +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, 17 Jul 2023 07:31:14 -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; Mon, 17 Jul 2023 07:31:09 -0700 From: Gavin Li To: , , , , , , , , , , , , CC: , , , , Subject: [PATCH net-next V2 1/4] virtio_net: extract interrupt coalescing settings to a structure Date: Mon, 17 Jul 2023 17:30:34 +0300 Message-ID: <20230717143037.21858-2-gavinl@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230717143037.21858-1-gavinl@nvidia.com> References: <20230717143037.21858-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: BN8NAM11FT083:EE_|CH2PR12MB4183:EE_ X-MS-Office365-Filtering-Correlation-Id: c8df80be-fe64-4b85-0a8e-08db86d2835c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: O4eXk4gpaPcKwpMhHaAgGFWry7oljrCimS3uiX0Wy4z95HRHP4+/2S/OYZln0HZKOwK2RmUaxJS1Xn7B13TIdDT6Mdsf4ZywGl3z5wqj7IJcpEJrzEcXOlPfqVFu2C+xMFu49pkvR9gfUoBVvx4R0T0NYsCu+J0z6pT3vxgXFHLa/rubBzj8SBemhaG2KiVeDrplAfe+DX/A9Nc1K5uWc7TGGSSGCb1s0W4t5fgBysUHoV1wY0I9h6avAxPNcCpo8lzC/JzGb26svHZ//ROAictlvC2YHbwnD3+iZ4Eh9Xr3ZCC2Bgi8gSfUEmdew1sDvcf1bLD/X1FPP/isc44Ec6IhHm3blbzJLEttCKri+W6JXEemSDWl4GCbgUaGpof5XOJ3JTGWBCs+iof16BeZnhlVYvTy2E0uzplJg7N9GWtDfM4mdqKJXNr6fOMnth8MX+IZ9T0+hn6hnMewfc+OUJvFzqfSC2j1VLarsTVmu7uQsoubxBFA3wfgdzJjSelUMOaGo00CoXGbTawU29jtDqhbLwmGnmSiphFLooTB1HmNAzfqo1lR39XYTuPjuzz4QU0opVp1uwWur2+S0bwHlyMR6SRpHJ91+KZnmUzum88gk4EnU9bChT6EEN9HDk86yWgYmjA8ieAB/5q3q3SNFP7x4V+PHlnka2BhD2LsgmiJ+yZ7XdVGi2qcTUa9k09orQUxmbWSzBy2/ESBSFwBw3XSjAZt539WkBj2PiUk00Vt2ddy7nmv4s3gnKW+Te/8WSdUx5v4OE0lZ6QSQWD3fYpscsRFlRxOWsGrENlItqbNq4vmkzPjl03wec4rQHLT 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)(396003)(39860400002)(376002)(346002)(82310400008)(451199021)(40470700004)(46966006)(36840700001)(86362001)(2906002)(36756003)(7416002)(40460700003)(55016003)(40480700001)(47076005)(83380400001)(16526019)(6286002)(426003)(336012)(186003)(36860700001)(1076003)(26005)(82740400003)(7636003)(356005)(921005)(7696005)(54906003)(110136005)(6636002)(70206006)(4326008)(316002)(70586007)(8676002)(478600001)(6666004)(5660300002)(8936002)(2616005)(41300700001)(83996005)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2023 14:31:30.6283 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c8df80be-fe64-4b85-0a8e-08db86d2835c 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: BN8NAM11FT083.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH2PR12MB4183 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 --- 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 Sat Feb 7 17:55:52 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 D69EEC001DC for ; Mon, 17 Jul 2023 14:32:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232020AbjGQOb7 (ORCPT ); Mon, 17 Jul 2023 10:31:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231631AbjGQObj (ORCPT ); Mon, 17 Jul 2023 10:31:39 -0400 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2052.outbound.protection.outlook.com [40.107.237.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCC1A1700; Mon, 17 Jul 2023 07:31:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Wy8Rg8QXcfBUw3RzC/CRgDP2d2ZJyUbsDXuTEd6E9a4bdZ/34MRgFKxZJlNieQYRkcMZ+5uPD8OrY1C3IThsQCLqY5kH4zWMTkTD/l5bcSeEnTYwRYZIhgav9uotDKRviA7KqE8iirsOsEhtY7PlY7QVCmp0Q2dsgxToNBY2PY47XGleeFcW36ahUY3bRCrwP/ONuK9YuaFht0lbAHST+X9bO/KpWce/wfruy+LDFa5hdRun6IaKKwYlmMF4k1r5nlm3P5mTAztLPPPYZhLhOBnZHMS8p9PIzx7fwY6pAH03JXlmlAyoFtBvaTTmtwZMf5EdlZ7o/Sau3YML+s7mgg== 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=XlreOFbKiYjNlQsohuVaUp8K26bT8HrsRTuJbVx6t2w8VymWp/QHk1TZQRycl2265bfXrDdcU26RMEpdEhwG4L1nbO6XGFrkmUfaTcpzp0ugXoG0CC/VArJcSMlkMxE7fXPgcu/oqWyfwSqTmBBfsKigxAyBrAV+rXjJ//QbHHt3ulgA2gg9gqIRExkIQcxRKMT0HhU7R4uya9Yc1lLLewsuf3Gg0boMBw34GTP+PxzjmmukVZcpzBAN6BgIHT1yhZ06Sb2RMmBOIh6wwM5VLnqK+3pZ8guolpn3Q8LXhNrP1Ri44v2nValbJolyayZ/3LdN6IiNZ4ypGZbrQ/1vdQ== 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=cOrOdt7bTtC1GuP26rsti1uEz/6U/mDAEqRRjLOSe/zdlPkvoNiCGt1CGmOCuqUvE/8t80w/ndsR+m09JVBpZ+hhrAh8GkXYp14LQzF7D4Pku4fT1nuZihG6TmHSj2VSRc5+cV65fil1ldUxY/nA0dmbj6ZaYT+lERb0nP+uAhfwRD+JjXKtllKkQZ1RBzLcQiHkuHCjSPMxto6JImI76xjCPomVW4WWme3pbNwRaA4KPD4b6GAvN/KGle1xe2YDxyowtnbXcHY9aOyAFP/kruygsp3jtU/VLbFrznxqj8Lt16PvGmQVeGISKKj2q7nZZpiAQ8DmbdasftBlFY3seg== Received: from MW2PR2101CA0030.namprd21.prod.outlook.com (2603:10b6:302:1::43) by BN9PR12MB5178.namprd12.prod.outlook.com (2603:10b6:408:11b::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.32; Mon, 17 Jul 2023 14:31:33 +0000 Received: from CO1NAM11FT064.eop-nam11.prod.protection.outlook.com (2603:10b6:302:1:cafe::da) by MW2PR2101CA0030.outlook.office365.com (2603:10b6:302:1::43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.8 via Frontend Transport; Mon, 17 Jul 2023 14:31: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 CO1NAM11FT064.mail.protection.outlook.com (10.13.175.77) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.32 via Frontend Transport; Mon, 17 Jul 2023 14:31: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; Mon, 17 Jul 2023 07:31:19 -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; Mon, 17 Jul 2023 07:31:14 -0700 From: Gavin Li To: , , , , , , , , , , , , CC: , , , , Subject: [PATCH net-next V2 2/4] virtio_net: extract get/set interrupt coalesce to a function Date: Mon, 17 Jul 2023 17:30:35 +0300 Message-ID: <20230717143037.21858-3-gavinl@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230717143037.21858-1-gavinl@nvidia.com> References: <20230717143037.21858-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: CO1NAM11FT064:EE_|BN9PR12MB5178:EE_ X-MS-Office365-Filtering-Correlation-Id: 8bd93da9-b68c-4264-d639-08db86d284d6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0xtLmoSPchXHC598K683zCrkzxHImS6Buv95nHYSSbjnQ/P/fAiSXRNL0AMRKvem8KSA9yUGfzUv9K/bqBImlhJTa4bOKYAzaeDo/1Jn2Ge4xmlLCwXt4BnMG+maoDMHg52CTM+3x8vQmP0bpWn8hxYkrqenTNrRkKsDMPJS0mQcMnUNryHQkp5ZLTxMKw6WX0z4oSDFmzv+edEV9o6Atgy0n8oGo5N964GxFK8QzMyjkoPwbzCNmosrKrAZCMh+iS4b4jzWIn7JpjyQx0cHsRT2NqoQQ//RIegzcYFf1rbmK4ZFPVwtl7ZS28EYiIQ8lI2NgStCKFtIVn7G8LBfFkTkQuUYyiQQOAyyTQHf3s0/24HrjTyq4S2GGcaZxg+sBos//7ix1UFqdLm6v1x7CGChJxwNn2P5yYgIDtNW/XSTy3gmfIJUZMPnks+SNC/nolNgoEFbvsKPLj3K3y6ka8v2s7Xg4xCSo/o9tWT+wGA1GR7EaCoLD6GMx2Ul7g1zdISrHo0/t4pjwPeIhjAo/aXI0FbW/bgk1IPiX85XwOxuAmD+qQDdayDCsIZh1fCgLc45nAAEFxRBRIzchDdFP7VV63Ie0i0bqb8X4uP9QN2JqdO1w1H3OPypQ7arslRQAWBqc5A+YNKHFExrUTigINePe24fyZLvcBq6RdGbyotqC12e1KjH8ZG4okfOKMQUF9UOtV9XDzI4gtu+ZO5T+ltitPvdqJmdlGoVrmxXDtAvpISHr35Ogtk2M824cwwfYzm3oPb2KAPV3+COGoWrRmnYm9x5Fe8kuIhamYBfor9B8b+9PcEMFNvaXZbah+RF 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)(39860400002)(136003)(346002)(396003)(376002)(82310400008)(451199021)(40470700004)(36840700001)(46966006)(86362001)(2906002)(36756003)(7416002)(40460700003)(55016003)(40480700001)(186003)(6286002)(16526019)(336012)(36860700001)(83380400001)(426003)(47076005)(1076003)(26005)(82740400003)(921005)(356005)(7636003)(70206006)(6666004)(7696005)(54906003)(110136005)(70586007)(6636002)(316002)(2616005)(4326008)(5660300002)(478600001)(41300700001)(8936002)(8676002)(83996005)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2023 14:31:33.2045 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8bd93da9-b68c-4264-d639-08db86d284d6 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: CO1NAM11FT064.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5178 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 --- 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 Sat Feb 7 17:55:52 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 4B9FAEB64DC for ; Mon, 17 Jul 2023 14:32:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231890AbjGQOcL (ORCPT ); Mon, 17 Jul 2023 10:32:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231440AbjGQOb6 (ORCPT ); Mon, 17 Jul 2023 10:31:58 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2054.outbound.protection.outlook.com [40.107.220.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 055DB1732; Mon, 17 Jul 2023 07:31:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MAZUbDGZmahxMV1AUTJFD3+A3kbhKOp7RyrZYlijezRgw+BUVjU3plXTqlM/k4/yDXWFeMoDkPAQM2zZZuWItLrDBWoN4ySanGLL7YRZ3JCSr+v39l3Ue0rgTdr3IGDWvbGewWH7YShjyjRtES/T1ml1lcO0A93vnxgD8aNIOmbPJYRu8Pbhcd2ouEa5f/S90bkF3MLRBjH6sYgDtgD/7259ws73WpS3QSHtZks+dVslpVcKiwvI1hok+kR4f1viLSklXo5QK4O8O4jviwD41Y6yC7qOvrqbdyzrNnh+JK/KOnnx5R81axKsTeaDTRB5Ctto4FOcQOEWJUcLKkcErQ== 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=UpOJqNzvTtWK7ysHUsvg12xKGHZO60SfY+TObzn8cOg=; b=fy3T49fuXAdsfciNR9uYdTagMb9L9rDi5fQyVg3is9gl+1pBTA3Iy0o92loRoymm+pX2RTgb+aXoHQCzq+79ZafybjcPvWbXF7QN1zmpQBkGbA4tWEx6ocOxinY2uTX+TCoCk5w5qwV3y/IFUBvA41geODLczBn4OisRkKQTHeBsSrP2kUvI5zGF8otOIt0Wuye3sn7Li5Wk/y0RhDBieYVAncWKZyyXvmew+d5sH/ZZA5aB3PXqhr5zgsZ7YkaoL+c73aOA2K9FZoH/VvuHa4vFgMfgm7BnqFlqzJnfLMPt66vL8dI98exA5cnikRDw7sdhcpvR2E+5lg8eVMgWQg== 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=UpOJqNzvTtWK7ysHUsvg12xKGHZO60SfY+TObzn8cOg=; b=Wo7EoAxFBp5d7FGk2NtUKV2asC5WspKWBhlLTTyaz2zgq7v0/J/SUQBd5YpEtjlr7ysTIlS83YfKsY38zXM6Y1ygT9V71t4RLEwOcvXL0ne4n+Fh4TzM7ekCcEw4+hle6/eVBtkst0mZqAUMZECbjTvACu8Haht2sLWGen3ikcOmofzgOePwGIuQOa9zr1L5unlGYfrDybqa9ayDNXgI2ar6ISK92GZqhIjeg+4ZRMZA9ATx43A+f5d2E8egtAKzgjUO2MKTEcwqqUx8GZSBOHYMNRj0ik1RFZ8sTQTGEBLKZea3hmKvdiK8ckihzMfZzpzGvGN45WkKSPjG0IlMmg== Received: from BN9PR03CA0802.namprd03.prod.outlook.com (2603:10b6:408:13f::27) by CY8PR12MB8364.namprd12.prod.outlook.com (2603:10b6:930:7f::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Mon, 17 Jul 2023 14:31:39 +0000 Received: from BN8NAM11FT040.eop-nam11.prod.protection.outlook.com (2603:10b6:408:13f:cafe::d5) by BN9PR03CA0802.outlook.office365.com (2603:10b6:408:13f::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.33 via Frontend Transport; Mon, 17 Jul 2023 14:31:38 +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 BN8NAM11FT040.mail.protection.outlook.com (10.13.177.166) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.33 via Frontend Transport; Mon, 17 Jul 2023 14:31:38 +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, 17 Jul 2023 07:31:24 -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; Mon, 17 Jul 2023 07:31:19 -0700 From: Gavin Li To: , , , , , , , , , , , , CC: , , , , Subject: [PATCH net-next V2 3/4] virtio_net: support per queue interrupt coalesce command Date: Mon, 17 Jul 2023 17:30:36 +0300 Message-ID: <20230717143037.21858-4-gavinl@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230717143037.21858-1-gavinl@nvidia.com> References: <20230717143037.21858-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: BN8NAM11FT040:EE_|CY8PR12MB8364:EE_ X-MS-Office365-Filtering-Correlation-Id: 6ccf7fc4-9395-4f1d-c7cc-08db86d28821 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Acg24GSbPcl+7JJs2ROTxepsIsV+EbOZweaDCNKXQ748/ntzSFY+lgNeJFXryGTRuSzfAIChC6WNg7Pu3M+Tm6oApXzo3qGM6w5qVc4w9k7Cxeu6a+7fkExlz0OBCKYLVAzoYB5Rz0KV2MZlALuYzCi3umpWlSgDXT0PErQNuTB8Q0qX7IUxnm5Pf7YgCEcgHo1iU6NNTAzkcnVKgtEmYStaiCSg+nnVKVUnw5PjwjMehacIyOINlmk+oAj5AuhnNhi/dYfeJfXZ+a2g9yYYfrnyyDwo2POK2s2OjFH7w3Qi1QVINUhgbn0RlHUJBcrU8dbnbVMvyMh+mbgj9IMJgLlzum0itbNSAoxgvS9KbRNBPQ9fcSUqPvnJqn/wqpRaNFpxXc3t5ELDzyM+VrPoSC3gsuN7hg4fmf9Aox8x2PR7sbYk4YXgMKVar6CP8kAzLQ0wwZ4eil7dcmMk5p2nCdC8wQgYsLMHkbVE9yb2D3C4E5Gi83iYCOag46NOGSGdE1rB2dsgiNyrZgDxU/hF26TiJnRf7JsHvcyHRaD4h+NEKs9ZeyGNPt63otvk21pQQqg77D0KIW2MHIWwy+tokSKcxzTu1fXNyN5IEcqSH5P1AhGW7ER5W8ErBdpwBscf/oK1lUXUKdFF4mY/w0K/LUp880EnSrJir5VcEQ+i5agCVcPDrNaRFImyZNf60F00ZrQn+njDyVXZnZjTAXROYL68aJ3pa0HOECEN1tX1i6UL/maKcpaLK46ODiPJ0UJJ+WgFswvdaYYDYH0ZUoXYsFgbJ3c0aOJKfQMlhWxwM91EeUIrk6rkCtygu+xG1i2R 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)(39860400002)(136003)(396003)(346002)(376002)(82310400008)(451199021)(40470700004)(36840700001)(46966006)(82740400003)(83380400001)(426003)(86362001)(47076005)(7696005)(6666004)(36756003)(36860700001)(2906002)(2616005)(6286002)(7416002)(186003)(16526019)(336012)(5660300002)(40460700003)(1076003)(26005)(41300700001)(8936002)(8676002)(40480700001)(478600001)(55016003)(70586007)(70206006)(316002)(6636002)(4326008)(110136005)(356005)(921005)(7636003)(54906003)(2101003)(83996005);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2023 14:31:38.6195 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6ccf7fc4-9395-4f1d-c7cc-08db86d28821 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: BN8NAM11FT040.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY8PR12MB8364 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 | 123 ++++++++++++++++++++++++++++---- include/uapi/linux/virtio_net.h | 14 ++++ 2 files changed, 125 insertions(+), 12 deletions(-) diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c index 802ed21453f5..1566c7de9436 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,59 @@ 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; + struct scatterlist sgs; + + coal_vq =3D kzalloc(sizeof(*coal_vq), GFP_KERNEL); + if (!coal_vq) + return -ENOMEM; + 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 +3151,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 +3191,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 +3203,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 +3241,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 +3388,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 Sat Feb 7 17:55:52 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 A2BA8EB64DC for ; Mon, 17 Jul 2023 14:32:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232063AbjGQOcP (ORCPT ); Mon, 17 Jul 2023 10:32:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231551AbjGQOcA (ORCPT ); Mon, 17 Jul 2023 10:32:00 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2070.outbound.protection.outlook.com [40.107.220.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA61C19A9; Mon, 17 Jul 2023 07:31:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ehPbu+nIkrHFUEpbCVWV4e2gWphnInTlTTZOTPsZ89O3tMBPYEUfHWqmzJG26YkmqWqFIgxB5T/LrMvblGPTDt306yR7AeEk9SaQcFH/LOxyeTxNFW1awIZ98faPOVa+mYewfgMWhbo0u+NtYdXbrwCT7mSAh81WqNALRn8yuMHaOYevuY7SxfDUoOgu/P8eflsS+GIpftemvC+LMCHcxGZ2DytlWnwJ0dq/i10L5Lj2cVa0scbHpz6QBWloTbSzUigv4Ja1PhhVs63cBjwx/7Yd2XrEMlKAKOlI72S5p+jDSv4ppjxi5D3r7zxW1Ql1vu0bahkhtp9wKVol59f6VQ== 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=TmThAU2YAJOzFnTrzw7PawSekE5lC5HJVtIHKCP6/YM=; b=nmroQyDvqgG6Ebm+uaW6Xa1cDAsYMmQFjnv5as9sbK391aXbNTCW8Hul/xR426RZQuMpJvRp5QCGW5DtnsRv64AuKQc3RFh7dmIHJzNNBJ0JORHmW4xNH65neSR+qQMXWBomjb6dTdhloM7WA+XKce3mRwl/cwvFecSLE7A0orCSgqoawU4viykcfpcXna0ATWx8zLstoX3+sX/+2y6rOrebDVz8I4+9N7SGGX9AMK7qrX8ZFGqd7F8b1jdhFy1EHibyunEdWXo4DnIUYKNQb5Wd/fkUzAfcRPvJjirQMu/Y8hQpRBBwvoYIStoeXgtdQx6zLcW3HCn1womCINpdzQ== 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=TmThAU2YAJOzFnTrzw7PawSekE5lC5HJVtIHKCP6/YM=; b=N2uBzeogGTRDU6PHqGavQ4Yu2LyVBCZM+71gNXw6SOZwVVSJoX7REUa5s6/MsStcBmEZhOaAViLuy+T8xKpJVYpJruxdkJk5lP8mNHf6tNTDC7XBSGw6yzKOnoDdOhEc4/PcVfAp7KT0T1bOGgEEKJ7zuInKZsy2MfYJvOxFpvTve/Cr85HbMB39zcY6DhXhlDVqqITzLu68nba2D4tKnvlydp8/YjRtBc+zNr/DTWWTgUBSMPcWT/qOPo6rRnGHp4ga6YJ8+WYrW1daNyXOxNbShFvznoCAEN1YRKYq+jf7Tgx7/qaDKC81+fmvso29VmAFEPihB4IgkODAeoysrw== Received: from MW3PR05CA0017.namprd05.prod.outlook.com (2603:10b6:303:2b::22) by BN9PR12MB5243.namprd12.prod.outlook.com (2603:10b6:408:100::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.31; Mon, 17 Jul 2023 14:31:42 +0000 Received: from CO1NAM11FT055.eop-nam11.prod.protection.outlook.com (2603:10b6:303:2b:cafe::ee) by MW3PR05CA0017.outlook.office365.com (2603:10b6:303:2b::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6609.22 via Frontend Transport; Mon, 17 Jul 2023 14:31:41 +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 CO1NAM11FT055.mail.protection.outlook.com (10.13.175.129) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6588.33 via Frontend Transport; Mon, 17 Jul 2023 14:31:41 +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, 17 Jul 2023 07:31:29 -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; Mon, 17 Jul 2023 07:31:24 -0700 From: Gavin Li To: , , , , , , , , , , , , CC: , , , , Subject: [PATCH net-next V2 4/4] virtio_net: enable per queue interrupt coalesce feature Date: Mon, 17 Jul 2023 17:30:37 +0300 Message-ID: <20230717143037.21858-5-gavinl@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230717143037.21858-1-gavinl@nvidia.com> References: <20230717143037.21858-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: CO1NAM11FT055:EE_|BN9PR12MB5243:EE_ X-MS-Office365-Filtering-Correlation-Id: a896d7df-6c00-4baf-9c77-08db86d289b4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: C5PKW1rwcysZJ7ek+aZ3FdTdSlaNAsJI0F4gtYXr4ab6Q3slmTWsSukyPkM0oGBwDj0H9HIiZjXxtlrOhpLea1PhIqcErsRyhnO3suaIWxP5QNXhMkpf+ymx7W0Cw87+DjUKJ/E1ceNiA5MMmg91wom9hWrVIGoPyPeMpYGWfvs1l6nIsOdi69w2dg1Sa6i8RXoqFnC8MOH/dgbWFYnZP1mjds60HiH+aacu7VY/cUSTQrN+DKT2WJVUcuGzHt23kAGU6Nisjtaf0Ibs3HVQm2kIb8kIEx3L+Zt51u8pth5dFE0RtY5btbOtl/jwmaakd39J1Wi6UYlpFYwgOXaeSD+uZ2TGI9mEt3OAWsDqO80qJBHUkmJwqXBgDhKsrKgvoCZYNDKxGFndOUWvc3CxtkZVnnyHzv8VEBl+oK4XxUUr5YvxMxHo0L19o6S+ULfxKcUQ6cxF4/hWEenhyNyUguNIOEUO/XRRJnyLEsQczDn08K/UeiG6QT3vVAGl60atbifVc4vcBq3lnBGvLjnNga1E49oUdf4PIDMXSYM3NIHKes7yLxfs3dHruX3VLWSwgObt7faS82Is4ETGb/OcBVoGkWMosE6YySuwFjFrzoaNiPI97BDVJKMjEHejdfRB8k2s8T3A7rZzOZvQS/cVB5ZCj2vxscp3NeVFnYvy4Q1I+TDKfwZ6UsnRGfxcSMciqMV6fkq1dqrPWaSFHvv32ShnYV1QUmfbtXmJ2DPs1tCNyx6gNFvBH9dcjqSzjUFdZeVddojZoN1Un4wnMTOMwtadkA3SUGyJIiFGOCRw1kWsbs0JIqgOobZCUo7pdaJ2 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)(346002)(376002)(136003)(82310400008)(451199021)(36840700001)(40470700004)(46966006)(478600001)(70586007)(70206006)(54906003)(5660300002)(4326008)(7416002)(6636002)(316002)(8936002)(55016003)(2906002)(40480700001)(41300700001)(8676002)(6666004)(110136005)(1076003)(26005)(40460700003)(7696005)(356005)(82740400003)(6286002)(7636003)(186003)(16526019)(921005)(2616005)(336012)(47076005)(426003)(83380400001)(36756003)(36860700001)(86362001)(83996005)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2023 14:31:41.3532 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a896d7df-6c00-4baf-9c77-08db86d289b4 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: CO1NAM11FT055.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR12MB5243 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 1566c7de9436..6d9de7c74961 100644 --- a/drivers/net/virtio_net.c +++ b/drivers/net/virtio_net.c @@ -4066,6 +4066,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; } @@ -4490,6 +4492,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