Received: by 2002:a05:7412:e79e:b0:f3:1519:9f41 with SMTP id o30csp33420rdd; Wed, 22 Nov 2023 08:43:06 -0800 (PST) X-Google-Smtp-Source: AGHT+IFUng9B2AC1AhFzd6aXsHLVYxapWIOvRlCyr8Ua6F5l/xfX2Ve9ruALvoShtutir9eJXFVB X-Received: by 2002:a05:6a20:e117:b0:18a:da90:68ec with SMTP id kr23-20020a056a20e11700b0018ada9068ecmr6528pzb.2.1700671385802; Wed, 22 Nov 2023 08:43:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700671385; cv=none; d=google.com; s=arc-20160816; b=dHHjpLs1B7FQZdugoFPynH8uDGea21k8hXD6oAnGX7QI/KnqGXWeyc+YmLo6fplMK6 cZRdpQgjSWhc/5dU+1o8OcsU0Gbz7PHmxEhdNi7erROFXlULAK4SxlYw4O7ytWbjORJC D+mp/YkpkWEc5ApksMxAFWwuFWqydCqhvwiWK2jlZxnIewW+peV3vgkL0m6edlDooO6P o3S2ylcF757Df4aY2QJbO2QU6wBX6ErImoEhxHYCKOhTUpu70O2XMPTRo0TF+RK5QWXc vFDNL3kVHrSdARDZOuPwRtLVPaCZsbjM4cqfov2QeUPDDFqe/Ted+RYMBAb7sWu3Niy1 YDGw== 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 :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id; bh=I4ORPC8Mk26pHsKvnOg0jsme9WyOYEtjUzxzgg+LjQg=; fh=Mc5mjxcXnsQzcoyoBKBcJCzXHeO64K7JX0Fnd+jWUvU=; b=nyKYgSiUCIxgFAmR/wEQ/JCTCoIQhC+YA+DwMJiUIK04+K6xtkABA1/WC1M21EBPfG s9AjwdL7XHn4YZ7Q0G43kFk/a/CSVB0I+3fMS4+Dl7PVi99y42HOYN8BTHHzckSuq3lX YirOuWFfVsQ2QzM+j61YxdaRLkpXq+dC4kmkX46tpzPJF3+gPPmMC26tTH/Pga4werCq 3At/R3Pby/Jwa5QlP/fQRU07blktqipT9P2idrxr/kaDYlDrdvH1YvAA5Qceh8Tn7DKk Jtukux4e5V0cSUwILt8Bxhme3QjJ9i6OzhRJi7+AHE14MTgsDtrCmybVr10/hmm8GwIv +P0g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id p17-20020a056a000b5100b006cb64315210si9106776pfo.9.2023.11.22.08.43.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 08:43:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 5F21380785D7; Wed, 22 Nov 2023 08:42:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229789AbjKVQlQ (ORCPT + 99 others); Wed, 22 Nov 2023 11:41:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234323AbjKVQk7 (ORCPT ); Wed, 22 Nov 2023 11:40:59 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 83A5010C7; Wed, 22 Nov 2023 08:40:19 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 15A91FEC; Wed, 22 Nov 2023 08:41:06 -0800 (PST) Received: from [10.57.4.117] (unknown [10.57.4.117]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B47D43F73F; Wed, 22 Nov 2023 08:40:15 -0800 (PST) Message-ID: <0bc60a26-af18-4108-8b8d-238a1df1775b@arm.com> Date: Wed, 22 Nov 2023 16:40:14 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] sched/pelt: avoid underestimate of task utilization To: Vincent Guittot Cc: lukasz.luba@arm.com, juri.lelli@redhat.com, mingo@redhat.com, dietmar.eggemann@arm.com, peterz@infradead.org, bsegall@google.com, rostedt@goodmis.org, bristot@redhat.com, mgorman@suse.de, vschneid@redhat.com, rafael@kernel.org, qyousef@layalina.io, viresh.kumar@linaro.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org References: <20231122140119.472110-1-vincent.guittot@linaro.org> Content-Language: en-US From: Hongyan Xia In-Reply-To: <20231122140119.472110-1-vincent.guittot@linaro.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-0.8 required=5.0 tests=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 fry.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 (fry.vger.email [0.0.0.0]); Wed, 22 Nov 2023 08:42:42 -0800 (PST) Hi Vincent, On 22/11/2023 14:01, Vincent Guittot wrote: > It has been reported that 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. Thanks for bringing this case up. I'm a bit nervous skipping util_est updates this way. While it is true that this avoids dropping util_est when the task is still busy doing stuff, it also avoids dropping util_est when the task really is becoming less busy. If a task has a legitimate reason to drop its utilization, it looks weird to me that its util_est dropping can be stopped by a new task joining this rq which pushes up runnable_avg. Also, something about rt-app. Is there an easy way to ask an rt-app thread to achieve a certain amount of throughput (like loops per second)? I think 'runs 1ms and sleeps 100us' may not entirely simulate a task that really wants to preserve a util_est of 888. If its utilization really is that high, its sleep time will become less and less when sharing the rq with another task, or even has no idle time and become 1024 which will trigger overutilization and migration. > > Signed-off-by: Vincent Guittot > --- > > This patch implements what I mentioned in [1]. I have been able to > reproduce such pattern with rt-app. > > [1] https://lore.kernel.org/lkml/CAKfTPtDd-HhF-YiNTtL9i5k0PfJbF819Yxu4YquzfXgwi7voyw@mail.gmail.com/#t > > kernel/sched/fair.c | 13 +++++++++++++ > 1 file changed, 13 insertions(+) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 07f555857698..eeb505d28905 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); > @@ -4892,6 +4897,14 @@ static inline void util_est_update(struct cfs_rq *cfs_rq, > if (task_util(p) > arch_scale_cpu_capacity(cpu_of(rq_of(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 > *