From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 ADAD921A42D for ; Thu, 9 Jan 2025 09:46:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736416005; cv=none; b=u0EFSIshAM1424kOZabc/O1orAJi4yJAqfphYT3XhP+Em+GUEkaVnW+yLK19YlxeLPGU2oXaQNnsHtoIp1F7Iu9MtXxxsXzxJpGzYng7qFPPBuswDtzxw1lV7ptLtk5poocIkXEyMb+zmUS9AfTgSLfLpWa7rIRZRJr/bZGJ/dg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736416005; c=relaxed/simple; bh=W6Ur1yOC2QojfATMl6xVmUmnLnHin+PhqFkAwFUMH7g=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=j1Odq546tN0yK9VmcSTwIssg+28RmUuJU5fiHr9reaCYyKvJtMRHr0jkJySvRSu/IiGilU91y2E5x0fTf/YwEUjSGGe7W3x1vcRlWFc2ngXCZhB+hiMM5sUqK/ArITZTLZT6f3J19gdXaXgadX3tZoIJhNj4wkK+CVmULJX35+8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=l0BHNbBf; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="l0BHNbBf" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=lWAm24dmzo3NBpt5wzYsqdcrW6WRORPzSzLgUzq0ZVo=; b=l0BHNbBf7jTJoCPOWxzbrr0Sq8 x5cXdYEnGtBcHwHAAoSEj14hvMd7nF0hC2NA7FfSNKp6X3UqXKypSqLBeCczKJgb4xAZsSv4lp+lQ m0hOmb9gYQeUjATUWMhXuId8TNhkZnB+aeqLnHiMRInSa7g3Z80j+Fu5R1bl2+j9c3AL03tRVKPE7 1pRgu8lEYGPnChlO5ZCfbPoBE7tRfuUNCYkX4bVmMmGgyjAB+3MAJ7RaWfXCp6BrixftyjKFGMQV6 /hucUOdzyRgsSlsZF5nvf80wyU4LrG/i0oNC+Ro+pjuk4SUemu70qm5QiD4W7M8TQX4zKmotJ1xwD zGeXE71Q==; Received: from 77-249-17-89.cable.dynamic.v4.ziggo.nl ([77.249.17.89] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tVp7U-000000057JG-27sR; Thu, 09 Jan 2025 09:46:28 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id AD77130057A; Thu, 9 Jan 2025 10:46:27 +0100 (CET) Date: Thu, 9 Jan 2025 10:46:27 +0100 From: Peter Zijlstra To: I Hsin Cheng Cc: mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, vschneid@redhat.com, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH] sched/fair: Refactor can_migrate_task() to elimate looping Message-ID: <20250109094627.GP20870@noisy.programming.kicks-ass.net> References: <20250108172948.452158-1-richard120310@gmail.com> 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=us-ascii Content-Disposition: inline In-Reply-To: <20250108172948.452158-1-richard120310@gmail.com> On Thu, Jan 09, 2025 at 01:29:47AM +0800, I Hsin Cheng wrote: > kernel/sched/fair.c | 16 ++++++++++------ > 1 file changed, 10 insertions(+), 6 deletions(-) > > diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c > index 2d16c8545..ce46f61da 100644 > --- a/kernel/sched/fair.c > +++ b/kernel/sched/fair.c > @@ -9404,12 +9404,16 @@ int can_migrate_task(struct task_struct *p, struct lb_env *env) > return 0; > > /* Prevent to re-select dst_cpu via env's CPUs: */ > - for_each_cpu_and(cpu, env->dst_grpmask, env->cpus) { > - if (cpumask_test_cpu(cpu, p->cpus_ptr)) { > - env->flags |= LBF_DST_PINNED; > - env->new_dst_cpu = cpu; > - break; > - } > + struct cpumask dst_mask; Except you cannot put cpumask on-stack... > + > + cpumask_and(&dst_mask, env->dst_grpmask, env->cpus); > + cpumask_and(&dst_mask, &dst_mask, p->cpus_ptr); > + > + cpu = cpumask_first(&dst_mask); > + > + if (cpu < nr_cpu_ids) { > + env->flags |= LBF_DST_PINNED; > + env->new_dst_cpu = cpu; > } > > return 0; > -- > 2.43.0 >