From nobody Wed Dec 31 18:48:45 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E83A5C4332F for ; Mon, 30 Oct 2023 17:32:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233911AbjJ3Rcy (ORCPT ); Mon, 30 Oct 2023 13:32:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229849AbjJ3Rcw (ORCPT ); Mon, 30 Oct 2023 13:32:52 -0400 X-Greylist: delayed 63 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Mon, 30 Oct 2023 10:32:49 PDT Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 423D59C for ; Mon, 30 Oct 2023 10:32:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inria.fr; s=dc; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=ByIrGYpnzkjEbWryrA2QUNyVJEVzplp0rRIRgaVq6tA=; b=JAnfXtPbtnMHaTFHHhmwwnLYBtBA275yoabzmGGRjGpddXsw/rlEHI+y qzUq6287mX/7vxOObz3GA/ahpdzrpXQ8gYoJJir7TxSev3s2DG7zUdQhu Tx5gDzgU8jyXFi+d+vU6KfUuV9llTVT4fINyg3ecpiHkowtAcjqkA9YQC c=; Authentication-Results: mail2-relais-roc.national.inria.fr; dkim=none (message not signed) header.i=none; spf=SoftFail smtp.mailfrom=keisuke.nishimura@inria.fr; dmarc=fail (p=none dis=none) d=inria.fr X-IronPort-AV: E=Sophos;i="6.03,263,1694728800"; d="scan'208";a="133946899" Received: from dt-aponte.paris.inria.fr (HELO keisuke-XPS-13-7390.paris.inria.fr) ([128.93.67.66]) by mail2-relais-roc.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Oct 2023 18:31:44 +0100 From: Keisuke Nishimura To: Ingo Molnar , Peter Zijlstra , Vincent Guittot Cc: linux-kernel@vger.kernel.org, Chen Yu , Shrikanth Hegde , Dietmar Eggemann , Mel Gorman , Valentin Schneider , Julia Lawall , Keisuke Nishimura Subject: [PATCH v2] sched/fair: Fix the decision for load balance Date: Mon, 30 Oct 2023 18:29:46 +0100 Message-Id: <20231030172945.1505532-1-keisuke.nishimura@inria.fr> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" should_we_balance is called for the decision to do load-balancing. When sched ticks invoke this function, only one CPU should return true. However, in the current code, two CPUs can return true. The following situation, where b means busy and i means idle, is an example, because CPU 0 and CPU 2 return true. [0, 1] [2, 3] b b i b This fix checks if there exists an idle CPU with busy sibling(s) after looking for a CPU on an idle core. If some idle CPUs with busy siblings are found, just the first one should do load-balancing. Fixes: b1bfeab9b002 ("sched/fair: Consider the idle state of the whole core= for load balance") Signed-off-by: Keisuke Nishimura Reviewed-by: Chen Yu --- kernel/sched/fair.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 2048138ce54b..69d63fae34f4 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -11079,12 +11079,16 @@ static int should_we_balance(struct lb_env *env) continue; } =20 - /* Are we the first idle CPU? */ + /* + * Are we the first idle core in a MC or higher domain + * or the first idle CPU in a SMT domain? + */ return cpu =3D=3D env->dst_cpu; } =20 - if (idle_smt =3D=3D env->dst_cpu) - return true; + /* Are we the first idle CPU with busy siblings? */ + if (idle_smt !=3D -1) + return idle_smt =3D=3D env->dst_cpu; =20 /* Are we the first CPU of this group ? */ return group_balance_cpu(sg) =3D=3D env->dst_cpu; --=20 2.34.1