sched/deadline: minor code cleanups
cover sched/deadline: minor code cleanups
While trying to understand the dl_server changes, noticed these minor code optimizations/cleanups possible.
Let me know if these should be squashed into one patch. Kept is separate as of now.
No change in functionality. Could save a few cycles.
Shrikanth Hegde (2):
sched/deadline: minor code cleanups sched/deadline: Use cpumask_weight_and in dl_bw_cpus
kernel/sched/deadline.c | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-)
Signature · 1 line
2.47.3
PATCH 1/2 sched/deadline: minor code cleanups
- In dl_server_timer, there is same dl_runtime check above. So this check is duplicate. This could save a few cycles.
- In select_task_rq_dl, there is only one goto statement, there is no need for it.
No functional changes.
--- kernel/sched/deadline.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
kernel/sched/deadline.c +1 -5
@@ -1166,9 +1166,6 @@ static enum hrtimer_restart dl_server_timer(struct hrtimer *timer, struct sched_sched_clock_tick ();update_rq_clock (rq); -if (!dl_se->dl_runtime) -return HRTIMER_NORESTART ; -if (dl_se->dl_defer_armed) {/* * First check if the server could consume runtime in background.
@@ -2173,7 +2170,7 @@ select_task_rq_dl(struct task_struct *p, int cpu, int flags)struct rq *rq;if (!(flags &WF_TTWU )) - goto out; +return cpu; rq =cpu_rq (cpu);
@@ -2211,7 +2208,6 @@ select_task_rq_dl(struct task_struct *p, int cpu, int flags) }rcu_read_unlock (); -out:return cpu; }
Signature · 1 line
2.47.3
PATCH 2/2 sched/deadline: Use cpumask_weight_and in dl_bw_cpus
In reply to Shrikanth Hegde- cpumask_subset(a,b) -> cpumask_weight(a) should be same as cpumask_weight_and(a,b)
- for_each_cpu_and(a,b) to count cpus could be replaced by cpumask_weight_and(a,b)
No Functional Change. It could save a few cycles since cpumask_weight_and would be more efficient. Plus one less stack variable.
--- kernel/sched/deadline.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)
kernel/sched/deadline.c +1 -10
@@ -125,20 +125,11 @@ static inline struct dl_bw *dl_bw_of(int i)static inline int dl_bw_cpus (int i) {struct root_domain *rd =cpu_rq (i)->rd; -int cpus;RCU_LOCKDEP_WARN (!rcu_read_lock_sched_held (),"sched RCU must be held" ); -if (cpumask_subset (rd->span, cpu_active_mask)) -return cpumask_weight (rd->span); - - cpus =0 ; - -for_each_cpu_and (i, rd->span, cpu_active_mask) - cpus++; - -return cpus; +return cpumask_weight_and (rd->span, cpu_active_mask); }static inline unsigned long __dl_bw_capacity (const struct cpumask *mask)
Signature · 1 line
2.47.3
Hello,
Quoted 11 lines · Shrikanth Hegde
While trying to understand the
dl_serverchanges, noticed these minor code optimizations/cleanups possible.Let me know if these should be squashed into one patch. Kept is separate as of now.
No change in functionality. Could save a few cycles.
Shrikanth Hegde (2):
sched/deadline: minor code cleanups sched/deadline: Usecpumask_weight_andindl_bw_cpus
For the series (I would keep the fixes separate)
Thanks,
Juri
Gentle Ping.
Quoted 11 lines · Juri Lelli
Hello,
Quoted 8 lines · Shrikanth Hegde
While trying to understand the
dl_serverchanges, noticed these minor code optimizations/cleanups possible.Let me know if these should be squashed into one patch. Kept is separate as of now.
No change in functionality. Could save a few cycles.
Quoted 8 lines
Quoted 3 lines
Shrikanth Hegde (2):
sched/deadline: minor code cleanups sched/deadline: Usecpumask_weight_andindl_bw_cpusFor the series (I would keep the fixes separate)
Acked-by Juri Lelli <[email protected]>
Thanks Juri.
Quoted 3 lines
Thanks,
Juri
Hi Peter, Ingo,
Do you have any comments on this?
Should I resend collecting the tag? It applies on v6.18-rc4
Peter Zijlstra
maintainerQuoted 18 lines · Shrikanth Hegde
- In
dl_server_timer, there is samedl_runtimecheck above. So this check is duplicate. This could save a few cycles.- In
select_task_rq_dl, there is only one goto statement, there is no need for it.No functional changes.
Signed-off-by Shrikanth Hegde <[email protected]>--- kernel/sched/deadline.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)kernel/sched/deadline.c +0
-0
kernel/sched/deadline.c static enum hrtimer_restart dl_server_timer(struct hrtimer *timer, struct sched_ · line 1171
Quoted 9 lines
kernel/sched/deadline.c +0
-3@@ -1166,9 +1166,6 @@ static enum hrtimer_restart dl_server_timer(struct hrtimer *timer, struct sched_sched_clock_tick ();update_rq_clock (rq); -if (!dl_se->dl_runtime) -return HRTIMER_NORESTART ; -if (dl_se->dl_defer_armed) {/* * First check if the server could consume runtime in background.
That one got lost here:
Quoted 10 lines
kernel/sched/deadline.c +1
-1@@ -2173,7 +2170,7 @@ select_task_rq_dl(struct task_struct *p, int cpu, int flags)struct rq *rq;if (!(flags &WF_TTWU )) - goto out; +return cpu; rq =cpu_rq (cpu);
kernel/sched/deadline.c select_task_rq_dl(struct task_struct *p, int cpu, int flags) · line 2212
Quoted 6 lines
kernel/sched/deadline.c +0
-1@@ -2211,7 +2208,6 @@ select_task_rq_dl(struct task_struct *p, int cpu, int flags) }rcu_read_unlock (); -out:return cpu; }
And this is completely different code, which would suggest it ought to have been a separate patch.
But yeah, that makes sense.
Peter Zijlstra
maintainerRe: [PATCH 2/2] sched/deadline: Use cpumask_weight_and in dl_bw_cpus
In reply to Shrikanth HegdeQuoted 28 lines · Shrikanth Hegde
-
cpumask_subset(a,b)->cpumask_weight(a)should be same ascpumask_weight_and(a,b)-
for_each_cpu_and(a,b)to count cpus could be replaced bycpumask_weight_and(a,b)No Functional Change. It could save a few cycles since
cpumask_weight_andwould be more efficient. Plus one less stack variable.Signed-off-by Shrikanth Hegde <[email protected]>--- kernel/sched/deadline.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)kernel/sched/deadline.c +0
-2@@ -125,20 +125,11 @@ static inline struct dl_bw *dl_bw_of(int i)static inline int dl_bw_cpus (int i) {struct root_domain *rd =cpu_rq (i)->rd; -int cpus;RCU_LOCKDEP_WARN (!rcu_read_lock_sched_held (),"sched RCU must be held" ); -if (cpumask_subset (rd->span, cpu_active_mask))
kernel/sched/deadline.c static inline struct dl_bw *dl_bw_of(int i) · line 133
Quoted 10 lines
kernel/sched/deadline.c +1
-8-return cpumask_weight (rd->span); - - cpus =0 ; - -for_each_cpu_and (i, rd->span, cpu_active_mask) - cpus++; - -return cpus; +return cpumask_weight_and (rd->span, cpu_active_mask); }
Right, let me stick that on top of the change I have in queue/sched/core
Peter Zijlstra
maintainerQuoted 31 lines · Peter Zijlstra
Quoted 18 lines · Shrikanth Hegde
- In
dl_server_timer, there is samedl_runtimecheck above. So this check is duplicate. This could save a few cycles.- In
select_task_rq_dl, there is only one goto statement, there is no need for it.No functional changes.
Signed-off-by Shrikanth Hegde <[email protected]>--- kernel/sched/deadline.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)kernel/sched/deadline.c +0
-0kernel/sched/deadline.c static enum hrtimer_restart dl_server_timer(struct hrtimer *timer, struct sched_ · line 1171
Quoted 9 lines
kernel/sched/deadline.c +0
-3@@ -1166,9 +1166,6 @@ static enum hrtimer_restart dl_server_timer(struct hrtimer *timer, struct sched_sched_clock_tick ();update_rq_clock (rq); -if (!dl_se->dl_runtime) -return HRTIMER_NORESTART ; -if (dl_se->dl_defer_armed) {/* * First check if the server could consume runtime in background. That one got lost here:
Quoted 1 line
I deleted this hunk and frobbed the changelog. Should be in queue/sched/core now.
[tip: sched/core] sched/deadline: Minor cleanup in select_task_rq_dl()
In reply to Shrikanth HegdeThe following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 46f61fb2e7678daae743d601efac3b957041ed56 Gitweb: https://git.kernel.org/tip/46f61fb2e7678daae743d601efac3b957041ed56 Author: Shrikanth Hegde <[email protected]> AuthorDate: Tue, 14 Oct 2025 15:33:41 +05:30 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 11 Nov 2025 12:33:40 +01:00
sched/deadline: Minor cleanup in select_task_rq_dl()
In select_task_rq_dl, there is only one goto statement, there is no need for it.
No functional changes.
--- kernel/sched/deadline.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/sched/deadline.c +1 -2
@@ -2384,7 +2384,7 @@ select_task_rq_dl(struct task_struct *p, int cpu, int flags)struct rq *rq;if (!(flags &WF_TTWU )) - goto out; +return cpu; rq =cpu_rq (cpu);
@@ -2422,7 +2422,6 @@ select_task_rq_dl(struct task_struct *p, int cpu, int flags) }rcu_read_unlock (); -out:return cpu; }
[tip: sched/core] sched/deadline: Use cpumask_weight_and() in dl_bw_cpus
In reply to Shrikanth HegdeThe following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 7259e53915cc99298952a35aa8772d33d1e51866 Gitweb: https://git.kernel.org/tip/7259e53915cc99298952a35aa8772d33d1e51866 Author: Shrikanth Hegde <[email protected]> AuthorDate: Tue, 14 Oct 2025 15:33:42 +05:30 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 11 Nov 2025 12:33:39 +01:00
sched/deadline: Use cpumask_weight_and() in dl_bw_cpus
cpumask_subset(a,b) -> cpumask_weight(a) should be same as cpumask_weight_and(a,b) for_each_cpu_and(a,b) to count cpus could be replaced by cpumask_weight_and(a,b)
No Functional Change. It could save a few cycles since cpumask_weight_and would be more efficient. Plus one less stack variable.
--- kernel/sched/deadline.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)
kernel/sched/deadline.c +1 -10
@@ -125,20 +125,11 @@ static inline struct dl_bw *dl_bw_of(int i)static inline int dl_bw_cpus (int i) {struct root_domain *rd =cpu_rq (i)->rd; -int cpus;RCU_LOCKDEP_WARN (!rcu_read_lock_sched_held (),"sched RCU must be held" ); -if (cpumask_subset (rd->span, cpu_active_mask)) -return cpumask_weight (rd->span); - - cpus =0 ; - -for_each_cpu_and (i, rd->span, cpu_active_mask) - cpus++; - -return cpus; +return cpumask_weight_and (rd->span, cpu_active_mask); }static inline unsigned long __dl_bw_capacity (const struct cpumask *mask)
[tip: sched/core] sched/deadline: Minor cleanup in select_task_rq_dl()
In reply to Shrikanth HegdeThe following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: 65177ea9f64d7402a0b8028e0dbbd01e8a9d1b1d Gitweb: https://git.kernel.org/tip/65177ea9f64d7402a0b8028e0dbbd01e8a9d1b1d Author: Shrikanth Hegde <[email protected]> AuthorDate: Tue, 14 Oct 2025 15:33:41 +05:30 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 11 Nov 2025 17:27:55 +01:00
sched/deadline: Minor cleanup in select_task_rq_dl()
In select_task_rq_dl, there is only one goto statement, there is no need for it.
No functional changes.
--- kernel/sched/deadline.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/sched/deadline.c +1 -2
@@ -2384,7 +2384,7 @@ select_task_rq_dl(struct task_struct *p, int cpu, int flags)struct rq *rq;if (!(flags &WF_TTWU )) - goto out; +return cpu; rq =cpu_rq (cpu);
@@ -2422,7 +2422,6 @@ select_task_rq_dl(struct task_struct *p, int cpu, int flags) }rcu_read_unlock (); -out:return cpu; }
[tip: sched/core] sched/deadline: Use cpumask_weight_and() in dl_bw_cpus
In reply to Shrikanth HegdeThe following commit has been merged into the sched/core branch of tip:
The following commit has been merged into the sched/core branch of tip:
Commit-ID: b4bfacd39216755c058f6d13c71c86a9bf5a1631 Gitweb: https://git.kernel.org/tip/b4bfacd39216755c058f6d13c71c86a9bf5a1631 Author: Shrikanth Hegde <[email protected]> AuthorDate: Tue, 14 Oct 2025 15:33:42 +05:30 Committer: Peter Zijlstra <[email protected]> CommitterDate: Tue, 11 Nov 2025 17:27:55 +01:00
sched/deadline: Use cpumask_weight_and() in dl_bw_cpus
cpumask_subset(a,b) -> cpumask_weight(a) should be same as cpumask_weight_and(a,b) for_each_cpu_and(a,b) to count cpus could be replaced by cpumask_weight_and(a,b)
No Functional Change. It could save a few cycles since cpumask_weight_and would be more efficient. Plus one less stack variable.
--- kernel/sched/deadline.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-)
kernel/sched/deadline.c +1 -10
@@ -125,20 +125,11 @@ static inline struct dl_bw *dl_bw_of(int i)static inline int dl_bw_cpus (int i) {struct root_domain *rd =cpu_rq (i)->rd; -int cpus;RCU_LOCKDEP_WARN (!rcu_read_lock_sched_held (),"sched RCU must be held" ); -if (cpumask_subset (rd->span, cpu_active_mask)) -return cpumask_weight (rd->span); - - cpus =0 ; - -for_each_cpu_and (i, rd->span, cpu_active_mask) - cpus++; - -return cpus; +return cpumask_weight_and (rd->span, cpu_active_mask); }static inline unsigned long __dl_bw_capacity (const struct cpumask *mask)