Received: by 2002:a89:d88:0:b0:1fa:5c73:8e2d with SMTP id eb8csp2586883lqb; Tue, 28 May 2024 04:53:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXYfMzmy/T7f++DKR7vsM3RPKUCQRwb68VYkFD0Bkl+TF8VdU0EAnOFALKTsbgeOugnxn+aZZ+m6PyxEf5+ku/2a6Z5uCg1hgCqPvpL9A== X-Google-Smtp-Source: AGHT+IGTGy79BWJH1de4etuIkKG14aAvs57SOmOaSBhBUGstMJj5SX9nzoAYmgxwpb+/HC6pjGnZ X-Received: by 2002:a25:ad28:0:b0:de5:5693:4e96 with SMTP id 3f1490d57ef6-df7721b3320mr11977037276.27.1716897227384; Tue, 28 May 2024 04:53:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716897227; cv=pass; d=google.com; s=arc-20160816; b=sZQyakpZNV+JQD7ISHfUXmBT1LLzRd4LYv8/RdE9nukopFGsTfFDzo5CjmchmL6NhW OKiG1iN+JM4ealUbIYhmZ1RMfBX2ey/0t3Cn2vzSPv7kYH7v8R+1PEiiImGdWqBgvOnr 9twb1sMCcsdNgH8GLcaJXSoKwUDuJktVhgk0ThQVf03vsnBENrJfND210pog4yOJUd83 KUwRXbXDaEfzrf2O6ipfMHLQa8zhUJkyi+GQAZBmjU3OmHTBBEGVXJxhajJImH7ol/2u ZjpLOXUqbDnIWpv1iIdhZuQqvrJtudTge7dYi8AasagfNSt48SSzcuYfCpB0y8RLTN2m TqUw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=k3y9U31s09Y2scXeoRSUoDenj7XRsYlGj4/Tl2jnoxw=; fh=tdY3RD71eVGyFr36motyabqJnjpt1q4YaYGxGQOLstc=; b=c9sj63GTnQoj2o/tVjgXIWNAvvnWFkqNBHoaz8GC17MyPfcwDQu8Uox6zNkurM6BUH o9V4i0n4cNeD2H1TV66lH+ISlkyV2/DkpYbi/aOMx+sYxMMBdGDQzfLKQBI+VJ1qe5Hl Z/GW3VW1bpWZdncngtcWYFzrupdJPzB2EHXtaOqN1roPrM7rnH9UAFiedipPLT/0vAwN m6TH/X49SBcOzv0xzLSEFBo2ZjJtArjeBfflQEaWr1HuLIif1iml9D0W/Gs+MqHpNIGv FLC2oHhXo2VdaSlF+69qPix/0FyKWqomUNv7e4vC48g2b0cI2Oq6Sjtet4rYDNAy7BC+ zbmg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-192228-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192228-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6ac162b4353si103057186d6.513.2024.05.28.04.53.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 04:53:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-192228-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-192228-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192228-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id E13081C2323D for ; Tue, 28 May 2024 11:53:35 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 195E516C85B; Tue, 28 May 2024 11:53:29 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A96A616C841 for ; Tue, 28 May 2024 11:53:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716897208; cv=none; b=SVke/ioJDZZnskGlXDt7osz8BRS5l7kQ2yW3E7CzOjzzLz9btqSyYDqpscdlZJ7fVg6t+kkZ96YwK30Isjry4gB2adHJ2PkXkfoiI2JtW3LlIqjuag4ftZrJbm7BTgsrsjq0GMJbsEdRIZKZ1aV6o3b14mao8eYz3quYfXvluDI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716897208; c=relaxed/simple; bh=EKRHtF39qAzZAiGhtZHJfZ9j4Jhv419BJMQlTmihAhw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=aFwHRdD8yrLjYUi95rf46NwODBLlif0aEVcHX4Bj29HZZL0hkdDRP6sHk1fu7mZkU+qyfb2TdMREcEsjUK7BImNhQCege/fmKSHLp2/YJ1AuOHerKvw4OsP3zye6aBDGwvz58g06EXAj/FuoJeY9JU0jhKzgVJDOvIxKCnbRV24= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 E36D3339; Tue, 28 May 2024 04:53:48 -0700 (PDT) Received: from [10.1.36.57] (e133649.arm.com [10.1.36.57]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8D5573F641; Tue, 28 May 2024 04:53:21 -0700 (PDT) Message-ID: <687a6cda-3c7d-480c-90bc-0987cf48ac7a@arm.com> Date: Tue, 28 May 2024 12:53:19 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC PATCH v3 6/6] Propagate negative bias To: Dietmar Eggemann , Ingo Molnar , Peter Zijlstra , Vincent Guittot , Juri Lelli , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider Cc: Qais Yousef , Morten Rasmussen , Lukasz Luba , Christian Loehle , pierre.gondois@arm.com, linux-kernel@vger.kernel.org References: Content-Language: en-US From: Hongyan Xia In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 26/05/2024 23:53, Dietmar Eggemann wrote: > On 07/05/2024 14:50, Hongyan Xia wrote: >> Negative bias is interesting, because dequeuing such a task will >> actually increase utilization. >> >> Solve by applying PELT decay to negative biases as well. This in fact >> can be implemented easily with some math tricks. >> >> Signed-off-by: Hongyan Xia >> --- >> kernel/sched/fair.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ >> 1 file changed, 44 insertions(+) >> >> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c >> index 0177d7e8f364..7259a61e9ae5 100644 >> --- a/kernel/sched/fair.c >> +++ b/kernel/sched/fair.c >> @@ -4863,6 +4863,45 @@ static inline unsigned long task_util_est_uclamp(struct task_struct *p) >> { >> return max(task_util_uclamp(p), _task_util_est_uclamp(p)); >> } >> + >> +/* >> + * Negative biases are tricky. If we remove them right away then dequeuing a >> + * uclamp_max task has the interesting effect that dequeuing results in a higher >> + * rq utilization. Solve this by applying PELT decay to the bias itself. >> + * >> + * Keeping track of a PELT-decayed negative bias is extra overhead. However, we >> + * observe this interesting math property, where y is the decay factor and p is >> + * the number of periods elapsed: >> + * >> + * util_new = util_old * y^p - neg_bias * y^p >> + * = (util_old - neg_bias) * y^p >> + * >> + * Therefore, we simply subtract the negative bias from util_avg the moment we >> + * dequeue, then the PELT signal itself is the total of util_avg and the decayed >> + * negative bias, and we no longer need to track the decayed bias separately. >> + */ >> +static void propagate_negative_bias(struct task_struct *p) >> +{ >> + if (task_util_bias(p) < 0 && !task_on_rq_migrating(p)) { >> + unsigned long neg_bias = -task_util_bias(p); >> + struct sched_entity *se = &p->se; >> + struct cfs_rq *cfs_rq; >> + >> + p->se.avg.util_avg_bias = 0; >> + >> + for_each_sched_entity(se) { >> + u32 divider, neg_sum; >> + >> + cfs_rq = cfs_rq_of(se); >> + divider = get_pelt_divider(&cfs_rq->avg); >> + neg_sum = neg_bias * divider; >> + sub_positive(&se->avg.util_avg, neg_bias); >> + sub_positive(&se->avg.util_sum, neg_sum); >> + sub_positive(&cfs_rq->avg.util_avg, neg_bias); >> + sub_positive(&cfs_rq->avg.util_sum, neg_sum); >> + } >> + } > > So you remove the 'task bias = clamp(util_avg, uclamp_min, uclamp_max) - > util_avg' from the se and cfs_rq util_avg' in case it's negative. I.e. > if the task is capped hard. > > Looks like this is the old issue that PELT has blocked contribution > whereas uclamp does not (runnable only). > > What's the rationale behind this? Is it because the task didn't get the > runtime it needed so we can remove this (artificially accrued) util_avg? > > Normally we wouldn't remove blocked util_avg and let it rather decay > periodically for cfs_rq's and at wakeup for tasks. Sorry I may not have understood what you asked. PELT has decaying effect whereas uclamp does not, so you will have the effect that dequeuing a task will immediately remove the bias, but util_avg won't be immediately gone. In the case of uclamp_max, assuming an always-running task with uclamp_max of 200, which means util_avg 1024 and util_avg_bias of -824. The moment this task is dequeued, the rq uclamp util will immediately go from 200 to 1024, and then 1024 slowly decay to 0. This patch is to mitigate this effect, so that it will just decay from 200 to 0 without spiking to 1024 first. Hopefully this answers your question. > [...]