From patchwork Tue Oct 3 10:42:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 147805 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2a8e:b0:403:3b70:6f57 with SMTP id in14csp1992836vqb; Tue, 3 Oct 2023 03:43:07 -0700 (PDT) X-Google-Smtp-Source: AGHT+IElLmKmgRmCbngz2BQ8U9F9eWERFICrAlwIm0nQDlcM+TMujNzfEIkKbaqWzskUabUIAUFv X-Received: by 2002:a05:6870:1703:b0:1dc:797a:daf4 with SMTP id h3-20020a056870170300b001dc797adaf4mr16195221oae.7.1696329786816; Tue, 03 Oct 2023 03:43:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696329786; cv=none; d=google.com; s=arc-20160816; b=AmRXUtH/Lbis/tr0oJ6DsLqk0/Mp68qk/Gi56ABfE2qMozUDwBNeHlORDMnZ9J8iG6 BxX5LAf4Yoz7hsYyIPlvmY7E0zoZMOytXk2u0+2JfcVYDm2ESoYhb744jZGArq7iXB30 LfX55z/8l22lVHolYDRY79s7f0uh8y+tQ+gz1k6B7ahdKTz/wb23nL6d0Ccd+diGfMyf ojq+wWQWdrEJdVdZo4VGIyjLlw4oDnG5t6hbdXcvY+E0ym24T/A3iZVI7mnEbom9Q1ht PNpfVvFUD6wYVaPYVgtvI4eH5t2uvIwgszHkPwT7vKFux4E11RjgEn8/qHLdBNmNA9ng 2euA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=WxE0dPjXVRoqzOKIikXrexpeB8LT3+xgtw9e0GJ98CA=; fh=H2MkSknZKy/XcUE0SNWlqZifRHvGVZQUr5cmv0Cbtz8=; b=ElFj1B/nX3gyjRFHiEt7eZ5YTnoK+IURdZRlu8QDpc+7VQzsov5TBtccJwk+LW8GQJ MXbOWS2C9lHc9FN7ogZwn5ve3rwyRn5+pQ6mzxXgvQe7SVokAii++Y9or9cOaUtkd1q4 +PcJYbgkaYq6cpy7EpVkj4BvEYpufsdG4cmfPxGdnUkeBqV7ElkWiZsUPLJajgEMW/nU 9n6lOvpY3n4KAXw0rMR7EEN7pH2qKPmOmiwoFnSqvZTzf85i0jHkUvcIFPUb93mqqoQm hiRpfdDi0ovj8TqtBikJEPmxoBTtDoBNKcclsJbELqx27kwu7u2s/2q4j8YuGa5ePE2b gnzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=PI1VAnl5; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id g25-20020a633759000000b00582dcfe3b41si1130857pgn.374.2023.10.03.03.43.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 03:43:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=PI1VAnl5; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 9E167801C037; Tue, 3 Oct 2023 03:43:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231735AbjJCKmp (ORCPT + 19 others); Tue, 3 Oct 2023 06:42:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231512AbjJCKmo (ORCPT ); Tue, 3 Oct 2023 06:42:44 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C870D3; Tue, 3 Oct 2023 03:42:39 -0700 (PDT) Date: Tue, 03 Oct 2023 10:42:37 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1696329758; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=WxE0dPjXVRoqzOKIikXrexpeB8LT3+xgtw9e0GJ98CA=; b=PI1VAnl5vXp/p41cdckqyCLKsAZHnORC58uYnD/1x4DUn5TRUYk0BwSTPGajCrS6KDKzHq mjr3pegcPsyhfiKvHCIAvs784DsGofxTwXimlxj6vpDkGCc8UEFNJTeea8wTqA8rsw6hGV tT/Oa1LxqGQdIu9EInYqnGQngdppKcmq4r8Rik8x8F1lO/DKEBR/7uBxMFfHRo80Rnm88y t3Tld6roh+bzaz2gali/D3hv0Pr3H0JZcN3tbEXOzyOBMrtohx4Isj7jW+diwfwHzRDO4j 65HYUUSfFTwxhNBLGMfjIHcnJiP8aFHtl1ahxcfBvSgWWDnTheJ28jWbh8CVyg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1696329758; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=WxE0dPjXVRoqzOKIikXrexpeB8LT3+xgtw9e0GJ98CA=; b=DbCMkLaBbmLuSH6+/uwvUGZk0OE1J0UpZ+F8cNEN8OSloOHYbAK2CE/mGWh8PHUCfZRo5Z YzzQ2SpGkc71wjBA== From: "tip-bot2 for Peter Zijlstra" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/urgent] sched/eevdf: Fix avg_vruntime() Cc: "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <169632975777.3135.1926466016577986434.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-0.9 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 pete.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 (pete.vger.email [0.0.0.0]); Tue, 03 Oct 2023 03:43:02 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778730702100205125 X-GMAIL-MSGID: 1778730702100205125 The following commit has been merged into the sched/urgent branch of tip: Commit-ID: 650cad561cce04b62a8c8e0446b685ef171bc3bb Gitweb: https://git.kernel.org/tip/650cad561cce04b62a8c8e0446b685ef171bc3bb Author: Peter Zijlstra AuthorDate: Tue, 26 Sep 2023 14:29:50 +02:00 Committer: Peter Zijlstra CommitterDate: Tue, 03 Oct 2023 12:32:29 +02:00 sched/eevdf: Fix avg_vruntime() The expectation is that placing a task at avg_vruntime() makes it eligible. Turns out there is a corner case where this is not the case. Specifically, avg_vruntime() relies on the fact that integer division is a flooring function (eg. it discards the remainder). By this property the value returned is slightly left of the true average. However! when the average is a negative (relative to min_vruntime) the effect is flipped and it becomes a ceil, with the result that the returned value is just right of the average and thus not eligible. Fixes: af4cf40470c2 ("sched/fair: Add cfs_rq::avg_vruntime") Signed-off-by: Peter Zijlstra (Intel) --- kernel/sched/fair.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 7d73652..ef7490c 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -664,6 +664,10 @@ void avg_vruntime_update(struct cfs_rq *cfs_rq, s64 delta) cfs_rq->avg_vruntime -= cfs_rq->avg_load * delta; } +/* + * Specifically: avg_runtime() + 0 must result in entity_eligible() := true + * For this to be so, the result of this function must have a left bias. + */ u64 avg_vruntime(struct cfs_rq *cfs_rq) { struct sched_entity *curr = cfs_rq->curr; @@ -677,8 +681,12 @@ u64 avg_vruntime(struct cfs_rq *cfs_rq) load += weight; } - if (load) + if (load) { + /* sign flips effective floor / ceil */ + if (avg < 0) + avg -= (load - 1); avg = div_s64(avg, load); + } return cfs_rq->min_vruntime + avg; }