All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shrikanth Hegde <sshegde@linux.ibm.com>
To: K Prateek Nayak <kprateek.nayak@amd.com>,
	Tim Chen <tim.c.chen@linux.intel.com>,
	Peter Zijlstra <peterz@infradead.org>
Cc: Ingo Molnar <mingo@kernel.org>, Chen Yu <yu.c.chen@intel.com>,
	Doug Nelson <doug.nelson@intel.com>,
	Mohini Narkhede <mohini.narkhede@intel.com>,
	linux-kernel@vger.kernel.org,
	Vincent Guittot <vincent.guittot@linaro.org>
Subject: Re: [PATCH v3] sched/fair: Skip sched_balance_running cmpxchg when balance is not due
Date: Fri, 7 Nov 2025 14:27:05 +0530	[thread overview]
Message-ID: <2edf1a85-4736-4e8b-bfc9-003dd1f34be7@linux.ibm.com> (raw)
In-Reply-To: <1d6c22aa-c882-4833-b0be-a3999d684885@amd.com>



On 11/7/25 8:27 AM, K Prateek Nayak wrote:
> Hello Tim,
> 
> On 11/7/2025 4:57 AM, Tim Chen wrote:
>> @@ -11757,6 +11772,7 @@ static int sched_balance_rq(int this_cpu, struct rq *this_rq,
>>   		.fbq_type	= all,
>>   		.tasks		= LIST_HEAD_INIT(env.tasks),
>>   	};
>> +	int need_unlock = false;
>>   
>>   	cpumask_and(cpus, sched_domain_span(sd), cpu_active_mask);
>>   
>> @@ -11768,6 +11784,13 @@ static int sched_balance_rq(int this_cpu, struct rq *this_rq,
>>   		goto out_balanced;
>>   	}
>>   
>> +	if (idle != CPU_NEWLY_IDLE && (sd->flags & SD_SERIALIZE)) {

Can you also try removing "idle != CPU_NEWLY_IDLE" and see the workload behavior?
If workloads don't observe regression, it might be worth serializing it too.

>> +		if (atomic_cmpxchg_acquire(&sched_balance_running, 0, 1)) {
>> +			goto out_balanced;
>> +		}
>> +		need_unlock = true;
>> +	}
>> +
>>   	group = sched_balance_find_src_group(&env);
>>   	if (!group) {
>>   		schedstat_inc(sd->lb_nobusyg[idle]);
>> @@ -11892,6 +11915,9 @@ static int sched_balance_rq(int this_cpu, struct rq *this_rq,
>>   			if (!cpumask_subset(cpus, env.dst_grpmask)) {
>>   				env.loop = 0;
>>   				env.loop_break = SCHED_NR_MIGRATE_BREAK;
>> +				if (need_unlock)
>> +					atomic_set_release(&sched_balance_running, 0);
> 
> I believe we should reset "need_unlock" to false here since "redo" can
> fail the atomic_cmpxchg_acquire() while still having "need_unlock" set
> to "true" and the "out_balanced" path will then perform the
> atomic_set_release() when another CPU is in middle of a busy / idle
> balance on a SD_SERIALIZE domain.

Yes. Setting need_unlock = false looks better.

> 
> We can also initialize the "need_unlock" to false just after
> the redo label too - whichever you prefer.
> 
> nit. "need_unlock" can just be a bool instead of an int.
> 
> Apart from that, feel free to include:
> 
> Reviewed-by: K Prateek Nayak <kprateek.nayak@amd.com>
> 
>> +
>>   				goto redo;
>>   			}
>>   			goto out_all_pinned;
>> @@ -12008,6 +12034,9 @@ static int sched_balance_rq(int this_cpu, struct rq *this_rq,
>>   	    sd->balance_interval < sd->max_interval)
>>   		sd->balance_interval *= 2;
>>   out:
>> +	if (need_unlock)
>> +		atomic_set_release(&sched_balance_running, 0);
>> +
>>   	return ld_moved;
>>   }
>>   
> 


  reply	other threads:[~2025-11-07  8:57 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-06 23:27 [PATCH v3] sched/fair: Skip sched_balance_running cmpxchg when balance is not due Tim Chen
2025-11-07  2:57 ` K Prateek Nayak
2025-11-07  8:57   ` Shrikanth Hegde [this message]
2025-11-07 17:43     ` Tim Chen
2025-11-10  3:58     ` K Prateek Nayak
2025-11-10 18:19       ` Tim Chen
2025-11-07 17:28   ` Tim Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2edf1a85-4736-4e8b-bfc9-003dd1f34be7@linux.ibm.com \
    --to=sshegde@linux.ibm.com \
    --cc=doug.nelson@intel.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=mohini.narkhede@intel.com \
    --cc=peterz@infradead.org \
    --cc=tim.c.chen@linux.intel.com \
    --cc=vincent.guittot@linaro.org \
    --cc=yu.c.chen@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.