From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc36.google.com (mail-oo1-xc36.google.com [IPv6:2607:f8b0:4864:20::c36]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.bufferbloat.net (Postfix) with ESMTPS id 27F8D3B2A4 for ; Mon, 8 Apr 2024 13:47:24 -0400 (EDT) Received: by mail-oo1-xc36.google.com with SMTP id 006d021491bc7-5a9c2045b8bso1091412eaf.0 for ; Mon, 08 Apr 2024 10:47:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712598443; x=1713203243; darn=lists.bufferbloat.net; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=JwaQrBi/Lb4swFNBzhz/Zq2k8S4Qq8Dh3rIl0JBflxU=; b=Bw4NV9L7K6LNqTTqZ/388NJs3x6v+zJZ2QxEeggNWQf4HaNTZ9sRBlIopFNV/+Rf/e IyVAJ3KqUXUoOhIzdqOLrj5p4FVZSSbf8BAGnCuxXS4mY4FomXmnhwSq/LtpsPx80l3+ iMzf1osz02lpuofjj2MHdD1tTXVC1O7cjERXpFEo3ERBPMTiR16/qf39XtRmNPZENmU2 jiIWjf/f5Jbi69BL7RdBPoBSXjqtgBAhNJyzzwmZ9lOYhbWqHdt91SRxVF49CCug1IQU 73jz4jkkY4OwrvWn0yxmxqBW+qjMA+xClOa3csGEgRwxXRSRlXuMm12p+bpAewHU6hwg NlXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712598443; x=1713203243; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=JwaQrBi/Lb4swFNBzhz/Zq2k8S4Qq8Dh3rIl0JBflxU=; b=pbSoAsIDAQjgGNv7ofwH78cxbMxNDlmCKly9jAMcG72aMqnv39j/m5ZTG51wgdSzuM wk8wU/ZcpylCMbs/qPfJXHdgTGlY7BWPUCbdy8OY62cGnIbgKiWdk94G7Q7F/vGon2S4 IgbOLyvQAh9oXqrgCsFMYHhNh5i/j2pbMpQnWpSlMS6hzc2T5XzHpDJ6BRvZaLesoz6V ng/ASzk+OnLEAxd9Xad31lOoXxVdS52uyB6wAlDHtBSlmtUHZrDglWZ5UH+TulcNWczl cXBZ1OTBonpCyDd42xQs6CHpRGxUZZ9jTIHKDWxZ4SJWUkeNUrZTYit4nAkgscKfUmGU 62cw== X-Forwarded-Encrypted: i=1; AJvYcCXshc7lkwyXRbwc+28hPa4k4IaS1ZAQNue8ww6IzPOFnd+JRQm1kAagcR9Sxqmbh5TVmnxUkvhO8ZzGxaLsLlEr4LGpEDHDQZLoyA== X-Gm-Message-State: AOJu0YzjVvHPKH0Dtx8sndhAGV+MSQ/y4zPETKaLaEduG4eZI5x5n35X 3xixU6DK0lLKdYMaOH7s3NojZd+cKi29qGIJ4RbriOhohD4YpEgA X-Google-Smtp-Source: AGHT+IFnY7oyhUQ2h1YHDDpIJAZW8c1j5v0T5sdQe4YExZyP043/DJ68ik+7HU4G7BhF8KWbj8RTDQ== X-Received: by 2002:a05:6358:9dae:b0:185:fea7:fecd with SMTP id d46-20020a0563589dae00b00185fea7fecdmr5923178rwo.0.1712598443274; Mon, 08 Apr 2024 10:47:23 -0700 (PDT) Received: from visitorckw-System-Product-Name.. ([140.113.216.168]) by smtp.gmail.com with ESMTPSA id k26-20020a63ff1a000000b005e4666261besm6821143pgi.50.2024.04.08.10.47.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Apr 2024 10:47:22 -0700 (PDT) From: Kuan-Wei Chiu To: toke@toke.dk 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 Message-Id: <20240408174716.751069-1-visitorckw@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Mon, 29 Apr 2024 18:18:51 -0400 Subject: [Cake] [PATCH net-next v2] net: sched: cake: Optimize the number of function calls and branches in heap construction X-BeenThere: cake@lists.bufferbloat.net X-Mailman-Version: 2.1.20 Precedence: list List-Id: Cake - FQ_codel the next generation List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Date: Mon, 08 Apr 2024 17:47:24 -0000 X-Original-Date: Tue, 9 Apr 2024 01:47:16 +0800 X-List-Received-Date: Mon, 08 Apr 2024 17:47:24 -0000 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 --- 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