mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] sched/fair: Use atomic_long_sub() in clear_tg_load_avg()
@ 2026-11-30  8:34 Li kunyu
  2026-11-30 12:03 ` Peter Zijlstra
  0 siblings, 1 reply; 2+ messages in thread
From: Li kunyu @ 2026-11-30  8:34 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
	rostedt, bsegall, mgorman, vschneid, kprateek.nayak
  Cc: linux-kernel, Li kunyu

clear_tg_load_avg() currently builds negative deltas with temporary
variables dl and dr, then calls atomic_long_add() to subtract the
cfs_rq's load and runnable contributions from the task group's shared
load_avg and runnable_avg.

Use atomic_long_sub() directly instead. This makes the subtraction
explicit and drops the temporary variables.

Signed-off-by: Li kunyu <likunyu@open-hieco.net>
---
 kernel/sched/fair.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
index da0d9e19c457..5338ae9b5565 100644
--- a/kernel/sched/fair.c
+++ b/kernel/sched/fair.c
@@ -5370,7 +5370,6 @@ static inline void update_tg_load_avg(struct cfs_rq *cfs_rq)
 
 static inline void clear_tg_load_avg(struct cfs_rq *cfs_rq)
 {
-	long dl, dr;
 	u64 now;
 
 	/*
@@ -5380,10 +5379,8 @@ static inline void clear_tg_load_avg(struct cfs_rq *cfs_rq)
 		return;
 
 	now = rq_clock(rq_of(cfs_rq));
-	dl = 0 - cfs_rq->tg_load_avg_contrib;
-	dr = 0 - cfs_rq->tg_runnable_avg_contrib;
-	atomic_long_add(dl, &cfs_rq->tg->load_avg);
-	atomic_long_add(dr, &cfs_rq->tg->runnable_avg);
+	atomic_long_sub(cfs_rq->tg_load_avg_contrib, &cfs_rq->tg->load_avg);
+	atomic_long_sub(cfs_rq->tg_runnable_avg_contrib, &cfs_rq->tg->runnable_avg);
 	cfs_rq->tg_load_avg_contrib = 0;
 	cfs_rq->tg_runnable_avg_contrib = 0;
 	cfs_rq->last_update_tg_load_avg = now;

base-commit: ca20d5a011d35fc25e328fe31ac47f7aae557c5a
-- 
2.47.3


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

* Re: [PATCH] sched/fair: Use atomic_long_sub() in clear_tg_load_avg()
  2026-11-30  8:34 [PATCH] sched/fair: Use atomic_long_sub() in clear_tg_load_avg() Li kunyu
@ 2026-11-30 12:03 ` Peter Zijlstra
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Zijlstra @ 2026-11-30 12:03 UTC (permalink / raw)
  To: Li kunyu
  Cc: mingo, juri.lelli, vincent.guittot, dietmar.eggemann, rostedt,
	bsegall, mgorman, vschneid, kprateek.nayak, linux-kernel

On Mon, Nov 30, 2026 at 04:34:59PM +0800, Li kunyu wrote:
> clear_tg_load_avg() currently builds negative deltas with temporary
> variables dl and dr, then calls atomic_long_add() to subtract the
> cfs_rq's load and runnable contributions from the task group's shared
> load_avg and runnable_avg.
> 
> Use atomic_long_sub() directly instead. This makes the subtraction
> explicit and drops the temporary variables.
> 
> Signed-off-by: Li kunyu <likunyu@open-hieco.net>
> ---
>  kernel/sched/fair.c | 7 ++-----
>  1 file changed, 2 insertions(+), 5 deletions(-)
> 
> diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
> index da0d9e19c457..5338ae9b5565 100644
> --- a/kernel/sched/fair.c
> +++ b/kernel/sched/fair.c
> @@ -5370,7 +5370,6 @@ static inline void update_tg_load_avg(struct cfs_rq *cfs_rq)
>  
>  static inline void clear_tg_load_avg(struct cfs_rq *cfs_rq)
>  {
> -	long dl, dr;
>  	u64 now;
>  
>  	/*
> @@ -5380,10 +5379,8 @@ static inline void clear_tg_load_avg(struct cfs_rq *cfs_rq)
>  		return;
>  
>  	now = rq_clock(rq_of(cfs_rq));
> -	dl = 0 - cfs_rq->tg_load_avg_contrib;
> -	dr = 0 - cfs_rq->tg_runnable_avg_contrib;
> -	atomic_long_add(dl, &cfs_rq->tg->load_avg);
> -	atomic_long_add(dr, &cfs_rq->tg->runnable_avg);
> +	atomic_long_sub(cfs_rq->tg_load_avg_contrib, &cfs_rq->tg->load_avg);
> +	atomic_long_sub(cfs_rq->tg_runnable_avg_contrib, &cfs_rq->tg->runnable_avg);
>  	cfs_rq->tg_load_avg_contrib = 0;
>  	cfs_rq->tg_runnable_avg_contrib = 0;
>  	cfs_rq->last_update_tg_load_avg = now;

Yeah, no. This way the code has the same form as the function above.

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

end of thread, other threads:[~2026-11-30 12:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-30  8:34 [PATCH] sched/fair: Use atomic_long_sub() in clear_tg_load_avg() Li kunyu
2026-11-30 12:03 ` Peter Zijlstra

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®