[v2,10/15] net/ice/base: optimize subtree searches
Checks
Commit Message
In a number of places throughout the driver code, we want to confirm
that a scheduler node is indeed a child of another node. Currently, this
is confirmed by searching down the tree from the base until the desired
node is hit, a search which may hit many irrelevant tree nodes when
recursing down wrong branches. By switching the direction of search, to
check upwards from the node to the parent, we can avoid any incorrect
paths, and so speed up processing.
Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
drivers/net/ice/base/ice_sched.c | 18 +++++-------------
1 file changed, 5 insertions(+), 13 deletions(-)
@@ -1475,20 +1475,12 @@ ice_sched_find_node_in_subtree(struct ice_hw *hw, struct ice_sched_node *base,
{
u16 i;
- for (i = 0; i < base->num_children; i++) {
- struct ice_sched_node *child = base->children[i];
-
- if (node == child)
- return true;
-
- if (child->tx_sched_layer > node->tx_sched_layer)
- return false;
-
- /* this recursion is intentional, and wouldn't
- * go more than 8 calls
- */
- if (ice_sched_find_node_in_subtree(hw, child, node))
+ if (base == node)
+ return true;
+ while (node->tx_sched_layer != 0 && node->parent != NULL) {
+ if (node->parent == base)
return true;
+ node = node->parent;
}
return false;
}