Skip to contentSkip to conversation

ixgbe: let the xdpdrv work with more than 64 cpus

PATCH Superseded [email protected] 4 participants 9 messages Aug 26, 2021 – Aug 27, 2021

Subsystems (4)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 ixgbe: let the xdpdrv work with more than 64 cpus

From: Jason Xing <[email protected]>

Originally, ixgbe driver doesn't allow the mounting of xdpdrv if the server is equipped with more than 64 cpus online. So it turns out that the loading of xdpdrv causes the "NOMEM" failure.

Actually, we can adjust the algorithm and then make it work through mapping the current cpu to some xdp ring with the protect of @tx_lock.

v4:
- Update the wrong commit messages. (Jason)

v3:
- Change nr_cpu_ids to num_online_cpus() (Maciej)
- Rename MAX_XDP_QUEUES to IXGBE_MAX_XDP_QS (Maciej)
- Rename ixgbe_determine_xdp_cpu() to ixgbe_determine_xdp_q_idx() (Maciej)
- Wrap ixgbe_xdp_ring_update_tail() with lock into one function (Maciej)

v2:
- Adjust cpu id in ixgbe_xdp_xmit(). (Jesper)
- Add a fallback path. (Maciej)
- Adjust other parts related to xdp ring.

Fixes 33fdc82f08 ("ixgbe: add support for XDP_TX action")
---
 drivers/net/ethernet/intel/ixgbe/ixgbe.h           | 15 ++++-
 drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c       |  9 ++-
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c      | 64 ++++++++++++++++------
 .../net/ethernet/intel/ixgbe/ixgbe_txrx_common.h   |  1 +
 drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c       |  9 +--
 5 files changed, 73 insertions(+), 25 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe.h +13 -2
index a604552..5f7f181 100644
@@ -82,6 +82,8 @@
 #define IXGBE_2K_TOO_SMALL_WITH_PADDING \
 ((NET_SKB_PAD + IXGBE_RXBUFFER_1536) > SKB_WITH_OVERHEAD(IXGBE_RXBUFFER_2K))
 
+DECLARE_STATIC_KEY_FALSE(ixgbe_xdp_locking_key);
+
 static inline int ixgbe_compute_pad(int rx_buf_len)
 {
 	int page_size, pad_size;
@@ -351,6 +353,7 @@ struct ixgbe_ring {
 	};
 	u16 rx_offset;
 	struct xdp_rxq_info xdp_rxq;
+	spinlock_t tx_lock;	/* used in XDP mode */
 	struct xsk_buff_pool *xsk_pool;
 	u16 ring_idx;		/* {rx,tx,xdp}_ring back reference idx */
 	u16 rx_buf_len;
@@ -375,7 +378,7 @@ enum ixgbe_ring_f_enum {
 #define IXGBE_MAX_FCOE_INDICES		8
 #define MAX_RX_QUEUES			(IXGBE_MAX_FDIR_INDICES + 1)
 #define MAX_TX_QUEUES			(IXGBE_MAX_FDIR_INDICES + 1)
-#define MAX_XDP_QUEUES			(IXGBE_MAX_FDIR_INDICES + 1)
+#define IXGBE_MAX_XDP_QS		(IXGBE_MAX_FDIR_INDICES + 1)
 #define IXGBE_MAX_L2A_QUEUES		4
 #define IXGBE_BAD_L2A_QUEUE		3
 #define IXGBE_MAX_MACVLANS		63
@@ -629,7 +632,7 @@ struct ixgbe_adapter {
 
 	/* XDP */
 	int num_xdp_queues;
-	struct ixgbe_ring *xdp_ring[MAX_XDP_QUEUES];
+	struct ixgbe_ring *xdp_ring[IXGBE_MAX_XDP_QS];
 	unsigned long *af_xdp_zc_qps; /* tracks AF_XDP ZC enabled rings */
 
 	/* TX */
@@ -772,6 +775,14 @@ struct ixgbe_adapter {
 #endif /* CONFIG_IXGBE_IPSEC */
 };
 
+static inline int ixgbe_determine_xdp_q_idx(int cpu)
+{
+	if (static_key_enabled(&ixgbe_xdp_locking_key))
+		return cpu % IXGBE_MAX_XDP_QS;
+	else
+		return cpu;
+}
+
 static inline u8 ixgbe_max_rss_indices(struct ixgbe_adapter *adapter)
 {
 	switch (adapter->hw.mac.type) {
drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c +8 -1
index 0218f6c..884bf99 100644
@@ -299,7 +299,10 @@ static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
 
 static int ixgbe_xdp_queues(struct ixgbe_adapter *adapter)
 {
-	return adapter->xdp_prog ? nr_cpu_ids : 0;
+	int queues;
+
+	queues = min_t(int, IXGBE_MAX_XDP_QS, num_online_cpus());
+	return adapter->xdp_prog ? queues : 0;
 }
 
 #define IXGBE_RSS_64Q_MASK	0x3F
@@ -947,6 +950,7 @@ static int ixgbe_alloc_q_vector(struct ixgbe_adapter *adapter,
 		ring->count = adapter->tx_ring_count;
 		ring->queue_index = xdp_idx;
 		set_ring_xdp(ring);
+		spin_lock_init(&ring->tx_lock);
 
 		/* assign ring to adapter */
 		WRITE_ONCE(adapter->xdp_ring[xdp_idx], ring);
@@ -1032,6 +1036,9 @@ static void ixgbe_free_q_vector(struct ixgbe_adapter *adapter, int v_idx)
 	adapter->q_vector[v_idx] = NULL;
 	__netif_napi_del(&q_vector->napi);
 
+	if (static_key_enabled(&ixgbe_xdp_locking_key))
+		static_branch_dec(&ixgbe_xdp_locking_key);
+
 	/*
 	 * after a call to __netif_napi_del() napi may still be used and
 	 * ixgbe_get_stats64() might access the rings on this vector,
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +48 -16

139 lines not on this page · raw message

drivers/net/ethernet/intel/ixgbe/ixgbe_txrx_common.h +1 -0
index 2aeec78..f6426d9 100644
@@ -23,6 +23,7 @@ void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
 void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
 		  struct sk_buff *skb);
 void ixgbe_xdp_ring_update_tail(struct ixgbe_ring *ring);
+void ixgbe_xdp_ring_update_tail_locked(struct ixgbe_ring *ring);
 void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter, u64 qmask);
 
 void ixgbe_txrx_ring_disable(struct ixgbe_adapter *adapter, int ring);
drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c +3 -6
index b1d22e4..82d00e4 100644
@@ -334,13 +334,10 @@ int ixgbe_clean_rx_irq_zc(struct ixgbe_q_vector *q_vector,
 		xdp_do_flush_map();
 
 	if (xdp_xmit & IXGBE_XDP_TX) {
-		struct ixgbe_ring *ring = adapter->xdp_ring[smp_processor_id()];
+		int index = ixgbe_determine_xdp_q_idx(smp_processor_id());
+		struct ixgbe_ring *ring = adapter->xdp_ring[index];
 
-		/* Force memory writes to complete before letting h/w
-		 * know there are new descriptors to fetch.
-		 */
-		wmb();
-		writel(ring->next_to_use, ring->tail);
+		ixgbe_xdp_ring_update_tail_locked(ring);
 	}
 
 	u64_stats_update_begin(&rx_ring->syncp);
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 8 lines · kerneljasonxing at gmail.com

From: Jason Xing <[email protected]>

Originally, ixgbe driver doesn't allow the mounting of xdpdrv if the server is equipped with more than 64 cpus online. So it turns out that the loading of xdpdrv causes the "NOMEM" failure.

Actually, we can adjust the algorithm and then make it work through mapping the current cpu to some xdp ring with the protect of @tx_lock.

Thank you very much for working on this!

you should put your sign off block here, and then end with a triple-dash "---"

then have your vN: updates below that, so they will be dropped from final git apply. It's ok to have more than one triple-dash.

Quoted 26 lines

v4:
- Update the wrong commit messages. (Jason)

v3:
- Change nr_cpu_ids to num_online_cpus() (Maciej)
- Rename MAX_XDP_QUEUES to IXGBE_MAX_XDP_QS (Maciej)
- Rename ixgbe_determine_xdp_cpu() to ixgbe_determine_xdp_q_idx() (Maciej)
- Wrap ixgbe_xdp_ring_update_tail() with lock into one function (Maciej)

v2:
- Adjust cpu id in ixgbe_xdp_xmit(). (Jesper)
- Add a fallback path. (Maciej)
- Adjust other parts related to xdp ring.

Fixes 33fdc82f08 ("ixgbe: add support for XDP_TX action")
---
 drivers/net/ethernet/intel/ixgbe/ixgbe.h           | 15 ++++-
 drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c       |  9 ++-
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c      | 64 ++++++++++++++++------
 .../net/ethernet/intel/ixgbe/ixgbe_txrx_common.h   |  1 +
 drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c       |  9 +--
 5 files changed, 73 insertions(+), 25 deletions(-)

...

Quoted 17 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +2 -3
@@ -8539,21 +8539,32 @@ static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
 int ixgbe_xmit_xdp_ring(struct ixgbe_adapter *adapter,
 			struct xdp_frame *xdpf)
 {
-	struct ixgbe_ring *ring = adapter->xdp_ring[smp_processor_id()];
 	struct ixgbe_tx_buffer *tx_buffer;
 	union ixgbe_adv_tx_desc *tx_desc;
+	struct ixgbe_ring *ring;
 	u32 len, cmd_type;
 	dma_addr_t dma;
+	int index, ret;
 	u16 i;
 
 	len = xdpf->len;
 
-	if (unlikely(!ixgbe_desc_unused(ring)))
-		return IXGBE_XDP_CONSUMED;

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb, · line 8561

Quoted 10 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +10 -0
+	index = ixgbe_determine_xdp_q_idx(smp_processor_id());
+	ring = adapter->xdp_ring[index];
+
+	if (static_branch_unlikely(&ixgbe_xdp_locking_key))
+		spin_lock(&ring->tx_lock);
+
+	if (unlikely(!ixgbe_desc_unused(ring))) {
+		ret = IXGBE_XDP_CONSUMED;
+		goto out;
+	}

This static key stuff is tricky code, but I guess if it works, then it's better than nothing.

As Maciej also commented, I'd like to see some before/after numbers for some of the xdp sample programs to make sure this doesn't cause a huge regression on the xdp transmit path. A small regression would be ok, since this *is* adding overhead.

Jesse

author
#2 lore raw
Quoted 11 lines · Jesse Brandeburg
Quoted 8 lines · kerneljasonxing at gmail.com

From: Jason Xing <[email protected]>

Originally, ixgbe driver doesn't allow the mounting of xdpdrv if the server is equipped with more than 64 cpus online. So it turns out that the loading of xdpdrv causes the "NOMEM" failure.

Actually, we can adjust the algorithm and then make it work through mapping the current cpu to some xdp ring with the protect of @tx_lock.

Quoted 8 lines

Thank you very much for working on this!

you should put your sign off block here, and then end with a triple-dash "---"

then have your vN: updates below that, so they will be dropped from final git apply. It's ok to have more than one triple-dash.

Thanks. Now I know much more about the submission.

Quoted 60 lines
Quoted 26 lines

v4:
- Update the wrong commit messages. (Jason)

v3:
- Change nr_cpu_ids to num_online_cpus() (Maciej)
- Rename MAX_XDP_QUEUES to IXGBE_MAX_XDP_QS (Maciej)
- Rename ixgbe_determine_xdp_cpu() to ixgbe_determine_xdp_q_idx() (Maciej)
- Wrap ixgbe_xdp_ring_update_tail() with lock into one function (Maciej)

v2:
- Adjust cpu id in ixgbe_xdp_xmit(). (Jesper)
- Add a fallback path. (Maciej)
- Adjust other parts related to xdp ring.

Fixes 33fdc82f08 ("ixgbe: add support for XDP_TX action")
---
 drivers/net/ethernet/intel/ixgbe/ixgbe.h           | 15 ++++-
 drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c       |  9 ++-
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c      | 64 ++++++++++++++++------
 .../net/ethernet/intel/ixgbe/ixgbe_txrx_common.h   |  1 +
 drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c       |  9 +--
 5 files changed, 73 insertions(+), 25 deletions(-)

...

Quoted 17 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +2 -3
@@ -8539,21 +8539,32 @@ static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb,
 int ixgbe_xmit_xdp_ring(struct ixgbe_adapter *adapter,
                      struct xdp_frame *xdpf)
 {
-     struct ixgbe_ring *ring = adapter->xdp_ring[smp_processor_id()];
      struct ixgbe_tx_buffer *tx_buffer;
      union ixgbe_adv_tx_desc *tx_desc;
+     struct ixgbe_ring *ring;
      u32 len, cmd_type;
      dma_addr_t dma;
+     int index, ret;
      u16 i;
 
      len = xdpf->len;
 
-     if (unlikely(!ixgbe_desc_unused(ring)))
-             return IXGBE_XDP_CONSUMED;

drivers/net/ethernet/intel/ixgbe/ixgbe_main.c static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb, · line 8561

Quoted 10 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +10 -0
+     index = ixgbe_determine_xdp_q_idx(smp_processor_id());
+     ring = adapter->xdp_ring[index];
+
+     if (static_branch_unlikely(&ixgbe_xdp_locking_key))
+             spin_lock(&ring->tx_lock);
+
+     if (unlikely(!ixgbe_desc_unused(ring))) {
+             ret = IXGBE_XDP_CONSUMED;
+             goto out;
+     }

This static key stuff is tricky code, but I guess if it works, then it's better than nothing.

Quoted 5 lines

As Maciej also commented, I'd like to see some before/after numbers for some of the xdp sample programs to make sure this doesn't cause a huge regression on the xdp transmit path. A small regression would be ok, since this *is* adding overhead.

Fine. It will take me some time. BTW, I'm wondering that, after I'm done with the analysis, should I just reply to this email directly or send the v5 patch including those numbers?

Thanks,
Jason

Quoted 2 lines

Jesse

#3 lore raw
In reply to [email protected]
Quoted 6 lines · kerneljasonxing at gmail.com

From: Jason Xing <[email protected]>

Originally, ixgbe driver doesn't allow the mounting of xdpdrv if the server is equipped with more than 64 cpus online. So it turns out that the loading of xdpdrv causes the "NOMEM" failure.

Quoted 8 lines

Actually, we can adjust the algorithm and then make it work through mapping the current cpu to some xdp ring with the protect of @tx_lock.

v4:
- Update the wrong commit messages. (Jason)

v3:
- Change nr_cpu_ids to num_online_cpus() (Maciej)

I suspect this is wrong.

Quoted 61 lines

- Rename MAX_XDP_QUEUES to IXGBE_MAX_XDP_QS (Maciej)
- Rename ixgbe_determine_xdp_cpu() to ixgbe_determine_xdp_q_idx() (Maciej)
- Wrap ixgbe_xdp_ring_update_tail() with lock into one function (Maciej)

v2:
- Adjust cpu id in ixgbe_xdp_xmit(). (Jesper)
- Add a fallback path. (Maciej)
- Adjust other parts related to xdp ring.

Fixes 33fdc82f08 ("ixgbe: add support for XDP_TX action")
---
 drivers/net/ethernet/intel/ixgbe/ixgbe.h           | 15 ++++-
 drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c       |  9 ++-
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c      | 64 ++++++++++++++++------
 .../net/ethernet/intel/ixgbe/ixgbe_txrx_common.h   |  1 +
 drivers/net/ethernet/intel/ixgbe/ixgbe_xsk.c       |  9 +--
 5 files changed, 73 insertions(+), 25 deletions(-)
drivers/net/ethernet/intel/ixgbe/ixgbe.h +5 -2
index a604552..5f7f181 100644
@@ -82,6 +82,8 @@
 #define IXGBE_2K_TOO_SMALL_WITH_PADDING \
 ((NET_SKB_PAD + IXGBE_RXBUFFER_1536) > SKB_WITH_OVERHEAD(IXGBE_RXBUFFER_2K))
 
+DECLARE_STATIC_KEY_FALSE(ixgbe_xdp_locking_key);
+
 static inline int ixgbe_compute_pad(int rx_buf_len)
 {
 	int page_size, pad_size;
@@ -351,6 +353,7 @@ struct ixgbe_ring {
 	};
 	u16 rx_offset;
 	struct xdp_rxq_info xdp_rxq;
+	spinlock_t tx_lock;	/* used in XDP mode */
 	struct xsk_buff_pool *xsk_pool;
 	u16 ring_idx;		/* {rx,tx,xdp}_ring back reference idx */
 	u16 rx_buf_len;
@@ -375,7 +378,7 @@ enum ixgbe_ring_f_enum {
 #define IXGBE_MAX_FCOE_INDICES		8
 #define MAX_RX_QUEUES			(IXGBE_MAX_FDIR_INDICES + 1)
 #define MAX_TX_QUEUES			(IXGBE_MAX_FDIR_INDICES + 1)
-#define MAX_XDP_QUEUES			(IXGBE_MAX_FDIR_INDICES + 1)
+#define IXGBE_MAX_XDP_QS		(IXGBE_MAX_FDIR_INDICES + 1)
 #define IXGBE_MAX_L2A_QUEUES		4
 #define IXGBE_BAD_L2A_QUEUE		3
 #define IXGBE_MAX_MACVLANS		63
@@ -629,7 +632,7 @@ struct ixgbe_adapter {
 
 	/* XDP */
 	int num_xdp_queues;
-	struct ixgbe_ring *xdp_ring[MAX_XDP_QUEUES];
+	struct ixgbe_ring *xdp_ring[IXGBE_MAX_XDP_QS];
 	unsigned long *af_xdp_zc_qps; /* tracks AF_XDP ZC enabled rings */
 
 	/* TX */

drivers/net/ethernet/intel/ixgbe/ixgbe.h struct ixgbe_adapter { · line 783

Quoted 9 lines
drivers/net/ethernet/intel/ixgbe/ixgbe.h +6 -0
@@ -772,6 +775,14 @@ struct ixgbe_adapter {
 #endif /* CONFIG_IXGBE_IPSEC */
 };
 
+static inline int ixgbe_determine_xdp_q_idx(int cpu)
+{
+	if (static_key_enabled(&ixgbe_xdp_locking_key))
+		return cpu % IXGBE_MAX_XDP_QS;
+	else
+		return cpu;

Even if num_online_cpus() is 8, the returned cpu here could be

0, 32, 64, 96, 128, 161, 197, 224

Are we sure this will still be ok ?

Quoted 10 lines
drivers/net/ethernet/intel/ixgbe/ixgbe.h +2 -0
+}
+
 static inline u8 ixgbe_max_rss_indices(struct ixgbe_adapter *adapter)
 {
 	switch (adapter->hw.mac.type) {
drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c +0 -0
index 0218f6c..884bf99 100644

drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter) · line 304

Quoted 7 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c +3 -1
@@ -299,7 +299,10 @@ static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
 
 static int ixgbe_xdp_queues(struct ixgbe_adapter *adapter)
 {
-	return adapter->xdp_prog ? nr_cpu_ids : 0;
+	int queues;
+
+	queues = min_t(int, IXGBE_MAX_XDP_QS, num_online_cpus());

num_online_cpus() might change later...

Quoted 21 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c +5 -0
+	return adapter->xdp_prog ? queues : 0;
 }
 
 #define IXGBE_RSS_64Q_MASK	0x3F
@@ -947,6 +950,7 @@ static int ixgbe_alloc_q_vector(struct ixgbe_adapter *adapter,
 		ring->count = adapter->tx_ring_count;
 		ring->queue_index = xdp_idx;
 		set_ring_xdp(ring);
+		spin_lock_init(&ring->tx_lock);
 
 		/* assign ring to adapter */
 		WRITE_ONCE(adapter->xdp_ring[xdp_idx], ring);
@@ -1032,6 +1036,9 @@ static void ixgbe_free_q_vector(struct ixgbe_adapter *adapter, int v_idx)
 	adapter->q_vector[v_idx] = NULL;
 	__netif_napi_del(&q_vector->napi);
 
+	if (static_key_enabled(&ixgbe_xdp_locking_key))
+		static_branch_dec(&ixgbe_xdp_locking_key);
+
 	/*
 
#4 lore raw
Quoted 9 lines · Eric Dumazet

drivers/net/ethernet/intel/ixgbe/ixgbe.h struct ixgbe_adapter { · line 783

Quoted 6 lines
drivers/net/ethernet/intel/ixgbe/ixgbe.h +6 -0
+static inline int ixgbe_determine_xdp_q_idx(int cpu)
+{
+	if (static_key_enabled(&ixgbe_xdp_locking_key))
+		return cpu % IXGBE_MAX_XDP_QS;
+	else
+		return cpu;

Even if num_online_cpus() is 8, the returned cpu here could be

Quoted 3 lines

0, 32, 64, 96, 128, 161, 197, 224

Are we sure this will still be ok ?

I'm not sure about that one myself. Jason?

Quoted 12 lines
Quoted 12 lines
drivers/net/ethernet/intel/ixgbe/ixgbe.h +2 -0
+}
+
 static inline u8 ixgbe_max_rss_indices(struct ixgbe_adapter *adapter)
 {
 	switch (adapter->hw.mac.type) {
drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c +0 -0
index 0218f6c..884bf99 100644
@@ -299,7 +299,10 @@ static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
 
Quoted 8 lines

drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter) · line 304

Quoted 6 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c +3 -1
 static int ixgbe_xdp_queues(struct ixgbe_adapter *adapter)
 {
-	return adapter->xdp_prog ? nr_cpu_ids : 0;
+	int queues;
+
+	queues = min_t(int, IXGBE_MAX_XDP_QS, num_online_cpus());

num_online_cpus() might change later...

I saw that too, but I wonder if it doesn't matter to the driver. If a CPU goes offline or comes online after the driver loads, we will use this logic to try to pick an available TX queue. But this is a complicated thing that is easy to get wrong, is there a common example of how to get it right?

A possible problem I guess is that if the "static_key_enabled" check returned false in the past, we would need to update that if the number of CPUs changes, do we need a notifier?

Also, now that I'm asking it, I dislike the global as it would apply to all ixgbe ports and each PF would increment and decrement it independently. Showing my ignorance here, but I haven't seen this utility in the kernel before in detail. Not sure if this is "OK" from multiple device (with the same driver / global namespace) perspective.

author
#5 lore raw
Quoted 39 lines · Jesse Brandeburg
Quoted 9 lines · Eric Dumazet

drivers/net/ethernet/intel/ixgbe/ixgbe.h struct ixgbe_adapter { · line 783

Quoted 6 lines
drivers/net/ethernet/intel/ixgbe/ixgbe.h +6 -0
+static inline int ixgbe_determine_xdp_q_idx(int cpu)
+{
+    if (static_key_enabled(&ixgbe_xdp_locking_key))
+            return cpu % IXGBE_MAX_XDP_QS;
+    else
+            return cpu;

Even if num_online_cpus() is 8, the returned cpu here could be

Quoted 3 lines

0, 32, 64, 96, 128, 161, 197, 224

Are we sure this will still be ok ?

I'm not sure about that one myself. Jason?

Quoted 12 lines
Quoted 12 lines
drivers/net/ethernet/intel/ixgbe/ixgbe.h +2 -0
+}
+
 static inline u8 ixgbe_max_rss_indices(struct ixgbe_adapter *adapter)
 {
     switch (adapter->hw.mac.type) {
drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c +0 -0
index 0218f6c..884bf99 100644
@@ -299,7 +299,10 @@ static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
 
Quoted 8 lines

drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter) · line 304

Quoted 6 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c +3 -1
 static int ixgbe_xdp_queues(struct ixgbe_adapter *adapter)
 {
-    return adapter->xdp_prog ? nr_cpu_ids : 0;
+    int queues;
+
+    queues = min_t(int, IXGBE_MAX_XDP_QS, num_online_cpus());

num_online_cpus() might change later...

Quoted 6 lines

I saw that too, but I wonder if it doesn't matter to the driver. If a CPU goes offline or comes online after the driver loads, we will use this logic to try to pick an available TX queue. But this is a complicated thing that is easy to get wrong, is there a common example of how to get it right?

Honestly, I'm a little confused right now. @nr_cpu_ids is the fixed number which means the total number of cpus the machine has. I think, using @nr_cpu_ids is safe one way or the other regardless of whether the cpu goes offline or not. What do you think?

Quoted 4 lines

A possible problem I guess is that if the "static_key_enabled" check returned false in the past, we would need to update that if the number of CPUs changes, do we need a notifier?

Things get complicated. If the number decreases down to @IXGBE_MAX_XDP_QS (which is 64), the notifier could be useful because we wouldn't need to use the @tx_lock. I'm wondering if we really need to implement one notifier for this kind of change?

Quoted 6 lines

Also, now that I'm asking it, I dislike the global as it would apply to all ixgbe ports and each PF would increment and decrement it independently. Showing my ignorance here, but I haven't seen this utility in the kernel before in detail. Not sure if this is "OK" from multiple device (with the same driver / global namespace) perspective.

#6 lore raw
Quoted 14 lines · Jason Xing
Quoted 12 lines · Jesse Brandeburg
Quoted 9 lines · Eric Dumazet

drivers/net/ethernet/intel/ixgbe/ixgbe.h struct ixgbe_adapter { · line 783

Quoted 6 lines
drivers/net/ethernet/intel/ixgbe/ixgbe.h +6 -0
+static inline int ixgbe_determine_xdp_q_idx(int cpu)
+{
+    if (static_key_enabled(&ixgbe_xdp_locking_key))
+            return cpu % IXGBE_MAX_XDP_QS;
+    else
+            return cpu;

Even if num_online_cpus() is 8, the returned cpu here could be

Quoted 5 lines
Quoted 5 lines
Quoted 3 lines

0, 32, 64, 96, 128, 161, 197, 224

Are we sure this will still be ok ?

I'm not sure about that one myself. Jason?

I meant num_possible_cpus(), Jason should have yelled at me in the first place, sorry. Lack of coffee probably. We use num_possible_cpus() on ice side.

Quoted 39 lines
Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
drivers/net/ethernet/intel/ixgbe/ixgbe.h +2 -0
+}
+
 static inline u8 ixgbe_max_rss_indices(struct ixgbe_adapter *adapter)
 {
     switch (adapter->hw.mac.type) {
drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c +0 -0
index 0218f6c..884bf99 100644
@@ -299,7 +299,10 @@ static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
 
Quoted 8 lines

drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter) · line 304

Quoted 6 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_lib.c +3 -1
 static int ixgbe_xdp_queues(struct ixgbe_adapter *adapter)
 {
-    return adapter->xdp_prog ? nr_cpu_ids : 0;
+    int queues;
+
+    queues = min_t(int, IXGBE_MAX_XDP_QS, num_online_cpus());

num_online_cpus() might change later...

Quoted 6 lines

I saw that too, but I wonder if it doesn't matter to the driver. If a CPU goes offline or comes online after the driver loads, we will use this logic to try to pick an available TX queue. But this is a complicated thing that is easy to get wrong, is there a common example of how to get it right?

Honestly, I'm a little confused right now. @nr_cpu_ids is the fixed number which means the total number of cpus the machine has. I think, using @nr_cpu_ids is safe one way or the other regardless of whether the cpu goes offline or not. What do you think?

Quoted 4 lines

A possible problem I guess is that if the "static_key_enabled" check returned false in the past, we would need to update that if the number of CPUs changes, do we need a notifier?

Quoted 10 lines

Things get complicated. If the number decreases down to @IXGBE_MAX_XDP_QS (which is 64), the notifier could be useful because we wouldn't need to use the @tx_lock. I'm wondering if we really need to implement one notifier for this kind of change?

Quoted 5 lines

Also, now that I'm asking it, I dislike the global as it would apply to all ixgbe ports and each PF would increment and decrement it independently. Showing my ignorance here, but I haven't seen this utility in the kernel before in detail. Not sure if this is "OK" from multiple device (with the same driver / global namespace) perspective.

I'm not sure if there's a flawless solution to that. static key approach won't have an impact for < 64 cpus systems but if you trigger this on one PF then rest of the PFs that this driver is serving will be affected.

OTOH see the discussion I had with Toke on a different approach:
https://lore.kernel.org/bpf/[email protected]/

Quoted 5 lines
Quoted 1 line

_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan at osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan

#7 lore raw
In reply to Jason Xing
Quoted 6 lines · Jason Xing

Honestly, I'm a little confused right now. @nr_cpu_ids is the fixed number which means the total number of cpus the machine has. I think, using @nr_cpu_ids is safe one way or the other regardless of whether the cpu goes offline or not. What do you think?

More exactly, nr_cpu_ids is the max number cpu id can reach, even in presence of holes.

I think that most/many num_online_cpus() in drivers/net are simply broken and should be replaced by nr_cpu_ids.

The assumptions of cpus being nicely numbered from [0 to X-1], with X==num_online_cpus() is wrong.

Same remark for num_possible_cpus(), see commit 88d4f0db7fa8 ("perf: Fix alloc_callchain_buffers()") for reference.

author
#8 lore raw
Quoted 12 lines · Eric Dumazet
Quoted 6 lines · Jason Xing

Honestly, I'm a little confused right now. @nr_cpu_ids is the fixed number which means the total number of cpus the machine has. I think, using @nr_cpu_ids is safe one way or the other regardless of whether the cpu goes offline or not. What do you think?

Quoted 6 lines

More exactly, nr_cpu_ids is the max number cpu id can reach, even in presence of holes.

I think that most/many num_online_cpus() in drivers/net are simply broken and should be replaced by nr_cpu_ids.

Thank you, Eric, really. I nearly made a terrible mistake.

Quoted 5 lines

The assumptions of cpus being nicely numbered from [0 to X-1], with X==num_online_cpus() is wrong.

Same remark for num_possible_cpus(), see commit 88d4f0db7fa8 ("perf: Fix alloc_callchain_buffers()") for reference.