On 11/24/26 10:52, David Marchand wrote:
Split the monolithic struct netdev_dpdk into three structures:
- netdev_dpdk_common: fields shared between eth and vhost
- netdev_dpdk_eth: ethernet specific fields
- netdev_dpdk_vhost: vhost specific fields

Each type specific struct embeds netdev_dpdk_common. The mutex and
list_node move to the per type structs since they are only relevant
to one type.

This opens an opportunity to optimise those structures layout.

The tl;dr looks like:

Before split:
   netdev_dpdk           896 bytes  14 cache lines

After split:
   netdev_dpdk_eth       824 bytes  13 cache lines
   netdev_dpdk_vhost     736 bytes  12 cache lines

The details.

Before the change, cache line uses for datapath (R = read, W = write):

Eth Rx: 2 cache lines (2R)
   CL0:  flags (R)
   CL4:  ingress_policer (R)

Eth Tx: 6 cache lines (4R + 2W)
   CL0:  port_id, max_packet_len, flags, tx_q (R)
   CL1:  dpdk_mp (R)
   CL2:  up.ol_flags (R)
   CL4:  qos_conf (R)
   CL5:  stats counters (W)
   CL10: stats_lock (W), sw_stats ptr (R)

Vhost Rx: 3 cache lines (3R)
   CL0:  flags (R)
   CL1:  vid, vhost_reconfigured, dpdk_mp (R)
   CL4:  ingress_policer, vhost_rxq_enabled (R)

Vhost Tx: 6 cache lines (4R + 2W)
   CL0:  max_packet_len, flags, tx_q (R)
   CL1:  dpdk_mp, vid, vhost_reconfigured,
         vhost_tx_retries_max (R)
   CL2:  up.ol_flags (R)
   CL4:  qos_conf (R)
   CL5:  stats counters (W)
   CL10: stats_lock (W), sw_stats ptr (R)

In all paths, read Rx fields (ingress_policer) and read Tx fields
(qos_conf, tx_q) can share the common hot cache line: they are only read
from the datapath, and only written from the control path, when the
QoS/policing configuration changes.  Such a write may still invalidate
the cache line for the PMD readers, but those updates are rare.

Control path only fields (mtu, socket_id, queue sizes, boolean flags,
etc...) can be packed into the padding of datapath blocks.
They are never written from the datapath: they only change from the
control path, either on reconfiguration events (mtu, socket_id, queue
sizes), or on runtime updates (MAC address change, QoS update, admin
state change, vhost connect/disconnect, carrier status polling).
There is no write sharing between PMD threads, but a control path write
may invalidate the corresponding datapath cache line.

The embedded netdev structure does not need to be marked as cache line
aligned, since it is already cache aligned by the preceding stats block,
and nothing after it requires isolation from datapath fields.

vhost_rxq_enabled can move into the vid hot cache line because it is
accessed in the Rx data path alongside vid and vhost_reconfigured.

Which ends up after splitting and packing as:

Eth Rx: 1 cache line (1R) (saved 1 cache line)
   CL1:  flags, ingress_policer (R)

Eth Tx: 5 cache lines (3R + 2W) (saved 1 cache line)
   CL0:  port_id (R)
   CL1:  max_packet_len, flags, tx_q, dpdk_mp, qos_conf (R)
   CL2:  stats counters (W)
   CL7:  stats_lock (W), sw_stats ptr (R)
   CL8:  up.ol_flags (R)

Vhost Rx: 2 cache lines (2R) (saved 1 cache line)
   CL0:  vid, vhost_reconfigured, vhost_rxq_enabled (R)
   CL1:  flags, dpdk_mp, ingress_policer (R)

Vhost Tx: 5 cache lines (3R + 2W) (saved 1 cache line)
   CL0:  vid, vhost_reconfigured, vhost_tx_retries_max (R)
   CL1:  max_packet_len, flags, tx_q, dpdk_mp, qos_conf (R)
   CL2:  stats counters (W)
   CL7:  stats_lock (W), sw_stats ptr (R)
   CL8:  up.ol_flags (R)

Note: the Tx path also reads up.n_txq when selecting the transmission
queue.  This field sits past the cache lines listed above, both before
and after the change, so it is not accounted for in those tables.


In that case, should probably include it in the tables above at least for vhost (as it's unlikely/conditional for eth) or were you were planning on moving it, so it would be same CL as ol_flags ?

Signed-off-by: David Marchand <[email protected]>
Acked-by: Eelco Chaudron <[email protected]>
---
Changes since RFC v1:
- did a major revamp on the structures layout,

---
  lib/netdev-dpdk-common.h | 134 ++-------
  lib/netdev-dpdk.c        | 614 +++++++++++++++++++--------------------
  2 files changed, 321 insertions(+), 427 deletions(-)

diff --git a/lib/netdev-dpdk-common.h b/lib/netdev-dpdk-common.h
index fbc5ed5fd..f7acd9cb0 100644
--- a/lib/netdev-dpdk-common.h
+++ b/lib/netdev-dpdk-common.h
@@ -34,6 +34,7 @@
  #include "openvswitch/vlog.h"
  #include "ovs-thread.h"
  #include "packets.h"
+#include "util.h"
struct dpdk_tx_queue;
  struct dpdk_qos_ingress_policer;
@@ -96,67 +97,25 @@ struct netdev_dpdk_sw_stats {
struct netdev_dpdk_common {
      PADDED_MEMBERS(CACHE_LINE_SIZE,
-        uint16_t port_id;
-
-        /* If true, device was attached by rte_eth_dev_attach(). */
-        bool attached;
-        /* If true, rte_eth_dev_start() was successfully called. */
-        bool started;
-        /* If true, this is a port representor. */
-        bool is_representor;
-        struct eth_addr hwaddr;
-        /* 1 pad bytes here. */
-        int mtu;
-        int socket_id;
          int max_packet_len;
          enum netdev_flags flags;
-        int link_reset_cnt;
-        union {
-            /* Device arguments for dpdk ports. */
-            char *devargs;
-            /* Identifier used to distinguish vhost devices from each other. */
-            char *vhost_id;
-        };
          struct dpdk_tx_queue *tx_q;
-        struct rte_eth_link link;
-    );
-
-    PADDED_MEMBERS(CACHE_LINE_SIZE,
-        struct ovs_mutex mutex;
          struct dpdk_mp *dpdk_mp;
- /* virtio identifier for vhost devices. */
-        ovsrcu_index vid;
-
-        /* True if vHost device is 'up' and has been reconfigured at least
-         * once. */
-        bool vhost_reconfigured;
-
-        atomic_uint8_t vhost_tx_retries_max;
-
-        /* Flags for virtio features recovery mechanism. */
-        uint8_t virtio_features_state;
-
-        /* 1 pad byte here. */
-    );
-
-    PADDED_MEMBERS(CACHE_LINE_SIZE,
-        struct netdev up;
-        struct ovs_list list_node;
-
          /* QoS configuration and lock for the device. */
          OVSRCU_TYPE(struct dpdk_qos_conf *) qos_conf;
/* Ingress Policer. */
          OVSRCU_TYPE(struct dpdk_qos_ingress_policer *) ingress_policer;
-        uint32_t policer_rate;
-        uint32_t policer_burst;
- /* Array of vhost rxq states, see vring_state_changed. */
-        bool *vhost_rxq_enabled;
+        /* No datapath fields below for this block. */
- /* Ensures that Rx metadata delivery is configured only once. */
-        bool rx_metadata_delivery_configured;
+        int mtu;
+        int socket_id;
+        /* DPDK-ETH hardware offload features,
+         * from the enum set 'dpdk_hw_ol_features'. */
+        uint32_t hw_ol_features;
+        struct eth_addr hwaddr;
      );
PADDED_MEMBERS(CACHE_LINE_SIZE,
@@ -164,77 +123,24 @@ struct netdev_dpdk_common {
          struct netdev_dpdk_sw_stats *sw_stats;
          /* Protects stats. */
          rte_spinlock_t stats_lock;
-        /* 36 pad bytes here. */
      );
- PADDED_MEMBERS(CACHE_LINE_SIZE,
-        /* The following properties cannot be changed when a device is running,
-         * so we remember the request and update them next time
-         * netdev_dpdk*_reconfigure() is called. */
-        int requested_mtu;
-        int requested_n_txq;
-        /* User input for n_rxq (see dpdk_set_rxq_config). */
-        int user_n_rxq;
-        /* user_n_rxq + an optional rx steering queue (see
-         * netdev_dpdk_reconfigure). This field is different from the other
-         * requested_* fields as it may contain a different value than the user
-         * input. */
-        int requested_n_rxq;
-        int requested_rxq_size;
-        int requested_txq_size;
-
-        /* Number of rx/tx descriptors for physical devices. */
-        int rxq_size;
-        int txq_size;
-
-        /* Socket ID detected when vHost device is brought up. */
-        int requested_socket_id;
-
-        /* Ignored by DPDK for vhost-user backends, only for VDUSE. */
-        uint8_t vhost_max_queue_pairs;
-
-        /* Denotes whether vHost port is client/server mode. */
-        uint64_t vhost_driver_flags;
-
-        /* DPDK-ETH Flow control. */
-        struct rte_eth_fc_conf fc_conf;
+    /* No datapath fields below for the rest of the structure. */
- /* DPDK-ETH hardware offload features,
-         * from the enum set 'dpdk_hw_ol_features'. */
-        uint32_t hw_ol_features;
+    struct netdev up;
- /* Properties for link state change detection mode.
-         * If lsc_interrupt_mode is set to false, poll mode is used,
-         * otherwise interrupt mode is used. */
-        bool requested_lsc_interrupt_mode;
-        bool lsc_interrupt_mode;
-
-        /* VF configuration. */
-        struct eth_addr requested_hwaddr;
-
-        /* Requested rx queue steering flags,
-         * from the enum set 'dpdk_rx_steer_flags'. */
-        uint64_t requested_rx_steer_flags;
-        uint64_t rx_steer_flags;
-        size_t rx_steer_flows_num;
-        struct rte_flow **rx_steer_flows;
-    );
-
-    PADDED_MEMBERS(CACHE_LINE_SIZE,
-        /* Names of all XSTATS counters. */
-        struct rte_eth_xstat_name *rte_xstats_names;
-        int rte_xstats_names_size;
-        int rte_xstats_ids_size;
-        uint64_t *rte_xstats_ids;
-    );
+    /* The following properties cannot be changed when a device is running,
+     * so we remember the request and update them next time
+     * netdev_dpdk*_reconfigure() is called. */
+    int requested_mtu;
+    int requested_n_txq;
+    int requested_n_rxq;
+    /* Socket ID detected when vHost device is brought up. */
+    int requested_socket_id;
+    uint32_t policer_rate;
+    uint32_t policer_burst;
  };
-static inline struct netdev_dpdk_common *
-netdev_dpdk_common_cast(const struct netdev *netdev)
-{
-    return CONTAINER_OF(netdev, struct netdev_dpdk_common, up);
-}
-
  enum dpdk_hw_ol_features {
      NETDEV_RX_CHECKSUM_OFFLOAD = 1 << 0,
      NETDEV_RX_HW_CRC_STRIP = 1 << 1,
diff --git a/lib/netdev-dpdk.c b/lib/netdev-dpdk.c
index a60066912..f55a85739 100644
--- a/lib/netdev-dpdk.c
+++ b/lib/netdev-dpdk.c
@@ -183,7 +183,7 @@ enum dpdk_rx_steer_flags {
      DPDK_RX_STEER_LACP = 1 << 0,
  };
-/* Flags for the netdev_dpdk virtio_features_state field.
+/* Flags for the netdev_dpdk_vhost virtio_features_state field.
   * This is used for the virtio features recovery mechanism linked to TSO
   * support. */
  #define OVS_VIRTIO_F_CLEAN (UINT8_C(1) << 0)
@@ -208,147 +208,122 @@ enum dpdk_rx_steer_flags {
   *
   * Example:
   *     struct netdev *netdev = netdev_from_name(name);
- *     struct netdev_dpdk *dev = netdev_dpdk_cast(netdev);
+ *     struct netdev_dpdk_eth *dev = netdev_dpdk_eth_cast(netdev);
   *
- *  Also, 'netdev' should be used instead of 'common->up', where 'netdev' was
- *  already defined.
+ *  'netdev' should be used instead of 'dev->common.up', where 'netdev'
+ *  was already defined.
+ *  'common' should be used instead of 'dev->common', where 'common'
+ *  was already defined.
   */
-struct netdev_dpdk {
+struct netdev_dpdk_eth {
      PADDED_MEMBERS(CACHE_LINE_SIZE,
          dpdk_port_t port_id;
+ /* No datapath fields below for this block. */
+
+        int link_reset_cnt;
+        /* User input for n_rxq (see dpdk_set_rxq_config). */
+        int user_n_rxq;
+        int requested_rxq_size;
+        int requested_txq_size;
+        /* Number of rx/tx descriptors for physical devices */
+        int rxq_size;
+        int txq_size;
+        int rte_xstats_names_size;
+        int rte_xstats_ids_size;
          /* If true, device was attached by rte_eth_dev_attach(). */
          bool attached;
          /* If true, rte_eth_dev_start() was successfully called. */
          bool started;
          /* If true, this is a port representor. */
          bool is_representor;
-        struct eth_addr hwaddr;
-        /* 1 pad bytes here. */
-        int mtu;
-        int socket_id;
-        int max_packet_len;
-        enum netdev_flags flags;
-        int link_reset_cnt;
-        union {
-            /* Device arguments for dpdk ports. */
-            char *devargs;
-            /* Identifier used to distinguish vhost devices from each other. */
-            char *vhost_id;
-        };
-        struct dpdk_tx_queue *tx_q;
-        struct rte_eth_link link;
+        /* Ensures that Rx metadata delivery is configured only once. */
+        bool rx_metadata_delivery_configured;
+        /* Properties for link state change detection mode.
+         * If lsc_interrupt_mode is set to false, poll mode is used,
+         * otherwise interrupt mode is used. */
+        bool requested_lsc_interrupt_mode;
+        bool lsc_interrupt_mode;
+        /* VF configuration. */
+        struct eth_addr requested_hwaddr;
      );
- PADDED_MEMBERS(CACHE_LINE_SIZE,
-        struct ovs_mutex mutex OVS_ACQ_AFTER(dpdk_eth_mutex, dpdk_vhost_mutex);
-        struct dpdk_mp *dpdk_mp;
-
-        /* virtio identifier for vhost devices */
-        ovsrcu_index vid;
-
-        /* True if vHost device is 'up' and has been reconfigured at least 
once */
-        bool vhost_reconfigured;
+    struct netdev_dpdk_common common;
- atomic_uint8_t vhost_tx_retries_max;
+    /* No datapath fields below for the rest of the structure. */
- /* Flags for virtio features recovery mechanism. */
-        uint8_t virtio_features_state;
+    struct ovs_mutex mutex OVS_ACQ_AFTER(dpdk_eth_mutex);
+    /* In dpdk_eth_list. */
+    struct ovs_list list_node OVS_GUARDED_BY(dpdk_eth_mutex);
- /* 1 pad byte here. */
-    );
+    /* Device arguments for dpdk ports. */
+    char *devargs;
- PADDED_MEMBERS(CACHE_LINE_SIZE,
-        struct netdev up;
-        /* In dpdk_eth_list or dpdk_vhost_list. */
-        struct ovs_list list_node;
+    struct rte_eth_link link;
- /* QoS configuration and lock for the device */
-        OVSRCU_TYPE(struct dpdk_qos_conf *) qos_conf;
+    /* Requested rx queue steering flags,
+     * from the enum set 'dpdk_rx_steer_flags'. */
+    uint64_t requested_rx_steer_flags;
+    uint64_t rx_steer_flags;
+    size_t rx_steer_flows_num;
+    struct rte_flow **rx_steer_flows;
- /* Ingress Policer */
-        OVSRCU_TYPE(struct dpdk_qos_ingress_policer *) ingress_policer;
-        uint32_t policer_rate;
-        uint32_t policer_burst;
+    /* Names of all XSTATS counters */
+    struct rte_eth_xstat_name *rte_xstats_names;
+    uint64_t *rte_xstats_ids;
- /* Array of vhost rxq states, see vring_state_changed. */
-        bool *vhost_rxq_enabled;
+    /* DPDK-ETH Flow control */
+    struct rte_eth_fc_conf fc_conf;
+};
- /* Ensures that Rx metadata delivery is configured only once. */
-        bool rx_metadata_delivery_configured;
-    );
+static struct netdev_dpdk_eth *
+netdev_dpdk_eth_cast(const struct netdev *netdev)
+{
+    return CONTAINER_OF(netdev, struct netdev_dpdk_eth, common.up);
+}
+struct netdev_dpdk_vhost {
      PADDED_MEMBERS(CACHE_LINE_SIZE,
-        struct netdev_stats stats;
-        struct netdev_dpdk_sw_stats *sw_stats;
-        /* Protects stats */
-        rte_spinlock_t stats_lock;
-        /* 36 pad bytes here. */
-    );
+        /* virtio identifier for vhost devices */
+        ovsrcu_index vid;
- PADDED_MEMBERS(CACHE_LINE_SIZE,
-        /* The following properties cannot be changed when a device is running,
-         * so we remember the request and update them next time
-         * netdev_dpdk*_reconfigure() is called */
-        int requested_mtu;
-        int requested_n_txq;
-        /* User input for n_rxq (see dpdk_set_rxq_config). */
-        int user_n_rxq;
-        /* user_n_rxq + an optional rx steering queue (see
-         * netdev_dpdk_eth_reconfigure). This field is different from the other
-         * requested_* fields as it may contain a different value than the user
-         * input. */
-        int requested_n_rxq;
-        int requested_rxq_size;
-        int requested_txq_size;
+        /* True if vHost device is 'up' and has been reconfigured at least
+         * once. */
+        bool vhost_reconfigured;
- /* Number of rx/tx descriptors for physical devices */
-        int rxq_size;
-        int txq_size;
+        atomic_uint8_t vhost_tx_retries_max;
- /* Socket ID detected when vHost device is brought up */
-        int requested_socket_id;
+        /* Array of vhost rxq states, see vring_state_changed. */
+        bool *vhost_rxq_enabled;
- /* Ignored by DPDK for vhost-user backends, only for VDUSE. */
-        uint8_t vhost_max_queue_pairs;
+        /* No datapath fields below for this block. */
+ /* Identifier used to distinguish vhost devices from each other. */
+        char *vhost_id;
          /* Denotes whether vHost port is client/server mode */
          uint64_t vhost_driver_flags;
+        /* Flags for virtio features recovery mechanism. */
+        uint8_t virtio_features_state;
+        /* Ignored by DPDK for vhost-user backends, only for VDUSE. */
+        uint8_t vhost_max_queue_pairs;
+    );
- /* DPDK-ETH Flow control */
-        struct rte_eth_fc_conf fc_conf;
-
-        /* DPDK-ETH hardware offload features,
-         * from the enum set 'dpdk_hw_ol_features' */
-        uint32_t hw_ol_features;
-
-        /* Properties for link state change detection mode.
-         * If lsc_interrupt_mode is set to false, poll mode is used,
-         * otherwise interrupt mode is used. */
-        bool requested_lsc_interrupt_mode;
-        bool lsc_interrupt_mode;
-
-        /* VF configuration. */
-        struct eth_addr requested_hwaddr;
+    struct netdev_dpdk_common common;
- /* Requested rx queue steering flags,
-         * from the enum set 'dpdk_rx_steer_flags'. */
-        uint64_t requested_rx_steer_flags;
-        uint64_t rx_steer_flags;
-        size_t rx_steer_flows_num;
-        struct rte_flow **rx_steer_flows;
-    );
+    /* No datapath fields below for the rest of the structure. */
- PADDED_MEMBERS(CACHE_LINE_SIZE,
-        /* Names of all XSTATS counters */
-        struct rte_eth_xstat_name *rte_xstats_names;
-        int rte_xstats_names_size;
-        int rte_xstats_ids_size;
-        uint64_t *rte_xstats_ids;
-    );
+    struct ovs_mutex mutex OVS_ACQ_AFTER(dpdk_vhost_mutex);
+    /* In dpdk_vhost_list. */
+    struct ovs_list list_node OVS_GUARDED_BY(dpdk_vhost_mutex);
  };
minor: A couple of comments in the common struct could be updated as they are referring to a specific dev type e.g. hw_ol_features, requested_socket_id.

I suppose the reverse is true - any comments in device specific types don't need to specify the type any more.

Other than that LGTM

_______________________________________________
dev mailing list
[email protected]
https://mail.openvswitch.org/mailman/listinfo/ovs-dev

Reply via email to