From nobody Sun Feb 8 19:21:09 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1492691344118817.3320036946568; Thu, 20 Apr 2017 05:29:04 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3F7F38BA65; Thu, 20 Apr 2017 12:29:02 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0542C81412; Thu, 20 Apr 2017 12:29:02 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id AA8FB18523C7; Thu, 20 Apr 2017 12:28:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v3KCLpsq020750 for ; Thu, 20 Apr 2017 08:21:51 -0400 Received: by smtp.corp.redhat.com (Postfix) id D844A189F3; Thu, 20 Apr 2017 12:21:51 +0000 (UTC) Received: from caroline.brq.redhat.com (dhcp129-198.brq.redhat.com [10.34.129.198]) by smtp.corp.redhat.com (Postfix) with ESMTP id 60E1F81411 for ; Thu, 20 Apr 2017 12:21:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 3F7F38BA65 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 3F7F38BA65 From: Martin Kletzander To: libvir-list@redhat.com Date: Thu, 20 Apr 2017 14:21:44 +0200 Message-Id: <9bed42851128762737af2fbf0ec1cfa9741626f7.1492690857.git.mkletzan@redhat.com> In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 1/3] util: Add virNetDevSetCoalesce function X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 20 Apr 2017 12:29:02 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" That function is able to configure coalesce settings for an interface, similarly to 'ethtool -C'. This function also updates back the structure so that it contains actual data on the device (if the device doesn't support some settings kernel might just return 0 and not set whatever is not supported), so this way we'll have up-to-date information in the live domain XML. Signed-off-by: Martin Kletzander --- configure.ac | 3 +- src/libvirt_private.syms | 1 + src/util/virnetdev.c | 83 ++++++++++++++++++++++++++++++++++++++++++++= ++++ src/util/virnetdev.h | 34 ++++++++++++++++++++ 4 files changed, 120 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 383493836bff..5f7a07a2a67a 100644 --- a/configure.ac +++ b/configure.ac @@ -347,7 +347,8 @@ AC_CHECK_TYPE([struct sockpeercred], ]]) AC_CHECK_DECLS([ETH_FLAG_TXVLAN, ETH_FLAG_NTUPLE, ETH_FLAG_RXHASH, ETH_FLA= G_LRO, - ETHTOOL_GGSO, ETHTOOL_GGRO, ETHTOOL_GFLAGS, ETHTOOL_GFEATU= RES], + ETHTOOL_GGSO, ETHTOOL_GGRO, ETHTOOL_GFLAGS, ETHTOOL_GFEATU= RES, + ETHTOOL_SCOALESCE, ETHTOOL_GCOALESCE], [], [], [[#include ]]) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 181e178753a4..83e979a2bdaa 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2077,6 +2077,7 @@ virNetDevRxFilterModeTypeFromString; virNetDevRxFilterModeTypeToString; virNetDevRxFilterNew; virNetDevSaveNetConfig; +virNetDevSetCoalesce; virNetDevSetMAC; virNetDevSetMTU; virNetDevSetMTUFromDevice; diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 170e34827f12..6ff1b489857d 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -3078,6 +3078,89 @@ virNetDevGetEthtoolGFeatures(virBitmapPtr bitmap ATT= RIBUTE_UNUSED, # endif +# if HAVE_DECL_ETHTOOL_SCOALESCE && HAVE_DECL_ETHTOOL_GCOALESCE +/** + * virNetDevSetCoalesce: + * @ifname: interface name to modify + * @coalesce: Coalesce settings to set and update + * + * This function sets the various coalesce settings for a given interface + * @ifname and updates them back into @coalesce. + * + * Returns 0 in case of success or -1 on failure + */ +int virNetDevSetCoalesce(const char *ifname, + virNetDevCoalescePtr coalesce) +{ + int fd =3D -1; + int ret =3D -1; + struct ifreq ifr; + struct ethtool_coalesce coal =3D {0}; + + if (!coalesce) + return 0; + + coal =3D (struct ethtool_coalesce) { + .cmd =3D ETHTOOL_SCOALESCE, + .rx_max_coalesced_frames =3D coalesce->rx_max_coalesced_frames, + .rx_coalesce_usecs_irq =3D coalesce->rx_coalesce_usecs_irq, + .rx_max_coalesced_frames_irq =3D coalesce->rx_max_coalesced_frames= _irq, + .tx_coalesce_usecs =3D coalesce->tx_coalesce_usecs, + .tx_max_coalesced_frames =3D coalesce->tx_max_coalesced_frames, + .tx_coalesce_usecs_irq =3D coalesce->tx_coalesce_usecs_irq, + .tx_max_coalesced_frames_irq =3D coalesce->tx_max_coalesced_frames= _irq, + .stats_block_coalesce_usecs =3D coalesce->stats_block_coalesce_use= cs, + .use_adaptive_rx_coalesce =3D coalesce->use_adaptive_rx_coalesce, + .use_adaptive_tx_coalesce =3D coalesce->use_adaptive_tx_coalesce, + .pkt_rate_low =3D coalesce->pkt_rate_low, + .rx_coalesce_usecs_low =3D coalesce->rx_coalesce_usecs_low, + .rx_max_coalesced_frames_low =3D coalesce->rx_max_coalesced_frames= _low, + .tx_coalesce_usecs_low =3D coalesce->tx_coalesce_usecs_low, + .tx_max_coalesced_frames_low =3D coalesce->tx_max_coalesced_frames= _low, + .pkt_rate_high =3D coalesce->pkt_rate_high, + .rx_coalesce_usecs_high =3D coalesce->rx_coalesce_usecs_high, + .rx_max_coalesced_frames_high =3D coalesce->rx_max_coalesced_frame= s_high, + .tx_coalesce_usecs_high =3D coalesce->tx_coalesce_usecs_high, + .tx_max_coalesced_frames_high =3D coalesce->tx_max_coalesced_frame= s_high, + .rate_sample_interval =3D coalesce->rate_sample_interval, + }; + + if ((fd =3D virNetDevSetupControl(ifname, &ifr)) < 0) + return -1; + + ifr.ifr_data =3D (void *) &coal; + + if (virNetDevSendEthtoolIoctl(fd, &ifr) < 0) { + virReportSystemError(errno, + _("Cannot set coalesce info on '%s'"), + ifname); + goto cleanup; + } + + coal =3D (struct ethtool_coalesce) { + .cmd =3D ETHTOOL_GCOALESCE, + }; + + /* Don't fail if the update itself fails */ + virNetDevSendEthtoolIoctl(fd, &ifr); + + ret =3D 0; + cleanup: + VIR_FORCE_CLOSE(fd); + return ret; +} +# else +int virNetDevSetCoalesce(const char *ifname, + virNetDevCoalescePtr coalesce ATTRIBUTE_UNUSED) +{ + virReportSystemError(ENOSYS, + _("Cannot set coalesce info on interface '%s'"), + ifname); + return -1; +} +# endif + + /** * virNetDevGetFeatures: * This function gets the nic offloads features available for ifname diff --git a/src/util/virnetdev.h b/src/util/virnetdev.h index 12a31236c546..19036cca25c0 100644 --- a/src/util/virnetdev.h +++ b/src/util/virnetdev.h @@ -112,6 +112,36 @@ typedef enum { VIR_ENUM_DECL(virNetDevFeature) +/* Modeled after struct ethtool_coalesce, see linux/ethtool.h for explanat= ions + * of particular fields */ +typedef struct _virNetDevCoalesce virNetDevCoalesce; +typedef virNetDevCoalesce *virNetDevCoalescePtr; +struct _virNetDevCoalesce { + uint32_t rx_coalesce_usecs; + uint32_t rx_max_coalesced_frames; + uint32_t rx_coalesce_usecs_irq; + uint32_t rx_max_coalesced_frames_irq; + uint32_t tx_coalesce_usecs; + uint32_t tx_max_coalesced_frames; + uint32_t tx_coalesce_usecs_irq; + uint32_t tx_max_coalesced_frames_irq; + uint32_t stats_block_coalesce_usecs; + uint32_t use_adaptive_rx_coalesce; + uint32_t use_adaptive_tx_coalesce; + uint32_t pkt_rate_low; + uint32_t rx_coalesce_usecs_low; + uint32_t rx_max_coalesced_frames_low; + uint32_t tx_coalesce_usecs_low; + uint32_t tx_max_coalesced_frames_low; + uint32_t pkt_rate_high; + uint32_t rx_coalesce_usecs_high; + uint32_t rx_max_coalesced_frames_high; + uint32_t tx_coalesce_usecs_high; + uint32_t tx_max_coalesced_frames_high; + uint32_t rate_sample_interval; +}; + + int virNetDevSetupControl(const char *ifname, virIfreq *ifr) ATTRIBUTE_RETURN_CHECK; @@ -144,6 +174,10 @@ int virNetDevRestoreMacAddress(const char *linkdev, const char *stateDir) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK; +int virNetDevSetCoalesce(const char *ifname, + virNetDevCoalescePtr coalesce) + ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK; + int virNetDevSetMTU(const char *ifname, int mtu) ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK; --=20 2.12.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list