diff mbox series

[v7,1/7] sched/topology: Adding function partition_sched_domains_locked()

Message ID 20190403084650.4414-2-juri.lelli@redhat.com
State Superseded
Headers show
Series [v7,1/7] sched/topology: Adding function partition_sched_domains_locked() | expand

Commit Message

Juri Lelli April 3, 2019, 8:46 a.m. UTC
From: Mathieu Poirier <mathieu.poirier@linaro.org>


Introducing function partition_sched_domains_locked() by taking
the mutex locking code out of the original function.  That way
the work done by partition_sched_domains_locked() can be reused
without dropping the mutex lock.

No change of functionality is introduced by this patch.

Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>

Acked-by: Tejun Heo <tj@kernel.org>

---
 include/linux/sched/topology.h | 10 ++++++++++
 kernel/sched/topology.c        | 17 +++++++++++++----
 2 files changed, 23 insertions(+), 4 deletions(-)

-- 
2.17.2

Comments

Peter Zijlstra April 5, 2019, 12:04 p.m. UTC | #1
On Wed, Apr 03, 2019 at 10:46:44AM +0200, Juri Lelli wrote:
> +/*

> + * Call with hotplug lock held


Is that spelled like:

	lockdep_assert_cpus_held();

?

> + */

> +void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[],

> +			     struct sched_domain_attr *dattr_new)

> +{

> +	mutex_lock(&sched_domains_mutex);

> +	partition_sched_domains_locked(ndoms_new, doms_new, dattr_new);

>  	mutex_unlock(&sched_domains_mutex);

>  }

> -- 

> 2.17.2

>
Juri Lelli April 5, 2019, 12:52 p.m. UTC | #2
Hi,

On 05/04/19 14:04, Peter Zijlstra wrote:
> On Wed, Apr 03, 2019 at 10:46:44AM +0200, Juri Lelli wrote:

> > +/*

> > + * Call with hotplug lock held

> 

> Is that spelled like:

> 

> 	lockdep_assert_cpus_held();

> 

> ?


Indeed, but I had that in previous versions and we removed that in v5
because it can lead to false positives [1,2]. IIRC, problem has to do
with hotplug and the fact that rebuilding from hotplug runs the
callbacks on the newly onlined CPU, not the task that acquired the lock.

Best,

- Juri

1 - https://lore.kernel.org/lkml/20180903142801.20046-1-juri.lelli@redhat.com/
2 - https://lore.kernel.org/lkml/20180613121711.5018-2-juri.lelli@redhat.com/
diff mbox series

Patch

diff --git a/include/linux/sched/topology.h b/include/linux/sched/topology.h
index 57c7ed3fe465..e7db602e898c 100644
--- a/include/linux/sched/topology.h
+++ b/include/linux/sched/topology.h
@@ -161,6 +161,10 @@  static inline struct cpumask *sched_domain_span(struct sched_domain *sd)
 	return to_cpumask(sd->span);
 }
 
+extern void partition_sched_domains_locked(int ndoms_new,
+					   cpumask_var_t doms_new[],
+					   struct sched_domain_attr *dattr_new);
+
 extern void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[],
 				    struct sched_domain_attr *dattr_new);
 
@@ -213,6 +217,12 @@  unsigned long arch_scale_cpu_capacity(struct sched_domain *sd, int cpu)
 
 struct sched_domain_attr;
 
+static inline void
+partition_sched_domains_locked(int ndoms_new, cpumask_var_t doms_new[],
+			       struct sched_domain_attr *dattr_new)
+{
+}
+
 static inline void
 partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[],
 			struct sched_domain_attr *dattr_new)
diff --git a/kernel/sched/topology.c b/kernel/sched/topology.c
index ab7f371a3a17..b63ac11d0831 100644
--- a/kernel/sched/topology.c
+++ b/kernel/sched/topology.c
@@ -2154,16 +2154,16 @@  static int dattrs_equal(struct sched_domain_attr *cur, int idx_cur,
  * ndoms_new == 0 is a special case for destroying existing domains,
  * and it will not create the default domain.
  *
- * Call with hotplug lock held
+ * Call with hotplug lock and sched_domains_mutex held
  */
-void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[],
-			     struct sched_domain_attr *dattr_new)
+void partition_sched_domains_locked(int ndoms_new, cpumask_var_t doms_new[],
+				    struct sched_domain_attr *dattr_new)
 {
 	bool __maybe_unused has_eas = false;
 	int i, j, n;
 	int new_topology;
 
-	mutex_lock(&sched_domains_mutex);
+	lockdep_assert_held(&sched_domains_mutex);
 
 	/* Always unregister in case we don't destroy any domains: */
 	unregister_sched_domain_sysctl();
@@ -2246,6 +2246,15 @@  void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[],
 	ndoms_cur = ndoms_new;
 
 	register_sched_domain_sysctl();
+}
 
+/*
+ * Call with hotplug lock held
+ */
+void partition_sched_domains(int ndoms_new, cpumask_var_t doms_new[],
+			     struct sched_domain_attr *dattr_new)
+{
+	mutex_lock(&sched_domains_mutex);
+	partition_sched_domains_locked(ndoms_new, doms_new, dattr_new);
 	mutex_unlock(&sched_domains_mutex);
 }