@@ -6774,10 +6774,36 @@ static struct root_domain *alloc_rootdomain(void)
67746774 return rd ;
67756775}
67766776
6777+ static void free_sched_groups (struct sched_group * sg , int free_sgp )
6778+ {
6779+ struct sched_group * tmp , * first ;
6780+
6781+ if (!sg )
6782+ return ;
6783+
6784+ first = sg ;
6785+ do {
6786+ tmp = sg -> next ;
6787+
6788+ if (free_sgp && atomic_dec_and_test (& sg -> sgp -> ref ))
6789+ kfree (sg -> sgp );
6790+
6791+ kfree (sg );
6792+ sg = tmp ;
6793+ } while (sg != first );
6794+ }
6795+
67776796static void free_sched_domain (struct rcu_head * rcu )
67786797{
67796798 struct sched_domain * sd = container_of (rcu , struct sched_domain , rcu );
6780- if (atomic_dec_and_test (& sd -> groups -> ref )) {
6799+
6800+ /*
6801+ * If its an overlapping domain it has private groups, iterate and
6802+ * nuke them all.
6803+ */
6804+ if (sd -> flags & SD_OVERLAP ) {
6805+ free_sched_groups (sd -> groups , 1 );
6806+ } else if (atomic_dec_and_test (& sd -> groups -> ref )) {
67816807 kfree (sd -> groups -> sgp );
67826808 kfree (sd -> groups );
67836809 }
@@ -6967,15 +6993,73 @@ struct sched_domain_topology_level;
69676993typedef struct sched_domain * (* sched_domain_init_f )(struct sched_domain_topology_level * tl , int cpu );
69686994typedef const struct cpumask * (* sched_domain_mask_f )(int cpu );
69696995
6996+ #define SDTL_OVERLAP 0x01
6997+
69706998struct sched_domain_topology_level {
69716999 sched_domain_init_f init ;
69727000 sched_domain_mask_f mask ;
7001+ int flags ;
69737002 struct sd_data data ;
69747003};
69757004
6976- /*
6977- * Assumes the sched_domain tree is fully constructed
6978- */
7005+ static int
7006+ build_overlap_sched_groups (struct sched_domain * sd , int cpu )
7007+ {
7008+ struct sched_group * first = NULL , * last = NULL , * groups = NULL , * sg ;
7009+ const struct cpumask * span = sched_domain_span (sd );
7010+ struct cpumask * covered = sched_domains_tmpmask ;
7011+ struct sd_data * sdd = sd -> private ;
7012+ struct sched_domain * child ;
7013+ int i ;
7014+
7015+ cpumask_clear (covered );
7016+
7017+ for_each_cpu (i , span ) {
7018+ struct cpumask * sg_span ;
7019+
7020+ if (cpumask_test_cpu (i , covered ))
7021+ continue ;
7022+
7023+ sg = kzalloc_node (sizeof (struct sched_group ) + cpumask_size (),
7024+ GFP_KERNEL , cpu_to_node (i ));
7025+
7026+ if (!sg )
7027+ goto fail ;
7028+
7029+ sg_span = sched_group_cpus (sg );
7030+
7031+ child = * per_cpu_ptr (sdd -> sd , i );
7032+ if (child -> child ) {
7033+ child = child -> child ;
7034+ cpumask_copy (sg_span , sched_domain_span (child ));
7035+ } else
7036+ cpumask_set_cpu (i , sg_span );
7037+
7038+ cpumask_or (covered , covered , sg_span );
7039+
7040+ sg -> sgp = * per_cpu_ptr (sdd -> sgp , cpumask_first (sg_span ));
7041+ atomic_inc (& sg -> sgp -> ref );
7042+
7043+ if (cpumask_test_cpu (cpu , sg_span ))
7044+ groups = sg ;
7045+
7046+ if (!first )
7047+ first = sg ;
7048+ if (last )
7049+ last -> next = sg ;
7050+ last = sg ;
7051+ last -> next = first ;
7052+ }
7053+ sd -> groups = groups ;
7054+
7055+ return 0 ;
7056+
7057+ fail :
7058+ free_sched_groups (first , 0 );
7059+
7060+ return - ENOMEM ;
7061+ }
7062+
69797063static int get_group (int cpu , struct sd_data * sdd , struct sched_group * * sg )
69807064{
69817065 struct sched_domain * sd = * per_cpu_ptr (sdd -> sd , cpu );
@@ -6987,30 +7071,34 @@ static int get_group(int cpu, struct sd_data *sdd, struct sched_group **sg)
69877071 if (sg ) {
69887072 * sg = * per_cpu_ptr (sdd -> sg , cpu );
69897073 (* sg )-> sgp = * per_cpu_ptr (sdd -> sgp , cpu );
7074+ atomic_set (& (* sg )-> sgp -> ref , 1 ); /* for claim_allocations */
69907075 }
69917076
69927077 return cpu ;
69937078}
69947079
69957080/*
6996- * build_sched_groups takes the cpumask we wish to span, and a pointer
6997- * to a function which identifies what group(along with sched group) a CPU
6998- * belongs to. The return value of group_fn must be a >= 0 and < nr_cpu_ids
6999- * (due to the fact that we keep track of groups covered with a struct cpumask).
7000- *
70017081 * build_sched_groups will build a circular linked list of the groups
70027082 * covered by the given span, and will set each group's ->cpumask correctly,
70037083 * and ->cpu_power to 0.
7084+ *
7085+ * Assumes the sched_domain tree is fully constructed
70047086 */
7005- static void
7006- build_sched_groups (struct sched_domain * sd )
7087+ static int
7088+ build_sched_groups (struct sched_domain * sd , int cpu )
70077089{
70087090 struct sched_group * first = NULL , * last = NULL ;
70097091 struct sd_data * sdd = sd -> private ;
70107092 const struct cpumask * span = sched_domain_span (sd );
70117093 struct cpumask * covered ;
70127094 int i ;
70137095
7096+ get_group (cpu , sdd , & sd -> groups );
7097+ atomic_inc (& sd -> groups -> ref );
7098+
7099+ if (cpu != cpumask_first (sched_domain_span (sd )))
7100+ return 0 ;
7101+
70147102 lockdep_assert_held (& sched_domains_mutex );
70157103 covered = sched_domains_tmpmask ;
70167104
@@ -7042,6 +7130,8 @@ build_sched_groups(struct sched_domain *sd)
70427130 last = sg ;
70437131 }
70447132 last -> next = first ;
7133+
7134+ return 0 ;
70457135}
70467136
70477137/*
@@ -7056,12 +7146,17 @@ build_sched_groups(struct sched_domain *sd)
70567146 */
70577147static void init_sched_groups_power (int cpu , struct sched_domain * sd )
70587148{
7059- WARN_ON (! sd || ! sd -> groups ) ;
7149+ struct sched_group * sg = sd -> groups ;
70607150
7061- if (cpu != group_first_cpu (sd -> groups ))
7062- return ;
7151+ WARN_ON (!sd || !sg );
7152+
7153+ do {
7154+ sg -> group_weight = cpumask_weight (sched_group_cpus (sg ));
7155+ sg = sg -> next ;
7156+ } while (sg != sd -> groups );
70637157
7064- sd -> groups -> group_weight = cpumask_weight (sched_group_cpus (sd -> groups ));
7158+ if (cpu != group_first_cpu (sg ))
7159+ return ;
70657160
70667161 update_group_power (sd , cpu );
70677162}
@@ -7182,16 +7277,15 @@ static enum s_alloc __visit_domain_allocation_hell(struct s_data *d,
71827277static void claim_allocations (int cpu , struct sched_domain * sd )
71837278{
71847279 struct sd_data * sdd = sd -> private ;
7185- struct sched_group * sg = sd -> groups ;
71867280
71877281 WARN_ON_ONCE (* per_cpu_ptr (sdd -> sd , cpu ) != sd );
71887282 * per_cpu_ptr (sdd -> sd , cpu ) = NULL ;
71897283
7190- if (cpu == cpumask_first (sched_group_cpus (sg ))) {
7191- WARN_ON_ONCE (* per_cpu_ptr (sdd -> sg , cpu ) != sg );
7284+ if (atomic_read (& (* per_cpu_ptr (sdd -> sg , cpu ))-> ref ))
71927285 * per_cpu_ptr (sdd -> sg , cpu ) = NULL ;
7286+
7287+ if (atomic_read (& (* per_cpu_ptr (sdd -> sgp , cpu ))-> ref ))
71937288 * per_cpu_ptr (sdd -> sgp , cpu ) = NULL ;
7194- }
71957289}
71967290
71977291#ifdef CONFIG_SCHED_SMT
@@ -7216,7 +7310,7 @@ static struct sched_domain_topology_level default_topology[] = {
72167310#endif
72177311 { sd_init_CPU , cpu_cpu_mask , },
72187312#ifdef CONFIG_NUMA
7219- { sd_init_NODE , cpu_node_mask , },
7313+ { sd_init_NODE , cpu_node_mask , SDTL_OVERLAP , },
72207314 { sd_init_ALLNODES , cpu_allnodes_mask , },
72217315#endif
72227316 { NULL , },
@@ -7284,7 +7378,9 @@ static void __sdt_free(const struct cpumask *cpu_map)
72847378 struct sd_data * sdd = & tl -> data ;
72857379
72867380 for_each_cpu (j , cpu_map ) {
7287- kfree (* per_cpu_ptr (sdd -> sd , j ));
7381+ struct sched_domain * sd = * per_cpu_ptr (sdd -> sd , j );
7382+ if (sd && (sd -> flags & SD_OVERLAP ))
7383+ free_sched_groups (sd -> groups , 0 );
72887384 kfree (* per_cpu_ptr (sdd -> sg , j ));
72897385 kfree (* per_cpu_ptr (sdd -> sgp , j ));
72907386 }
@@ -7336,8 +7432,11 @@ static int build_sched_domains(const struct cpumask *cpu_map,
73367432 struct sched_domain_topology_level * tl ;
73377433
73387434 sd = NULL ;
7339- for (tl = sched_domain_topology ; tl -> init ; tl ++ )
7435+ for (tl = sched_domain_topology ; tl -> init ; tl ++ ) {
73407436 sd = build_sched_domain (tl , & d , cpu_map , attr , sd , i );
7437+ if (tl -> flags & SDTL_OVERLAP || sched_feat (FORCE_SD_OVERLAP ))
7438+ sd -> flags |= SD_OVERLAP ;
7439+ }
73417440
73427441 while (sd -> child )
73437442 sd = sd -> child ;
@@ -7349,13 +7448,13 @@ static int build_sched_domains(const struct cpumask *cpu_map,
73497448 for_each_cpu (i , cpu_map ) {
73507449 for (sd = * per_cpu_ptr (d .sd , i ); sd ; sd = sd -> parent ) {
73517450 sd -> span_weight = cpumask_weight (sched_domain_span (sd ));
7352- get_group ( i , sd -> private , & sd -> groups );
7353- atomic_inc ( & sd -> groups -> ref );
7354-
7355- if ( i != cpumask_first ( sched_domain_span ( sd )))
7356- continue ;
7357-
7358- build_sched_groups ( sd );
7451+ if ( sd -> flags & SD_OVERLAP ) {
7452+ if ( build_overlap_sched_groups ( sd , i ))
7453+ goto error ;
7454+ } else {
7455+ if ( build_sched_groups ( sd , i ))
7456+ goto error ;
7457+ }
73597458 }
73607459 }
73617460
0 commit comments