All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] cpufreq: powernv: Adding fast_switch for schedutil
@ 2016-11-04  5:27 Akshay Adiga
  2016-11-04  5:27 ` [PATCH 2/2] cpufreq: powernv: Use PMSR to verify global and local pstate Akshay Adiga
  2016-11-04  6:33 ` [PATCH 1/2] cpufreq: powernv: Adding fast_switch for schedutil Viresh Kumar
  0 siblings, 2 replies; 7+ messages in thread
From: Akshay Adiga @ 2016-11-04  5:27 UTC (permalink / raw)
  To: rjw, viresh.kumar, linux-pm, linux-kernel, linuxppc-dev; +Cc: Akshay Adiga

Adding fast_switch which does light weight operation to
set the desired pstate.

Signed-off-by: Akshay Adiga <akshay.adiga@linux.vnet.ibm.com>
---
 drivers/cpufreq/powernv-cpufreq.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c
index d3ffde8..09a0496 100644
--- a/drivers/cpufreq/powernv-cpufreq.c
+++ b/drivers/cpufreq/powernv-cpufreq.c
@@ -752,9 +752,12 @@ static int powernv_cpufreq_cpu_init(struct cpufreq_policy *policy)
 	spin_lock_init(&gpstates->gpstate_lock);
 	ret = cpufreq_table_validate_and_show(policy, powernv_freqs);
 
-	if (ret < 0)
+	if (ret < 0) {
 		kfree(policy->driver_data);
+		return ret;
+	}
 
+	policy->fast_switch_possible = true;
 	return ret;
 }
 
@@ -897,6 +900,22 @@ static void powernv_cpufreq_stop_cpu(struct cpufreq_policy *policy)
 	del_timer_sync(&gpstates->timer);
 }
 
+static unsigned int powernv_fast_switch(struct cpufreq_policy *policy,
+					unsigned int target_freq)
+{
+	int index;
+	struct powernv_smp_call_data freq_data;
+
+	index = cpufreq_table_find_index_dl(policy, target_freq);
+	if (index < 0 || index >= powernv_pstate_info.nr_pstates)
+		return CPUFREQ_ENTRY_INVALID;
+	freq_data.pstate_id = powernv_freqs[index].driver_data;
+	freq_data.gpstate_id = powernv_freqs[index].driver_data;
+	set_pstate(&freq_data);
+
+	return powernv_freqs[index].frequency;
+}
+
 static struct cpufreq_driver powernv_cpufreq_driver = {
 	.name		= "powernv-cpufreq",
 	.flags		= CPUFREQ_CONST_LOOPS,
@@ -904,6 +923,7 @@ static struct cpufreq_driver powernv_cpufreq_driver = {
 	.exit		= powernv_cpufreq_cpu_exit,
 	.verify		= cpufreq_generic_frequency_table_verify,
 	.target_index	= powernv_cpufreq_target_index,
+	.fast_switch	= powernv_fast_switch,
 	.get		= powernv_cpufreq_get,
 	.stop_cpu	= powernv_cpufreq_stop_cpu,
 	.attr		= powernv_cpu_freq_attr,
-- 
2.7.4

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

* [PATCH 2/2] cpufreq: powernv: Use PMSR to verify global and local pstate
  2016-11-04  5:27 [PATCH 1/2] cpufreq: powernv: Adding fast_switch for schedutil Akshay Adiga
@ 2016-11-04  5:27 ` Akshay Adiga
  2016-11-04  6:41   ` Viresh Kumar
  2016-11-04  6:33 ` [PATCH 1/2] cpufreq: powernv: Adding fast_switch for schedutil Viresh Kumar
  1 sibling, 1 reply; 7+ messages in thread
From: Akshay Adiga @ 2016-11-04  5:27 UTC (permalink / raw)
  To: rjw, viresh.kumar, linux-pm, linux-kernel, linuxppc-dev; +Cc: Akshay Adiga

As fast_switch may get called in interrupt disable mode, it does not
update the global_pstate_info data structure. Hence the global_pstate_info
has stale data whenever pstate is updated through fast_swtich().

So the gpstate_timer can fire after a fast_switch() call has update
the pstates to a different value. Hence the timer handler cannot rely
on the cached values of local and global pstate and needs to read it
from the PMSR. 

Signed-off-by: Akshay Adiga <akshay.adiga@linux.vnet.ibm.com>

---
 drivers/cpufreq/powernv-cpufreq.c | 32 ++++++++++++++++++++++----------
 1 file changed, 22 insertions(+), 10 deletions(-)

diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c
index 09a0496..57713b5 100644
--- a/drivers/cpufreq/powernv-cpufreq.c
+++ b/drivers/cpufreq/powernv-cpufreq.c
@@ -592,7 +592,8 @@ void gpstate_timer_handler(unsigned long data)
 {
 	struct cpufreq_policy *policy = (struct cpufreq_policy *)data;
 	struct global_pstate_info *gpstates = policy->driver_data;
-	int gpstate_idx;
+	int gpstate_idx, lpstate_idx;
+	unsigned long val;
 	unsigned int time_diff = jiffies_to_msecs(jiffies)
 					- gpstates->last_sampled_time;
 	struct powernv_smp_call_data freq_data;
@@ -600,21 +601,36 @@ void gpstate_timer_handler(unsigned long data)
 	if (!spin_trylock(&gpstates->gpstate_lock))
 		return;
 
+	/*
+	 * If PMCR was last updated was using fast_swtich then
+	 * We may have wrong in gpstate->last_lpstate_idx
+	 * value. Hence, read from PMCR to get correct data.
+	 */
+	val = get_pmspr(SPRN_PMCR);
+	freq_data.gpstate_id = (val >> (56)) & 0xFF;
+	freq_data.pstate_id = (val >> (48)) & 0xFF;
+	if (freq_data.gpstate_id  == freq_data.pstate_id) {
+		reset_gpstates(policy);
+		spin_unlock(&gpstates->gpstate_lock);
+		return;
+	}
+
 	gpstates->last_sampled_time += time_diff;
 	gpstates->elapsed_time += time_diff;
-	freq_data.pstate_id = idx_to_pstate(gpstates->last_lpstate_idx);
 
-	if ((gpstates->last_gpstate_idx == gpstates->last_lpstate_idx) ||
-	    (gpstates->elapsed_time > MAX_RAMP_DOWN_TIME)) {
+	if (gpstates->elapsed_time > MAX_RAMP_DOWN_TIME) {
 		gpstate_idx = pstate_to_idx(freq_data.pstate_id);
 		reset_gpstates(policy);
 		gpstates->highest_lpstate_idx = gpstate_idx;
 	} else {
+		lpstate_idx = pstate_to_idx(freq_data.pstate_id);
 		gpstate_idx = calc_global_pstate(gpstates->elapsed_time,
 						 gpstates->highest_lpstate_idx,
-						 gpstates->last_lpstate_idx);
+						 lpstate_idx);
 	}
-
+	freq_data.gpstate_id = idx_to_pstate(gpstate_idx);
+	gpstates->last_gpstate_idx = gpstate_idx;
+	gpstates->last_lpstate_idx = lpstate_idx;
 	/*
 	 * If local pstate is equal to global pstate, rampdown is over
 	 * So timer is not required to be queued.
@@ -622,10 +638,6 @@ void gpstate_timer_handler(unsigned long data)
 	if (gpstate_idx != gpstates->last_lpstate_idx)
 		queue_gpstate_timer(gpstates);
 
-	freq_data.gpstate_id = idx_to_pstate(gpstate_idx);
-	gpstates->last_gpstate_idx = pstate_to_idx(freq_data.gpstate_id);
-	gpstates->last_lpstate_idx = pstate_to_idx(freq_data.pstate_id);
-
 	spin_unlock(&gpstates->gpstate_lock);
 
 	/* Timer may get migrated to a different cpu on cpu hot unplug */
-- 
2.7.4

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

* Re: [PATCH 1/2] cpufreq: powernv: Adding fast_switch for schedutil
  2016-11-04  5:27 [PATCH 1/2] cpufreq: powernv: Adding fast_switch for schedutil Akshay Adiga
  2016-11-04  5:27 ` [PATCH 2/2] cpufreq: powernv: Use PMSR to verify global and local pstate Akshay Adiga
@ 2016-11-04  6:33 ` Viresh Kumar
  2016-11-07  7:32     ` Akshay Adiga
  1 sibling, 1 reply; 7+ messages in thread
From: Viresh Kumar @ 2016-11-04  6:33 UTC (permalink / raw)
  To: Akshay Adiga; +Cc: rjw, linux-pm, linux-kernel, linuxppc-dev

On 04-11-16, 10:57, Akshay Adiga wrote:
> Adding fast_switch which does light weight operation to
> set the desired pstate.
> 
> Signed-off-by: Akshay Adiga <akshay.adiga@linux.vnet.ibm.com>
> ---
>  drivers/cpufreq/powernv-cpufreq.c | 22 +++++++++++++++++++++-
>  1 file changed, 21 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c
> index d3ffde8..09a0496 100644
> --- a/drivers/cpufreq/powernv-cpufreq.c
> +++ b/drivers/cpufreq/powernv-cpufreq.c
> @@ -752,9 +752,12 @@ static int powernv_cpufreq_cpu_init(struct cpufreq_policy *policy)
>  	spin_lock_init(&gpstates->gpstate_lock);
>  	ret = cpufreq_table_validate_and_show(policy, powernv_freqs);
>  
> -	if (ret < 0)
> +	if (ret < 0) {
>  		kfree(policy->driver_data);
> +		return ret;
> +	}
>  
> +	policy->fast_switch_possible = true;
>  	return ret;
>  }
>  
> @@ -897,6 +900,22 @@ static void powernv_cpufreq_stop_cpu(struct cpufreq_policy *policy)
>  	del_timer_sync(&gpstates->timer);
>  }
>  
> +static unsigned int powernv_fast_switch(struct cpufreq_policy *policy,
> +					unsigned int target_freq)
> +{
> +	int index;
> +	struct powernv_smp_call_data freq_data;
> +
> +	index = cpufreq_table_find_index_dl(policy, target_freq);
> +	if (index < 0 || index >= powernv_pstate_info.nr_pstates)
> +		return CPUFREQ_ENTRY_INVALID;

I don't think such a check is required at all. It wouldn't happen without a BUG
in kernel.

> +	freq_data.pstate_id = powernv_freqs[index].driver_data;
> +	freq_data.gpstate_id = powernv_freqs[index].driver_data;
> +	set_pstate(&freq_data);
> +
> +	return powernv_freqs[index].frequency;
> +}
> +
>  static struct cpufreq_driver powernv_cpufreq_driver = {
>  	.name		= "powernv-cpufreq",
>  	.flags		= CPUFREQ_CONST_LOOPS,
> @@ -904,6 +923,7 @@ static struct cpufreq_driver powernv_cpufreq_driver = {
>  	.exit		= powernv_cpufreq_cpu_exit,
>  	.verify		= cpufreq_generic_frequency_table_verify,
>  	.target_index	= powernv_cpufreq_target_index,
> +	.fast_switch	= powernv_fast_switch,
>  	.get		= powernv_cpufreq_get,
>  	.stop_cpu	= powernv_cpufreq_stop_cpu,
>  	.attr		= powernv_cpu_freq_attr,
> -- 
> 2.7.4

-- 
viresh

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

* Re: [PATCH 2/2] cpufreq: powernv: Use PMSR to verify global and local pstate
  2016-11-04  5:27 ` [PATCH 2/2] cpufreq: powernv: Use PMSR to verify global and local pstate Akshay Adiga
@ 2016-11-04  6:41   ` Viresh Kumar
  2016-11-07  7:32     ` Akshay Adiga
  0 siblings, 1 reply; 7+ messages in thread
From: Viresh Kumar @ 2016-11-04  6:41 UTC (permalink / raw)
  To: Akshay Adiga; +Cc: rjw, linux-pm, linux-kernel, linuxppc-dev

On 04-11-16, 10:57, Akshay Adiga wrote:
> As fast_switch may get called in interrupt disable mode, it does not

s/in interrupt disable mode/with interrupts disabled
s/it does/it may

> update the global_pstate_info data structure. Hence the global_pstate_info
> has stale data whenever pstate is updated through fast_swtich().

s/has/may have
s/swtich/switch

> 
> So the gpstate_timer can fire after a fast_switch() call has update

s/So the/The
s/a fast_swtich() call has update/the fast_switch() call has updated

> the pstates to a different value. Hence the timer handler cannot rely
> on the cached values of local and global pstate and needs to read it
> from the PMSR. 
> 
> Signed-off-by: Akshay Adiga <akshay.adiga@linux.vnet.ibm.com>
> 
> ---
>  drivers/cpufreq/powernv-cpufreq.c | 32 ++++++++++++++++++++++----------
>  1 file changed, 22 insertions(+), 10 deletions(-)

I am not the best guy to judge the code changes here. Can you please include
Shilpa and Gautham to the mail chain and get there feedback.

-- 
viresh

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

* Re: [PATCH 1/2] cpufreq: powernv: Adding fast_switch for schedutil
  2016-11-04  6:33 ` [PATCH 1/2] cpufreq: powernv: Adding fast_switch for schedutil Viresh Kumar
@ 2016-11-07  7:32     ` Akshay Adiga
  0 siblings, 0 replies; 7+ messages in thread
From: Akshay Adiga @ 2016-11-07  7:32 UTC (permalink / raw)
  To: Viresh Kumar; +Cc: rjw, linux-pm, linux-kernel, linuxppc-dev

Thanks Viresh for taking a look at it.

I will make the mentioned changes in the next version of the patch.


Regards

Akshay Adiga


On 11/04/2016 12:03 PM, Viresh Kumar wrote:
> On 04-11-16, 10:57, Akshay Adiga wrote:
>> Adding fast_switch which does light weight operation to
>> set the desired pstate.
>>
>> Signed-off-by: Akshay Adiga <akshay.adiga@linux.vnet.ibm.com>
>> ---
>>   drivers/cpufreq/powernv-cpufreq.c | 22 +++++++++++++++++++++-
>>   1 file changed, 21 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c
>> index d3ffde8..09a0496 100644
>> --- a/drivers/cpufreq/powernv-cpufreq.c
>> +++ b/drivers/cpufreq/powernv-cpufreq.c
>> @@ -752,9 +752,12 @@ static int powernv_cpufreq_cpu_init(struct cpufreq_policy *policy)
>>   	spin_lock_init(&gpstates->gpstate_lock);
>>   	ret = cpufreq_table_validate_and_show(policy, powernv_freqs);
>>   
>> -	if (ret < 0)
>> +	if (ret < 0) {
>>   		kfree(policy->driver_data);
>> +		return ret;
>> +	}
>>   
>> +	policy->fast_switch_possible = true;
>>   	return ret;
>>   }
>>   
>> @@ -897,6 +900,22 @@ static void powernv_cpufreq_stop_cpu(struct cpufreq_policy *policy)
>>   	del_timer_sync(&gpstates->timer);
>>   }
>>   
>> +static unsigned int powernv_fast_switch(struct cpufreq_policy *policy,
>> +					unsigned int target_freq)
>> +{
>> +	int index;
>> +	struct powernv_smp_call_data freq_data;
>> +
>> +	index = cpufreq_table_find_index_dl(policy, target_freq);
>> +	if (index < 0 || index >= powernv_pstate_info.nr_pstates)
>> +		return CPUFREQ_ENTRY_INVALID;
> I don't think such a check is required at all. It wouldn't happen without a BUG
> in kernel.
>> +	freq_data.pstate_id = powernv_freqs[index].driver_data;
>> +	freq_data.gpstate_id = powernv_freqs[index].driver_data;
>> +	set_pstate(&freq_data);
>> +
>> +	return powernv_freqs[index].frequency;
>> +}
>> +
>>   static struct cpufreq_driver powernv_cpufreq_driver = {
>>   	.name		= "powernv-cpufreq",
>>   	.flags		= CPUFREQ_CONST_LOOPS,
>> @@ -904,6 +923,7 @@ static struct cpufreq_driver powernv_cpufreq_driver = {
>>   	.exit		= powernv_cpufreq_cpu_exit,
>>   	.verify		= cpufreq_generic_frequency_table_verify,
>>   	.target_index	= powernv_cpufreq_target_index,
>> +	.fast_switch	= powernv_fast_switch,
>>   	.get		= powernv_cpufreq_get,
>>   	.stop_cpu	= powernv_cpufreq_stop_cpu,
>>   	.attr		= powernv_cpu_freq_attr,
>> -- 
>> 2.7.4

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

* Re: [PATCH 1/2] cpufreq: powernv: Adding fast_switch for schedutil
@ 2016-11-07  7:32     ` Akshay Adiga
  0 siblings, 0 replies; 7+ messages in thread
From: Akshay Adiga @ 2016-11-07  7:32 UTC (permalink / raw)
  To: Viresh Kumar; +Cc: linuxppc-dev, rjw, linux-kernel, linux-pm

Thanks Viresh for taking a look at it.

I will make the mentioned changes in the next version of the patch.


Regards

Akshay Adiga


On 11/04/2016 12:03 PM, Viresh Kumar wrote:
> On 04-11-16, 10:57, Akshay Adiga wrote:
>> Adding fast_switch which does light weight operation to
>> set the desired pstate.
>>
>> Signed-off-by: Akshay Adiga <akshay.adiga@linux.vnet.ibm.com>
>> ---
>>   drivers/cpufreq/powernv-cpufreq.c | 22 +++++++++++++++++++++-
>>   1 file changed, 21 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/cpufreq/powernv-cpufreq.c b/drivers/cpufreq/powernv-cpufreq.c
>> index d3ffde8..09a0496 100644
>> --- a/drivers/cpufreq/powernv-cpufreq.c
>> +++ b/drivers/cpufreq/powernv-cpufreq.c
>> @@ -752,9 +752,12 @@ static int powernv_cpufreq_cpu_init(struct cpufreq_policy *policy)
>>   	spin_lock_init(&gpstates->gpstate_lock);
>>   	ret = cpufreq_table_validate_and_show(policy, powernv_freqs);
>>   
>> -	if (ret < 0)
>> +	if (ret < 0) {
>>   		kfree(policy->driver_data);
>> +		return ret;
>> +	}
>>   
>> +	policy->fast_switch_possible = true;
>>   	return ret;
>>   }
>>   
>> @@ -897,6 +900,22 @@ static void powernv_cpufreq_stop_cpu(struct cpufreq_policy *policy)
>>   	del_timer_sync(&gpstates->timer);
>>   }
>>   
>> +static unsigned int powernv_fast_switch(struct cpufreq_policy *policy,
>> +					unsigned int target_freq)
>> +{
>> +	int index;
>> +	struct powernv_smp_call_data freq_data;
>> +
>> +	index = cpufreq_table_find_index_dl(policy, target_freq);
>> +	if (index < 0 || index >= powernv_pstate_info.nr_pstates)
>> +		return CPUFREQ_ENTRY_INVALID;
> I don't think such a check is required at all. It wouldn't happen without a BUG
> in kernel.
>> +	freq_data.pstate_id = powernv_freqs[index].driver_data;
>> +	freq_data.gpstate_id = powernv_freqs[index].driver_data;
>> +	set_pstate(&freq_data);
>> +
>> +	return powernv_freqs[index].frequency;
>> +}
>> +
>>   static struct cpufreq_driver powernv_cpufreq_driver = {
>>   	.name		= "powernv-cpufreq",
>>   	.flags		= CPUFREQ_CONST_LOOPS,
>> @@ -904,6 +923,7 @@ static struct cpufreq_driver powernv_cpufreq_driver = {
>>   	.exit		= powernv_cpufreq_cpu_exit,
>>   	.verify		= cpufreq_generic_frequency_table_verify,
>>   	.target_index	= powernv_cpufreq_target_index,
>> +	.fast_switch	= powernv_fast_switch,
>>   	.get		= powernv_cpufreq_get,
>>   	.stop_cpu	= powernv_cpufreq_stop_cpu,
>>   	.attr		= powernv_cpu_freq_attr,
>> -- 
>> 2.7.4

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

* Re: [PATCH 2/2] cpufreq: powernv: Use PMSR to verify global and local pstate
  2016-11-04  6:41   ` Viresh Kumar
@ 2016-11-07  7:32     ` Akshay Adiga
  0 siblings, 0 replies; 7+ messages in thread
From: Akshay Adiga @ 2016-11-07  7:32 UTC (permalink / raw)
  To: Viresh Kumar; +Cc: linuxppc-dev, rjw, linux-kernel, linux-pm

Thanks Viresh for taking a look at it.

I will make the mentioned changes in the next version of the patch and
will add Shilpa and Gautham to the mail chain.

Regards

Akshay Adiga


On 11/04/2016 12:11 PM, Viresh Kumar wrote:
> On 04-11-16, 10:57, Akshay Adiga wrote:
>> As fast_switch may get called in interrupt disable mode, it does not
> s/in interrupt disable mode/with interrupts disabled
> s/it does/it may
>
>> update the global_pstate_info data structure. Hence the global_pstate_info
>> has stale data whenever pstate is updated through fast_swtich().
> s/has/may have
> s/swtich/switch
>
>> So the gpstate_timer can fire after a fast_switch() call has update
> s/So the/The
> s/a fast_swtich() call has update/the fast_switch() call has updated
>
>> the pstates to a different value. Hence the timer handler cannot rely
>> on the cached values of local and global pstate and needs to read it
>> from the PMSR.
>>
>> Signed-off-by: Akshay Adiga <akshay.adiga@linux.vnet.ibm.com>
>>
>> ---
>>   drivers/cpufreq/powernv-cpufreq.c | 32 ++++++++++++++++++++++----------
>>   1 file changed, 22 insertions(+), 10 deletions(-)
> I am not the best guy to judge the code changes here. Can you please include
> Shilpa and Gautham to the mail chain and get there feedback.
>
>
>

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

end of thread, other threads:[~2016-11-07  7:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-11-04  5:27 [PATCH 1/2] cpufreq: powernv: Adding fast_switch for schedutil Akshay Adiga
2016-11-04  5:27 ` [PATCH 2/2] cpufreq: powernv: Use PMSR to verify global and local pstate Akshay Adiga
2016-11-04  6:41   ` Viresh Kumar
2016-11-07  7:32     ` Akshay Adiga
2016-11-04  6:33 ` [PATCH 1/2] cpufreq: powernv: Adding fast_switch for schedutil Viresh Kumar
2016-11-07  7:32   ` Akshay Adiga
2016-11-07  7:32     ` Akshay Adiga

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.