[PATCH net-next] net: sched: cake: Optimize number of calls to cake_heapify()

From: Kuan-Wei Chiu
Date: Sat Apr 06 2024 - 19:55:49 EST


Improve the max-heap construction process by reducing unnecessary
heapify operations. Specifically, adjust the starting condition from
n / 2 to n / 2 - 1 in the loop that iterates over all non-leaf
elements.

Signed-off-by: Kuan-Wei Chiu <visitorckw@xxxxxxxxx>
---
net/sched/sch_cake.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/sched/sch_cake.c b/net/sched/sch_cake.c
index edee926ccde8..2eabc4dc5b79 100644
--- a/net/sched/sch_cake.c
+++ b/net/sched/sch_cake.c
@@ -1512,7 +1512,7 @@ static unsigned int cake_drop(struct Qdisc *sch, struct sk_buff **to_free)
if (!q->overflow_timeout) {
int i;
/* Build fresh max-heap */
- for (i = CAKE_MAX_TINS * CAKE_QUEUES / 2; i >= 0; i--)
+ for (i = CAKE_MAX_TINS * CAKE_QUEUES / 2 - 1; i >= 0; i--)
cake_heapify(q, i);
}
q->overflow_timeout = 65535;
--
2.34.1