Re: [Intel-wired-lan] [PATCH iwl-net v2 3/3] ice: fix rebuilding the Tx scheduler tree for large queue counts

2025-05-09 Thread Michal Kubiak
On Fri, May 09, 2025 at 03:07:56PM +0200, Przemek Kitszel wrote:
> 
> > +ice_sched_rm_vsi_subtree(struct ice_port_info *pi,
> > +struct ice_sched_node *vsi_node, u8 owner, u8 tc)
> > +{
> > +   u16 vsi_handle = vsi_node->vsi_handle;
> > +   bool all_vsi_nodes_removed = true;
> > +   int j = 0;
> > +
> > +   while (vsi_node) {
> > +   struct ice_sched_node *next_vsi_node;
> > +
> > +   if (ice_sched_is_leaf_node_present(vsi_node)) {
> > +   ice_debug(pi->hw, ICE_DBG_SCHED, "VSI has leaf nodes in 
> > TC %d\n", tc);
> > +   return -EBUSY;
> > +   }
> > +   while (j < vsi_node->num_children) {
> > +   if (vsi_node->children[j]->owner == owner) {
> > +   ice_free_sched_node(pi, vsi_node->children[j]);
> > +
> > +   /* reset the counter again since the num
> > +* children will be updated after node removal
> > +*/
> > +   j = 0;
> 
> I know this code is a copy-pasta, but it looks that there is no need to
> reset the counter (whole array isn't reshuffled), just don't increase it
> 
You are right. After analyzing the `ice_free_sched_node()` function, it seems
we should just keep the value of `j`. After removing the child node, other
children nodes will be shifted towards the beginning of the array.

> IOW, would be good to check if this line (and the semi-obvious and
> half-wrong comment) could be removed.

I would prefer to change the code, since I'm touching it.

> 
> you could keep my RB tag, thank you again for the series!
>

Let's wait until early next week to gather more potential comments.
Then I will address it in v3.

This minor fix will not be directly related to the core of the series,
so the v2 can still be used to test the workings of XDP on multi-core machines.

Thanks,
Michal

> > +   } else {
> > +   j++;
> > +   }
> > +   }
> > +
> > +   next_vsi_node = ice_sched_find_next_vsi_node(vsi_node);
> > +
> > +   /* remove the VSI if it has no children */
> > +   if (!vsi_node->num_children)
> > +   ice_free_sched_node(pi, vsi_node);
> > +   else
> > +   all_vsi_nodes_removed = false;
> > +
> > +   vsi_node = next_vsi_node;
> > +   }
> > +
> > +   /* clean up aggregator related VSI info if any */
> > +   if (all_vsi_nodes_removed)
> > +   ice_sched_rm_agg_vsi_info(pi, vsi_handle);
> > +
> > +   return 0;
> > +}


Re: [Intel-wired-lan] [PATCH iwl-net v2 3/3] ice: fix rebuilding the Tx scheduler tree for large queue counts

2025-05-09 Thread Przemek Kitszel




+ice_sched_rm_vsi_subtree(struct ice_port_info *pi,
+struct ice_sched_node *vsi_node, u8 owner, u8 tc)
+{
+   u16 vsi_handle = vsi_node->vsi_handle;
+   bool all_vsi_nodes_removed = true;
+   int j = 0;
+
+   while (vsi_node) {
+   struct ice_sched_node *next_vsi_node;
+
+   if (ice_sched_is_leaf_node_present(vsi_node)) {
+   ice_debug(pi->hw, ICE_DBG_SCHED, "VSI has leaf nodes in TC 
%d\n", tc);
+   return -EBUSY;
+   }
+   while (j < vsi_node->num_children) {
+   if (vsi_node->children[j]->owner == owner) {
+   ice_free_sched_node(pi, vsi_node->children[j]);
+
+   /* reset the counter again since the num
+* children will be updated after node removal
+*/
+   j = 0;


I know this code is a copy-pasta, but it looks that there is no need to
reset the counter (whole array isn't reshuffled), just don't increase it

IOW, would be good to check if this line (and the semi-obvious and
half-wrong comment) could be removed.

you could keep my RB tag, thank you again for the series!


+   } else {
+   j++;
+   }
+   }
+
+   next_vsi_node = ice_sched_find_next_vsi_node(vsi_node);
+
+   /* remove the VSI if it has no children */
+   if (!vsi_node->num_children)
+   ice_free_sched_node(pi, vsi_node);
+   else
+   all_vsi_nodes_removed = false;
+
+   vsi_node = next_vsi_node;
+   }
+
+   /* clean up aggregator related VSI info if any */
+   if (all_vsi_nodes_removed)
+   ice_sched_rm_agg_vsi_info(pi, vsi_handle);
+
+   return 0;
+}


[Intel-wired-lan] [PATCH iwl-net v2 3/3] ice: fix rebuilding the Tx scheduler tree for large queue counts

2025-05-09 Thread Michal Kubiak
The current implementation of the Tx scheduler allows the tree to be
rebuilt as the user adds more Tx queues to the VSI. In such a case,
additional child nodes are added to the tree to support the new number
of queues.
Unfortunately, this algorithm does not take into account that the limit
of the VSI support node may be exceeded, so an additional node in the
VSI layer may be required to handle all the requested queues.

Such a scenario occurs when adding XDP Tx queues on machines with many
CPUs. Although the driver still respects the queue limit returned by
the FW, the Tx scheduler was unable to add those queues to its tree
and returned one of the errors below.

Such a scenario occurs when adding XDP Tx queues on machines with many
CPUs (e.g. at least 321 CPUs, if there is already 128 Tx/Rx queue pairs).
Although the driver still respects the queue limit returned by the FW,
the Tx scheduler was unable to add those queues to its tree and returned
the following errors:

 Failed VSI LAN queue config for XDP, error: -5
or:
 Failed to set LAN Tx queue context, error: -22

Fix this problem by extending the tree rebuild algorithm to check if the
current VSI node can support the requested number of queues. If it
cannot, create as many additional VSI support nodes as necessary to
handle all the required Tx queues. Symmetrically, adjust the VSI node removal
algorithm to remove all nodes associated with the given VSI.
Also, make the search for the next free VSI node more restrictive. That is,
add queue group nodes only to the VSI support nodes that have a matching
VSI handle.
Finally, fix the comment describing the tree update algorithm to better
reflect the current scenario.

Fixes: b0153fdd7e8a ("ice: update VSI config dynamically")
Reviewed-by: Dawid Osuchowski 
Reviewed-by: Przemek Kitszel 
Signed-off-by: Michal Kubiak 
---
 drivers/net/ethernet/intel/ice/ice_sched.c | 176 +
 1 file changed, 148 insertions(+), 28 deletions(-)

diff --git a/drivers/net/ethernet/intel/ice/ice_sched.c 
b/drivers/net/ethernet/intel/ice/ice_sched.c
index 6524875b34d3..51da7186e402 100644
--- a/drivers/net/ethernet/intel/ice/ice_sched.c
+++ b/drivers/net/ethernet/intel/ice/ice_sched.c
@@ -84,6 +84,27 @@ ice_sched_find_node_by_teid(struct ice_sched_node 
*start_node, u32 teid)
return NULL;
 }
 
+/**
+ * ice_sched_find_next_vsi_node - find the next node for a given VSI
+ * @vsi_node: VSI support node to start search with
+ *
+ * Return: Next VSI support node, or NULL.
+ *
+ * The function returns a pointer to the next node from the VSI layer
+ * assigned to the given VSI, or NULL if there is no such a node.
+ */
+static struct ice_sched_node *
+ice_sched_find_next_vsi_node(struct ice_sched_node *vsi_node)
+{
+   unsigned int vsi_handle = vsi_node->vsi_handle;
+
+   while ((vsi_node = vsi_node->sibling) != NULL)
+   if (vsi_node->vsi_handle == vsi_handle)
+   break;
+
+   return vsi_node;
+}
+
 /**
  * ice_aqc_send_sched_elem_cmd - send scheduling elements cmd
  * @hw: pointer to the HW struct
@@ -1084,8 +1105,10 @@ ice_sched_add_nodes_to_layer(struct ice_port_info *pi,
if (parent->num_children < max_child_nodes) {
new_num_nodes = max_child_nodes - parent->num_children;
} else {
-   /* This parent is full, try the next sibling */
-   parent = parent->sibling;
+   /* This parent is full,
+* try the next available sibling.
+*/
+   parent = ice_sched_find_next_vsi_node(parent);
/* Don't modify the first node TEID memory if the
 * first node was added already in the above call.
 * Instead send some temp memory for all other
@@ -1528,12 +1551,23 @@ ice_sched_get_free_qparent(struct ice_port_info *pi, 
u16 vsi_handle, u8 tc,
/* get the first queue group node from VSI sub-tree */
qgrp_node = ice_sched_get_first_node(pi, vsi_node, qgrp_layer);
while (qgrp_node) {
+   struct ice_sched_node *next_vsi_node;
+
/* make sure the qgroup node is part of the VSI subtree */
if (ice_sched_find_node_in_subtree(pi->hw, vsi_node, qgrp_node))
if (qgrp_node->num_children < max_children &&
qgrp_node->owner == owner)
break;
qgrp_node = qgrp_node->sibling;
+   if (qgrp_node)
+   continue;
+
+   next_vsi_node = ice_sched_find_next_vsi_node(vsi_node);
+   if (!next_vsi_node)
+   break;
+
+   vsi_node = next_vsi_node;
+   qgrp_node = ice_sched_get_first_node(pi, vsi_node, qgrp_layer);
}
 
/* Select the best queue group */
@@ -1779,7 +1813,11 @@