Skip to contentSkip to conversation

sched/deadline: minor code cleanups

PATCH Applied Shrikanth Hegde 4 participants 12 messages Oct 14, 2025 – Nov 11, 2025 Scheduler

lore
Share & tools
lore
#0 lore raw

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
#1 lore raw

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
index 7b7671060bf9..8b7c4ee41fd8 100644
@@ -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
maintainer
#2 lore raw
Quoted 18 lines · Shrikanth Hegde

- 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 +0 -0
index 7b7671060bf9..8b7c4ee41fd8 100644

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:

https://lkml.kernel.org/r/[email protected]

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.

maintainer
#3 lore raw
Quoted 31 lines · Peter Zijlstra
Quoted 18 lines · Shrikanth Hegde

- 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 +0 -0
index 7b7671060bf9..8b7c4ee41fd8 100644

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 1 line

https://lkml.kernel.org/r/[email protected]

I deleted this hunk and frobbed the changelog. Should be in queue/sched/core now.

#4 lore raw

[tip: sched/core] sched/deadline: Minor cleanup in select_task_rq_dl()

In reply to Shrikanth Hegde
The 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
index e46df89..141c9b9 100644
@@ -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;
 }
 
#5 lore raw

[tip: sched/core] sched/deadline: Minor cleanup in select_task_rq_dl()

In reply to Shrikanth Hegde
The 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
index 4dd4b2f..67f540c 100644
@@ -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;
 }
 
#6 lore raw

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
index 8b7c4ee41fd8..a18f64b2e47c 100644
@@ -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
maintainer
#7 lore raw

Re: [PATCH 2/2] sched/deadline: Use cpumask_weight_and in dl_bw_cpus

Quoted 28 lines · 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 +0 -2
index 8b7c4ee41fd8..a18f64b2e47c 100644
@@ -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

#8 lore raw

[tip: sched/core] sched/deadline: Use cpumask_weight_and() in dl_bw_cpus

In reply to Shrikanth Hegde
The 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
index 4d6eaf2..e46df89 100644
@@ -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)
#9 lore raw

[tip: sched/core] sched/deadline: Use cpumask_weight_and() in dl_bw_cpus

In reply to Shrikanth Hegde
The 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
index e958cf9..4dd4b2f 100644
@@ -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)
maintainer Acked-by on the v1 series
#10 lore raw
In reply to Shrikanth Hegde

Hello,

Quoted 11 lines · Shrikanth Hegde

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

For the series (I would keep the fixes separate)

Thanks,
Juri

#11 lore raw

Gentle Ping.

Quoted 11 lines · Juri Lelli

Hello,

Quoted 8 lines · Shrikanth Hegde

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.

Quoted 8 lines
Quoted 3 lines

Shrikanth Hegde (2):
sched/deadline: minor code cleanups sched/deadline: Use cpumask_weight_and in dl_bw_cpus

For the series (I would keep the fixes separate)

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