From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 40030372665 for ; Mon, 22 Jun 2026 23:55:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782172536; cv=none; b=i3Bi0gahwJdSpZolaCCZu1fiRw03RZ29mrFk9gDZRDpMW4DSfuE7yJtjpBC91+DoOYk8OY+2Fj7ugx8Hxq1B+59R7Vz5oIa4ywPVq6T0aCHBo1A7scTwtOUM7Q7Ht9Xr3sfe/PMtvhGfgEtKKRvaw34oCcLh6HyYlT0hHqge6w8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782172536; c=relaxed/simple; bh=xqTTARIjfuZL/TzYafjUsaZtElpWOzKIQUdIG0iqn5Q=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sXLTAzd4CSxB+Fmyp6h0F9mImSxd7wJ8y194YUjvF2DQASOMgfl8IHyT7ZUUHxbWUMrmjWGbUJ2T6om4Y6kGLNzXpt4/22dy+Y48FKU6rpRqwXOWsxoojwMNkk5/X5TG1rHIJ/ygLdo08SseHCut1289jP3wTKjF+4Yerk4N/lo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=l95Uw6PA; arc=none smtp.client-ip=192.198.163.18 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="l95Uw6PA" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1782172535; x=1813708535; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=xqTTARIjfuZL/TzYafjUsaZtElpWOzKIQUdIG0iqn5Q=; b=l95Uw6PAUIy8ALYdbHvev+FHDiFf2LiJfPrvfdz+bLkHvjUPy1CPiJdG gZ/vXflRFh23m75ZPlC3KFI+lokF3Qyz3q19fd53SGLLFGIJZEl8uB0fx n/gBad21pbDQAQcrDlmpNTzVjhdqPjNGg8mKUu+72+ocHXBpWh0OLK6ej f5hiVLLjPqmZXtTVFphvTrN0szyfohUUYZJ6MT2QzncGlcY1pyGZl/4GR IzC1k6+9IHheWI1b/K/TW4v299lsgebe4ZGM/grZ3c5hCr+qBMYKuwhPW czzp+EBptVvDWiAX769bkL4pDCr6gPK2EMgUjSuKI261cebJrk5N70xtF A==; X-CSE-ConnectionGUID: PAwXpLY+T4OnOlKsx1nmWg== X-CSE-MsgGUID: cPf9Zl5fSHWOe4QaMwQ3wA== X-IronPort-AV: E=McAfee;i="6800,10657,11825"; a="82014494" X-IronPort-AV: E=Sophos;i="6.24,219,1774335600"; d="scan'208";a="82014494" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2026 16:55:31 -0700 X-CSE-ConnectionGUID: E/D5BFCYRDqKmEN7T6HYYg== X-CSE-MsgGUID: tKrZY11BThG2skw3+NpzAQ== X-ExtLoop1: 1 Received: from unknown (HELO [172.25.112.21]) ([172.25.112.21]) by fmviesa003.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2026 16:55:30 -0700 From: Ricardo Neri Date: Mon, 22 Jun 2026 17:05:53 -0700 Subject: [PATCH v5 3/6] sched/fair: Check CPU capacity before comparing group types during load balance Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260622-rneri-fix-cas-clusters-v5-3-19968f2d1497@linux.intel.com> References: <20260622-rneri-fix-cas-clusters-v5-0-19968f2d1497@linux.intel.com> In-Reply-To: <20260622-rneri-fix-cas-clusters-v5-0-19968f2d1497@linux.intel.com> To: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Valentin Schneider , Tim C Chen , Chen Yu , Christian Loehle , K Prateek Nayak , Barry Song Cc: "Rafael J. Wysocki" , Andrea Righi , Len Brown , ricardo.neri@intel.com, linux-kernel@vger.kernel.org, Vincent Guittot , Ricardo Neri X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1782173185; l=3169; i=ricardo.neri-calderon@linux.intel.com; s=20250602; h=from:subject:message-id; bh=xqTTARIjfuZL/TzYafjUsaZtElpWOzKIQUdIG0iqn5Q=; b=A3WWDsiTUPVAdOSZTXen9tZTWxtqQeCQ1gNbLf8Sys+ShuPxOmp1i4NS1JB0WLt71iRCypwjv +lH5z4cGXcoB0hy19Susff4fsRutbC39bXyZ0VnMXW6eUn236YUX3ji X-Developer-Key: i=ricardo.neri-calderon@linux.intel.com; a=ed25519; pk=NfZw5SyQ2lxVfmNMaMR6KUj3+0OhcwDPyRzFDH9gY2w= update_sd_pick_busiest() may incorrectly select a fully_busy group as the busiest group when its per-CPU capacity exceeds that of the destination CPU. This happens because the type of busiest group is initialized to group_has_spare and allows the fully_busy group to win the type comparison. update_sd_pick_busiest() should not choose a candidate scheduling group with at most one runnable task if its per-CPU capacity is greater than that of the destination CPU. Such a check already exists, but it is done too late: after the type comparison, preventing a subsequent fully_busy group of equal per-CPU capacity from being correctly selected. Move this check to occur before comparing group types. Fixes: 0b0695f2b34a ("sched/fair: Rework load_balance()") Reviewed-by: Christian Loehle Reviewed-by: Chen Yu Reviewed-by: Tim Chen Reviewed-by: Vincent Guittot Tested-by: Christian Loehle Signed-off-by: Ricardo Neri --- Changes in v5: * Added Tested-by tag from Christian. Thanks! Changes in v4: * Dropped note on SMT not being affected since SMT + asym capacity is now supported. * Added Reviewed-by tags from Vincent, Tim, and Chen Yu. Thanks! Changes in v3: * Added a Fixes tag. (Christian) * Added Reviewed-by tag from Christian. Thanks! Changes in v2: * Added a note clarifying that SMT and SD_ASYM_CPUCAPACITY are mutually exclusive. (Tim) * Kept parentheses around bitwise operators for clarity. * Rewrote patch description for clarity. --- kernel/sched/fair.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 31baa0000616..030675e249b5 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -11944,6 +11944,17 @@ static bool update_sd_pick_busiest(struct lb_env *env, sds->local_stat.group_type != group_has_spare)) return false; + /* + * Candidate sg has no more than one task per CPU and has higher + * per-CPU capacity. Migrating tasks to less capable CPUs may harm + * throughput. Maximize throughput, power/energy consequences are not + * considered. + */ + if ((env->sd->flags & SD_ASYM_CPUCAPACITY) && + (sgs->group_type <= group_fully_busy) && + (capacity_greater(sg->sgc->min_capacity, capacity_of(env->dst_cpu)))) + return false; + if (sgs->group_type > busiest->group_type) return true; @@ -12050,17 +12061,6 @@ static bool update_sd_pick_busiest(struct lb_env *env, break; } - /* - * Candidate sg has no more than one task per CPU and has higher - * per-CPU capacity. Migrating tasks to less capable CPUs may harm - * throughput. Maximize throughput, power/energy consequences are not - * considered. - */ - if ((env->sd->flags & SD_ASYM_CPUCAPACITY) && - (sgs->group_type <= group_fully_busy) && - (capacity_greater(sg->sgc->min_capacity, capacity_of(env->dst_cpu)))) - return false; - return true; } -- 2.43.0