mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] sched: Combine ENQUEUE_MIGRATED check in activate_task()
@ 2025-07-24 12:12 Zhongqiu Han
  2025-07-25  7:14 ` K Prateek Nayak
  0 siblings, 1 reply; 3+ messages in thread
From: Zhongqiu Han @ 2025-07-24 12:12 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
	rostedt, bsegall, mgorman, vschneid
  Cc: linux-kernel, quic_zhonhan

Combine the task_on_rq_migrating() check and the sched_mm_cid_migrate_to()
invocation into a single conditional block. This removes a redundant flag
check and slightly reduces the instruction count in a hot path.

Signed-off-by: Zhongqiu Han <quic_zhonhan@quicinc.com>
---
- This is a slight optimization and code cleanup, please let me know if you'd prefer to keep the current structure.
- Thanks

 kernel/sched/core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 2343f5691c54..d6063cf503ee 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -2118,10 +2118,10 @@ inline bool dequeue_task(struct rq *rq, struct task_struct *p, int flags)
 
 void activate_task(struct rq *rq, struct task_struct *p, int flags)
 {
-	if (task_on_rq_migrating(p))
+	if (task_on_rq_migrating(p)) {
 		flags |= ENQUEUE_MIGRATED;
-	if (flags & ENQUEUE_MIGRATED)
 		sched_mm_cid_migrate_to(rq, p);
+	}
 
 	enqueue_task(rq, p, flags);
 
-- 
2.43.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] sched: Combine ENQUEUE_MIGRATED check in activate_task()
  2025-07-24 12:12 [PATCH] sched: Combine ENQUEUE_MIGRATED check in activate_task() Zhongqiu Han
@ 2025-07-25  7:14 ` K Prateek Nayak
  2025-07-28  9:44   ` Zhongqiu Han
  0 siblings, 1 reply; 3+ messages in thread
From: K Prateek Nayak @ 2025-07-25  7:14 UTC (permalink / raw)
  To: Zhongqiu Han, mingo, peterz, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman, vschneid
  Cc: linux-kernel

Hello Zhongqiu,

On 7/24/2025 5:42 PM, Zhongqiu Han wrote:
> Combine the task_on_rq_migrating() check and the sched_mm_cid_migrate_to()
> invocation into a single conditional block. This removes a redundant flag
> check and slightly reduces the instruction count in a hot path.
> 
> Signed-off-by: Zhongqiu Han <quic_zhonhan@quicinc.com>
> ---
> - This is a slight optimization and code cleanup, please let me know if you'd prefer to keep the current structure.
> - Thanks
> 
>  kernel/sched/core.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 2343f5691c54..d6063cf503ee 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -2118,10 +2118,10 @@ inline bool dequeue_task(struct rq *rq, struct task_struct *p, int flags)
>  
>  void activate_task(struct rq *rq, struct task_struct *p, int flags)
>  {
> -	if (task_on_rq_migrating(p))
> +	if (task_on_rq_migrating(p)) {
>  		flags |= ENQUEUE_MIGRATED;
> -	if (flags & ENQUEUE_MIGRATED)

I think "ENQUEUE_MIGRATED" can be individually set without
task_on_rq_migrating() in the wakeup path via ttwu_do_activate().

In that case "p->on_rq", goes from "0" to "TASK_ON_RQ_QUEUED" directly
without going through an intermediate "TASK_ON_RQ_MIGRATING" but
"ENQUEUE_MIGRATED" will be set if "p->task_cpu" was changed during
wakeup.

-- 
Thanks and Regards,
Prateek

>  		sched_mm_cid_migrate_to(rq, p);
> +	}
>  
>  	enqueue_task(rq, p, flags);
>  


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] sched: Combine ENQUEUE_MIGRATED check in activate_task()
  2025-07-25  7:14 ` K Prateek Nayak
@ 2025-07-28  9:44   ` Zhongqiu Han
  0 siblings, 0 replies; 3+ messages in thread
From: Zhongqiu Han @ 2025-07-28  9:44 UTC (permalink / raw)
  To: K Prateek Nayak, mingo, peterz, juri.lelli, vincent.guittot,
	dietmar.eggemann, rostedt, bsegall, mgorman, vschneid
  Cc: linux-kernel, Zhongqiu Han

On 7/25/2025 3:14 PM, K Prateek Nayak wrote:
> Hello Zhongqiu,
> 
> On 7/24/2025 5:42 PM, Zhongqiu Han wrote:
>> Combine the task_on_rq_migrating() check and the sched_mm_cid_migrate_to()
>> invocation into a single conditional block. This removes a redundant flag
>> check and slightly reduces the instruction count in a hot path.
>>
>> Signed-off-by: Zhongqiu Han <quic_zhonhan@quicinc.com>
>> ---
>> - This is a slight optimization and code cleanup, please let me know if you'd prefer to keep the current structure.
>> - Thanks
>>
>>   kernel/sched/core.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
>> index 2343f5691c54..d6063cf503ee 100644
>> --- a/kernel/sched/core.c
>> +++ b/kernel/sched/core.c
>> @@ -2118,10 +2118,10 @@ inline bool dequeue_task(struct rq *rq, struct task_struct *p, int flags)
>>   
>>   void activate_task(struct rq *rq, struct task_struct *p, int flags)
>>   {
>> -	if (task_on_rq_migrating(p))
>> +	if (task_on_rq_migrating(p)) {
>>   		flags |= ENQUEUE_MIGRATED;
>> -	if (flags & ENQUEUE_MIGRATED)
> 
> I think "ENQUEUE_MIGRATED" can be individually set without
> task_on_rq_migrating() in the wakeup path via ttwu_do_activate().
> 
> In that case "p->on_rq", goes from "0" to "TASK_ON_RQ_QUEUED" directly
> without going through an intermediate "TASK_ON_RQ_MIGRATING" but
> "ENQUEUE_MIGRATED" will be set if "p->task_cpu" was changed during
> wakeup.
> 
Hi Prateek

You're right. Thanks for the nice review~



-- 
Thx and BRs,
Zhongqiu Han

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-07-28  9:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-24 12:12 [PATCH] sched: Combine ENQUEUE_MIGRATED check in activate_task() Zhongqiu Han
2025-07-25  7:14 ` K Prateek Nayak
2025-07-28  9:44   ` Zhongqiu Han

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®