linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cpuidle: powernv/pseries: Decrease the snooze residency
@ 2015-05-29 12:32 Shilpasri G Bhat
  2015-05-29 13:47 ` Preeti U Murthy
  0 siblings, 1 reply; 6+ messages in thread
From: Shilpasri G Bhat @ 2015-05-29 12:32 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: anton, rjw, preeti, Daniel Lezcano, linux-kernel, linux-pm,
	Shilpasri G Bhat

The idle cpus which stay in snooze for a long period can degrade the
perfomance of the sibling cpus. If the cpu stays in snooze for more
than target residency of the next available idle state, then exit from
snooze. This gives a chance to the cpuidle governor to re-evaluate the
last idle state of the cpu to promote it to deeper idle states.

Signed-off-by: Shilpasri G Bhat <shilpa.bhat@linux.vnet.ibm.com>
---
 drivers/cpuidle/cpuidle-powernv.c | 12 ++++++++++++
 drivers/cpuidle/cpuidle-pseries.c | 11 +++++++++++
 2 files changed, 23 insertions(+)

diff --git a/drivers/cpuidle/cpuidle-powernv.c b/drivers/cpuidle/cpuidle-powernv.c
index 5937207..1e3ef5e 100644
--- a/drivers/cpuidle/cpuidle-powernv.c
+++ b/drivers/cpuidle/cpuidle-powernv.c
@@ -29,18 +29,25 @@ struct cpuidle_driver powernv_idle_driver = {
 
 static int max_idle_state;
 static struct cpuidle_state *cpuidle_state_table;
+static u64 snooze_timeout;
+static bool snooze_timeout_en;
 
 static int snooze_loop(struct cpuidle_device *dev,
 			struct cpuidle_driver *drv,
 			int index)
 {
+	u64 snooze_exit_time;
+
 	local_irq_enable();
 	set_thread_flag(TIF_POLLING_NRFLAG);
 
+	snooze_exit_time = get_tb() + snooze_timeout;
 	ppc64_runlatch_off();
 	while (!need_resched()) {
 		HMT_low();
 		HMT_very_low();
+		if (snooze_timeout_en && get_tb() > snooze_exit_time)
+			break;
 	}
 
 	HMT_medium();
@@ -252,6 +259,11 @@ static int powernv_idle_probe(void)
 		cpuidle_state_table = powernv_states;
 		/* Device tree can indicate more idle states */
 		max_idle_state = powernv_add_idle_states();
+		if (max_idle_state > 1) {
+			snooze_timeout_en = true;
+			snooze_timeout = powernv_states[1].target_residency *
+					 tb_ticks_per_usec;
+		}
  	} else
  		return -ENODEV;
 
diff --git a/drivers/cpuidle/cpuidle-pseries.c b/drivers/cpuidle/cpuidle-pseries.c
index bb9e2b6..07135e0 100644
--- a/drivers/cpuidle/cpuidle-pseries.c
+++ b/drivers/cpuidle/cpuidle-pseries.c
@@ -27,6 +27,8 @@ struct cpuidle_driver pseries_idle_driver = {
 
 static int max_idle_state;
 static struct cpuidle_state *cpuidle_state_table;
+static u64 snooze_timeout;
+static bool snooze_timeout_en;
 
 static inline void idle_loop_prolog(unsigned long *in_purr)
 {
@@ -58,14 +60,18 @@ static int snooze_loop(struct cpuidle_device *dev,
 			int index)
 {
 	unsigned long in_purr;
+	u64 snooze_exit_time;
 
 	idle_loop_prolog(&in_purr);
 	local_irq_enable();
 	set_thread_flag(TIF_POLLING_NRFLAG);
+	snooze_exit_time = get_tb() + snooze_timeout;
 
 	while (!need_resched()) {
 		HMT_low();
 		HMT_very_low();
+		if (snooze_timeout_en && get_tb() > snooze_exit_time)
+			break;
 	}
 
 	HMT_medium();
@@ -244,6 +250,11 @@ static int pseries_idle_probe(void)
 	} else
 		return -ENODEV;
 
+	if (max_idle_state > 1) {
+		snooze_timeout_en = true;
+		snooze_timeout = cpuidle_state_table[1].target_residency *
+				 tb_ticks_per_usec;
+	}
 	return 0;
 }
 
-- 
1.9.3

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

* Re: [PATCH] cpuidle: powernv/pseries: Decrease the snooze residency
  2015-05-29 12:32 [PATCH] cpuidle: powernv/pseries: Decrease the snooze residency Shilpasri G Bhat
@ 2015-05-29 13:47 ` Preeti U Murthy
  2015-05-30  6:01   ` Vaidyanathan Srinivasan
  0 siblings, 1 reply; 6+ messages in thread
From: Preeti U Murthy @ 2015-05-29 13:47 UTC (permalink / raw)
  To: Shilpasri G Bhat, linuxppc-dev
  Cc: linux-pm, Daniel Lezcano, rjw, linux-kernel, anton

Hi Shilpa,

The subject does not convey the purpose of this patch clearly IMO.
I would definitely suggest changing the subject to something like
"Auto promotion of snooze to deeper idle state" or similar.

On 05/29/2015 06:02 PM, Shilpasri G Bhat wrote:
> The idle cpus which stay in snooze for a long period can degrade the
> perfomance of the sibling cpus. If the cpu stays in snooze for more
> than target residency of the next available idle state, then exit from
> snooze. This gives a chance to the cpuidle governor to re-evaluate the
> last idle state of the cpu to promote it to deeper idle states.
> 
> Signed-off-by: Shilpasri G Bhat <shilpa.bhat@linux.vnet.ibm.com>
> ---
>  drivers/cpuidle/cpuidle-powernv.c | 12 ++++++++++++
>  drivers/cpuidle/cpuidle-pseries.c | 11 +++++++++++
>  2 files changed, 23 insertions(+)
> 
> diff --git a/drivers/cpuidle/cpuidle-pseries.c b/drivers/cpuidle/cpuidle-pseries.c
> index bb9e2b6..07135e0 100644
> --- a/drivers/cpuidle/cpuidle-pseries.c
> +++ b/drivers/cpuidle/cpuidle-pseries.c
> @@ -27,6 +27,8 @@ struct cpuidle_driver pseries_idle_driver = {
>  
>  static int max_idle_state;
>  static struct cpuidle_state *cpuidle_state_table;
> +static u64 snooze_timeout;
> +static bool snooze_timeout_en;
>  
>  static inline void idle_loop_prolog(unsigned long *in_purr)
>  {
> @@ -58,14 +60,18 @@ static int snooze_loop(struct cpuidle_device *dev,
>  			int index)
>  {
>  	unsigned long in_purr;
> +	u64 snooze_exit_time;
>  
>  	idle_loop_prolog(&in_purr);
>  	local_irq_enable();
>  	set_thread_flag(TIF_POLLING_NRFLAG);
> +	snooze_exit_time = get_tb() + snooze_timeout;
>  
>  	while (!need_resched()) {
>  		HMT_low();
>  		HMT_very_low();
> +		if (snooze_timeout_en && get_tb() > snooze_exit_time)
> +			break;
>  	}
>  
>  	HMT_medium();
> @@ -244,6 +250,11 @@ static int pseries_idle_probe(void)
>  	} else
>  		return -ENODEV;
>  
> +	if (max_idle_state > 1) {
> +		snooze_timeout_en = true;
> +		snooze_timeout = cpuidle_state_table[1].target_residency *
> +				 tb_ticks_per_usec;
> +	}

Any idea why we don't have snooze defined on the shared lpar configuration ?

Regards
Preeti U Murthy
>  	return 0;
>  }
>  
> 

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

* Re: [PATCH] cpuidle: powernv/pseries: Decrease the snooze residency
  2015-05-29 13:47 ` Preeti U Murthy
@ 2015-05-30  6:01   ` Vaidyanathan Srinivasan
  2015-05-30  8:00     ` Preeti U Murthy
  2015-05-31  1:38     ` Benjamin Herrenschmidt
  0 siblings, 2 replies; 6+ messages in thread
From: Vaidyanathan Srinivasan @ 2015-05-30  6:01 UTC (permalink / raw)
  To: Preeti U Murthy
  Cc: Shilpasri G Bhat, linuxppc-dev, Daniel Lezcano, rjw, linux-kernel,
	anton, linux-pm

* Preeti U Murthy <preeti@linux.vnet.ibm.com> [2015-05-29 19:17:17]:

[snip]

> > +	if (max_idle_state > 1) {
> > +		snooze_timeout_en = true;
> > +		snooze_timeout = cpuidle_state_table[1].target_residency *
> > +				 tb_ticks_per_usec;
> > +	}
> 
> Any idea why we don't have snooze defined on the shared lpar configuration ?

In shared lpar case, spinning in guest context may potentially take
away cycles from other lpars waiting to run on the same physical cpu.

So the policy in shared lpar case is to let PowerVM hypervisor know
immediately that the guest cpu is idle which will allow the hypervisor
to use the cycles for other tasks/lpars.

--Vaidy

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

* Re: [PATCH] cpuidle: powernv/pseries: Decrease the snooze residency
  2015-05-30  6:01   ` Vaidyanathan Srinivasan
@ 2015-05-30  8:00     ` Preeti U Murthy
  2015-05-31  1:38     ` Benjamin Herrenschmidt
  1 sibling, 0 replies; 6+ messages in thread
From: Preeti U Murthy @ 2015-05-30  8:00 UTC (permalink / raw)
  To: svaidy
  Cc: Shilpasri G Bhat, linuxppc-dev, Daniel Lezcano, rjw, linux-kernel,
	anton, linux-pm

On 05/30/2015 11:31 AM, Vaidyanathan Srinivasan wrote:
> * Preeti U Murthy <preeti@linux.vnet.ibm.com> [2015-05-29 19:17:17]:
> 
> [snip]
> 
>>> +	if (max_idle_state > 1) {
>>> +		snooze_timeout_en = true;
>>> +		snooze_timeout = cpuidle_state_table[1].target_residency *
>>> +				 tb_ticks_per_usec;
>>> +	}
>>
>> Any idea why we don't have snooze defined on the shared lpar configuration ?
> 
> In shared lpar case, spinning in guest context may potentially take
> away cycles from other lpars waiting to run on the same physical cpu.
> 
> So the policy in shared lpar case is to let PowerVM hypervisor know
> immediately that the guest cpu is idle which will allow the hypervisor
> to use the cycles for other tasks/lpars.
> 

Oh Ok! Thanks for the clarification !

Regards
Preeti U Murthy
> --Vaidy
> 

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

* Re: [PATCH] cpuidle: powernv/pseries: Decrease the snooze residency
  2015-05-30  6:01   ` Vaidyanathan Srinivasan
  2015-05-30  8:00     ` Preeti U Murthy
@ 2015-05-31  1:38     ` Benjamin Herrenschmidt
  2015-06-03 15:35       ` Vaidyanathan Srinivasan
  1 sibling, 1 reply; 6+ messages in thread
From: Benjamin Herrenschmidt @ 2015-05-31  1:38 UTC (permalink / raw)
  To: svaidy
  Cc: Preeti U Murthy, linux-pm, Daniel Lezcano, rjw, linux-kernel,
	anton, Shilpasri G Bhat, linuxppc-dev

On Sat, 2015-05-30 at 11:31 +0530, Vaidyanathan Srinivasan wrote:
> In shared lpar case, spinning in guest context may potentially take
> away cycles from other lpars waiting to run on the same physical cpu.
> 
> So the policy in shared lpar case is to let PowerVM hypervisor know
> immediately that the guest cpu is idle which will allow the hypervisor
> to use the cycles for other tasks/lpars.

But that will have negative side effects under KVM no ?

Suresh mentioned something with his new directed interrupts code that we
had many cases where the interrupts ended up arriving shortly after we
exited to host for NAP'ing ...

Snooze might fix it...

Ben.

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

* Re: [PATCH] cpuidle: powernv/pseries: Decrease the snooze residency
  2015-05-31  1:38     ` Benjamin Herrenschmidt
@ 2015-06-03 15:35       ` Vaidyanathan Srinivasan
  0 siblings, 0 replies; 6+ messages in thread
From: Vaidyanathan Srinivasan @ 2015-06-03 15:35 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Preeti U Murthy, linux-pm, Daniel Lezcano, rjw, linux-kernel,
	anton, Shilpasri G Bhat, linuxppc-dev

* Benjamin Herrenschmidt <benh@au1.ibm.com> [2015-05-30 20:38:22]:

> On Sat, 2015-05-30 at 11:31 +0530, Vaidyanathan Srinivasan wrote:
> > In shared lpar case, spinning in guest context may potentially take
> > away cycles from other lpars waiting to run on the same physical cpu.
> > 
> > So the policy in shared lpar case is to let PowerVM hypervisor know
> > immediately that the guest cpu is idle which will allow the hypervisor
> > to use the cycles for other tasks/lpars.
> 
> But that will have negative side effects under KVM no ?

Yes, you have a good point.  If one of the thread in the core goes to
cede, it can still come back quickly since the KVM guest context is
not switched yet.  But in single threaded guest, this can force an
unnecessary exit/context switch overhead.

Now that we have fixed the snooze loop to be bounded and exit
predictably, KVM guest should actually use snooze state to improve
latency.

I will test this scenario and enable snooze state for KVM guest.
 
> Suresh mentioned something with his new directed interrupts code that we
> had many cases where the interrupts ended up arriving shortly after we
> exited to host for NAP'ing ...
> 
> Snooze might fix it...

Right.  This scenario is worth experimenting and then introduce snooze
loop for guest.

--Vaidy

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

end of thread, other threads:[~2015-06-03 15:36 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-29 12:32 [PATCH] cpuidle: powernv/pseries: Decrease the snooze residency Shilpasri G Bhat
2015-05-29 13:47 ` Preeti U Murthy
2015-05-30  6:01   ` Vaidyanathan Srinivasan
2015-05-30  8:00     ` Preeti U Murthy
2015-05-31  1:38     ` Benjamin Herrenschmidt
2015-06-03 15:35       ` Vaidyanathan Srinivasan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).