Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp196362rdg; Thu, 12 Oct 2023 03:04:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH2pepkfNk90TyHhouhLkWo1To/HD3sZbEYyhzGdFpNI1q+yL14HEsywVxBkSjGqcJFDVAE X-Received: by 2002:a17:902:8649:b0:1c6:15fc:999 with SMTP id y9-20020a170902864900b001c615fc0999mr21630885plt.45.1697105084400; Thu, 12 Oct 2023 03:04:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697105084; cv=none; d=google.com; s=arc-20160816; b=fGUZzeTRGgzGBFwNdt9nYkRb/fB9a8Y9mC0V9eUyOMWjhSORmVqqfODYhT5P3e2Nkp p/bQrZGg9FKWavwDIDFCdxo6OhnqbIZIZU3rNJaVXC/a1uxeUVL2OVl/AhzYPbxc7xfC m9X9OagznH5dNMNzPMy6oLvnAqYXOdiIrIuu7OdY/+dHtcIIe+fiOPCbnatQ6ZADIz9m 0bfNb4pBlfSvPs09/NX6urlPcFisGdA3cHcDCud0Tv6IcTjqLbJQ4Jh1mkvv9MWg1vk9 nVEIqray0qubwsNyfDF7qgvm+La0yAySl2fs1lEUh6PjaEWEemTISRkRwyP6FgnUpsLb nH5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=WXAPa5EKPqpyaUOPwf59NxGETBLmnhLA24XZS+cRTr4=; fh=R3o6BkwSs8a5BzFibkaN9bVj+yv8ZhzyaGeHM8WvFus=; b=Ncb5IFQnI7kKCxYPgda9f/XNMIYfvqhLGrnQJCKeTOP7Iz+tgJaF/hzS3LvvRn/x6v ORXQGEAK9PiB5wZLK8O9PvdxvcDlc9C++uoR8MhngHQjHHMeTvDNP5oW4sAT+RLpnzN6 OGdmm+MAZIL8Ld42lQZuwsdNMlOaP4AA5yzwpL5OvaR7542OjJ5LTRRnZp0h4/yaToHN +LTLtSd/ePJj0X2T6s0os/gn319CK/TDqfHwdEwCoTYliu8+FNFv6tP3YCXF8nazeu8W RyAx1rdiv2zHItv4tAW6Ga517ULWoT4M9p5cmbH3SB2EVZpStIK9glNHT4NVTDsemDuX Ctcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=B7PXomLW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id b11-20020a170903228b00b001b811261289si1964725plh.482.2023.10.12.03.04.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 03:04:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=B7PXomLW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 8812D818CC99; Thu, 12 Oct 2023 03:04:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235457AbjJLKEf (ORCPT + 99 others); Thu, 12 Oct 2023 06:04:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235638AbjJLKEd (ORCPT ); Thu, 12 Oct 2023 06:04:33 -0400 Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F3AAC9 for ; Thu, 12 Oct 2023 03:04:29 -0700 (PDT) Received: by mail-io1-xd34.google.com with SMTP id ca18e2360f4ac-79fa5d9f3a2so32445239f.3 for ; Thu, 12 Oct 2023 03:04:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1697105069; x=1697709869; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=WXAPa5EKPqpyaUOPwf59NxGETBLmnhLA24XZS+cRTr4=; b=B7PXomLWr5xmcdU8i9QVIYXLVFflim5G1xeCCWNwk8KVWhu/1cOmFPDyE9GNPGkBwZ +B5SVA39BdBsud6MZnZnzrWZIv1mhQ9ck1dXhUiqK0WS4AKeuXCb52vT3ZG445BAOYlX JguI56nygYbpXhjlDeNfb+EXNiF4nuGfEyRasWQgT9JEViVFHaDiXtWnv6wqsZFUKU/v ngsK7qfsJjkM5JQhaV4rKww0GG+ulND6UyCB5Hh1/RsOrmhjv6PoZMecTxanll9RX1A/ R6G1zRaniwurimfW1Qg53Nb/5tv8Danvc2oEehqqqrQOWrHsNQ7bGrq6fbRyHb8ClmDL do9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697105069; x=1697709869; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WXAPa5EKPqpyaUOPwf59NxGETBLmnhLA24XZS+cRTr4=; b=wpaDpE7qMZ/NHQrCbiiagToJK+513xOGb/KynOBuWTkJFL8YCmkWW1HtXock6kml+Q HmvEpiqHBzcZ6W6v9mSoGuu0VFga9K062Z/nq33mXlV3OIH63yYVxVxSWrjq450WxcOI 1vwby93/9rJMiaoq6Z0vc0NGR184b8N5wmo/PiiDcolTtdCZyeWVfVKBETMH5RFyu3w4 RmUWisqP5RM7PBzQj4NA3acldkOYVxKcoaoAq6sMjDIuC9DiN68YFuvBXCmPokBYvPyG UpSV6AkQR2JM87a4oH7yTdTPZQHgXIulCAs0ocj2CldPCYiBx3n19ogt1yMF8k47imfV wxtw== X-Gm-Message-State: AOJu0YzClwQ0zo7CdJzE1eqrpoJsd6D/BUe7jh488MxRSLPgxGRMxXPF PDa5YwZXOzY6TsIHyieHr9vZLQ== X-Received: by 2002:a05:6602:2807:b0:7a5:a391:73ae with SMTP id d7-20020a056602280700b007a5a39173aemr7716132ioe.17.1697105069110; Thu, 12 Oct 2023 03:04:29 -0700 (PDT) Received: from [10.84.153.115] ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id y28-20020a056a001c9c00b00690d1269691sm2603788pfw.22.2023.10.12.03.04.19 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 Oct 2023 03:04:28 -0700 (PDT) Message-ID: <99cabaee-df77-4da4-9521-3877a507ba48@bytedance.com> Date: Thu, 12 Oct 2023 18:04:17 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Re: [PATCH] sched/fair: fix pick_eevdf to always find the correct se Content-Language: en-US To: Peter Zijlstra Cc: Benjamin Segall , mingo@kernel.org, vincent.guittot@linaro.org, linux-kernel@vger.kernel.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, mgorman@suse.de, bristot@redhat.com, corbet@lwn.net, qyousef@layalina.io, chris.hyser@oracle.com, patrick.bellasi@matbug.net, pjt@google.com, pavel@ucw.cz, qperret@google.com, tim.c.chen@linux.intel.com, joshdon@google.com, timj@gnu.org, kprateek.nayak@amd.com, yu.c.chen@intel.com, youssefesmat@chromium.org, joel@joelfernandes.org, efault@gmx.de, tglx@linutronix.de References: <20230531115839.089944915@infradead.org> <20230531124603.931005524@infradead.org> <6b606049-3412-437f-af25-a4c33139e2d8@bytedance.com> <20231011131454.GN14330@noisy.programming.kicks-ass.net> From: Abel Wu In-Reply-To: <20231011131454.GN14330@noisy.programming.kicks-ass.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Thu, 12 Oct 2023 03:04:41 -0700 (PDT) On 10/11/23 9:14 PM, Peter Zijlstra Wrote: > On Wed, Oct 11, 2023 at 08:12:09PM +0800, Abel Wu wrote: > > As the paper explains, you get two walks, one down the eligibility path, > and then one down the heap. I think the current code structure > represents that fairly well. Yes, it does. I just wonder if the 2-step search is necessary, since they obey the same rule of heap search: 1) node->min_deadline > node->left->min_deadline 1.1) BUG 2) node->min_deadline = node->left->min_deadline 2.1) go left if tiebreak on vruntime 3) node->min_deadline < node->left->min_deadline 3.1) return @node if it has min deadline, or 3.2) go right which gives: while (node) { if ((left = node->left)) { /* 1.1 */ BUG_ON(left->min < node->min); /* 2.1 */ if (left->min == node->min) { node = left; continue; } } /* 3.1 */ if (node->deadline == node->min) return node; /* 3.2 */ node = node->right; } The above returns the entity with ealiest deadline (and with smallest vruntime if have same deadline). Then comes with eligibility: 0) it helps pruning the tree since the right subtree of a non-eligible node can't contain any eligible node. 3.2.1) record left as a fallback iff the eligibility check is active, and saving the best one is enough since none of them contain non-eligible node, IOW the one with min deadline in the left tree must be eligible. 4) the eligibility check ends immediately once go left from an eligible node, including switch to the fallback which is essentially is the 'left' of an eligible node. 5) fallback to the candidate (if exists) if failed to find an eligible entity with earliest deadline. which makes: candidate = NULL; need_check = true; while (node) { /* 0 */ if (need_check && !eligible(node)) { node = node->left; goto next; } if ((left = node->left)) { /* 1.1 */ BUG_ON(left->min < node->min); /* 2.1 */ if (left->min == node->min) { node = left; /* 4 */ need_check = false; continue; } /* 3.2.1 */ if (need_check) candidate = better(candidate, left); } /* 3.1 */ if (node->deadline == node->min) return node; /* 3.2 */ node = node->right; next: /* 5 */ if (!node && candidate) { node = candidate; need_check = false; /* 4 */ candidate = NULL; } } The search ends with a 'best' entity on the tree, comparing it with curr which is out of tree makes things a whole. But it's absolutely fine to me to honor the 2-step search given by the paper if you think that is already clear enough :) Best, Abel