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 A84D3C4332F for ; Tue, 31 Oct 2023 13:39:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344625AbjJaNj7 (ORCPT ); Tue, 31 Oct 2023 09:39:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37636 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344599AbjJaNj6 (ORCPT ); Tue, 31 Oct 2023 09:39:58 -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 D45EB9F for ; Tue, 31 Oct 2023 06:39:54 -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=+R/StZ0rnd3KPlOJD7FBs4MnY5uMyxTojGwy+D7cBfE=; b=dxs7i03DmLPGojj/9w98djg9obg0R40MvthZamq0P5raUwyVO57WH+6U 17INflnLwHjfbd9T71diB3EpXtd5f7mYbfGzQXqDKekM0KkpBbOJfUeyb RspWzT5u8TpqsPMO8XTgrDUW+FLh0Gn0s+FJnhut8FfOmnhdAQ1kdG5zM k=; 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,265,1694728800"; d="scan'208";a="70220528" 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; 31 Oct 2023 14:39:53 +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 v3] sched/fair: Fix the decision for load balance Date: Tue, 31 Oct 2023 14:38:22 +0100 Message-Id: <20231031133821.1570861-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 | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 2048138ce54b..921f4f65adef 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 non-SMT domain or higher, + * 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