Skip to contentSkip to conversation

sched/fair: add SD_CLUSTER in comments

PATCH In review [email protected] 5 participants 20 messages Feb 1, 2024 – Feb 7, 2024 Scheduler

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/4 sched/fair: add SD_CLUSTER in comments

From: Alex Shi <[email protected]>

The description of SD_CLUSTER is missing. Add it.

To: Ricardo Neri <[email protected]>
To: Valentin Schneider <[email protected]>
To: Vincent Guittot <[email protected]>
To: Juri Lelli <[email protected]>
To: Peter Zijlstra <[email protected]>
To: Ingo Molnar <[email protected]>

---
 kernel/sched/topology.c | 1 +
 1 file changed, 1 insertion(+)
kernel/sched/topology.c +1 -0
index 10d1391e7416..8b45f16a1890 100644
@@ -1554,6 +1554,7 @@ static struct cpumask		***sched_domains_numa_masks;
  * function:
  *
  *   SD_SHARE_CPUCAPACITY   - describes SMT topologies
+ *   SD_CLUSTER             - describes CPU Cluster topologies
  *   SD_SHARE_PKG_RESOURCES - describes shared caches
  *   SD_NUMA                - describes NUMA topologies
  *
Signature · 1 line
2.43.0
#1 lore raw

PATCH v3 2/4 sched/fair: remove unused parameters

From: Alex Shi <[email protected]>

sds isn't used in function sched_asym(), so remove it to cleanup code.

To: Valentin Schneider <[email protected]>
To: Vincent Guittot <[email protected]>
To: Juri Lelli <[email protected]>
To: Peter Zijlstra <[email protected]>
To: Ingo Molnar <[email protected]>

---
 kernel/sched/fair.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
kernel/sched/fair.c +2 -4
index 46ba8329b10a..8d70417f5125 100644
@@ -9750,7 +9750,6 @@ static bool sched_use_asym_prio(struct sched_domain *sd, int cpu)
 /**
  * sched_asym - Check if the destination CPU can do asym_packing load balance
  * @env:	The load balancing environment
- * @sds:	Load-balancing data with statistics of the local group
  * @sgs:	Load-balancing statistics of the candidate busiest group
  * @group:	The candidate busiest group
  *
@@ -9769,8 +9768,7 @@ static bool sched_use_asym_prio(struct sched_domain *sd, int cpu)
  * otherwise.
  */
 static inline bool
-sched_asym(struct lb_env *env, struct sd_lb_stats *sds,  struct sg_lb_stats *sgs,
-	   struct sched_group *group)
+sched_asym(struct lb_env *env, struct sg_lb_stats *sgs, struct sched_group *group)
 {
 	/* Ensure that the whole local core is idle, if applicable. */
 	if (!sched_use_asym_prio(env->sd, env->dst_cpu))
@@ -9941,7 +9939,7 @@ static inline void update_sg_lb_stats(struct lb_env *env,
 	/* Check if dst CPU is idle and preferred to this group */
 	if (!local_group && env->sd->flags & SD_ASYM_PACKING &&
 	    env->idle != CPU_NOT_IDLE && sgs->sum_h_nr_running &&
-	    sched_asym(env, sds, sgs, group)) {
+	    sched_asym(env, sgs, group)) {
 		sgs->group_asym_packing = 1;
 	}
 
Signature · 1 line
2.43.0
#4 lore raw

PATCH v3 3/4 sched/fair: packing func sched_use_asym_prio()/sched_asym_prefer()

In reply to [email protected]

From: Alex Shi <[email protected]>

Consolidate the functions sched_use_asym_prio() and sched_asym_prefer() into one. and rename sched_asym() as sched_group_asym(). This makes the code easier to read. No functional changes.

To: Ricardo Neri <[email protected]>
To: Valentin Schneider <[email protected]>
To: Vincent Guittot <[email protected]>
To: Peter Zijlstra <[email protected]>
To: Ingo Molnar <[email protected]>

---
 kernel/sched/fair.c | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)
kernel/sched/fair.c +18 -17
index 8d70417f5125..44fd5e2ca642 100644
@@ -9747,8 +9747,15 @@ static bool sched_use_asym_prio(struct sched_domain *sd, int cpu)
 	return sd->flags & SD_SHARE_CPUCAPACITY || is_core_idle(cpu);
 }
 
+static inline bool sched_asym(struct sched_domain *sd, int dst_cpu, int src_cpu)
+{
+	/* Check if asym balance applicable, then check priorities.*/
+	return sched_use_asym_prio(sd, dst_cpu) &&
+		sched_asym_prefer(dst_cpu, src_cpu);
+}
+
 /**
- * sched_asym - Check if the destination CPU can do asym_packing load balance
+ * sched_group_asym - Check if the destination CPU can do asym_packing balance
  * @env:	The load balancing environment
  * @sgs:	Load-balancing statistics of the candidate busiest group
  * @group:	The candidate busiest group
@@ -9768,22 +9775,18 @@ static bool sched_use_asym_prio(struct sched_domain *sd, int cpu)
  * otherwise.
  */
 static inline bool
-sched_asym(struct lb_env *env, struct sg_lb_stats *sgs, struct sched_group *group)
+sched_group_asym(struct lb_env *env, struct sg_lb_stats *sgs, struct sched_group *group)
 {
-	/* Ensure that the whole local core is idle, if applicable. */
-	if (!sched_use_asym_prio(env->sd, env->dst_cpu))
-		return false;
-
 	/*
-	 * CPU priorities does not make sense for SMT cores with more than one
+	 * CPU priorities do not make sense for SMT cores with more than one
 	 * busy sibling.
 	 */
-	if (group->flags & SD_SHARE_CPUCAPACITY) {
-		if (sgs->group_weight - sgs->idle_cpus != 1)
-			return false;
-	}
 
-	return sched_asym_prefer(env->dst_cpu, group->asym_prefer_cpu);
+	if ((group->flags & SD_SHARE_CPUCAPACITY) &&
+	    (sgs->group_weight - sgs->idle_cpus != 1))
+		return false;
+
+	return sched_asym(env->sd, env->dst_cpu, group->asym_prefer_cpu);
 }
 
 /* One group has more than one SMT CPU while the other group does not */
@@ -9939,7 +9942,7 @@ static inline void update_sg_lb_stats(struct lb_env *env,
 	/* Check if dst CPU is idle and preferred to this group */
 	if (!local_group && env->sd->flags & SD_ASYM_PACKING &&
 	    env->idle != CPU_NOT_IDLE && sgs->sum_h_nr_running &&
-	    sched_asym(env, sgs, group)) {
+	    sched_group_asym(env, sgs, group)) {
 		sgs->group_asym_packing = 1;
 	}
 
@@ -11038,8 +11041,7 @@ static struct rq *find_busiest_queue(struct lb_env *env,
 		 * SMT cores with more than one busy sibling.
 		 */
 		if ((env->sd->flags & SD_ASYM_PACKING) &&
-		    sched_use_asym_prio(env->sd, i) &&
-		    sched_asym_prefer(i, env->dst_cpu) &&
+		    sched_asym(env->sd, i, env->dst_cpu) &&
 		    nr_running == 1)
 			continue;
 
@@ -11909,8 +11911,7 @@ static void nohz_balancer_kick(struct rq *rq)
 		 * preferred CPU must be idle.
 		 */
 		for_each_cpu_and(i, sched_domain_span(sd), nohz.idle_cpus_mask) {
-			if (sched_use_asym_prio(sd, i) &&
-			    sched_asym_prefer(i, cpu)) {
+			if (sched_asym(sd, i, cpu)) {
 				flags = NOHZ_STATS_KICK | NOHZ_BALANCE_KICK;
 				goto unlock;
 			}
Signature · 1 line
2.43.0
#7 lore raw

PATCH v3 4/4 sched/fair: Check the SD_ASYM_PACKING flag in sched_use_asym_prio()

In reply to [email protected]

From: Alex Shi <[email protected]>

sched_use_asym_prio() checks whether CPU priorities should be used. It makes sense to check for the SD_ASYM_PACKING() inside the function. Since both sched_asym() and sched_group_asym() use sched_use_asym_prio(), remove the now superfluous checks for the flag in various places"

To: Ricardo Neri <[email protected]>
To: Ben Segall <[email protected]>
To: Steven Rostedt <[email protected]>
To: Dietmar Eggemann <[email protected]>
To: Valentin Schneider <[email protected]>
To: Daniel Bristot de Oliveira <[email protected]>
To: Vincent Guittot <[email protected]>
To: Juri Lelli <[email protected]>
To: Peter Zijlstra <[email protected]>
To: Ingo Molnar <[email protected]>

---
 kernel/sched/fair.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
kernel/sched/fair.c +7 -8
index 44fd5e2ca642..bd32efbea688 100644
@@ -9741,6 +9741,9 @@ group_type group_classify(unsigned int imbalance_pct,
  */
 static bool sched_use_asym_prio(struct sched_domain *sd, int cpu)
 {
+	if (!(sd->flags & SD_ASYM_PACKING))
+		return false;
+
 	if (!sched_smt_active())
 		return true;
 
@@ -9940,11 +9943,9 @@ static inline void update_sg_lb_stats(struct lb_env *env,
 	sgs->group_weight = group->group_weight;
 
 	/* Check if dst CPU is idle and preferred to this group */
-	if (!local_group && env->sd->flags & SD_ASYM_PACKING &&
-	    env->idle != CPU_NOT_IDLE && sgs->sum_h_nr_running &&
-	    sched_group_asym(env, sgs, group)) {
+	if (!local_group && env->idle != CPU_NOT_IDLE && sgs->sum_h_nr_running &&
+			sched_group_asym(env, sgs, group))
 		sgs->group_asym_packing = 1;
-	}
 
 	/* Check for loaded SMT group to be balanced to dst CPU */
 	if (!local_group && smt_balance(env, sgs, group))
@@ -11040,9 +11041,7 @@ static struct rq *find_busiest_queue(struct lb_env *env,
 		 * If balancing between cores, let lower priority CPUs help
 		 * SMT cores with more than one busy sibling.
 		 */
-		if ((env->sd->flags & SD_ASYM_PACKING) &&
-		    sched_asym(env->sd, i, env->dst_cpu) &&
-		    nr_running == 1)
+		if (sched_asym(env->sd, i, env->dst_cpu) && nr_running == 1)
 			continue;
 
 		switch (env->migration_type) {
@@ -11138,7 +11137,7 @@ asym_active_balance(struct lb_env *env)
 	 * the lower priority @env::dst_cpu help it. Do not follow
 	 * CPU priority.
 	 */
-	return env->idle != CPU_NOT_IDLE && (env->sd->flags & SD_ASYM_PACKING) &&
+	return env->idle != CPU_NOT_IDLE &&
 	       sched_use_asym_prio(env->sd, env->dst_cpu) &&
 	       (sched_asym_prefer(env->dst_cpu, env->src_cpu) ||
 		!sched_use_asym_prio(env->sd, env->src_cpu));
Signature · 1 line
2.43.0
reviewer Reviewed-by on v3 2/4
#2 lore raw

Re: [PATCH v3 2/4] sched/fair: remove unused parameters

In reply to [email protected]
Quoted 6 lines · On 01/02/24 19:54, [email protected] wrote:

From: Alex Shi <[email protected]>

sds isn't used in function sched_asym(), so remove it to cleanup code.

AFAICT this is unsused as of:
c9ca07886aaa ("sched/fair: Do not even the number of busy CPUs via asym_packing")

Quoted 42 lines

To: Valentin Schneider <[email protected]>
To: Vincent Guittot <[email protected]>
To: Juri Lelli <[email protected]>
To: Peter Zijlstra <[email protected]>
To: Ingo Molnar <[email protected]>

---
 kernel/sched/fair.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
kernel/sched/fair.c +2 -5
index 46ba8329b10a..8d70417f5125 100644
@@ -9750,7 +9750,6 @@ static bool sched_use_asym_prio(struct sched_domain *sd, int cpu)
 /**
  * sched_asym - Check if the destination CPU can do asym_packing load balance
  * @env:	The load balancing environment
- * @sds:	Load-balancing data with statistics of the local group
  * @sgs:	Load-balancing statistics of the candidate busiest group
  * @group:	The candidate busiest group
  *
@@ -9769,8 +9768,7 @@ static bool sched_use_asym_prio(struct sched_domain *sd, int cpu)
  * otherwise.
  */
 static inline bool
-sched_asym(struct lb_env *env, struct sd_lb_stats *sds,  struct sg_lb_stats *sgs,
-	   struct sched_group *group)
+sched_asym(struct lb_env *env, struct sg_lb_stats *sgs, struct sched_group *group)
 {
      /* Ensure that the whole local core is idle, if applicable. */
      if (!sched_use_asym_prio(env->sd, env->dst_cpu))
@@ -9941,7 +9939,7 @@ static inline void update_sg_lb_stats(struct lb_env *env,
      /* Check if dst CPU is idle and preferred to this group */
      if (!local_group && env->sd->flags & SD_ASYM_PACKING &&
          env->idle != CPU_NOT_IDLE && sgs->sum_h_nr_running &&
-	    sched_asym(env, sds, sgs, group)) {
+	    sched_asym(env, sgs, group)) {
              sgs->group_asym_packing = 1;
      }
 
--

2.43.0

#10 lore raw
In reply to [email protected]

Subject nit: the prefix should be sched/topology

Quoted 20 lines · On 01/02/24 19:54, [email protected] wrote:

From: Alex Shi <[email protected]>

The description of SD_CLUSTER is missing. Add it.

To: Ricardo Neri <[email protected]>
To: Valentin Schneider <[email protected]>
To: Vincent Guittot <[email protected]>
To: Juri Lelli <[email protected]>
To: Peter Zijlstra <[email protected]>
To: Ingo Molnar <[email protected]>

---
 kernel/sched/topology.c | 1 +
 1 file changed, 1 insertion(+)
kernel/sched/topology.c +0 -0
index 10d1391e7416..8b45f16a1890 100644

kernel/sched/topology.c static struct cpumask ***sched_domains_numa_masks; · line 1557

Quoted 4 lines
kernel/sched/topology.c +1 -0
@@ -1554,6 +1554,7 @@ static struct cpumask		***sched_domains_numa_masks;
  * function:
  *
  *   SD_SHARE_CPUCAPACITY   - describes SMT topologies
+ *   SD_CLUSTER             - describes CPU Cluster topologies

So I know this is the naming we've gone for the "Cluster" naming, but this comment isn't really explaining anything.

include/linux/sched/sd_flags.h has a bit more info already:
* Domain members share CPU cluster (LLC tags or L2 cache)

I had to go through a bit of git history to remember what the CLUSTER thing was about, how about this:

* SD_CLUSTER - describes shared shared caches, cache tags or busses
* SD_SHARE_PKG_RESOURCES - describes shared LLC cache

And looking at this it would make sense to:
rename SD_CLUSTER into SD_SHARE_PKG_RESOURCES
rename SD_SHARE_PKG_RESOURCES into SD_SHARE_LLC
but that's another topic...

Quoted 5 lines
kernel/sched/topology.c +0 -1
  *   SD_SHARE_PKG_RESOURCES - describes shared caches
  *   SD_NUMA                - describes NUMA topologies
  *
--

2.43.0

#5 lore raw

Re: [PATCH v3 3/4] sched/fair: packing func sched_use_asym_prio()/sched_asym_prefer()

In reply to [email protected]

Hi Ricardo,

Since your good suggestions took in this and the next patch, do you mind to give Reviewed-by for both of them?

Thanks
Alex

Quoted 96 lines · On 2/1/24 7:54 PM, [email protected] wrote:

From: Alex Shi <[email protected]>

Consolidate the functions sched_use_asym_prio() and sched_asym_prefer() into one. and rename sched_asym() as sched_group_asym(). This makes the code easier to read. No functional changes.

To: Ricardo Neri <[email protected]>
To: Valentin Schneider <[email protected]>
To: Vincent Guittot <[email protected]>
To: Peter Zijlstra <[email protected]>
To: Ingo Molnar <[email protected]>

---
 kernel/sched/fair.c | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)
kernel/sched/fair.c +18 -17
index 8d70417f5125..44fd5e2ca642 100644
@@ -9747,8 +9747,15 @@ static bool sched_use_asym_prio(struct sched_domain *sd, int cpu)
 	return sd->flags & SD_SHARE_CPUCAPACITY || is_core_idle(cpu);
 }
 
+static inline bool sched_asym(struct sched_domain *sd, int dst_cpu, int src_cpu)
+{
+	/* Check if asym balance applicable, then check priorities.*/
+	return sched_use_asym_prio(sd, dst_cpu) &&
+		sched_asym_prefer(dst_cpu, src_cpu);
+}
+
 /**
- * sched_asym - Check if the destination CPU can do asym_packing load balance
+ * sched_group_asym - Check if the destination CPU can do asym_packing balance
  * @env:	The load balancing environment
  * @sgs:	Load-balancing statistics of the candidate busiest group
  * @group:	The candidate busiest group
@@ -9768,22 +9775,18 @@ static bool sched_use_asym_prio(struct sched_domain *sd, int cpu)
  * otherwise.
  */
 static inline bool
-sched_asym(struct lb_env *env, struct sg_lb_stats *sgs, struct sched_group *group)
+sched_group_asym(struct lb_env *env, struct sg_lb_stats *sgs, struct sched_group *group)
 {
-	/* Ensure that the whole local core is idle, if applicable. */
-	if (!sched_use_asym_prio(env->sd, env->dst_cpu))
-		return false;
-
 	/*
-	 * CPU priorities does not make sense for SMT cores with more than one
+	 * CPU priorities do not make sense for SMT cores with more than one
 	 * busy sibling.
 	 */
-	if (group->flags & SD_SHARE_CPUCAPACITY) {
-		if (sgs->group_weight - sgs->idle_cpus != 1)
-			return false;
-	}
 
-	return sched_asym_prefer(env->dst_cpu, group->asym_prefer_cpu);
+	if ((group->flags & SD_SHARE_CPUCAPACITY) &&
+	    (sgs->group_weight - sgs->idle_cpus != 1))
+		return false;
+
+	return sched_asym(env->sd, env->dst_cpu, group->asym_prefer_cpu);
 }
 
 /* One group has more than one SMT CPU while the other group does not */
@@ -9939,7 +9942,7 @@ static inline void update_sg_lb_stats(struct lb_env *env,
 	/* Check if dst CPU is idle and preferred to this group */
 	if (!local_group && env->sd->flags & SD_ASYM_PACKING &&
 	    env->idle != CPU_NOT_IDLE && sgs->sum_h_nr_running &&
-	    sched_asym(env, sgs, group)) {
+	    sched_group_asym(env, sgs, group)) {
 		sgs->group_asym_packing = 1;
 	}
 
@@ -11038,8 +11041,7 @@ static struct rq *find_busiest_queue(struct lb_env *env,
 		 * SMT cores with more than one busy sibling.
 		 */
 		if ((env->sd->flags & SD_ASYM_PACKING) &&
-		    sched_use_asym_prio(env->sd, i) &&
-		    sched_asym_prefer(i, env->dst_cpu) &&
+		    sched_asym(env->sd, i, env->dst_cpu) &&
 		    nr_running == 1)
 			continue;
 
@@ -11909,8 +11911,7 @@ static void nohz_balancer_kick(struct rq *rq)
 		 * preferred CPU must be idle.
 		 */
 		for_each_cpu_and(i, sched_domain_span(sd), nohz.idle_cpus_mask) {
-			if (sched_use_asym_prio(sd, i) &&
-			    sched_asym_prefer(i, cpu)) {
+			if (sched_asym(sd, i, cpu)) {
 				flags = NOHZ_STATS_KICK | NOHZ_BALANCE_KICK;
 				goto unlock;
 			}
#11 lore raw
In reply to Valentin Schneider
Quoted 32 lines · Valentin Schneider

Subject nit: the prefix should be sched/topology

Quoted 20 lines · On 01/02/24 19:54, [email protected] wrote:

From: Alex Shi <[email protected]>

The description of SD_CLUSTER is missing. Add it.

To: Ricardo Neri <[email protected]>
To: Valentin Schneider <[email protected]>
To: Vincent Guittot <[email protected]>
To: Juri Lelli <[email protected]>
To: Peter Zijlstra <[email protected]>
To: Ingo Molnar <[email protected]>

---
 kernel/sched/topology.c | 1 +
 1 file changed, 1 insertion(+)
kernel/sched/topology.c +0 -0
index 10d1391e7416..8b45f16a1890 100644

kernel/sched/topology.c static struct cpumask ***sched_domains_numa_masks; · line 1557

Quoted 4 lines
kernel/sched/topology.c +1 -0
@@ -1554,6 +1554,7 @@ static struct cpumask		***sched_domains_numa_masks;
  * function:
  *
  *   SD_SHARE_CPUCAPACITY   - describes SMT topologies
+ *   SD_CLUSTER             - describes CPU Cluster topologies

So I know this is the naming we've gone for the "Cluster" naming, but this comment isn't really explaining anything.

Quoted 7 lines

include/linux/sched/sd_flags.h has a bit more info already:
* Domain members share CPU cluster (LLC tags or L2 cache)

I had to go through a bit of git history to remember what the CLUSTER thing was about, how about this:

* SD_CLUSTER - describes shared shared caches, cache tags or busses

Double "shared", so could we use:
* SD_CLUSTER - describes shared caches, cache tags or busses?

Quoted 6 lines

* SD_SHARE_PKG_RESOURCES - describes shared LLC cache

And looking at this it would make sense to:
rename SD_CLUSTER into SD_SHARE_PKG_RESOURCES
rename SD_SHARE_PKG_RESOURCES into SD_SHARE_LLC
but that's another topic...

Uh, naming is a hard things. :)

Thanks
Alex

Quoted 7 lines
Quoted 6 lines
kernel/sched/topology.c +0 -1
  *   SD_SHARE_PKG_RESOURCES - describes shared caches
  *   SD_NUMA                - describes NUMA topologies
  *
--

2.43.0

#3 lore raw

Re: [PATCH v3 2/4] sched/fair: remove unused parameters

In reply to Valentin Schneider
Quoted 10 lines · Valentin Schneider
Quoted 6 lines · On 01/02/24 19:54, [email protected] wrote:

From: Alex Shi <[email protected]>

sds isn't used in function sched_asym(), so remove it to cleanup code.

AFAICT this is unsused as of:
c9ca07886aaa ("sched/fair: Do not even the number of busy CPUs via asym_packing")

Maybe a Fixes: c9ca07886aaa ("sched/fair: Do not even the number of busy CPUs via asym_packing") is in order?

#6 lore raw

Re: [PATCH v3 3/4] sched/fair: packing func sched_use_asym_prio()/sched_asym_prefer()

In reply to [email protected]
Quoted 1 line · On Thu, Feb 01, 2024 at 07:54:46PM +0800, [email protected] wrote:

From: Alex Shi <[email protected]>

subject:

sched/fair: packing func sched_use_asym_prio()/sched_asym_prefer()

Do not use gerund mood in the subject. Better to say:
sched/fair: Rework sched_use_asym_prio() and sched_asym_prefer()

Quoted 4 lines

Consolidate the functions sched_use_asym_prio() and sched_asym_prefer() into one. and rename sched_asym() as sched_group_asym(). This makes the code easier to read. No functional changes.

Maybe giving more reasons?

sched_use_asym_prio() sched_asym_prefer() are used together in various places. Consolidate them into a single function sched_asym().

The existing sched_group_asym() is only used when collecting statistics of a scheduling group. Rename it as sched_group_asym().

Quoted 16 lines

To: Ricardo Neri <[email protected]>
To: Valentin Schneider <[email protected]>
To: Vincent Guittot <[email protected]>
To: Peter Zijlstra <[email protected]>
To: Ingo Molnar <[email protected]>

---
 kernel/sched/fair.c | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)
kernel/sched/fair.c +0 -0
index 8d70417f5125..44fd5e2ca642 100644

kernel/sched/fair.c static bool sched_use_asym_prio(struct sched_domain *sd, int cpu) · line 9752

Quoted 6 lines
kernel/sched/fair.c +3 -0
@@ -9747,8 +9747,15 @@ static bool sched_use_asym_prio(struct sched_domain *sd, int cpu)
 	return sd->flags & SD_SHARE_CPUCAPACITY || is_core_idle(cpu);
 }
 
+static inline bool sched_asym(struct sched_domain *sd, int dst_cpu, int src_cpu)
+{
+	/* Check if asym balance applicable, then check priorities.*/

Perhaps the comment can be made more descriptive:

	/*
	 * First check if @dst_cpu can do asym_packing load balance. Only do it
	 * if it has higher priority than @src_cpu.
	 */
Quoted 22 lines
kernel/sched/fair.c +6 -6
+	return sched_use_asym_prio(sd, dst_cpu) &&
+		sched_asym_prefer(dst_cpu, src_cpu);
+}
+
 /**
- * sched_asym - Check if the destination CPU can do asym_packing load balance
+ * sched_group_asym - Check if the destination CPU can do asym_packing balance
  * @env:	The load balancing environment
  * @sgs:	Load-balancing statistics of the candidate busiest group
  * @group:	The candidate busiest group
@@ -9768,22 +9775,18 @@ static bool sched_use_asym_prio(struct sched_domain *sd, int cpu)
  * otherwise.
  */
 static inline bool
-sched_asym(struct lb_env *env, struct sg_lb_stats *sgs, struct sched_group *group)
+sched_group_asym(struct lb_env *env, struct sg_lb_stats *sgs, struct sched_group *group)
 {
-	/* Ensure that the whole local core is idle, if applicable. */
-	if (!sched_use_asym_prio(env->sd, env->dst_cpu))
-		return false;
-
 	/*

kernel/sched/fair.c static bool sched_use_asym_prio(struct sched_domain *sd, int cpu) · line 9786

Quoted 10 lines
kernel/sched/fair.c +1 -6
-	 * CPU priorities does not make sense for SMT cores with more than one
+	 * CPU priorities do not make sense for SMT cores with more than one
 	 * busy sibling.
 	 */
-	if (group->flags & SD_SHARE_CPUCAPACITY) {
-		if (sgs->group_weight - sgs->idle_cpus != 1)
-			return false;
-	}
 
-	return sched_asym_prefer(env->dst_cpu, group->asym_prefer_cpu);

After applying this patch there is a blank line between the comment and the return statement. Can you remove it?

Quoted 40 lines
kernel/sched/fair.c +8 -5
+	if ((group->flags & SD_SHARE_CPUCAPACITY) &&
+	    (sgs->group_weight - sgs->idle_cpus != 1))
+		return false;
+
+	return sched_asym(env->sd, env->dst_cpu, group->asym_prefer_cpu);
 }
 
 /* One group has more than one SMT CPU while the other group does not */
@@ -9939,7 +9942,7 @@ static inline void update_sg_lb_stats(struct lb_env *env,
 	/* Check if dst CPU is idle and preferred to this group */
 	if (!local_group && env->sd->flags & SD_ASYM_PACKING &&
 	    env->idle != CPU_NOT_IDLE && sgs->sum_h_nr_running &&
-	    sched_asym(env, sgs, group)) {
+	    sched_group_asym(env, sgs, group)) {
 		sgs->group_asym_packing = 1;
 	}
 
@@ -11038,8 +11041,7 @@ static struct rq *find_busiest_queue(struct lb_env *env,
 		 * SMT cores with more than one busy sibling.
 		 */
 		if ((env->sd->flags & SD_ASYM_PACKING) &&
-		    sched_use_asym_prio(env->sd, i) &&
-		    sched_asym_prefer(i, env->dst_cpu) &&
+		    sched_asym(env->sd, i, env->dst_cpu) &&
 		    nr_running == 1)
 			continue;
 
@@ -11909,8 +11911,7 @@ static void nohz_balancer_kick(struct rq *rq)
 		 * preferred CPU must be idle.
 		 */
 		for_each_cpu_and(i, sched_domain_span(sd), nohz.idle_cpus_mask) {
-			if (sched_use_asym_prio(sd, i) &&
-			    sched_asym_prefer(i, cpu)) {
+			if (sched_asym(sd, i, cpu)) {
 				flags = NOHZ_STATS_KICK | NOHZ_BALANCE_KICK;
 				goto unlock;
 			}
Signature · 1 line
2.43.0
#8 lore raw

Re: [PATCH v3 4/4] sched/fair: Check the SD_ASYM_PACKING flag in sched_use_asym_prio()

In reply to [email protected]
Quoted 6 lines · On Thu, Feb 01, 2024 at 07:54:47PM +0800, [email protected] wrote:

From: Alex Shi <[email protected]>

sched_use_asym_prio() checks whether CPU priorities should be used. It makes sense to check for the SD_ASYM_PACKING() inside the function. Since both sched_asym() and sched_group_asym() use sched_use_asym_prio(), remove the now superfluous checks for the flag in various places"

s/places"/places./

Quoted 31 lines

To: Ricardo Neri <[email protected]>
To: Ben Segall <[email protected]>
To: Steven Rostedt <[email protected]>
To: Dietmar Eggemann <[email protected]>
To: Valentin Schneider <[email protected]>
To: Daniel Bristot de Oliveira <[email protected]>
To: Vincent Guittot <[email protected]>
To: Juri Lelli <[email protected]>
To: Peter Zijlstra <[email protected]>
To: Ingo Molnar <[email protected]>

---
 kernel/sched/fair.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
kernel/sched/fair.c +3 -0
index 44fd5e2ca642..bd32efbea688 100644
@@ -9741,6 +9741,9 @@ group_type group_classify(unsigned int imbalance_pct,
  */
 static bool sched_use_asym_prio(struct sched_domain *sd, int cpu)
 {
+	if (!(sd->flags & SD_ASYM_PACKING))
+		return false;
+
 	if (!sched_smt_active())
 		return true;
 

kernel/sched/fair.c static inline void update_sg_lb_stats(struct lb_env *env, · line 9947

Quoted 8 lines
kernel/sched/fair.c +2 -3
@@ -9940,11 +9943,9 @@ static inline void update_sg_lb_stats(struct lb_env *env,
 	sgs->group_weight = group->group_weight;
 
 	/* Check if dst CPU is idle and preferred to this group */
-	if (!local_group && env->sd->flags & SD_ASYM_PACKING &&
-	    env->idle != CPU_NOT_IDLE && sgs->sum_h_nr_running &&
-	    sched_group_asym(env, sgs, group)) {
+	if (!local_group && env->idle != CPU_NOT_IDLE && sgs->sum_h_nr_running &&
+			sched_group_asym(env, sgs, group))

You should align sched_group_asym() to !local_group.

Quoted 17 lines
kernel/sched/fair.c +1 -4
 		sgs->group_asym_packing = 1;
-	}
 
 	/* Check for loaded SMT group to be balanced to dst CPU */
 	if (!local_group && smt_balance(env, sgs, group))
@@ -11040,9 +11041,7 @@ static struct rq *find_busiest_queue(struct lb_env *env,
 		 * If balancing between cores, let lower priority CPUs help
 		 * SMT cores with more than one busy sibling.
 		 */
-		if ((env->sd->flags & SD_ASYM_PACKING) &&
-		    sched_asym(env->sd, i, env->dst_cpu) &&
-		    nr_running == 1)
+		if (sched_asym(env->sd, i, env->dst_cpu) && nr_running == 1)
 			continue;
 
 		switch (env->migration_type) {

kernel/sched/fair.c asym_active_balance(struct lb_env *env) · line 11142

Quoted 7 lines
kernel/sched/fair.c +1 -1
@@ -11138,7 +11137,7 @@ asym_active_balance(struct lb_env *env)
 	 * the lower priority @env::dst_cpu help it. Do not follow
 	 * CPU priority.
 	 */
-	return env->idle != CPU_NOT_IDLE && (env->sd->flags & SD_ASYM_PACKING) &&
+	return env->idle != CPU_NOT_IDLE &&
 	       sched_use_asym_prio(env->sd, env->dst_cpu) &&
 	       (sched_asym_prefer(env->dst_cpu, env->src_cpu) ||

Perhaps you can rearrange the spaghetti of conditions to make better use of the full 80-column line.

#12 lore raw
In reply to Valentin Schneider
Quoted 32 lines · Valentin Schneider

Subject nit: the prefix should be sched/topology

Quoted 20 lines · On 01/02/24 19:54, [email protected] wrote:

From: Alex Shi <[email protected]>

The description of SD_CLUSTER is missing. Add it.

To: Ricardo Neri <[email protected]>
To: Valentin Schneider <[email protected]>
To: Vincent Guittot <[email protected]>
To: Juri Lelli <[email protected]>
To: Peter Zijlstra <[email protected]>
To: Ingo Molnar <[email protected]>

---
 kernel/sched/topology.c | 1 +
 1 file changed, 1 insertion(+)
kernel/sched/topology.c +0 -0
index 10d1391e7416..8b45f16a1890 100644

kernel/sched/topology.c static struct cpumask ***sched_domains_numa_masks; · line 1557

Quoted 4 lines
kernel/sched/topology.c +1 -0
@@ -1554,6 +1554,7 @@ static struct cpumask		***sched_domains_numa_masks;
  * function:
  *
  *   SD_SHARE_CPUCAPACITY   - describes SMT topologies
+ *   SD_CLUSTER             - describes CPU Cluster topologies

So I know this is the naming we've gone for the "Cluster" naming, but this comment isn't really explaining anything.

Quoted 2 lines

include/linux/sched/sd_flags.h has a bit more info already:
* Domain members share CPU cluster (LLC tags or L2 cache)

I also thought of this, but I didn't want to suggest to repeat in topolog.c what is described in sd_flags.h.

Maybe it is better to remove the descriptions of all flags here and instead direct the reader to sd_flags.h?

Quoted 5 lines

I had to go through a bit of git history to remember what the CLUSTER thing was about, how about this:

* SD_CLUSTER - describes shared shared caches, cache tags or busses

AFAIK, this describes a subset of CPUs in the package that share a resource, likely L2 cache.

Quoted 4 lines

* SD_SHARE_PKG_RESOURCES - describes shared LLC cache

And looking at this it would make sense to:
rename SD_CLUSTER into SD_SHARE_PKG_RESOURCES

but not all CPUs in the package share the resource

Quoted 3 lines

rename SD_SHARE_PKG_RESOURCES into SD_SHARE_LLC
but that's another topic...

#9 lore raw

Re: [PATCH v3 4/4] sched/fair: Check the SD_ASYM_PACKING flag in sched_use_asym_prio()

In reply to Ricardo Neri
Quoted 43 lines · Ricardo Neri
Quoted 6 lines · On Thu, Feb 01, 2024 at 07:54:47PM +0800, [email protected] wrote:

From: Alex Shi <[email protected]>

sched_use_asym_prio() checks whether CPU priorities should be used. It makes sense to check for the SD_ASYM_PACKING() inside the function. Since both sched_asym() and sched_group_asym() use sched_use_asym_prio(), remove the now superfluous checks for the flag in various places"

s/places"/places./

Quoted 33 lines

To: Ricardo Neri <[email protected]>
To: Ben Segall <[email protected]>
To: Steven Rostedt <[email protected]>
To: Dietmar Eggemann <[email protected]>
To: Valentin Schneider <[email protected]>
To: Daniel Bristot de Oliveira <[email protected]>
To: Vincent Guittot <[email protected]>
To: Juri Lelli <[email protected]>
To: Peter Zijlstra <[email protected]>
To: Ingo Molnar <[email protected]>

---
 kernel/sched/fair.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
kernel/sched/fair.c +3 -0
index 44fd5e2ca642..bd32efbea688 100644
@@ -9741,6 +9741,9 @@ group_type group_classify(unsigned int imbalance_pct,
  */
 static bool sched_use_asym_prio(struct sched_domain *sd, int cpu)
 {
+	if (!(sd->flags & SD_ASYM_PACKING))
+		return false;
+
 	if (!sched_smt_active())
 		return true;
 
@@ -9940,11 +9943,9 @@ static inline void update_sg_lb_stats(struct lb_env *env,
 	sgs->group_weight = group->group_weight;
 
Quoted 8 lines

kernel/sched/fair.c static inline void update_sg_lb_stats(struct lb_env *env, · line 9947

Quoted 6 lines
kernel/sched/fair.c +2 -3
 	/* Check if dst CPU is idle and preferred to this group */
-	if (!local_group && env->sd->flags & SD_ASYM_PACKING &&
-	    env->idle != CPU_NOT_IDLE && sgs->sum_h_nr_running &&
-	    sched_group_asym(env, sgs, group)) {
+	if (!local_group && env->idle != CPU_NOT_IDLE && sgs->sum_h_nr_running &&
+			sched_group_asym(env, sgs, group))

You should align sched_group_asym() to !local_group.

Thanks for all suggestion. I will take them in next version.

Quoted 16 lines
Quoted 16 lines
kernel/sched/fair.c +1 -4
 		sgs->group_asym_packing = 1;
-	}
 
 	/* Check for loaded SMT group to be balanced to dst CPU */
 	if (!local_group && smt_balance(env, sgs, group))
@@ -11040,9 +11041,7 @@ static struct rq *find_busiest_queue(struct lb_env *env,
 		 * If balancing between cores, let lower priority CPUs help
 		 * SMT cores with more than one busy sibling.
 		 */
-		if ((env->sd->flags & SD_ASYM_PACKING) &&
-		    sched_asym(env->sd, i, env->dst_cpu) &&
-		    nr_running == 1)
+		if (sched_asym(env->sd, i, env->dst_cpu) && nr_running == 1)
 			continue;
 
Quoted 12 lines

kernel/sched/fair.c asym_active_balance(struct lb_env *env) · line 11142

Quoted 9 lines
kernel/sched/fair.c +1 -1
 		switch (env->migration_type) {
@@ -11138,7 +11137,7 @@ asym_active_balance(struct lb_env *env)
 	 * the lower priority @env::dst_cpu help it. Do not follow
 	 * CPU priority.
 	 */
-	return env->idle != CPU_NOT_IDLE && (env->sd->flags & SD_ASYM_PACKING) &&
+	return env->idle != CPU_NOT_IDLE &&
 	       sched_use_asym_prio(env->sd, env->dst_cpu) &&
 	       (sched_asym_prefer(env->dst_cpu, env->src_cpu) ||

Perhaps you can rearrange the spaghetti of conditions to make better use of the full 80-column line.

80-column doesn't work here, will try 100 column.

Thanks
Alex

#19 lore raw
In reply to Valentin Schneider
Quoted 32 lines · Valentin Schneider

Subject nit: the prefix should be sched/topology

Quoted 20 lines · On 01/02/24 19:54, [email protected] wrote:

From: Alex Shi <[email protected]>

The description of SD_CLUSTER is missing. Add it.

To: Ricardo Neri <[email protected]>
To: Valentin Schneider <[email protected]>
To: Vincent Guittot <[email protected]>
To: Juri Lelli <[email protected]>
To: Peter Zijlstra <[email protected]>
To: Ingo Molnar <[email protected]>

---
 kernel/sched/topology.c | 1 +
 1 file changed, 1 insertion(+)
kernel/sched/topology.c +0 -0
index 10d1391e7416..8b45f16a1890 100644

kernel/sched/topology.c static struct cpumask ***sched_domains_numa_masks; · line 1557

Quoted 4 lines
kernel/sched/topology.c +1 -0
@@ -1554,6 +1554,7 @@ static struct cpumask		***sched_domains_numa_masks;
  * function:
  *
  *   SD_SHARE_CPUCAPACITY   - describes SMT topologies
+ *   SD_CLUSTER             - describes CPU Cluster topologies

So I know this is the naming we've gone for the "Cluster" naming, but this comment isn't really explaining anything.

Quoted 3 lines

include/linux/sched/sd_flags.h has a bit more info already:
* Domain members share CPU cluster (LLC tags or L2 cache)

Cluster topology in scheduler should mean CPUs beyond the SMT which are sharing some cache resources (currently L2 on some Intel platforms or L3 Tag on our platforms) but not the LLC.

A drawing in c5e22feffdd7 ("topology: Represent clusters of CPUs within a die") has a good illustration and comment of cpus_share_resources() also illustrate this a bit:

/*
* Whether CPUs are share cache resources, which means LLC on non-cluster
* machines and LLC tag or L2 on machines with clusters.
*/
bool cpus_share_resources(int this_cpu, int that_cpu)

Quoted 20 lines

I had to go through a bit of git history to remember what the CLUSTER thing was about, how about this:

* SD_CLUSTER - describes shared shared caches, cache tags or busses
* SD_SHARE_PKG_RESOURCES - describes shared LLC cache

And looking at this it would make sense to:
rename SD_CLUSTER into SD_SHARE_PKG_RESOURCES
rename SD_SHARE_PKG_RESOURCES into SD_SHARE_LLC
but that's another topic...

Quoted 5 lines
kernel/sched/topology.c +0 -1
  *   SD_SHARE_PKG_RESOURCES - describes shared caches
  *   SD_NUMA                - describes NUMA topologies
  *
--

2.43.0

.

#13 lore raw
In reply to Ricardo Neri
Quoted 33 lines · Ricardo Neri
Quoted 32 lines · Valentin Schneider

Subject nit: the prefix should be sched/topology

Quoted 20 lines · On 01/02/24 19:54, [email protected] wrote:

From: Alex Shi <[email protected]>

The description of SD_CLUSTER is missing. Add it.

To: Ricardo Neri <[email protected]>
To: Valentin Schneider <[email protected]>
To: Vincent Guittot <[email protected]>
To: Juri Lelli <[email protected]>
To: Peter Zijlstra <[email protected]>
To: Ingo Molnar <[email protected]>

---
 kernel/sched/topology.c | 1 +
 1 file changed, 1 insertion(+)
kernel/sched/topology.c +0 -0
index 10d1391e7416..8b45f16a1890 100644

kernel/sched/topology.c static struct cpumask ***sched_domains_numa_masks; · line 1557

Quoted 4 lines
kernel/sched/topology.c +1 -0
@@ -1554,6 +1554,7 @@ static struct cpumask		***sched_domains_numa_masks;
  * function:
  *
  *   SD_SHARE_CPUCAPACITY   - describes SMT topologies
+ *   SD_CLUSTER             - describes CPU Cluster topologies

So I know this is the naming we've gone for the "Cluster" naming, but this comment isn't really explaining anything.

Quoted 8 lines
Quoted 2 lines

include/linux/sched/sd_flags.h has a bit more info already:
* Domain members share CPU cluster (LLC tags or L2 cache)

I also thought of this, but I didn't want to suggest to repeat in topolog.c what is described in sd_flags.h.

Maybe it is better to remove the descriptions of all flags here and instead direct the reader to sd_flags.h?

yes, good idea for getting their meaning directly from the header file. So is it fine for next sending?

sched/fair: remove duplicate comments for SD_ flags

Originally, it missed SD_CLUSTER flag description, but comparing to copy the flags meaning from sd_flags.h, reader is better to get info from there.

Keep SD_ASYM_PACKING unchange for a point from another way.

To: Ricardo Neri <[email protected]>
To: Valentin Schneider <[email protected]>
To: Vincent Guittot <[email protected]>
To: Juri Lelli <[email protected]>
To: Peter Zijlstra <[email protected]>
To: Ingo Molnar <[email protected]>

kernel/sched/topology.c +1 -5
index 10d1391e7416..96a24bf954ad 100644
@@ -1551,11 +1551,7 @@ static struct cpumask            ***sched_domains_numa_masks;
  *
  * These flags are purely descriptive of the topology and do not prescribe
  * behaviour. Behaviour is artificial and mapped in the below sd_init()
- * function:
- *
- *   SD_SHARE_CPUCAPACITY   - describes SMT topologies
- *   SD_SHARE_PKG_RESOURCES - describes shared caches
- *   SD_NUMA                - describes NUMA topologies
+ * function, for details in include/linux/sched/sd_flags.h:
  *
  * Odd one out, which beside describing the topology has a quirk also
  * prescribes the desired behaviour that goes along with it:
Quoted 20 lines
Quoted 6 lines

I had to go through a bit of git history to remember what the CLUSTER thing was about, how about this:

* SD_CLUSTER - describes shared shared caches, cache tags or busses

AFAIK, this describes a subset of CPUs in the package that share a resource, likely L2 cache.

Quoted 4 lines

* SD_SHARE_PKG_RESOURCES - describes shared LLC cache

And looking at this it would make sense to:
rename SD_CLUSTER into SD_SHARE_PKG_RESOURCES

but not all CPUs in the package share the resource

Quoted 3 lines

rename SD_SHARE_PKG_RESOURCES into SD_SHARE_LLC
but that's another topic...

#16 lore raw
In reply to Ricardo Neri
Quoted 33 lines · Ricardo Neri
Quoted 32 lines · Valentin Schneider

Subject nit: the prefix should be sched/topology

Quoted 20 lines · On 01/02/24 19:54, [email protected] wrote:

From: Alex Shi <[email protected]>

The description of SD_CLUSTER is missing. Add it.

To: Ricardo Neri <[email protected]>
To: Valentin Schneider <[email protected]>
To: Vincent Guittot <[email protected]>
To: Juri Lelli <[email protected]>
To: Peter Zijlstra <[email protected]>
To: Ingo Molnar <[email protected]>

---
 kernel/sched/topology.c | 1 +
 1 file changed, 1 insertion(+)
kernel/sched/topology.c +0 -0
index 10d1391e7416..8b45f16a1890 100644

kernel/sched/topology.c static struct cpumask ***sched_domains_numa_masks; · line 1557

Quoted 4 lines
kernel/sched/topology.c +1 -0
@@ -1554,6 +1554,7 @@ static struct cpumask		***sched_domains_numa_masks;
  * function:
  *
  *   SD_SHARE_CPUCAPACITY   - describes SMT topologies
+ *   SD_CLUSTER             - describes CPU Cluster topologies

So I know this is the naming we've gone for the "Cluster" naming, but this comment isn't really explaining anything.

Quoted 9 lines
Quoted 2 lines

include/linux/sched/sd_flags.h has a bit more info already:
* Domain members share CPU cluster (LLC tags or L2 cache)

I also thought of this, but I didn't want to suggest to repeat in topolog.c what is described in sd_flags.h.

Maybe it is better to remove the descriptions of all flags here and instead direct the reader to sd_flags.h?

Yeah I agree on less duplication.

Quoted 9 lines
Quoted 5 lines

I had to go through a bit of git history to remember what the CLUSTER thing was about, how about this:

* SD_CLUSTER - describes shared shared caches, cache tags or busses

AFAIK, this describes a subset of CPUs in the package that share a resource, likely L2 cache.

Quoted 6 lines
Quoted 4 lines

* SD_SHARE_PKG_RESOURCES - describes shared LLC cache

And looking at this it would make sense to:
rename SD_CLUSTER into SD_SHARE_PKG_RESOURCES

but not all CPUs in the package share the resource

But SD_CLUSTER never expands beyond the package, right?

Regardless, my main point is that having both SD_CLUSTER and SD_SHARE_PKG_RESOURCES is a source of confusion (at the very least for myself), and given SD_SHARE_PKG_RESOURCES is really used to mean "shares LLC" (see update_top_cache_domain()), we could make that flag more explicit and lift some ambiguity with SD_CLUSTER.

Quoted 4 lines
Quoted 4 lines

rename SD_SHARE_PKG_RESOURCES into SD_SHARE_LLC
but that's another topic...

#14 lore raw
In reply to kuiliang Shi
Quoted 39 lines · kuiliang Shi
Quoted 36 lines · Ricardo Neri
Quoted 34 lines · Valentin Schneider

Subject nit: the prefix should be sched/topology

Quoted 20 lines · On 01/02/24 19:54, [email protected] wrote:

From: Alex Shi <[email protected]>

The description of SD_CLUSTER is missing. Add it.

To: Ricardo Neri <[email protected]>
To: Valentin Schneider <[email protected]>
To: Vincent Guittot <[email protected]>
To: Juri Lelli <[email protected]>
To: Peter Zijlstra <[email protected]>
To: Ingo Molnar <[email protected]>

---
 kernel/sched/topology.c | 1 +
 1 file changed, 1 insertion(+)
kernel/sched/topology.c +0 -0
index 10d1391e7416..8b45f16a1890 100644

kernel/sched/topology.c static struct cpumask ***sched_domains_numa_masks; · line 1557

Quoted 4 lines
kernel/sched/topology.c +1 -0
@@ -1554,6 +1554,7 @@ static struct cpumask		***sched_domains_numa_masks;
  * function:
  *
  *   SD_SHARE_CPUCAPACITY   - describes SMT topologies
+ *   SD_CLUSTER             - describes CPU Cluster topologies

So I know this is the naming we've gone for the "Cluster" naming, but this comment isn't really explaining anything.

include/linux/sched/sd_flags.h has a bit more info already:
* Domain members share CPU cluster (LLC tags or L2 cache)

Quoted 8 lines
Quoted 5 lines

I also thought of this, but I didn't want to suggest to repeat in topolog.c what is described in sd_flags.h.

Maybe it is better to remove the descriptions of all flags here and instead direct the reader to sd_flags.h?

yes, good idea for getting their meaning directly from the header file. So is it fine for next sending?

Some tweaks below.

Quoted 2 lines

sched/fair: remove duplicate comments for SD_ flags

sched/topology: Remove duplicate descriptions from TOPOLOGY_SD_FLAGS

Quoted 4 lines

Originally, it missed SD_CLUSTER flag description, but comparing to copy the flags meaning from sd_flags.h, reader is better to get info from there.

These flags are already documented in include/linux/sched/sd_flags.h.

Keep the comment on SD_ASYM_PACKING as it is a special case.

Quoted 16 lines

Keep SD_ASYM_PACKING unchange for a point from another way.

To: Ricardo Neri <[email protected]>
To: Valentin Schneider <[email protected]>
To: Vincent Guittot <[email protected]>
To: Juri Lelli <[email protected]>
To: Peter Zijlstra <[email protected]>
To: Ingo Molnar <[email protected]>

kernel/sched/topology.c +0 -0
index 10d1391e7416..96a24bf954ad 100644

kernel/sched/topology.c static struct cpumask ***sched_domains_numa_masks; · line 1558

Quoted 8 lines
kernel/sched/topology.c +0 -5
@@ -1551,11 +1551,7 @@ static struct cpumask            ***sched_domains_numa_masks;
  *
  * These flags are purely descriptive of the topology and do not prescribe
  * behaviour. Behaviour is artificial and mapped in the below sd_init()
- * function:
- *
- *   SD_SHARE_CPUCAPACITY   - describes SMT topologies
- *   SD_SHARE_PKG_RESOURCES - describes shared caches
- *   SD_NUMA                - describes NUMA topologies

Maybe only remove the descriptions but keep the enumeration?

kernel/sched/topology.c static struct cpumask ***sched_domains_numa_masks; · line 1554

Quoted 1 line
kernel/sched/topology.c +1 -0
+ * function, for details in include/linux/sched/sd_flags.h:

function. For details, see include/linux/sched/sd_flags.h.

#17 lore raw
In reply to Valentin Schneider
Quoted 55 lines · Valentin Schneider
Quoted 33 lines · Ricardo Neri
Quoted 32 lines · Valentin Schneider

Subject nit: the prefix should be sched/topology

Quoted 20 lines · On 01/02/24 19:54, [email protected] wrote:

From: Alex Shi <[email protected]>

The description of SD_CLUSTER is missing. Add it.

To: Ricardo Neri <[email protected]>
To: Valentin Schneider <[email protected]>
To: Vincent Guittot <[email protected]>
To: Juri Lelli <[email protected]>
To: Peter Zijlstra <[email protected]>
To: Ingo Molnar <[email protected]>

---
 kernel/sched/topology.c | 1 +
 1 file changed, 1 insertion(+)
kernel/sched/topology.c +0 -0
index 10d1391e7416..8b45f16a1890 100644

kernel/sched/topology.c static struct cpumask ***sched_domains_numa_masks; · line 1557

Quoted 4 lines
kernel/sched/topology.c +1 -0
@@ -1554,6 +1554,7 @@ static struct cpumask		***sched_domains_numa_masks;
  * function:
  *
  *   SD_SHARE_CPUCAPACITY   - describes SMT topologies
+ *   SD_CLUSTER             - describes CPU Cluster topologies

So I know this is the naming we've gone for the "Cluster" naming, but this comment isn't really explaining anything.

Quoted 9 lines
Quoted 2 lines

include/linux/sched/sd_flags.h has a bit more info already:
* Domain members share CPU cluster (LLC tags or L2 cache)

I also thought of this, but I didn't want to suggest to repeat in topolog.c what is described in sd_flags.h.

Maybe it is better to remove the descriptions of all flags here and instead direct the reader to sd_flags.h?

Yeah I agree on less duplication.

Quoted 9 lines
Quoted 5 lines

I had to go through a bit of git history to remember what the CLUSTER thing was about, how about this:

* SD_CLUSTER - describes shared shared caches, cache tags or busses

AFAIK, this describes a subset of CPUs in the package that share a resource, likely L2 cache.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

* SD_SHARE_PKG_RESOURCES - describes shared LLC cache

And looking at this it would make sense to:
rename SD_CLUSTER into SD_SHARE_PKG_RESOURCES

but not all CPUs in the package share the resource

But SD_CLUSTER never expands beyond the package, right?

Correct.

Quoted 4 lines

Regardless, my main point is that having both SD_CLUSTER and SD_SHARE_PKG_RESOURCES is a source of confusion (at the very least for myself),

Agreed!

Quoted 3 lines

and given SD_SHARE_PKG_RESOURCES is really used to mean "shares LLC" (see update_top_cache_domain()), we could make that flag more explicit and lift some ambiguity with SD_CLUSTER.

As Yicong stated, cluster topology should mean CPUs beyond SMT that share some resource but not LLC.

It makes sense to me to keep SD_CLUSTER name as it is today and rename SD_SHARE_PKG_RESOURCES as SD_SHARE_LLC.

#18 lore raw
Quoted 78 lines · Ricardo Neri
Quoted 55 lines · Valentin Schneider
Quoted 33 lines · Ricardo Neri
Quoted 32 lines · Valentin Schneider

Subject nit: the prefix should be sched/topology

Quoted 20 lines · On 01/02/24 19:54, [email protected] wrote:

From: Alex Shi <[email protected]>

The description of SD_CLUSTER is missing. Add it.

To: Ricardo Neri <[email protected]>
To: Valentin Schneider <[email protected]>
To: Vincent Guittot <[email protected]>
To: Juri Lelli <[email protected]>
To: Peter Zijlstra <[email protected]>
To: Ingo Molnar <[email protected]>

---
 kernel/sched/topology.c | 1 +
 1 file changed, 1 insertion(+)
kernel/sched/topology.c +0 -0
index 10d1391e7416..8b45f16a1890 100644

kernel/sched/topology.c static struct cpumask ***sched_domains_numa_masks; · line 1557

Quoted 4 lines
kernel/sched/topology.c +1 -0
@@ -1554,6 +1554,7 @@ static struct cpumask		***sched_domains_numa_masks;
  * function:
  *
  *   SD_SHARE_CPUCAPACITY   - describes SMT topologies
+ *   SD_CLUSTER             - describes CPU Cluster topologies

So I know this is the naming we've gone for the "Cluster" naming, but this comment isn't really explaining anything.

Quoted 9 lines
Quoted 2 lines

include/linux/sched/sd_flags.h has a bit more info already:
* Domain members share CPU cluster (LLC tags or L2 cache)

I also thought of this, but I didn't want to suggest to repeat in topolog.c what is described in sd_flags.h.

Maybe it is better to remove the descriptions of all flags here and instead direct the reader to sd_flags.h?

Yeah I agree on less duplication.

Quoted 9 lines
Quoted 5 lines

I had to go through a bit of git history to remember what the CLUSTER thing was about, how about this:

* SD_CLUSTER - describes shared shared caches, cache tags or busses

AFAIK, this describes a subset of CPUs in the package that share a resource, likely L2 cache.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

* SD_SHARE_PKG_RESOURCES - describes shared LLC cache

And looking at this it would make sense to:
rename SD_CLUSTER into SD_SHARE_PKG_RESOURCES

but not all CPUs in the package share the resource

But SD_CLUSTER never expands beyond the package, right?

Correct.

Quoted 4 lines

Regardless, my main point is that having both SD_CLUSTER and SD_SHARE_PKG_RESOURCES is a source of confusion (at the very least for myself),

Agreed!

Quoted 3 lines

and given SD_SHARE_PKG_RESOURCES is really used to mean "shares LLC" (see update_top_cache_domain()), we could make that flag more explicit and lift some ambiguity with SD_CLUSTER.

Quoted 5 lines

As Yicong stated, cluster topology should mean CPUs beyond SMT that share some resource but not LLC.

It makes sense to me to keep SD_CLUSTER name as it is today and rename SD_SHARE_PKG_RESOURCES as SD_SHARE_LLC.

yes, agree with his.

#15 lore raw
In reply to Ricardo Neri
Quoted 90 lines · Ricardo Neri
Quoted 39 lines · kuiliang Shi
Quoted 36 lines · Ricardo Neri
Quoted 34 lines · Valentin Schneider

Subject nit: the prefix should be sched/topology

Quoted 20 lines · On 01/02/24 19:54, [email protected] wrote:

From: Alex Shi <[email protected]>

The description of SD_CLUSTER is missing. Add it.

To: Ricardo Neri <[email protected]>
To: Valentin Schneider <[email protected]>
To: Vincent Guittot <[email protected]>
To: Juri Lelli <[email protected]>
To: Peter Zijlstra <[email protected]>
To: Ingo Molnar <[email protected]>

---
 kernel/sched/topology.c | 1 +
 1 file changed, 1 insertion(+)
kernel/sched/topology.c +0 -0
index 10d1391e7416..8b45f16a1890 100644

kernel/sched/topology.c static struct cpumask ***sched_domains_numa_masks; · line 1557

Quoted 4 lines
kernel/sched/topology.c +1 -0
@@ -1554,6 +1554,7 @@ static struct cpumask		***sched_domains_numa_masks;
  * function:
  *
  *   SD_SHARE_CPUCAPACITY   - describes SMT topologies
+ *   SD_CLUSTER             - describes CPU Cluster topologies

So I know this is the naming we've gone for the "Cluster" naming, but this comment isn't really explaining anything.

include/linux/sched/sd_flags.h has a bit more info already:
* Domain members share CPU cluster (LLC tags or L2 cache)

Quoted 8 lines
Quoted 5 lines

I also thought of this, but I didn't want to suggest to repeat in topolog.c what is described in sd_flags.h.

Maybe it is better to remove the descriptions of all flags here and instead direct the reader to sd_flags.h?

yes, good idea for getting their meaning directly from the header file. So is it fine for next sending?

Some tweaks below.

Quoted 2 lines

sched/fair: remove duplicate comments for SD_ flags

sched/topology: Remove duplicate descriptions from TOPOLOGY_SD_FLAGS

Quoted 4 lines

Originally, it missed SD_CLUSTER flag description, but comparing to copy the flags meaning from sd_flags.h, reader is better to get info from there.

These flags are already documented in include/linux/sched/sd_flags.h.

Keep the comment on SD_ASYM_PACKING as it is a special case.

Quoted 16 lines

Keep SD_ASYM_PACKING unchange for a point from another way.

To: Ricardo Neri <[email protected]>
To: Valentin Schneider <[email protected]>
To: Vincent Guittot <[email protected]>
To: Juri Lelli <[email protected]>
To: Peter Zijlstra <[email protected]>
To: Ingo Molnar <[email protected]>

kernel/sched/topology.c +0 -0
index 10d1391e7416..96a24bf954ad 100644

kernel/sched/topology.c static struct cpumask ***sched_domains_numa_masks; · line 1558

Quoted 8 lines
kernel/sched/topology.c +0 -5
@@ -1551,11 +1551,7 @@ static struct cpumask            ***sched_domains_numa_masks;
  *
  * These flags are purely descriptive of the topology and do not prescribe
  * behaviour. Behaviour is artificial and mapped in the below sd_init()
- * function:
- *
- *   SD_SHARE_CPUCAPACITY   - describes SMT topologies
- *   SD_SHARE_PKG_RESOURCES - describes shared caches
- *   SD_NUMA                - describes NUMA topologies

Maybe only remove the descriptions but keep the enumeration?

Quoted 4 lines

kernel/sched/topology.c static struct cpumask ***sched_domains_numa_masks; · line 1554

Quoted 1 line
kernel/sched/topology.c +1 -0
+ * function, for details in include/linux/sched/sd_flags.h:

function. For details, see include/linux/sched/sd_flags.h.

Thanks for comments. will update in next version.

Quoted 1 line