[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <871q7ehnts.fsf@toke.dk>
Date: Tue, 09 Apr 2024 11:45:03 +0200
From: Toke Høiland-Jørgensen <toke@...e.dk>
To: Kuan-Wei Chiu <visitorckw@...il.com>
Cc: jhs@...atatu.com, xiyou.wangcong@...il.com, jiri@...nulli.us,
davem@...emloft.net, edumazet@...gle.com, kuba@...nel.org,
pabeni@...hat.com, jserv@...s.ncku.edu.tw, cake@...ts.bufferbloat.net,
netdev@...r.kernel.org, linux-kernel@...r.kernel.org, Kuan-Wei Chiu
<visitorckw@...il.com>
Subject: Re: [PATCH net-next v2] net: sched: cake: Optimize the number of
function calls and branches in heap construction
Kuan-Wei Chiu <visitorckw@...il.com> writes:
> When constructing a heap, heapify operations are required on all
> non-leaf nodes. Thus, determining the index of the first non-leaf node
> is crucial. In a heap, the left child's index of node i is 2 * i + 1
> and the right child's index is 2 * i + 2. Node CAKE_MAX_TINS *
> CAKE_QUEUES / 2 has its left and right children at indexes
> CAKE_MAX_TINS * CAKE_QUEUES + 1 and CAKE_MAX_TINS * CAKE_QUEUES + 2,
> respectively, which are beyond the heap's range, indicating it as a
> leaf node. Conversely, node CAKE_MAX_TINS * CAKE_QUEUES / 2 - 1 has a
> left child at index CAKE_MAX_TINS * CAKE_QUEUES - 1, confirming its
> non-leaf status. The loop should start from it since it's not a leaf
> node.
>
> By starting the loop from CAKE_MAX_TINS * CAKE_QUEUES / 2 - 1, we
> minimize function calls and branch condition evaluations. This
> adjustment theoretically reduces two function calls (one for
> cake_heapify() and another for cake_heap_get_backlog()) and five branch
> evaluations (one for iterating all non-leaf nodes, one within
> cake_heapify()'s while loop, and three more within the while loop
> with if conditions).
>
> Signed-off-by: Kuan-Wei Chiu <visitorckw@...il.com>
Acked-by: Toke Høiland-Jørgensen <toke@...e.dk>
Powered by blists - more mailing lists