Skip to contentSkip to conversation

sched/deadline: simplify dl_bw_cpus() using cpumask_weight_and()

PATCH In review Miaohe Lin 6 participants 8 messages May 22, 2023 – Jun 14, 2023 Scheduler

lore
Share & tools
lore

Miaohe Lin

author
#0 lore raw

PATCH 1/1 sched/deadline: simplify dl_bw_cpus() using cpumask_weight_and()

cpumask_weight_and() can be used to count of bits both in rd->span and cpu_active_mask. No functional change intended.

---
 kernel/sched/deadline.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
kernel/sched/deadline.c +1 -10
index 166c3e6eae61..fe983ed7bb12 100644
@@ -110,20 +110,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.27.0
Acked-by on v1 1/1
#1 lore raw
Quoted 22 lines · Miaohe Lin

cpumask_weight_and() can be used to count of bits both in rd->span and cpu_active_mask. No functional change intended.

---
  kernel/sched/deadline.c | 11 +----------
  1 file changed, 1 insertion(+), 10 deletions(-)
kernel/sched/deadline.c +0 -2
index 166c3e6eae61..fe983ed7bb12 100644
@@ -110,20 +110,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 118

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);
  }

-- Mukesh

Quoted 2 lines
kernel/sched/deadline.c +0 -0
  static inline unsigned long __dl_bw_capacity(const struct cpumask *mask)
reviewer Reviewed-by on v1 1/1
#2 lore raw
In reply to Miaohe Lin
Quoted 24 lines · Miaohe Lin

cpumask_weight_and() can be used to count of bits both in rd->span and cpu_active_mask. No functional change intended.

---
 kernel/sched/deadline.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
kernel/sched/deadline.c +0 -4
index 166c3e6eae61..fe983ed7bb12 100644
@@ -110,20 +110,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);
-

kernel/sched/deadline.c static inline struct dl_bw *dl_bw_of(int i) · line 120

Quoted 10 lines
kernel/sched/deadline.c +1 -6
-	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)
author
#5 lore raw
In reply to Miaohe Lin
Quoted 4 lines · Miaohe Lin

cpumask_weight_and() can be used to count of bits both in rd->span and cpu_active_mask. No functional change intended.

friendly ping... :)

Quoted 31 lines
---
 kernel/sched/deadline.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
kernel/sched/deadline.c +1 -10
index 166c3e6eae61..fe983ed7bb12 100644
@@ -110,20 +110,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)
Reviewed-by
#6 lore raw
Quoted 7 lines · On Tue, Jun 13, 2023 at 08:19:22PM +0800 Miaohe Lin wrote:
Quoted 4 lines · Miaohe Lin

cpumask_weight_and() can be used to count of bits both in rd->span and cpu_active_mask. No functional change intended.

friendly ping... :)

This looks reasonable, and better, to me.

Quoted 33 lines
Quoted 32 lines
---
 kernel/sched/deadline.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
kernel/sched/deadline.c +1 -10
index 166c3e6eae61..fe983ed7bb12 100644
@@ -110,20 +110,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)
author
#7 lore raw
Quoted 5 lines · Phil Auld
Quoted 4 lines · On Tue, Jun 13, 2023 at 08:19:22PM +0800 Miaohe Lin wrote:
Quoted 3 lines · Miaohe Lin

cpumask_weight_and() can be used to count of bits both in rd->span and cpu_active_mask. No functional change intended.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

friendly ping... :)

This looks reasonable, and better, to me.

Many thanks for all of your reviews. :)

Quoted 35 lines
Quoted 34 lines
Quoted 33 lines

---
 kernel/sched/deadline.c | 11 +----------
 1 file changed, 1 insertion(+), 10 deletions(-)
kernel/sched/deadline.c +1 -10
index 166c3e6eae61..fe983ed7bb12 100644
@@ -110,20 +110,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)