Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1868023lqe; Tue, 9 Apr 2024 02:50:46 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUiQzwX6WBm1DBrLCJHPioi3+OzEZOoK98wtOXmw9GH4tIIbdr2BrBO4nHV4WiQpnIVvCxidsGNewaZvkMcaa75gW8OUh/BLflt10qSOw== X-Google-Smtp-Source: AGHT+IGuoDmvrnlSVN625vU0Ix0yquoBkORHZkFTD934m1DuxHwHvyh0T3V/OlYyFJTglBVI9sQH X-Received: by 2002:a17:902:dac6:b0:1e4:55d8:e15f with SMTP id q6-20020a170902dac600b001e455d8e15fmr2714475plx.32.1712656246171; Tue, 09 Apr 2024 02:50:46 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712656246; cv=pass; d=google.com; s=arc-20160816; b=ug/cMH+5WxJj7jcOi2arhjgkNfK2lI6nqz0qDpp3GA8gmeMkD/aSzZuvk28iSPFdAu q4rtM5Xp9t5LQ6Gy6DBOtHAdkaoSZtQn63j+eVG9Gf9NS+smFeimY5UHeIWC1rdX2E8X /Wc9OFmB0fQlzGcT7XgpqS1RWqHf8cjU/RI9sltnnB8N99Xf818wcprXr6jQngnele0M 1Gb17Vu6fji7FJUBK97nkstt7BZ6nQ3bem/jnt+YwKcGctm1/d8CQ/V0ydiKaIu28d6K vgDvVhX+RhpsMxBtb0EFF6dy3wrYpeWOa9fMBuZsF8OsbiZW8J9KydH0N86ffYk0uhQ2 xoTQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:references :in-reply-to:subject:cc:to:dkim-signature:from; bh=7OKr4HycDUeB/zx8rBNu9gxtoijefw8jgpd7xIePUfQ=; fh=TzIoB/6DY0VcRO1znsOhO2wRnIy8wlPouvV6e/ttnww=; b=An7rP8QJqi79hzN+vPrZkNmsoVYYUWnoujHKhgiO06hQZKQo4gOIFhHuOUqI3BNecb PHnZK713jhXWgQF/c+uPdMgLBYjuFGf1kTwnLUWfwJKOO7KRrUK0Y2NS5j4+9/Fwq7r3 mHjR4A83fiozBzNoldCnHAmrduKkLqvKvXpvWQwOCCf4Zz2OzxklRRq+9KI7hf/Hbq1U OnYZRJWQY7ytnt3zNIEnHgD4aVJXwMwiL1WSFElDXuXGMFVbu0ZmdUwe5CX6tr5jZGUN VonywaM3DZypOyTwGCAaxBqFZQIhfXHSuLhrwHG3XrWMm4A5WlrSNyALs2A5ws/TYQaz JCkw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@toke.dk header.s=20161023 header.b=J1tiPFsk; arc=pass (i=1 spf=pass spfdomain=toke.dk dkim=pass dkdomain=toke.dk dmarc=pass fromdomain=toke.dk); spf=pass (google.com: domain of linux-kernel+bounces-136586-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136586-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=toke.dk Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id h7-20020a63e147000000b005dccfa9a75asi8224001pgk.845.2024.04.09.02.50.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 02:50:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-136586-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@toke.dk header.s=20161023 header.b=J1tiPFsk; arc=pass (i=1 spf=pass spfdomain=toke.dk dkim=pass dkdomain=toke.dk dmarc=pass fromdomain=toke.dk); spf=pass (google.com: domain of linux-kernel+bounces-136586-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136586-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=toke.dk Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id AC743B236C7 for ; Tue, 9 Apr 2024 09:45:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3132580029; Tue, 9 Apr 2024 09:45:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=toke.dk header.i=@toke.dk header.b="J1tiPFsk" Received: from mail.toke.dk (mail.toke.dk [45.145.95.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C73427E774; Tue, 9 Apr 2024 09:45:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.145.95.4 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712655917; cv=none; b=uExT/ziH95vGeclfrRrmuYp2iJPXPfB4LNqzR3Q6nJUz7UPKHGzdHVzliZ4YjtxF9bKD2w93OXdc/U6ZustW79gCaZJR5kMMtd/sX+y0tSiEl9jfPvrhyMdsgEQlwBHfllUAhVKpIXvzm3QYWTHDJIjGUA0bcnpabBLp5ggEY0A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712655917; c=relaxed/simple; bh=7OKr4HycDUeB/zx8rBNu9gxtoijefw8jgpd7xIePUfQ=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=YIRjnaEKGVex4nF4M3O2dwk8yT4SRELPfenEp7o2As30fC9i0+0APe/mGRH2sht+GskAs+u6306BaFd3cyeYxOLFU81hweIFLDD9Z988EeWibjZpevbaaWcFKSOwXX8+HmRMSA5TbiVEkG8X0eFXcm/6CpdocEomDqnSvRK1HJ8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=toke.dk; spf=pass smtp.mailfrom=toke.dk; dkim=pass (2048-bit key) header.d=toke.dk header.i=@toke.dk header.b=J1tiPFsk; arc=none smtp.client-ip=45.145.95.4 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=toke.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=toke.dk From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=toke.dk; s=20161023; t=1712655903; bh=7OKr4HycDUeB/zx8rBNu9gxtoijefw8jgpd7xIePUfQ=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=J1tiPFsk9FCwNjYBmljWSGdsrXeJyiwirEHHvVen2Uh35VRFDdhBPVG/RTTXdPoAX TMvFcJZQp1aTUYf7YWbBs0EUMw2yoFF6BqJrv0G/VR2OClsb9aGPFG861t6Y6FGrbG DrFBoHao4ZKGjsRrj6QWwLz5FwetZ+g640M8Kg3QKJePV/PTEVpHUjYzoFMKLDmVug c4scIHdjgRqCs4saDZgRX/EydaWn/d0G3iqKvciQ00iyzwyQip0TAig02Tih5S0jxQ loYscQccqiVg93MfmS+G6HSO2UvFFznIZvVlToA+jujb58tzsTFVcIbPaRLI03zK5j gNbooxZuWXj2Q== To: Kuan-Wei Chiu Cc: jhs@mojatatu.com, xiyou.wangcong@gmail.com, jiri@resnulli.us, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, jserv@ccns.ncku.edu.tw, cake@lists.bufferbloat.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Kuan-Wei Chiu Subject: Re: [PATCH net-next v2] net: sched: cake: Optimize the number of function calls and branches in heap construction In-Reply-To: <20240408174716.751069-1-visitorckw@gmail.com> References: <20240408174716.751069-1-visitorckw@gmail.com> Date: Tue, 09 Apr 2024 11:45:03 +0200 X-Clacks-Overhead: GNU Terry Pratchett Message-ID: <871q7ehnts.fsf@toke.dk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Kuan-Wei Chiu 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 Acked-by: Toke H=C3=B8iland-J=C3=B8rgensen