From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (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 EF84025EF9C for ; Mon, 8 Jun 2026 12:47:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780922842; cv=none; b=ZnZDO56nNfhdP2j728mSsLOrbfx+teclKl7hSWOse1a+GOUHX4B5kyd3qxrTWRJtgcHHuu/6qQqeJTqkeHBRASZloNGV/MJ5jKjxj0TsUWo5kX0VeH1AUP5iRyUSFFqze2hMd7+ISiA5s4fhWMOf7COvEYJZb2nY0CDvA+qJl8E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780922842; c=relaxed/simple; bh=saTX2eKNxw/HbXvX9wE267EUwvGf5JSeNd1MTe62di4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cV7fy5qHCnjTLWSj2RdQqqemNABhUDbmfaks+842gD+EbgGtnvPKsKkcaIoT67KY/rMZZHu+zbuoE6efvgOVjgnhvVQ9QyPafaJI5jqsmOH4kgAc7C6fj4YmLLgPdZVASXoSbgyT8h+L1iIlWJXLkrmKkMPc2Varm/Fz+OTGEpU= 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=lbIQkflc; arc=none smtp.client-ip=198.175.65.15 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="lbIQkflc" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1780922839; x=1812458839; h=from:date:subject:mime-version:content-transfer-encoding: message-id:references:in-reply-to:to:cc; bh=saTX2eKNxw/HbXvX9wE267EUwvGf5JSeNd1MTe62di4=; b=lbIQkflcjBpEC9aYERKLLrXcKdst1/B45GHCKf5aom0n6nvtqcDuO/G4 BdYLCqw985PAcxFmtP95ZzwYpdMGwoEjmCFsuB+C4poy5QgTAwB9rm9DK gYDXIgZaMOJUx+mGRsCpgb08MWNW4iVmb6cwJOIwHT25CSQlyBM4ZWLXZ oU1ZlEt/xJ6U0TUs9Q0KPiQed8xba9K/qnIIJfp40LIe3QrVC4KoONEu+ TwcLbczJCij0LH+020Ep9KUnje0JiCdWp5vS/aNLyDRmzIx3YbJYKEt+/ zj0CSHrUe9x+eduEyix78LjqkwUBbvcb9w4CNHjDKCeXD6de6wkdKt9ly w==; X-CSE-ConnectionGUID: WTfzAYX8STSd3PxnOPWQpA== X-CSE-MsgGUID: ZaJbjEJkTEuXnDv0kcf+sg== X-IronPort-AV: E=McAfee;i="6800,10657,11810"; a="85281919" X-IronPort-AV: E=Sophos;i="6.24,194,1774335600"; d="scan'208";a="85281919" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jun 2026 05:47:15 -0700 X-CSE-ConnectionGUID: T567r3DgRAe8fbWuUXXF3A== X-CSE-MsgGUID: qsZhracpRQK/7QxlBV5Nkg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.24,194,1774335600"; d="scan'208";a="247409312" Received: from unknown (HELO [172.25.112.21]) ([172.25.112.21]) by fmviesa004.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jun 2026 05:47:15 -0700 From: Ricardo Neri Date: Mon, 08 Jun 2026 05:57:13 -0700 Subject: [PATCH v4 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: <20260608-rneri-fix-cas-clusters-v4-3-1526711c944c@linux.intel.com> References: <20260608-rneri-fix-cas-clusters-v4-0-1526711c944c@linux.intel.com> In-Reply-To: <20260608-rneri-fix-cas-clusters-v4-0-1526711c944c@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 , Barry Song Cc: "Rafael J. Wysocki" , Andrea Righi , K Prateek Nayak , 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=1780923493; l=3047; i=ricardo.neri-calderon@linux.intel.com; s=20250602; h=from:subject:message-id; bh=saTX2eKNxw/HbXvX9wE267EUwvGf5JSeNd1MTe62di4=; b=HzcOYxlGJ/5HQEpCF4iQOoJBlgau6HQWBM+6LEW9OG+aKCpRka2UGkRkYvv62FPD4A5CBPoON frtRWQHXkxcDPZnBrP0KtW+n0QeQnya2xbp8wvyDEwKnTfXQcUb4sv+ 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 Signed-off-by: Ricardo Neri --- 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 86987c69bddd..a30ba02df688 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -11934,6 +11934,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; @@ -12040,17 +12051,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