Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp1865055lqz; Mon, 1 Apr 2024 22:48:21 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXnx98JVbN6UxQruxpfNHQIGsLUT95l4Bfny8Fm486S/9tIrN7tCd9d/kRL5nUqMobt1eXYyut408UPcEMED/l7GRCn6ncyXkWSbtNeEA== X-Google-Smtp-Source: AGHT+IGWUL8WiRsnH6lE8tH75RoCbtvK/6xf+zXrl5hXGn8kO96Mqvk6TUNbE3wcB2U2T8VYRqUs X-Received: by 2002:a05:6a00:2403:b0:6e6:f9e1:fd07 with SMTP id z3-20020a056a00240300b006e6f9e1fd07mr11107083pfh.10.1712036901316; Mon, 01 Apr 2024 22:48:21 -0700 (PDT) Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id e12-20020a656bcc000000b005dcbda499c9si11220939pgw.261.2024.04.01.22.48.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 Apr 2024 22:48:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-127412-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=KdESN32f; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-127412-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-127412-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id F2977283B55 for ; Tue, 2 Apr 2024 05:48:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A4F1B18628; Tue, 2 Apr 2024 05:48:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="KdESN32f" Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com [209.85.128.175]) (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 34BF2CA6F for ; Tue, 2 Apr 2024 05:48:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712036895; cv=none; b=bfWggioQ8iNOEc4RvQQqYhazCxBRp+EoA12xh9cIkqLa11aTMTF3Gs4aI5qCmVaWeRT9l3VtafvTE7IVJBTpu5f92In9yuXpRL6m1a71efygY1BI3+QBZzr9O52jnS/95MWJiGvFj+JeQjmT6p8FfP/sl/WHc09FnSAW4Pn4qww= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712036895; c=relaxed/simple; bh=Y78rJj8+C6yXAfWJEDvmRi7jXwsL00HBbfbNEJA7KZI=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=ePZsVhlGRkxSvrPzRL234dJzgpqNwF8uwrkBhc0IH8IYOCUyLgjkj/eS9R+GJvSLFnkoUEwO+fSOJhdqQ6seVHMsvVpJRXqAr9tjRPMqpgbRlxpDn06n315QiWEWgsOu6+OL2SDPHN70AozIl9+hK53JadZ7cvAyHmMJGlaeARU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=KdESN32f; arc=none smtp.client-ip=209.85.128.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-60a104601dcso49217017b3.2 for ; Mon, 01 Apr 2024 22:48:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712036893; x=1712641693; 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=LicSR3wkx45YuxnJnubGsVzsBl0pkMbBOEPlM15UIC8=; b=KdESN32fiI69wYH7cOn+QfyL9IMsT5fFtEjO3072n8II2r337rQGjtOCFJ52/NqvE+ ZJQzKbWYGSf2BPUwWpMaS2W4gGDXoQdewBpC68NMzDPzhlicfCMLP5lsGvuo54CipMmB NALNmq6nfNoUNV77jdwvTyetgAFO4wpeok/Cu/avUsQxG7QjiaB9aGO2j1OKEJc8bMpz QE36diFKDbKkwDt9L51TfR4Rht/6Bmqp2ifTHOjUdWfTgkY73iHK8peTLBFSYhSjikxB Ont3G6hgwqFa1qXG+pA//qtHSrK9XoRnWoi4WuG48Tj0WjX6vO474YEkWZsCWGUTy0wc S34w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712036893; x=1712641693; 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=LicSR3wkx45YuxnJnubGsVzsBl0pkMbBOEPlM15UIC8=; b=Y7bldNNof5F/dVwSvl1lKl/fGTUTWkUN+VZRaEZpvSXNBSNyTxp74N/PnwX3IVYeI4 2wm+7BTmgaNYMVLVdsTa8zJLBrNrb5cH7WxZers+Khudp+Fu17sZ3/Ifon7FeAOjJAxX x2WXgFp6UY+VlKNN4fAYYSgCQiKLMvKxTo2CVmdwJIjp8D/kUO7R2FP93K/x8LO4w9ih f/aVjaPTd/24GK+j4K4Nyzlqr2e1RQFNhJmLxVyRT+yJC0328spyS9C3RcClZd1ZmbGw qEkNszrsf7ulMeLZIgp1LRGY6PiTCCPogE5EKpQ6CwbLhtTN9wP3wbxfe68uJthiC3Zf Qz6w== X-Forwarded-Encrypted: i=1; AJvYcCUnKiT6LlR6K2BPD/h89FWDlyGsLpVK4PNkcWYzmbSjLFJ5FNSy0PVIZX5+++1SkzXXxTi0m9OKNCWZcC4PG+NRo/9cvlmelhH4a0T1 X-Gm-Message-State: AOJu0YxU+XLkLD2iNibqCTJdrEUC1e1Cn0LYLCiBXdiRtjnThS9uhl8Z 56H38w7cQOCZ7Xy2xTGdhzLvbfZrbko7vKjvnJGS5B1CbQO4ye6lRGz8zOOcu4/hKqYWb06WSMv Aa3PobIJoDAPeuuT6I4uTk/99uu4= X-Received: by 2002:a05:6902:34b:b0:db9:9537:2c39 with SMTP id e11-20020a056902034b00b00db995372c39mr9318049ybs.2.1712036893108; Mon, 01 Apr 2024 22:48:13 -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: Dawei Li Date: Mon, 1 Apr 2024 22:47:36 -0700 Message-ID: Subject: Re: [PATCH v2] sched/fair: fix initial util_avg calculation To: Vishal Chourasia Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , 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 Hi Vishal Thanks for the comment! Do you suggest using scale_load_down() in place of se_weight()? It's a soft bug we should fix one way or another before what the comment mentions really happens. 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 1024 > > times. > > > > The reason is that se->load.weight has the unit/scale as the scaled-up > > 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. With > > 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 the > > 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_en= tity *se) > > * With new tasks being created, their initial util_avgs are extrapola= ted > > * based on the cfs_rq's current util_avg: > > * > > - * util_avg =3D cfs_rq->util_avg / (cfs_rq->load_avg + 1) * se.load.= 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 desired > > * value. Moreover, the sum of the util_avgs may be divergent, such > > @@ -1078,7 +1079,7 @@ void post_init_entity_util_avg(struct task_struct= *p) > > > > if (cap > 0) { > > if (cfs_rq->avg.util_avg !=3D 0) { > > - sa->util_avg =3D cfs_rq->avg.util_avg * se->load= weight; > > + sa->util_avg =3D cfs_rq->avg.util_avg * se_weigh= t(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 resoluti= on. > */ > 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 > >