Received: by 2002:ab2:2994:0:b0:1ef:ca3e:3cd5 with SMTP id n20csp498855lqb; Thu, 14 Mar 2024 18:59:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWOSdKkJDiLObQ710diGwT2V5L88ilRlR5tyAO7AXqOHEibuLbccqRhtUqdUG4jyX6f/Fx/p/MAWMjPq4je3AjhIdiKCa0RXrQioOD2hA== X-Google-Smtp-Source: AGHT+IFCUIrRbKQtPlic6Qx9whpZSn6zoUMEcrhBNsguVN2jBYRbzNykowkMlBU5KvDEcWgC4Q8n X-Received: by 2002:a17:90b:3d4:b0:29b:22f9:c8e6 with SMTP id go20-20020a17090b03d400b0029b22f9c8e6mr1665567pjb.19.1710467989167; Thu, 14 Mar 2024 18:59:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710467989; cv=pass; d=google.com; s=arc-20160816; b=qM74rUcP4xQOmhCQ9ddUmebLWm5Tfpao8D4GyRkfp24CTh7vaVUAWmRono1SiFW9uF kGdUjeICKbwg1yQFb2YZ5+u+fy6ZSX9wKk6JBh90ZKNP50AineZjC1oA9fui29oNl3Aa SGflFm71X2RRfGuBjchaRbnW75l9xXOmHWz335M24JsvO7pJUGzn7ILqYozqoj+Qmfmn yYCng/IMP+5zUDyabpYlMIuC8kPJcIYImvIyCg0MUP5cnsaVcGS06nzNC4RfRw6b+1oa 2TryYi4DZJenwvnBzLFJmRTyic3CCDjRfxMVkfwfU6kNZzovzo642OtnqSikq8PNW/Ox bS7w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=01D4Shz91ZXQp0AsK5UAAqfBWEt2jNNLBzet4PYM1dM=; fh=WASXBFP4lfZ5ZXzME/5j6YxUnpnqrsV9xCQBTi8uccA=; b=LkDhkXMElXwQa6QtEXbHQC9KxxW7a0wTEIh0mF8lIFW+cR5oJ7ziM17KGu2BeROZI6 wcX3zivMGlLdKtC8gO0dGlGfz00w49+20tYfCJkOnOfK30rV0jq18umWFhQbQxQ/S5ce xi8c2gDE7oVBiGt/LC3+IyHUEuZmU/8u3by0Q2+GLK9d/SjlbUgKfMaWf3cEceFj3pLk Pi0epYppamQ0LgNXHi9JjGiW5p1LV3SPE466Te/1eh3r8lLGbTF+Aj7MtCI0wHFxLA0c D9vW0ktKuP5UqEPCrwGxqtG/pT5Gp2Byu8voAtZN9NXKDeV3vIP80jOAd0CVemRxUfu4 kb3A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Fx7HCM5R; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-103977-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-103977-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id t15-20020a17090a4e4f00b0029c649242f6si1783844pjl.42.2024.03.14.18.59.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Mar 2024 18:59:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-103977-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Fx7HCM5R; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-103977-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-103977-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (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 D4678283593 for ; Fri, 15 Mar 2024 01:59:48 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7A8686FD2; Fri, 15 Mar 2024 01:59:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Fx7HCM5R" Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) (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 4D6F86FA9 for ; Fri, 15 Mar 2024 01:59:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.178 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710467982; cv=none; b=G4ImnaOXOce69Jvky2aM0cyLQofasC+uGHUHAhhsa2dC+DQZ72I9tMyZzFUyg87pzqEWxV/NOUwM+xsvq0jxCKP/hfGBTO6lBoIsqqDuD8KoEvQsomuTSZCBnbCCv5VaaDhu7MJLiw+/RN69MrZIiVTgn/B7Gyr+3icASLBuhF4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710467982; c=relaxed/simple; bh=MbNgZ46a4w6dGK4rz5hedwYJCosUFMkEU495Sftkeg8=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=hFKpZJ2nQdhgLMW2/3BHwM6va2oFJ5u0npa4uIEupUaeHkwp9TXOHEhwB1xH3YIXNhtLV9T9Ru6KqaAUtCn7YdIPL20AjLuVQFhStlyFHNUGksE9odJCd29J16JRlQF40w64Ks8Mr9T89NFiqzqz/nvmRUZmL46QzyypnJY1DqM= 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=Fx7HCM5R; arc=none smtp.client-ip=209.85.210.178 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-pf1-f178.google.com with SMTP id d2e1a72fcca58-6e6a9fafacdso1392482b3a.2 for ; Thu, 14 Mar 2024 18:59:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710467980; x=1711072780; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=01D4Shz91ZXQp0AsK5UAAqfBWEt2jNNLBzet4PYM1dM=; b=Fx7HCM5RClY5jZri7Iuj2G/VvMM9Bu20jyorfLsDlwniMbpWDuYGaAW41B9n4WeMJQ B2h/5eYfOiquX5siD/bUTVcZVVRwayhOu4P3/2jzhWJVr+cUI8Etg8NOY9BShdZT3uRT /MdiefQBgVq8+pGNgD0VechjOlMlOmIKV9MjKB1Aofb3PehKQLPXF0+kw5JjeHqlMFxh r4jdqzIoQ63TPeSab2M+aSYXW6qXRN4TDcyDpw3M9+4eskBWjU+tleKF2La6D8qbA71g 5M1M+T5nLQu9Tl9my7hwHjg2Na5FaVlRV0UAVYAvzsWbP3SO/NmQzJY/lLPKeGZfTGMp dtMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710467980; x=1711072780; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=01D4Shz91ZXQp0AsK5UAAqfBWEt2jNNLBzet4PYM1dM=; b=OvpxFSlO8d/slMAJB0Njz8Udevlpb8XX+RgtEU2dol7MhlLTLEMfM52BQheiH7ul5x gyjYGK0P7nMiOLvt+aWEZ9hFTjLmQ4gYg2Q6w5F89zCs9R4H85saXatQWFMeVNj1dYXp GUTVasIs3+6OKqNFb5NhVMgusjSJcuiwW8fJSTmccNBjMHWN7ck3dBV0b5YHEMc7XSXh zNWnab+tzXWT8KxPCEn/vVlSE/dpajoLetTQsoi/Pa/ikw8qbUovmm2MsclfZyLSo4su WXB2ccwPJLsiV+0MZhiKYMUu671IS0svMuGk0WF+sZHNRB2e0wG9DtYlebYpXI0grNcp 4MCQ== X-Forwarded-Encrypted: i=1; AJvYcCXKpbL22eDYxFDt0fdfH6FTxxdpMxIgNHJLZTsfoRfRj3htlNYgZyCkNzDA2w71M4Lve60QsSnyQgxGPjviYU75KMjFdV/DLnz+a8h7 X-Gm-Message-State: AOJu0YyFiAi1Z4NbH8EniUdSfoqxoLWgiEzq9by4dZ5+9DPAzNAzG6zV Yin71zkP2OGfqowi0/j/0hT9iw42pNW9Jl7Ljd+5V0tcAPl7WqVA X-Received: by 2002:a05:6a20:9381:b0:1a3:4777:7941 with SMTP id x1-20020a056a20938100b001a347777941mr2107593pzh.33.1710467980429; Thu, 14 Mar 2024 18:59:40 -0700 (PDT) Received: from ub23.localdomain (c-24-16-118-101.hsd1.wa.comcast.net. [24.16.118.101]) by smtp.gmail.com with ESMTPSA id i7-20020a17090332c700b001d949393c50sm2451086plr.187.2024.03.14.18.59.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Mar 2024 18:59:40 -0700 (PDT) From: Dawei Li To: Cc: Dawei Li , 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 Subject: [PATCH v2] sched/fair: fix initial util_avg calculation Date: Thu, 14 Mar 2024 18:59:16 -0700 Message-Id: <20240315015916.21545-1-daweilics@gmail.com> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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_entity *se) * With new tasks being created, their initial util_avgs are extrapolated * based on the cfs_rq's current util_avg: * - * util_avg = cfs_rq->util_avg / (cfs_rq->load_avg + 1) * se.load.weight + * util_avg = 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 != 0) { - sa->util_avg = cfs_rq->avg.util_avg * se->load.weight; + sa->util_avg = cfs_rq->avg.util_avg * se_weight(se); sa->util_avg /= (cfs_rq->avg.load_avg + 1); if (sa->util_avg > cap) -- 2.40.1