Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp1928523lqz; Tue, 2 Apr 2024 01:50:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXmHsWpP0HhTjUAoBFp2aOigRHBOBDXzEI1IqaIQS9/Do+U/tyx81b5JR+NJWXXAX7pmVCw/hHALGW3QYl8ftY511wxrlois3jK8irOcg== X-Google-Smtp-Source: AGHT+IEy3VvhVcktz7qxkHXs0IJaMzBQ09kExdfsy5FIVGDwAEUFg20tNhQzOSZBY3/fUckaT+Yt X-Received: by 2002:a05:6214:5d2:b0:691:823b:1bf6 with SMTP id t18-20020a05621405d200b00691823b1bf6mr11602242qvz.47.1712047822380; Tue, 02 Apr 2024 01:50:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712047822; cv=pass; d=google.com; s=arc-20160816; b=li0ZJcsyCms5vHRTMSm/q7v5HCHuLCzEI6ExPsNBbj20DbseSHitLNWAYnQtfXfOVm WWErh/ySYuSi5n9DxNhe/BWOn1s5bHf3ULEc/TpSsR5FiZ3B49ddKf15kPOG5Ywzemz0 UdD4sJvg62ALAYBGl7x4pRrKLWmuEle3jDXpf3qXuTT7mJ4u5FC3BE9g4H7j8hZa718I LVQSrBVz+6VW7KnRivNsXcJjUBsrcgjcdguH5DawsuyHNCnp29cqi7PpD+CkzhweqGE/ 0yGRS0PNNocDYL16fF4JRPtE/GGckmzmLc+66aDy6jqUDoUVepjHWlwQs4cEC5e0zv22 YnNQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=cz7rwc4geH+1dxlJ323CGCG7tEqlqWjReSINIJGPJKU=; fh=J7uI+58UF9XUie0l7V7gvxhjqZGxNrQR7bCQL3TZ74M=; b=o7TyTpL07WHY2fop5+90qmPqcWbBUVE3jceHAZW0I6DN7mNtGWsi0DUcTHq8R0/cj3 zHZXMJzNonZYviHZlVW6XQ4AJcg8YebJSvpX8dRs/PVT9ZiJvEGhaRCMgnb+c6xgzHF2 gTU0tY38iklWE835mnizw5Jko28Nt7JF3ijCNTC6AXjqG91CXcctvy57THjrT9iFnzsl GeX+w1nZ6hIhzxviHEF7L0s04KTZfjCOybB1WtBadoNO1fRvI0eQcLEXxr4DblSrrFzh 0HsAWw0GulQTSVJfq0/hD6N9/j1SYRAIEPAcBumR/qxQCX42uuJR6aHEXVA/Ar2vPVY9 IMLQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Uw95NDyf; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-127583-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127583-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id l10-20020a0ce08a000000b006967b8a7c2dsi11891163qvk.297.2024.04.02.01.50.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 01:50:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-127583-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; dkim=pass header.i=@linaro.org header.s=google header.b=Uw95NDyf; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-127583-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127583-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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 0FD601C22481 for ; Tue, 2 Apr 2024 08:50:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5B35653380; Tue, 2 Apr 2024 08:50:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Uw95NDyf" Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5F5F46B80 for ; Tue, 2 Apr 2024 08:50:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712047810; cv=none; b=HVTDhwofAQvQiP+u1dpScU0lGmQtCqerGiA6ORLrpQSJgaR8omWbX6hMzJW6gvhSThFffbIRWiLwwCOycjLoejbzUP2jCUyrBkAIzz4P5g7mROHEpE8DWeWLFEKLq84O+Xcw3uHbI+W2i7o1L1J+Vb2P0ngqnCTLH3XzRos+dx0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712047810; c=relaxed/simple; bh=efnEV+jz+9UHrcY2jlfavBbD8PHpHnq48JZQ1nNzHus=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=G/LVLwENnYthyNziPhpJ2jCcSA0xeKw7WMnJrnrx7D9mSkQiz3i87hSbU7pGvAFoRBLP3BnOJxvflWWTx4TCsrCCfm9zDyaomeRsQ/7LUOQh1q7LNu5rvDFDnkbvKGN0HjIR0jhvIahC0G0wLdCrwzELZwQS8FL+8WrsRwQuB9o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=Uw95NDyf; arc=none smtp.client-ip=209.85.216.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-29f749b6667so3382633a91.0 for ; Tue, 02 Apr 2024 01:50:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1712047808; x=1712652608; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=cz7rwc4geH+1dxlJ323CGCG7tEqlqWjReSINIJGPJKU=; b=Uw95NDyfLvUcd40aP83taY4Kfll3UA2QFAkPhfEH4R5selYNLNazDANvTtdm6mZ1fo dEsZe6neuj0eItcvXJTFHP76s+66C+S7IlZatCHqV15I+j1LYDIJ8giavZAzrRluoLvQ EDSvY8EgiOvLglj9BxI8QyAlh/T4mLvisHmiXFxufi8aEEekbO4zMksQvBxzdkWQGzoH Rntwx5sfIEFyhsRjisSodhoLiEfLbeiyW6c1W+VVNykFtoiHuFc3apoZZlHEoaqqH//k fQWlM75SqmGVi2CawulwUNldWlNn8Wddecc9pmpIBywYOsonuRSL1KUYKxPFMNe6Cyll 4avA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712047808; x=1712652608; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cz7rwc4geH+1dxlJ323CGCG7tEqlqWjReSINIJGPJKU=; b=QMXCL75FQE/VdO+6cha/Fd0zSoGZcXO2Cuh2UL4iySfdqYAL/5rm329d5NLrwjwr5k IAYX9MOl17iO0HJmpz/LVZwjI1qAqJP9Rgb11xEXDI+uUfBHhF5cJryUMMewj/fRmSWL YbAZzDD0RiQqREbUzzofkfqcXXuuTMSTWZnfF6N4NDLzYCgvnWdDCCTx5J9n4sASAtWO IERro4ZePrZAM38gH3xNcKr0ZHviyEoHJsrLleBglcbr51tNxXIr8WktiPFx/xZWZnhH +DyBwc///9434lHwnL4QRzJxuPuXraOrqD7mlOJyV4ZdMBXcU65s9TENsBcTTz8p1byB EEMQ== X-Forwarded-Encrypted: i=1; AJvYcCX9KaLrouzpSyTPRuAtVJqOfidjxlGekegKi+dX9mZCvqpX5SgziPm9St863fYWnq32RDTmKXtJ/RilRot962X/PDzBMaflrPHCivbt X-Gm-Message-State: AOJu0YzDTAW1Jmy3k9PJbQ7vnKJOD3O1RZpMjGklxVH4FHrAjzFY0PRr VK6lrbsXAbt7bg45udG6H0r8iyAld+m16Jp/19StasJtNjNJGd0uv3k1cjwQul1tswYVl0Tz/HN ax1QguFSf7XDAbB0nCmrCryxlxTYvSV9V8emM3g== X-Received: by 2002:a17:90b:46c6:b0:2a2:176f:fba9 with SMTP id jx6-20020a17090b46c600b002a2176ffba9mr9417095pjb.43.1712047808026; Tue, 02 Apr 2024 01:50:08 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240315015916.21545-1-daweilics@gmail.com> In-Reply-To: From: Vincent Guittot Date: Tue, 2 Apr 2024 10:49:56 +0200 Message-ID: Subject: Re: [PATCH v2] sched/fair: fix initial util_avg calculation To: Vishal Chourasia Cc: Dawei Li , Ingo Molnar , Peter Zijlstra , Juri Lelli , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, 2 Apr 2024 at 10:44, Vishal Chourasia wrote= : > > On 02/04/24 11:17 am, Dawei Li wrote: > > Hi Vishal > > > > Thanks for the comment! > > Do you suggest using scale_load_down() in place of se_weight()? > scale_load_down should be better. se_weight is used for computing sched_entity's pelt signal so keep using it looks better but all this clearly just nitpick because that doesn't make any difference > > It's a soft bug we should fix one way or another before what the > > comment mentions really happens. > IIUC, We should be moving towards using full load resolution > for all the calculations. In that case, we need not worry about scaling l= oad at > all. Maybe someone could provide context here. > > > I am actually confused that we have both se_weight() and > > scale_load_down(), and they do the same thing. > > > > Best regards, > > Dawei > > > > On Mon, Apr 1, 2024 at 3:36=E2=80=AFAM Vishal Chourasia wrote: > >> > >> On Thu, Mar 14, 2024 at 06:59:16PM -0700, Dawei Li wrote: > >>> Change se->load.weight to se_weight(se) in the calculation for the > >>> initial util_avg to avoid unnecessarily inflating the util_avg by 102= 4 > >>> times. > >>> > >>> The reason is that se->load.weight has the unit/scale as the scaled-u= p > >>> load, while cfs_rg->avg.load_avg has the unit/scale as the true task > >>> weight (as mapped directly from the task's nice/priority value). With > >>> CONFIG_32BIT, the scaled-up load is equal to the true task weight. Wi= th > >>> CONFIG_64BIT, the scaled-up load is 1024 times the true task weight. > >>> Thus, the current code may inflate the util_avg by 1024 times. The > >>> follow-up capping will not allow the util_avg value to go wild. But t= he > >>> calculation should have the correct logic. > >>> > >>> Signed-off-by: Dawei Li > >>> --- > >>> Changes in v2: > >>> - update the commit message > >>> --- > >>> kernel/sched/fair.c | 5 +++-- > >>> 1 file changed, 3 insertions(+), 2 deletions(-) > >>> > >>> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > >>> index a19ea290b790..5f98f639bdb9 100644 > >>> --- a/kernel/sched/fair.c > >>> +++ b/kernel/sched/fair.c > >>> @@ -1031,7 +1031,8 @@ void init_entity_runnable_average(struct sched_= entity *se) > >>> * With new tasks being created, their initial util_avgs are extrapo= lated > >>> * based on the cfs_rq's current util_avg: > >>> * > >>> - * util_avg =3D cfs_rq->util_avg / (cfs_rq->load_avg + 1) * se.loa= d.weight > >>> + * util_avg =3D cfs_rq->avg.util_avg / (cfs_rq->avg.load_avg + 1) > >>> + * * se_weight(se) > >>> * > >>> * However, in many cases, the above util_avg does not give a desire= d > >>> * value. Moreover, the sum of the util_avgs may be divergent, such > >>> @@ -1078,7 +1079,7 @@ void post_init_entity_util_avg(struct task_stru= ct *p) > >>> > >>> if (cap > 0) { > >>> if (cfs_rq->avg.util_avg !=3D 0) { > >>> - sa->util_avg =3D cfs_rq->avg.util_avg * se->lo= ad.weight; > >>> + sa->util_avg =3D cfs_rq->avg.util_avg * se_wei= ght(se); > >> Hi, > >> > >> The comment above the declaration of se_weight function says we should= be > >> using full load resolution and get rid of this helper. > >> > >> Should we be adding new user of the helper? > >> > >> /* > >> * XXX we want to get rid of these helpers and use the full load resol= ution. > >> */ > >> static inline long se_weight(struct sched_entity *se) > >> { > >> return scale_load_down(se->load.weight); > >> } > >> > >> > >>> sa->util_avg /=3D (cfs_rq->avg.load_avg + 1); > >>> > >>> if (sa->util_avg > cap) > >>> -- > >>> 2.40.1 > >>> >