Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp235146rdh; Thu, 23 Nov 2023 02:31:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IEjvFw98Uh0COs2NtAzpZu5CB6MswHKHCE4YR0rsAV6L+m0Ueo+Mooyg4q41fntKqN3sYrG X-Received: by 2002:a17:902:d48f:b0:1cc:449b:68a8 with SMTP id c15-20020a170902d48f00b001cc449b68a8mr5789069plg.46.1700735464112; Thu, 23 Nov 2023 02:31:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700735464; cv=none; d=google.com; s=arc-20160816; b=DC7eKTSORAcY55ktQDLlcxuCkjkth0K3TJ1ikUKclzDSlgO6hU3GFYwnsQxsm7cZHl RsA0zmwyrBp3pKGKSSBoPf/WN+xGvCYqB+314OXTyRe5U4uLvoQQaWVF14kNFKP4+jeh 5AtMmPK3RITqC0Hzdp7fjvgqdLEBhtVN2/ssrw9AlpnIDIo+IU9fImeYjNVxVBK6Y5km MIrrw8Ilr6lvq07ipSn4fcJ5e4V4xum7vUuBT1uccE0LPlH2X/cmOuvaxZDdu6KkjKo+ qqXhEk5eCdDOIARRPFGnO0H3Rnkc/A9lZztI/9+3u6byZxEkgauRfeewl2jnJ7QaDQYP sHqw== 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:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=trfyvi6MbJesxcsRP4W62yufX/0CgsLs8XGabx+92Bo=; fh=DG2Jz+AKcYJNCOWbK0MqrepzYcDaxcrvxtLt3ow6UxA=; b=uk4UtHfX/D84tcGZS40WO/5pfv4OnePsTFq6xsoamGvvYM2ynAQ0kX1htRjQhQX/ty 3Dr+h1g6VdeTr32Sj+4dXYCSZZi5aJ8qBWEqLy6+h8jS/gJt4N2EQJEAZxdMhKQJL4dC AygRd6rBoZh4fthbZB3TuAeTIZxOjR4HNMTsCOFVNzo6ZwcwuoGmGp7HQLhG6WyKAVA8 byk7zs0ly1KL/SvEPTXFbnNEdZNmSDLYF0vwqMH5HmPh/byfb2BrGOBMC8rcJ/Q1/4RM mbOOICDWtMoOfoaXWJR/MlvD1eX24stAVTKlZiUGM2Mm3NEqCrPkt1oXQLwALVy6GOPv qD7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="L6Qcn/9e"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id o6-20020a170902d4c600b001ca1bd194b4si885747plg.416.2023.11.23.02.31.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 02:31:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="L6Qcn/9e"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 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 lipwig.vger.email (Postfix) with ESMTP id DD63480784FF; Thu, 23 Nov 2023 02:30:43 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344599AbjKWKa1 (ORCPT + 99 others); Thu, 23 Nov 2023 05:30:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229477AbjKWKaZ (ORCPT ); Thu, 23 Nov 2023 05:30:25 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 857BB1A8; Thu, 23 Nov 2023 02:30:31 -0800 (PST) Date: Thu, 23 Nov 2023 10:30:29 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1700735430; 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: in-reply-to:in-reply-to:references:references; bh=trfyvi6MbJesxcsRP4W62yufX/0CgsLs8XGabx+92Bo=; b=L6Qcn/9e7P3K926jTTlxdaenBq994wa3zCvGQmqMS0dJMgfO5s3TSJ7jFQgUv1IUPo0ui/ L4t1OtelGrFCjqJ60BthSoTF1jelkeMMZQUPYKFMWlH8CRIFTsU5LV6bNvQhkUfm2FnqiS Roz0++Tfq9hKTgk+9HSMRTrbzXtFJAygZZcLnmZw24UnhHXSutri1OnuTXwb5KO31BQvgo ztEEn5kH3SjTdNP33xSGE35MKo+X5gq4x+gq6zmExQe+JQN7aap1tjC/tMzrasQeacbgkl pKCue1kqiSWEg4t3AajF5jQfEjgbk+vAgslxt4PMG96ukaFQYHsUdRARquIveg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1700735430; 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: in-reply-to:in-reply-to:references:references; bh=trfyvi6MbJesxcsRP4W62yufX/0CgsLs8XGabx+92Bo=; b=ptONsAgoo7+FVD6kaLTsUHcxSSLMWGbMfVAkzSFF1JY6By0ocu0G3IU4E0E34NQRFf3ly5 +LSW8Ew7NhZRAgDw== From: "tip-bot2 for Vincent Guittot" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] sched/pelt: Avoid underestimation of task utilization Cc: Lukasz Luba , Vincent Guittot , Ingo Molnar , Hongyan Xia , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20231122140119.472110-1-vincent.guittot@linaro.org> References: <20231122140119.472110-1-vincent.guittot@linaro.org> MIME-Version: 1.0 Message-ID: <170073542912.398.8772998793614415245.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.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 (lipwig.vger.email [0.0.0.0]); Thu, 23 Nov 2023 02:30:44 -0800 (PST) The following commit has been merged into the sched/core branch of tip: Commit-ID: 50181c0cff31281b9f1071575ffba8a102375ece Gitweb: https://git.kernel.org/tip/50181c0cff31281b9f1071575ffba8a102375ece Author: Vincent Guittot AuthorDate: Wed, 22 Nov 2023 15:01:19 +01:00 Committer: Ingo Molnar CommitterDate: Thu, 23 Nov 2023 11:24:28 +01:00 sched/pelt: Avoid underestimation of task utilization Lukasz Luba reported that a thread's util_est can significantly decrease as a result of sharing the CPU with other threads. The use case can be easily reproduced with a periodic task TA that runs 1ms and sleeps 100us. When the task is alone on the CPU, its max utilization and its util_est is around 888. If another similar task starts to run on the same CPU, TA will have to share the CPU runtime and its maximum utilization will decrease around half the CPU capacity (512) then TA's util_est will follow this new maximum trend which is only the result of sharing the CPU with others tasks. Such situation can be detected with runnable_avg wich is close or equal to util_avg when TA is alone, but increases above util_avg when TA shares the CPU with other threads and wait on the runqueue. [ We prefer an util_est that overestimate rather than under estimate because in 1st case we will not provide enough performance to the task which will remain under-provisioned, whereas in the other case we will create some idle time which will enable to reduce contention and as a result reduces the util_est so the overestimate will be transient whereas the underestimate will remain. ] [ mingo: Refined the changelog, added comments from the LKML discussion. ] Reported-by: Lukasz Luba Signed-off-by: Vincent Guittot Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/lkml/CAKfTPtDd-HhF-YiNTtL9i5k0PfJbF819Yxu4YquzfXgwi7voyw@mail.gmail.com/#t Link: https://lore.kernel.org/r/20231122140119.472110-1-vincent.guittot@linaro.org Cc: Hongyan Xia --- kernel/sched/fair.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 07f5558..53dea95 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -4774,6 +4774,11 @@ static inline unsigned long task_util(struct task_struct *p) return READ_ONCE(p->se.avg.util_avg); } +static inline unsigned long task_runnable(struct task_struct *p) +{ + return READ_ONCE(p->se.avg.runnable_avg); +} + static inline unsigned long _task_util_est(struct task_struct *p) { struct util_est ue = READ_ONCE(p->se.avg.util_est); @@ -4893,6 +4898,14 @@ static inline void util_est_update(struct cfs_rq *cfs_rq, return; /* + * To avoid underestimate of task utilization, skip updates of EWMA if + * we cannot grant that thread got all CPU time it wanted. + */ + if ((ue.enqueued + UTIL_EST_MARGIN) < task_runnable(p)) + goto done; + + + /* * Update Task's estimated utilization * * When *p completes an activation we can consolidate another sample