All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH  1/1] cpu-hotplug: export cpu_hotplug_enable/cpu_hotplug_disable
@ 2015-06-22  2:56 K. Y. Srinivasan
  2015-06-23 16:57 ` KY Srinivasan
  0 siblings, 1 reply; 8+ messages in thread
From: K. Y. Srinivasan @ 2015-06-22  2:56 UTC (permalink / raw)
  To: gregkh, linux-kernel, devel, mingo, peterz, rafael.j.wysocki, tglx
  Cc: Vitaly Kuznetsov, K. Y. Srinivasan

From: Vitaly Kuznetsov <vkuznets@redhat.com>

Loaded Hyper-V module will use these functions to disable CPU
hotplug under certain circumstances. Convert cpu_hotplug_disabled
to a counter (protected by cpu_add_remove_lock) to support e.g.
disable -> disable -> enable call sequences.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
---
 Documentation/power/suspend-and-cpuhotplug.txt |    6 +++---
 kernel/cpu.c                                   |   13 ++++++++-----
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/Documentation/power/suspend-and-cpuhotplug.txt b/Documentation/power/suspend-and-cpuhotplug.txt
index 2850df3..2fc9095 100644
--- a/Documentation/power/suspend-and-cpuhotplug.txt
+++ b/Documentation/power/suspend-and-cpuhotplug.txt
@@ -72,7 +72,7 @@ More details follow:
                                         |
                                         v
                            Disable regular cpu hotplug
-                        by setting cpu_hotplug_disabled=1
+                        by increasing cpu_hotplug_disabled
                                         |
                                         v
                             Release cpu_add_remove_lock
@@ -89,7 +89,7 @@ Resuming back is likewise, with the counterparts being (in the order of
 execution during resume):
 * enable_nonboot_cpus() which involves:
    |  Acquire cpu_add_remove_lock
-   |  Reset cpu_hotplug_disabled to 0, thereby enabling regular cpu hotplug
+   |  Decrease cpu_hotplug_disabled, thereby enabling regular cpu hotplug
    |  Call _cpu_up() [for all those cpus in the frozen_cpus mask, in a loop]
    |  Release cpu_add_remove_lock
    v
@@ -120,7 +120,7 @@ after the entire cycle is complete (i.e., suspend + resume).
                            Acquire cpu_add_remove_lock
                                         |
                                         v
-                          If cpu_hotplug_disabled is 1
+                          If cpu_hotplug_disabled > 0
                                 return gracefully
                                         |
                                         |
diff --git a/kernel/cpu.c b/kernel/cpu.c
index 94bbe46..8f35ee6 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -190,17 +190,19 @@ void cpu_hotplug_done(void)
 void cpu_hotplug_disable(void)
 {
 	cpu_maps_update_begin();
-	cpu_hotplug_disabled = 1;
+	cpu_hotplug_disabled++;
 	cpu_maps_update_done();
 }
+EXPORT_SYMBOL_GPL(cpu_hotplug_disable);
 
 void cpu_hotplug_enable(void)
 {
 	cpu_maps_update_begin();
-	cpu_hotplug_disabled = 0;
+	if (cpu_hotplug_disabled)
+		cpu_hotplug_disabled--;
 	cpu_maps_update_done();
 }
-
+EXPORT_SYMBOL_GPL(cpu_hotplug_enable);
 #endif	/* CONFIG_HOTPLUG_CPU */
 
 /* Need to know about CPUs going up/down? */
@@ -600,7 +602,7 @@ int disable_nonboot_cpus(void)
 	if (!error) {
 		BUG_ON(num_online_cpus() > 1);
 		/* Make sure the CPUs won't be enabled by someone else */
-		cpu_hotplug_disabled = 1;
+		cpu_hotplug_disabled++;
 	} else {
 		pr_err("Non-boot CPUs are not disabled\n");
 	}
@@ -622,7 +624,8 @@ void __ref enable_nonboot_cpus(void)
 
 	/* Allow everyone to use the CPU hotplug again */
 	cpu_maps_update_begin();
-	cpu_hotplug_disabled = 0;
+	if (cpu_hotplug_disabled)
+		cpu_hotplug_disabled--;
 	if (cpumask_empty(frozen_cpus))
 		goto out;
 
-- 
1.7.4.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
Please read the FAQ at  http://www.tux.org/lkml/

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* RE: [PATCH  1/1] cpu-hotplug: export cpu_hotplug_enable/cpu_hotplug_disable
  2015-06-22  2:56 [PATCH 1/1] cpu-hotplug: export cpu_hotplug_enable/cpu_hotplug_disable K. Y. Srinivasan
@ 2015-06-23 16:57 ` KY Srinivasan
  2015-06-23 18:13   ` Peter Zijlstra
  0 siblings, 1 reply; 8+ messages in thread
From: KY Srinivasan @ 2015-06-23 16:57 UTC (permalink / raw)
  To: KY Srinivasan, gregkh, linux-kernel, devel, mingo, peterz,
	rafael.j.wysocki, tglx
  Cc: Vitaly Kuznetsov



> -----Original Message-----
> From: K. Y. Srinivasan [mailto:kys@microsoft.com]
> Sent: Sunday, June 21, 2015 7:56 PM
> To: gregkh@linuxfoundation.org; linux-kernel@vger.kernel.org;
> devel@linuxdriverproject.org; mingo@kernel.org; peterz@infradead.org;
> rafael.j.wysocki@intel.com; tglx@linutronix.de
> Cc: Vitaly Kuznetsov; KY Srinivasan
> Subject: [PATCH 1/1] cpu-hotplug: export
> cpu_hotplug_enable/cpu_hotplug_disable
> 
> From: Vitaly Kuznetsov <vkuznets@redhat.com>
> 
> Loaded Hyper-V module will use these functions to disable CPU
> hotplug under certain circumstances. Convert cpu_hotplug_disabled
> to a counter (protected by cpu_add_remove_lock) to support e.g.
> disable -> disable -> enable call sequences.

Greg is willing to take this patch through his tree if gets an ack. Please provide your feedback.

Regards,

K. Y
> 
> Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> Signed-off-by: K. Y. Srinivasan <kys@microsoft.com>
> ---
>  Documentation/power/suspend-and-cpuhotplug.txt |    6 +++---
>  kernel/cpu.c                                   |   13 ++++++++-----
>  2 files changed, 11 insertions(+), 8 deletions(-)
> 
> diff --git a/Documentation/power/suspend-and-cpuhotplug.txt
> b/Documentation/power/suspend-and-cpuhotplug.txt
> index 2850df3..2fc9095 100644
> --- a/Documentation/power/suspend-and-cpuhotplug.txt
> +++ b/Documentation/power/suspend-and-cpuhotplug.txt
> @@ -72,7 +72,7 @@ More details follow:
>                                          |
>                                          v
>                             Disable regular cpu hotplug
> -                        by setting cpu_hotplug_disabled=1
> +                        by increasing cpu_hotplug_disabled
>                                          |
>                                          v
>                              Release cpu_add_remove_lock
> @@ -89,7 +89,7 @@ Resuming back is likewise, with the counterparts being
> (in the order of
>  execution during resume):
>  * enable_nonboot_cpus() which involves:
>     |  Acquire cpu_add_remove_lock
> -   |  Reset cpu_hotplug_disabled to 0, thereby enabling regular cpu hotplug
> +   |  Decrease cpu_hotplug_disabled, thereby enabling regular cpu hotplug
>     |  Call _cpu_up() [for all those cpus in the frozen_cpus mask, in a loop]
>     |  Release cpu_add_remove_lock
>     v
> @@ -120,7 +120,7 @@ after the entire cycle is complete (i.e., suspend +
> resume).
>                             Acquire cpu_add_remove_lock
>                                          |
>                                          v
> -                          If cpu_hotplug_disabled is 1
> +                          If cpu_hotplug_disabled > 0
>                                  return gracefully
>                                          |
>                                          |
> diff --git a/kernel/cpu.c b/kernel/cpu.c
> index 94bbe46..8f35ee6 100644
> --- a/kernel/cpu.c
> +++ b/kernel/cpu.c
> @@ -190,17 +190,19 @@ void cpu_hotplug_done(void)
>  void cpu_hotplug_disable(void)
>  {
>  	cpu_maps_update_begin();
> -	cpu_hotplug_disabled = 1;
> +	cpu_hotplug_disabled++;
>  	cpu_maps_update_done();
>  }
> +EXPORT_SYMBOL_GPL(cpu_hotplug_disable);
> 
>  void cpu_hotplug_enable(void)
>  {
>  	cpu_maps_update_begin();
> -	cpu_hotplug_disabled = 0;
> +	if (cpu_hotplug_disabled)
> +		cpu_hotplug_disabled--;
>  	cpu_maps_update_done();
>  }
> -
> +EXPORT_SYMBOL_GPL(cpu_hotplug_enable);
>  #endif	/* CONFIG_HOTPLUG_CPU */
> 
>  /* Need to know about CPUs going up/down? */
> @@ -600,7 +602,7 @@ int disable_nonboot_cpus(void)
>  	if (!error) {
>  		BUG_ON(num_online_cpus() > 1);
>  		/* Make sure the CPUs won't be enabled by someone else
> */
> -		cpu_hotplug_disabled = 1;
> +		cpu_hotplug_disabled++;
>  	} else {
>  		pr_err("Non-boot CPUs are not disabled\n");
>  	}
> @@ -622,7 +624,8 @@ void __ref enable_nonboot_cpus(void)
> 
>  	/* Allow everyone to use the CPU hotplug again */
>  	cpu_maps_update_begin();
> -	cpu_hotplug_disabled = 0;
> +	if (cpu_hotplug_disabled)
> +		cpu_hotplug_disabled--;
>  	if (cpumask_empty(frozen_cpus))
>  		goto out;
> 
> --
> 1.7.4.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH  1/1] cpu-hotplug: export cpu_hotplug_enable/cpu_hotplug_disable
  2015-06-23 16:57 ` KY Srinivasan
@ 2015-06-23 18:13   ` Peter Zijlstra
  2015-06-24  9:43     ` Vitaly Kuznetsov
  0 siblings, 1 reply; 8+ messages in thread
From: Peter Zijlstra @ 2015-06-23 18:13 UTC (permalink / raw)
  To: KY Srinivasan
  Cc: gregkh, linux-kernel, devel, mingo, rafael.j.wysocki, tglx,
	Vitaly Kuznetsov

On Tue, Jun 23, 2015 at 04:57:05PM +0000, KY Srinivasan wrote:

> > diff --git a/kernel/cpu.c b/kernel/cpu.c
> > index 94bbe46..8f35ee6 100644
> > --- a/kernel/cpu.c
> > +++ b/kernel/cpu.c
> > @@ -190,17 +190,19 @@ void cpu_hotplug_done(void)
> >  void cpu_hotplug_disable(void)
> >  {
> >  	cpu_maps_update_begin();
> > -	cpu_hotplug_disabled = 1;
> > +	cpu_hotplug_disabled++;
> >  	cpu_maps_update_done();
> >  }
> > +EXPORT_SYMBOL_GPL(cpu_hotplug_disable);
> > 
> >  void cpu_hotplug_enable(void)
> >  {
> >  	cpu_maps_update_begin();
> > -	cpu_hotplug_disabled = 0;
> > +	if (cpu_hotplug_disabled)
> > +		cpu_hotplug_disabled--;

No that just papers over bugs.

> >  	cpu_maps_update_done();
> >  }

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH  1/1] cpu-hotplug: export cpu_hotplug_enable/cpu_hotplug_disable
  2015-06-23 18:13   ` Peter Zijlstra
@ 2015-06-24  9:43     ` Vitaly Kuznetsov
  2015-06-24  9:54       ` Thomas Gleixner
  2015-06-24 10:27       ` Peter Zijlstra
  0 siblings, 2 replies; 8+ messages in thread
From: Vitaly Kuznetsov @ 2015-06-24  9:43 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: KY Srinivasan, gregkh, linux-kernel, devel, mingo,
	rafael.j.wysocki, tglx

Peter Zijlstra <peterz@infradead.org> writes:

> On Tue, Jun 23, 2015 at 04:57:05PM +0000, KY Srinivasan wrote:
>
>> > diff --git a/kernel/cpu.c b/kernel/cpu.c
>> > index 94bbe46..8f35ee6 100644
>> > --- a/kernel/cpu.c
>> > +++ b/kernel/cpu.c
>> > @@ -190,17 +190,19 @@ void cpu_hotplug_done(void)
>> >  void cpu_hotplug_disable(void)
>> >  {
>> >  	cpu_maps_update_begin();
>> > -	cpu_hotplug_disabled = 1;
>> > +	cpu_hotplug_disabled++;
>> >  	cpu_maps_update_done();
>> >  }
>> > +EXPORT_SYMBOL_GPL(cpu_hotplug_disable);
>> > 
>> >  void cpu_hotplug_enable(void)
>> >  {
>> >  	cpu_maps_update_begin();
>> > -	cpu_hotplug_disabled = 0;
>> > +	if (cpu_hotplug_disabled)
>> > +		cpu_hotplug_disabled--;
>
> No that just papers over bugs.
>

Yes, but these bugs are not in Linux. I don't see any other way for a
platform to enable/disable cpu hotplug in runtime.

-- 
  Vitaly

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/1] cpu-hotplug: export cpu_hotplug_enable/cpu_hotplug_disable
  2015-06-24  9:43     ` Vitaly Kuznetsov
@ 2015-06-24  9:54       ` Thomas Gleixner
  2015-06-24 11:11         ` Vitaly Kuznetsov
  2015-06-24 10:27       ` Peter Zijlstra
  1 sibling, 1 reply; 8+ messages in thread
From: Thomas Gleixner @ 2015-06-24  9:54 UTC (permalink / raw)
  To: Vitaly Kuznetsov
  Cc: Peter Zijlstra, KY Srinivasan, gregkh, linux-kernel, devel,
	mingo, rafael.j.wysocki

On Wed, 24 Jun 2015, Vitaly Kuznetsov wrote:

> Peter Zijlstra <peterz@infradead.org> writes:
> 
> > On Tue, Jun 23, 2015 at 04:57:05PM +0000, KY Srinivasan wrote:
> >
> >> > diff --git a/kernel/cpu.c b/kernel/cpu.c
> >> > index 94bbe46..8f35ee6 100644
> >> > --- a/kernel/cpu.c
> >> > +++ b/kernel/cpu.c
> >> > @@ -190,17 +190,19 @@ void cpu_hotplug_done(void)
> >> >  void cpu_hotplug_disable(void)
> >> >  {
> >> >  	cpu_maps_update_begin();
> >> > -	cpu_hotplug_disabled = 1;
> >> > +	cpu_hotplug_disabled++;
> >> >  	cpu_maps_update_done();
> >> >  }
> >> > +EXPORT_SYMBOL_GPL(cpu_hotplug_disable);
> >> > 
> >> >  void cpu_hotplug_enable(void)
> >> >  {
> >> >  	cpu_maps_update_begin();
> >> > -	cpu_hotplug_disabled = 0;
> >> > +	if (cpu_hotplug_disabled)
> >> > +		cpu_hotplug_disabled--;
> >
> > No that just papers over bugs.
> >
> 
> Yes, but these bugs are not in Linux. I don't see any other way for a
> platform to enable/disable cpu hotplug in runtime.

What? cpu_hotplug_disable()/enable() do that today. They just do not
support recursion and we have not yet seen any argument WHY that's
required at all.

Thanks,

	tglx

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH  1/1] cpu-hotplug: export cpu_hotplug_enable/cpu_hotplug_disable
  2015-06-24  9:43     ` Vitaly Kuznetsov
  2015-06-24  9:54       ` Thomas Gleixner
@ 2015-06-24 10:27       ` Peter Zijlstra
  2015-06-24 11:14         ` Vitaly Kuznetsov
  1 sibling, 1 reply; 8+ messages in thread
From: Peter Zijlstra @ 2015-06-24 10:27 UTC (permalink / raw)
  To: Vitaly Kuznetsov
  Cc: KY Srinivasan, gregkh, linux-kernel, devel, mingo,
	rafael.j.wysocki, tglx

On Wed, Jun 24, 2015 at 11:43:33AM +0200, Vitaly Kuznetsov wrote:
> Peter Zijlstra <peterz@infradead.org> writes:
> > On Tue, Jun 23, 2015 at 04:57:05PM +0000, KY Srinivasan wrote:
> >
> >> > diff --git a/kernel/cpu.c b/kernel/cpu.c
> >> > index 94bbe46..8f35ee6 100644
> >> > --- a/kernel/cpu.c
> >> > +++ b/kernel/cpu.c
> >> > @@ -190,17 +190,19 @@ void cpu_hotplug_done(void)
> >> >  void cpu_hotplug_disable(void)
> >> >  {
> >> >  	cpu_maps_update_begin();
> >> > -	cpu_hotplug_disabled = 1;
> >> > +	cpu_hotplug_disabled++;
> >> >  	cpu_maps_update_done();
> >> >  }
> >> > +EXPORT_SYMBOL_GPL(cpu_hotplug_disable);
> >> > 
> >> >  void cpu_hotplug_enable(void)
> >> >  {
> >> >  	cpu_maps_update_begin();
> >> > -	cpu_hotplug_disabled = 0;
> >> > +	if (cpu_hotplug_disabled)
> >> > +		cpu_hotplug_disabled--;
> >
> > No that just papers over bugs.
> 
> Yes, but these bugs are not in Linux. I don't see any other way for a
> platform to enable/disable cpu hotplug in runtime.

Any code using this had better be open source, if not I really don't
care anyway.

That really ought to be:

	WARN_ON(--cpu_hotplug_disabled < 0);

You do not make underflows go away.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/1] cpu-hotplug: export cpu_hotplug_enable/cpu_hotplug_disable
  2015-06-24  9:54       ` Thomas Gleixner
@ 2015-06-24 11:11         ` Vitaly Kuznetsov
  0 siblings, 0 replies; 8+ messages in thread
From: Vitaly Kuznetsov @ 2015-06-24 11:11 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Peter Zijlstra, KY Srinivasan, gregkh, linux-kernel, devel,
	mingo, rafael.j.wysocki

Thomas Gleixner <tglx@linutronix.de> writes:

> On Wed, 24 Jun 2015, Vitaly Kuznetsov wrote:
>
>> Peter Zijlstra <peterz@infradead.org> writes:
>> 
>> > On Tue, Jun 23, 2015 at 04:57:05PM +0000, KY Srinivasan wrote:
>> >
>> >> > diff --git a/kernel/cpu.c b/kernel/cpu.c
>> >> > index 94bbe46..8f35ee6 100644
>> >> > --- a/kernel/cpu.c
>> >> > +++ b/kernel/cpu.c
>> >> > @@ -190,17 +190,19 @@ void cpu_hotplug_done(void)
>> >> >  void cpu_hotplug_disable(void)
>> >> >  {
>> >> >  	cpu_maps_update_begin();
>> >> > -	cpu_hotplug_disabled = 1;
>> >> > +	cpu_hotplug_disabled++;
>> >> >  	cpu_maps_update_done();
>> >> >  }
>> >> > +EXPORT_SYMBOL_GPL(cpu_hotplug_disable);
>> >> > 
>> >> >  void cpu_hotplug_enable(void)
>> >> >  {
>> >> >  	cpu_maps_update_begin();
>> >> > -	cpu_hotplug_disabled = 0;
>> >> > +	if (cpu_hotplug_disabled)
>> >> > +		cpu_hotplug_disabled--;
>> >
>> > No that just papers over bugs.
>> >
>> 
>> Yes, but these bugs are not in Linux. I don't see any other way for a
>> platform to enable/disable cpu hotplug in runtime.
>
> What? cpu_hotplug_disable()/enable() do that today. They just do not
> support recursion and we have not yet seen any argument WHY that's
> required at all.

They do, my patch just exports them. Despite the fact that I have no
specific usecase in my mind at this time I still see a theoretical
possibility of this being useful - when two pieces of code are trying to
enable/disable cpu hotplug simultaneously. Without making
cpu_hotplug_disabled a counter disable->disable->enable sequence will
lead to cpu hotplug being enabled.

-- 
  Vitaly

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH  1/1] cpu-hotplug: export cpu_hotplug_enable/cpu_hotplug_disable
  2015-06-24 10:27       ` Peter Zijlstra
@ 2015-06-24 11:14         ` Vitaly Kuznetsov
  0 siblings, 0 replies; 8+ messages in thread
From: Vitaly Kuznetsov @ 2015-06-24 11:14 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: KY Srinivasan, gregkh, linux-kernel, devel, mingo,
	rafael.j.wysocki, tglx

Peter Zijlstra <peterz@infradead.org> writes:

> On Wed, Jun 24, 2015 at 11:43:33AM +0200, Vitaly Kuznetsov wrote:
>> Peter Zijlstra <peterz@infradead.org> writes:
>> > On Tue, Jun 23, 2015 at 04:57:05PM +0000, KY Srinivasan wrote:
>> >
>> >> > diff --git a/kernel/cpu.c b/kernel/cpu.c
>> >> > index 94bbe46..8f35ee6 100644
>> >> > --- a/kernel/cpu.c
>> >> > +++ b/kernel/cpu.c
>> >> > @@ -190,17 +190,19 @@ void cpu_hotplug_done(void)
>> >> >  void cpu_hotplug_disable(void)
>> >> >  {
>> >> >  	cpu_maps_update_begin();
>> >> > -	cpu_hotplug_disabled = 1;
>> >> > +	cpu_hotplug_disabled++;
>> >> >  	cpu_maps_update_done();
>> >> >  }
>> >> > +EXPORT_SYMBOL_GPL(cpu_hotplug_disable);
>> >> > 
>> >> >  void cpu_hotplug_enable(void)
>> >> >  {
>> >> >  	cpu_maps_update_begin();
>> >> > -	cpu_hotplug_disabled = 0;
>> >> > +	if (cpu_hotplug_disabled)
>> >> > +		cpu_hotplug_disabled--;
>> >
>> > No that just papers over bugs.
>> 
>> Yes, but these bugs are not in Linux. I don't see any other way for a
>> platform to enable/disable cpu hotplug in runtime.
>
> Any code using this had better be open source, if not I really don't
> care anyway.
>
> That really ought to be:
>
> 	WARN_ON(--cpu_hotplug_disabled < 0);
>
> You do not make underflows go away.

Sorry, I was under an impression you were referring to the patch as a
whole :-) Yes, I agree, let's add this WARN_ON().

-- 
  Vitaly

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-06-24 11:14 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-22  2:56 [PATCH 1/1] cpu-hotplug: export cpu_hotplug_enable/cpu_hotplug_disable K. Y. Srinivasan
2015-06-23 16:57 ` KY Srinivasan
2015-06-23 18:13   ` Peter Zijlstra
2015-06-24  9:43     ` Vitaly Kuznetsov
2015-06-24  9:54       ` Thomas Gleixner
2015-06-24 11:11         ` Vitaly Kuznetsov
2015-06-24 10:27       ` Peter Zijlstra
2015-06-24 11:14         ` Vitaly Kuznetsov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.