Received: by 2002:a05:7412:419a:b0:f3:1519:9f41 with SMTP id i26csp325308rdh; Thu, 23 Nov 2023 05:12:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IHPidcZz2z0HXxm3sHBodBDhg4dlc+kL0fXTrNzKdUAbR7mb8eQvozsWudYO7L9StSS5a6M X-Received: by 2002:a17:902:e88b:b0:1cf:7cfc:c39b with SMTP id w11-20020a170902e88b00b001cf7cfcc39bmr4079958plg.7.1700745167981; Thu, 23 Nov 2023 05:12:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700745167; cv=none; d=google.com; s=arc-20160816; b=bwRE9/cpnObb7LXkK6HACbSPMuIdiCbKhb7oCvsVpDVOOSXL+LtzfiM/FA+N4iUkAP ghV7wEHKPW6Fp7MvkOqIMzBU/ebfy2UqRBOYBHZKbPyqPqp28K8gVBuhJ+cHF4CWY66w ymJNI/ze5WXCy52MQbcSG4XZgQdTjVuNpzVu597pPzUYI8pmVaft9N5eKuzNUrDzhAsw GKIzZANGRqxs0jHxhLJzw2tmIrgQy0+02wcHZlsovA8KIC8mzfP2Gd5W5zGiASdFR2WZ az08IN2uyxSS+LkhHB44JKKXfO9XhV+zd5qd0TrHUliIkNVv+PobExeZ98a6P8TKQG0B teSA== 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:cc :references:to:content-language:subject:user-agent:mime-version:date :message-id; bh=hgy5COkqAxDosB1Fjm1tH/cRJ8Eh1dLV8xDRgKAWDTU=; fh=ucOVaD/nScFZiUWeAmlTMtCFSdYEqyNPJ7lamfdnraA=; b=Y0j8C0I5ACDMIYipYUuns6kIvRdtrUeGeZQLAsUO0+eaECWHZIwAoTWo1AvSiN804e WaOl4DuxIQoYK0jt0Ggykk2mp7A10oMnpRU75dhAOa1VdY8lQ+ZX49xuJ/yh24c2YD0a tnZyDog1L+/BvRg/VV9w2bkepZnyI/RKySYWInQKrLLE8OhmQfGjQcYKI6XT5FWjLuYV 6Rcey2Vm9fsTmLrinpjR8ZdA5DS5g8MfXATljFaXVM04MVia1y7dWMX+EYVOe1R41zVS PAwjmuQFmjrBCCL7p7OhHmj5e6IdsSN9eTBFwiacCafgyzFzFokszAMXU5NhJ/uQZN5X eu/A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id n17-20020a170902d2d100b001cf7ce5e6cesi1082333plc.417.2023.11.23.05.12.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Nov 2023 05:12:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id 9F89582164FD; Thu, 23 Nov 2023 05:12:42 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345422AbjKWNMb (ORCPT + 99 others); Thu, 23 Nov 2023 08:12:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345425AbjKWNM2 (ORCPT ); Thu, 23 Nov 2023 08:12:28 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0FB83D64; Thu, 23 Nov 2023 05:12:31 -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 F1C871042; Thu, 23 Nov 2023 05:13:16 -0800 (PST) Received: from [10.57.4.190] (unknown [10.57.4.190]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 25DA43F6C4; Thu, 23 Nov 2023 05:12:28 -0800 (PST) Message-ID: <3a381307-81a2-40ab-a2bf-f899e3fd7c80@arm.com> Date: Thu, 23 Nov 2023 13:13:27 +0000 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] sched/pelt: avoid underestimate of task utilization Content-Language: en-US To: Vincent Guittot References: <20231122140119.472110-1-vincent.guittot@linaro.org> Cc: mingo@redhat.com, peterz@infradead.org, rafael@kernel.org, qyousef@layalina.io, mgorman@suse.de, bsegall@google.com, rostedt@goodmis.org, linux-pm@vger.kernel.org, dietmar.eggemann@arm.com, juri.lelli@redhat.com, bristot@redhat.com, vschneid@redhat.com, linux-kernel@vger.kernel.org, viresh.kumar@linaro.org From: Lukasz Luba 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=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Thu, 23 Nov 2023 05:12:42 -0800 (PST) On 11/22/23 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. > > 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 Thanks Vincet for looking at it! I didn't have to to come back to this issue. > > 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 > * That looks reasonable to do. I cannot test it right now on my pixel6. It should do the trick to the task util that we need in bigger apps than rt-app as well. Reviewed-by: Lukasz luba