daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
1c4d83
From e9f92c88163841d3f1d29fa5b44ae4c6f71bb014 Mon Sep 17 00:00:00 2001
1c4d83
From: Daan De Meyer <daan.j.demeyer@gmail.com>
1c4d83
Date: Wed, 18 Aug 2021 07:59:13 +0100
1c4d83
Subject: [PATCH] udev: Support "max" string for BufferSize options (#20458)
1c4d83
1c4d83
"max" indicates the hardware advertised maximum queue buffer size
1c4d83
should be used.
1c4d83
1c4d83
The max sizes can be checked by running `ethtool -g <dev>` (Preset maximums).
1c4d83
Since the buffer sizes can't be set to 0 by users, internally we use 0 to
1c4d83
indicate that the hardware advertised maximum should be used.
1c4d83
---
1c4d83
 man/systemd.link.xml      | 20 ++++++++++++--------
1c4d83
 src/shared/ethtool-util.c | 40 +++++++++++++++++++++++++--------------
1c4d83
 src/shared/ethtool-util.h |  2 ++
1c4d83
 3 files changed, 40 insertions(+), 22 deletions(-)
1c4d83
1c4d83
diff --git a/man/systemd.link.xml b/man/systemd.link.xml
1c4d83
index 1c18f35fc8..fd744ebaed 100644
1c4d83
--- a/man/systemd.link.xml
1c4d83
+++ b/man/systemd.link.xml
1c4d83
@@ -735,29 +735,33 @@
1c4d83
       <varlistentry>
1c4d83
         <term><varname>RxBufferSize=</varname></term>
1c4d83
         <listitem>
1c4d83
-          <para>Takes an integer. Specifies the maximum number of pending packets in the NIC receive buffer.
1c4d83
-          When unset, the kernel's default will be used.</para>
1c4d83
+          <para>Takes an integer or <literal>max</literal>. Specifies the maximum number of pending packets
1c4d83
+          in the NIC receive buffer. When unset, the kernel's default will be used. If set to
1c4d83
+          <literal>max</literal>, the hardware's advertised maximum size will be used.</para>
1c4d83
         </listitem>
1c4d83
       </varlistentry>
1c4d83
       <varlistentry>
1c4d83
         <term><varname>RxMiniBufferSize=</varname></term>
1c4d83
         <listitem>
1c4d83
-          <para>Takes an integer. Specifies the maximum number of pending packets in the NIC mini receive buffer.
1c4d83
-          When unset, the kernel's default will be used.</para>
1c4d83
+          <para>Takes an integer or <literal>max</literal>. Specifies the maximum number of pending packets
1c4d83
+          in the NIC mini receive buffer. When unset, the kernel's default will be used. If set to
1c4d83
+          <literal>max</literal>, the hardware's advertised maximum size will be used.</para>
1c4d83
         </listitem>
1c4d83
       </varlistentry>
1c4d83
       <varlistentry>
1c4d83
         <term><varname>RxJumboBufferSize=</varname></term>
1c4d83
         <listitem>
1c4d83
-          <para>Takes an integer. Specifies the maximum number of pending packets in the NIC jumbo receive buffer.
1c4d83
-          When unset, the kernel's default will be used.</para>
1c4d83
+          <para>Takes an integer or <literal>max</literal>. Specifies the maximum number of pending packets
1c4d83
+          in the NIC jumbo receive buffer. When unset, the kernel's default will be used. If set to
1c4d83
+          <literal>max</literal>, the hardware's advertised maximum size will be used.</para>
1c4d83
         </listitem>
1c4d83
       </varlistentry>
1c4d83
       <varlistentry>
1c4d83
         <term><varname>TxBufferSize=</varname></term>
1c4d83
         <listitem>
1c4d83
-          <para>Takes an integer. Specifies the maximum number of pending packets in the NIC transmit buffer.
1c4d83
-          When unset, the kernel's default will be used.</para>
1c4d83
+          <para>Takes an integer or <literal>max</literal>. Specifies the maximum number of pending packets
1c4d83
+          in the NIC transmit buffer. When unset, the kernel's default will be used. If set to
1c4d83
+          <literal>max</literal>, the hardware's advertised maximum size will be used.</para>
1c4d83
         </listitem>
1c4d83
       </varlistentry>
1c4d83
       <varlistentry>
1c4d83
diff --git a/src/shared/ethtool-util.c b/src/shared/ethtool-util.c
1c4d83
index f77f6943ca..ed251ec8dd 100644
1c4d83
--- a/src/shared/ethtool-util.c
1c4d83
+++ b/src/shared/ethtool-util.c
1c4d83
@@ -399,16 +399,24 @@ int ethtool_set_nic_buffer_size(int *ethtool_fd, const char *ifname, const netde
1c4d83
                 return -errno;
1c4d83
 
1c4d83
         if (ring->rx_pending_set)
1c4d83
-                UPDATE(ecmd.rx_pending, ring->rx_pending, need_update);
1c4d83
+                UPDATE(ecmd.rx_pending,
1c4d83
+                       ring->rx_pending == 0 ? ecmd.rx_max_pending : ring->rx_pending,
1c4d83
+                       need_update);
1c4d83
 
1c4d83
         if (ring->rx_mini_pending_set)
1c4d83
-                UPDATE(ecmd.rx_mini_pending, ring->rx_mini_pending, need_update);
1c4d83
+                UPDATE(ecmd.rx_mini_pending,
1c4d83
+                       ring->rx_mini_pending == 0 ? ecmd.rx_mini_max_pending : ring->rx_mini_pending,
1c4d83
+                       need_update);
1c4d83
 
1c4d83
         if (ring->rx_jumbo_pending_set)
1c4d83
-                UPDATE(ecmd.rx_jumbo_pending, ring->rx_jumbo_pending, need_update);
1c4d83
+                UPDATE(ecmd.rx_jumbo_pending,
1c4d83
+                       ring->rx_jumbo_pending == 0 ? ecmd.rx_jumbo_max_pending : ring->rx_jumbo_pending,
1c4d83
+                       need_update);
1c4d83
 
1c4d83
         if (ring->tx_pending_set)
1c4d83
-                UPDATE(ecmd.tx_pending, ring->tx_pending, need_update);
1c4d83
+                UPDATE(ecmd.tx_pending,
1c4d83
+                       ring->tx_pending == 0 ? ecmd.tx_max_pending : ring->tx_pending,
1c4d83
+                       need_update);
1c4d83
 
1c4d83
         if (!need_update)
1c4d83
                 return 0;
1c4d83
@@ -1037,16 +1045,20 @@ int config_parse_nic_buffer_size(
1c4d83
         assert(rvalue);
1c4d83
         assert(data);
1c4d83
 
1c4d83
-        r = safe_atou32(rvalue, &k);
1c4d83
-        if (r < 0) {
1c4d83
-                log_syntax(unit, LOG_WARNING, filename, line, r,
1c4d83
-                           "Failed to parse interface buffer value, ignoring: %s", rvalue);
1c4d83
-                return 0;
1c4d83
-        }
1c4d83
-        if (k < 1) {
1c4d83
-                log_syntax(unit, LOG_WARNING, filename, line, 0,
1c4d83
-                           "Invalid %s= value, ignoring: %s", lvalue, rvalue);
1c4d83
-                return 0;
1c4d83
+        if (streq(rvalue, "max"))
1c4d83
+                k = 0;
1c4d83
+        else {
1c4d83
+                r = safe_atou32(rvalue, &k);
1c4d83
+                if (r < 0) {
1c4d83
+                        log_syntax(unit, LOG_WARNING, filename, line, r,
1c4d83
+                                "Failed to parse interface buffer value, ignoring: %s", rvalue);
1c4d83
+                        return 0;
1c4d83
+                }
1c4d83
+                if (k < 1) {
1c4d83
+                        log_syntax(unit, LOG_WARNING, filename, line, 0,
1c4d83
+                                "Invalid %s= value, ignoring: %s", lvalue, rvalue);
1c4d83
+                        return 0;
1c4d83
+                }
1c4d83
         }
1c4d83
 
1c4d83
         if (streq(lvalue, "RxBufferSize")) {
1c4d83
diff --git a/src/shared/ethtool-util.h b/src/shared/ethtool-util.h
1c4d83
index 7d28766624..aea131914e 100644
1c4d83
--- a/src/shared/ethtool-util.h
1c4d83
+++ b/src/shared/ethtool-util.h
1c4d83
@@ -70,6 +70,8 @@ typedef struct netdev_channels {
1c4d83
 } netdev_channels;
1c4d83
 
1c4d83
 typedef struct netdev_ring_param {
1c4d83
+        /* For any of the 4 following settings, a value of 0 indicates the hardware advertised maximum should
1c4d83
+         * be used. */
1c4d83
         uint32_t rx_pending;
1c4d83
         uint32_t rx_mini_pending;
1c4d83
         uint32_t rx_jumbo_pending;
1c4d83
-- 
1c4d83
2.31.1
1c4d83