From nobody Thu Dec 18 17:05:19 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 3B812C25B47 for ; Fri, 27 Oct 2023 17:25:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345964AbjJ0RZp (ORCPT ); Fri, 27 Oct 2023 13:25:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33668 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232381AbjJ0RZm (ORCPT ); Fri, 27 Oct 2023 13:25:42 -0400 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05309CC for ; Fri, 27 Oct 2023 10:25:39 -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=h9F9MGQEWuO7FbcDirGpZveGbR00hMm8fS3YRyaKU7Q=; b=jzIIkwuiXIENTVPNiKWjpFny6CwewVRxqTiOvzQxpAqDVglH7On4tLne 3ws+G/bmbYUWlsSAhsgw66AFzslIxj0G8sNLUF5/mtsdJnzReidQbmqGX N02Oa6TawMO10w3MFrrKAhpYjikfATqWYSQCn37XIsf+xazwUHljVgOBR Q=; Authentication-Results: mail3-relais-sop.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,256,1694728800"; d="scan'208";a="69978968" Received: from dt-aponte.paris.inria.fr (HELO keisuke-XPS-13-7390.paris.inria.fr) ([128.93.67.66]) by mail3-relais-sop.national.inria.fr with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Oct 2023 19:25:38 +0200 From: Keisuke Nishimura To: Ingo Molnar , Peter Zijlstra , Vincent Guittot Cc: linux-kernel@vger.kernel.org, Dietmar Eggemann , Mel Gorman , Valentin Schneider , Julia Lawall , Keisuke Nishimura Subject: [PATCH] sched/fair: Fix the decision for load balance Date: Fri, 27 Oct 2023 19:17:43 +0200 Message-Id: <20231027171742.1426070-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 Reviewed-by: Shrikanth Hegde Reviewed-by: Vincent Guittot --- 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 2048138ce54b..eff0316d6c7d 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -11083,8 +11083,9 @@ static int should_we_balance(struct lb_env *env) return cpu =3D=3D env->dst_cpu; } =20 - if (idle_smt =3D=3D env->dst_cpu) - return true; + /* Is there an 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