Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp712690rdg; Thu, 12 Oct 2023 20:47:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE1q7KS/VIEiZ95PmCa+8EdJ8W5y8An7CYqbFxOGpM8OEJBhqjfocjR4jHYbs6yxQa7iz1t X-Received: by 2002:a05:6808:251:b0:3a4:6b13:b721 with SMTP id m17-20020a056808025100b003a46b13b721mr25121801oie.46.1697168846974; Thu, 12 Oct 2023 20:47:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697168846; cv=none; d=google.com; s=arc-20160816; b=pfgpTB2+xSKznh3qedfdSmMIdXQOQ+HAA5lduvMd44r18IUTDatUbJ9TbSiNWO2gbm pSZWku/6wn0J6UZzWF/zJcBY9AhVQgxAam1HlLUAcIOoXhS5ifdyemoVaITbnCmW+eHO XK8Fh0bhStJOm9XnJaDB0mKr1ZIfuzCt52ilXEdG4sOXDLPF2JyLgCmYYgCaJspEODmi nS36xOWOGsQNL69y8p/ySG8ogDY19hp3wMd/iNI7gAej1eJPDDJmNX4dUTZplAXPnP+b FPwfMxl2c890L1Wt8yHXGOGm2QqPrDPOF1fraRhLVlatd0ZxbDvHdGwpGy5ENBeYgzWI qydw== 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=33P5FFRygetlcU5+dGmEWjGqVa6SrGuz6L2T8K/a7s4=; fh=jABIjUGhIZjOxiJ3PElCxawbOLyk2aMf7MFpvfeX0TY=; b=yTwdiW972gzDw+k83uQqW4ybEiBvBiqQqvs99nEs5qh59gdPH6hzLtvnivf3mGP7Fy +H6hvcUxEtET/HJr5NMdsgVNOdjZ3nSeZbvKIocsDYYWgcJHepUDvUfavd95g9xf3zeV Lm2t3f5gfwiiOSXQDTJLZB69xamcXxeZOwMpSYf6lALiQRA8L8iJbYBnRcsQ+66bVYf/ rAnfoJ+iP+upgSQmEnzTPBorhhh8fkyrXAG/Q5T7/W3akXBgft4uuN+bzboS+8w2hUOK nyzsxkByzAE64x06Jxeje7i7GJC0eRb9NOX7HZb/WtMhP2YiSEy+V3TbrygRSqVbIYst YKCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b="N1XhCv/s"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id c7-20020a631c47000000b0059ceeb24a48si3792993pgm.680.2023.10.12.20.47.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 20:47:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b="N1XhCv/s"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 79A9D82A856A; Thu, 12 Oct 2023 20:47:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229556AbjJMDrD (ORCPT + 99 others); Thu, 12 Oct 2023 23:47:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46060 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229437AbjJMDrC (ORCPT ); Thu, 12 Oct 2023 23:47:02 -0400 Received: from mail-pl1-x62a.google.com (mail-pl1-x62a.google.com [IPv6:2607:f8b0:4864:20::62a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11C3DB7 for ; Thu, 12 Oct 2023 20:46:38 -0700 (PDT) Received: by mail-pl1-x62a.google.com with SMTP id d9443c01a7336-1c9d922c039so13966675ad.3 for ; Thu, 12 Oct 2023 20:46:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1697168797; x=1697773597; 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=33P5FFRygetlcU5+dGmEWjGqVa6SrGuz6L2T8K/a7s4=; b=N1XhCv/sQWoTsG0v0+clT6fI9n0WsXHuAynW0y2LGiPgB9L7mijTLLO3okQ1JMBkMT bZ072SGPVHP5heyJ7pJpXscsSbXWW+A00ZJf/kx97NVqNmfxAohYyaJnGD8c1ehDxvJy YzkYhYQv4gcxVZZ+mBNBOZ9VBCAhOyVSvz0kdYUhEdj5Hstu1qXDiclvcUQCrvZ7D8nb qWfvbCNHIe/DcRzyaGEc5PBGKp8NnRAlEHB5j7W2qrsyMgtPwRjCeSABlph1RSE9sHr/ hvuJhHEs+U9KKIah63UETC5CZKt2qQyo5pnyo0JC9z65VsHeyK0AZhEOd7QZ9uuG/nD2 ZysA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697168797; x=1697773597; 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=33P5FFRygetlcU5+dGmEWjGqVa6SrGuz6L2T8K/a7s4=; b=UQjfRSy5CyN6w7qEYx8SOGyol5/UjqHbQkqXYfNMQCIwQwExgGuQy+YGe+g/30dg/V 24AqWIgXLLSu0h+TFyQqQjRd4VxOet5LNUGn78NLYtsPSdl15NTo9lDFlY1FDYulU0SV B8dR1lGth+C0rR+HZUo5vMKI/h3nP940shFkCH/IWLyfspwS22RwTCI3+wV/XRTcHTuk H57+DmCbcl7I+ZdcvIXwN6gGU5jE1ZO53DRqmlDmP8RE++wyuQXWiasy+OUVCs08XeEJ Mjwy6lIc66NPgnwjAwnfkAaVM5ElqAJ0HQ3k6OxuaI82Y4Cq8g06cjTN5I66vyrtQ0bw xv5g== X-Gm-Message-State: AOJu0Yy+d7TM43XnKP1mfbQsilXYlegARZWvjPyg1VkxddCb60LKHRRZ X9OfkQ/syPmBndJe5MgUiLPwsg== X-Received: by 2002:a17:903:110f:b0:1c3:3b5c:1fbf with SMTP id n15-20020a170903110f00b001c33b5c1fbfmr34206950plh.10.1697168797524; Thu, 12 Oct 2023 20:46:37 -0700 (PDT) Received: from [10.84.153.115] ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id iz12-20020a170902ef8c00b001c9c3c377f2sm2772958plb.203.2023.10.12.20.46.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 Oct 2023 20:46:37 -0700 (PDT) Message-ID: Date: Fri, 13 Oct 2023 11:46:24 +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: Benjamin Segall Cc: Peter Zijlstra , 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> <699cc8b1-f341-4af7-9c47-fee961c5c4b7@bytedance.com> From: Abel Wu In-Reply-To: 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 howler.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 (howler.vger.email [0.0.0.0]); Thu, 12 Oct 2023 20:47:24 -0700 (PDT) On 10/13/23 1:51 AM, Benjamin Segall Wrote: > Abel Wu writes: > >> On 10/12/23 5:01 AM, Benjamin Segall Wrote: >>> Abel Wu writes: >>> >>>> On 9/30/23 8:09 AM, Benjamin Segall Wrote: >>>>> + /* >>>>> + * Now best_left and all of its children are eligible, and we are just >>>>> + * looking for deadline == min_deadline >>>>> + */ >>>>> + node = &best_left->run_node; >>>>> + while (node) { >>>>> + struct sched_entity *se = __node_2_se(node); >>>>> + >>>>> + /* min_deadline is the current node */ >>>>> + if (se->deadline == se->min_deadline) >>>>> + return se; >>>> >>>> IMHO it would be better tiebreak on vruntime by moving this hunk to .. >>>> >>>>> + >>>>> + /* min_deadline is in the left branch */ >>>>> if (node->rb_left && >>>>> __node_2_se(node->rb_left)->min_deadline == se->min_deadline) { >>>>> node = node->rb_left; >>>>> continue; >>>>> } >>>> >>>> .. here, thoughts? >>> Yeah, that should work and be better on the tiebreak (and my test code >>> agrees). There's an argument that the tiebreak will never really come up >>> and it's better to avoid the potential one extra cache line from >>> "__node_2_se(node->rb_left)->min_deadline" though. >> >> I see. Then probably do the same thing in the first loop? >> > > We effectively do that already sorta by accident almost always - > computing best and best_left via deadline_gt rather than gte prioritizes > earlier elements, which always have a better vruntime. Sorry for not clarifying clearly about the 'same thing'. What I meant was to avoid touch left if the node itself has the min deadline. @@ -894,6 +894,9 @@ static struct sched_entity *__pick_eevdf(struct cfs_rq *cfs_rq) if (!best || deadline_gt(deadline, best, se)) best = se; + if (se->deadline == se->min_deadline) + break; + /* * Every se in a left branch is eligible, keep track of the * branch with the best min_deadline @@ -913,10 +916,6 @@ static struct sched_entity *__pick_eevdf(struct cfs_rq *cfs_rq) break; } - /* min_deadline is at this node, no need to look right */ - if (se->deadline == se->min_deadline) - break; - /* else min_deadline is in the right branch. */ node = node->rb_right; } (But still thanks for the convincing explanation on fairness.) Best, Abel > > Then when we do the best_left->min_deadline vs best->deadline > computation, we prioritize best_left, which is the one case it can be > wrong, we'd need an additional > "if (se->min_deadline == best->deadline && > (s64)(se->vruntime - best->vruntime) > 0) return best;" check at the end > of the second loop. > > (Though again I don't know how much this sort of never-going-to-happen > slight fairness improvement is worth compared to the extra bit of > overhead)