linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 1/5] cpufreq: Don't wait for CPU to going offline to restart governor
  2014-07-25  1:07 [PATCH v4 0/5] Simplify hotplug/suspend handling Saravana Kannan
@ 2014-07-25  1:07 ` Saravana Kannan
  2014-07-31 20:47   ` Saravana Kannan
  0 siblings, 1 reply; 3+ messages in thread
From: Saravana Kannan @ 2014-07-25  1:07 UTC (permalink / raw)
  To: linux-arm-kernel

There's no need to wait for the CPU going down to fully go offline to
restart the governor. We can stop the governor, change policy->cpus and
immediately restart the governor. This should reduce the time without any
CPUfreq monitoring and also help future patches with simplifying the code.

Signed-off-by: Saravana Kannan <skannan@codeaurora.org>
---
 drivers/cpufreq/cpufreq.c | 33 ++++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
index 62259d2..ee0eb7b 100644
--- a/drivers/cpufreq/cpufreq.c
+++ b/drivers/cpufreq/cpufreq.c
@@ -1390,6 +1390,21 @@ static int __cpufreq_remove_dev_prepare(struct device *dev,
 		cpufreq_driver->stop_cpu(policy);
 	}
 
+	down_write(&policy->rwsem);
+	cpumask_clear_cpu(cpu, policy->cpus);
+	up_write(&policy->rwsem);
+
+	if (cpus > 1 && has_target()) {
+		ret = __cpufreq_governor(policy, CPUFREQ_GOV_START);
+		if (!ret)
+			ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
+
+		if (ret) {
+			pr_err("%s: Failed to start governor\n", __func__);
+			return ret;
+		}
+	}
+
 	return 0;
 }
 
@@ -1410,15 +1425,12 @@ static int __cpufreq_remove_dev_finish(struct device *dev,
 		return -EINVAL;
 	}
 
-	down_write(&policy->rwsem);
+	down_read(&policy->rwsem);
 	cpus = cpumask_weight(policy->cpus);
-
-	if (cpus > 1)
-		cpumask_clear_cpu(cpu, policy->cpus);
-	up_write(&policy->rwsem);
+	up_read(&policy->rwsem);
 
 	/* If cpu is last user of policy, free policy */
-	if (cpus == 1) {
+	if (cpus == 0) {
 		if (has_target()) {
 			ret = __cpufreq_governor(policy,
 					CPUFREQ_GOV_POLICY_EXIT);
@@ -1447,15 +1459,6 @@ static int __cpufreq_remove_dev_finish(struct device *dev,
 
 		if (!cpufreq_suspended)
 			cpufreq_policy_free(policy);
-	} else if (has_target()) {
-		ret = __cpufreq_governor(policy, CPUFREQ_GOV_START);
-		if (!ret)
-			ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
-
-		if (ret) {
-			pr_err("%s: Failed to start governor\n", __func__);
-			return ret;
-		}
 	}
 
 	per_cpu(cpufreq_cpu_data, cpu) = NULL;
-- 
1.8.2.1

The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation

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

* [PATCH v4 1/5] cpufreq: Don't wait for CPU to going offline to restart governor
  2014-07-25  1:07 ` [PATCH v4 1/5] cpufreq: Don't wait for CPU to going offline to restart governor Saravana Kannan
@ 2014-07-31 20:47   ` Saravana Kannan
  0 siblings, 0 replies; 3+ messages in thread
From: Saravana Kannan @ 2014-07-31 20:47 UTC (permalink / raw)
  To: linux-arm-kernel

On 07/24/2014 06:07 PM, Saravana Kannan wrote:
> There's no need to wait for the CPU going down to fully go offline to
> restart the governor. We can stop the governor, change policy->cpus and
> immediately restart the governor. This should reduce the time without any
> CPUfreq monitoring and also help future patches with simplifying the code.
>
> Signed-off-by: Saravana Kannan <skannan@codeaurora.org>
> ---
>   drivers/cpufreq/cpufreq.c | 33 ++++++++++++++++++---------------
>   1 file changed, 18 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
> index 62259d2..ee0eb7b 100644
> --- a/drivers/cpufreq/cpufreq.c
> +++ b/drivers/cpufreq/cpufreq.c
> @@ -1390,6 +1390,21 @@ static int __cpufreq_remove_dev_prepare(struct device *dev,
>   		cpufreq_driver->stop_cpu(policy);
>   	}
>
> +	down_write(&policy->rwsem);
> +	cpumask_clear_cpu(cpu, policy->cpus);
> +	up_write(&policy->rwsem);
> +
> +	if (cpus > 1 && has_target()) {
> +		ret = __cpufreq_governor(policy, CPUFREQ_GOV_START);
> +		if (!ret)
> +			ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
> +
> +		if (ret) {
> +			pr_err("%s: Failed to start governor\n", __func__);
> +			return ret;
> +		}
> +	}
> +
>   	return 0;
>   }
>
> @@ -1410,15 +1425,12 @@ static int __cpufreq_remove_dev_finish(struct device *dev,
>   		return -EINVAL;
>   	}
>
> -	down_write(&policy->rwsem);
> +	down_read(&policy->rwsem);
>   	cpus = cpumask_weight(policy->cpus);
> -
> -	if (cpus > 1)
> -		cpumask_clear_cpu(cpu, policy->cpus);
> -	up_write(&policy->rwsem);
> +	up_read(&policy->rwsem);
>
>   	/* If cpu is last user of policy, free policy */
> -	if (cpus == 1) {
> +	if (cpus == 0) {
>   		if (has_target()) {
>   			ret = __cpufreq_governor(policy,
>   					CPUFREQ_GOV_POLICY_EXIT);
> @@ -1447,15 +1459,6 @@ static int __cpufreq_remove_dev_finish(struct device *dev,
>
>   		if (!cpufreq_suspended)
>   			cpufreq_policy_free(policy);
> -	} else if (has_target()) {
> -		ret = __cpufreq_governor(policy, CPUFREQ_GOV_START);
> -		if (!ret)
> -			ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
> -
> -		if (ret) {
> -			pr_err("%s: Failed to start governor\n", __func__);
> -			return ret;
> -		}
>   	}
>
>   	per_cpu(cpufreq_cpu_data, cpu) = NULL;
>

This patch should also fix another issue reported in-house recently. 
cpufreq_update_policy() fails for an ONLINE CPU. This is the scenario 
that triggers it:

Thead A
- Cluster with 4 CPUs
- CPU3 is going down.
- Governor is STOPed.
- CPU3 is removed, but governor not STARTed yet.

Thread B
- get_online_cpus()
- We cross this hotplug barrier since since POST_DEAD is sent AFTER 
releasing the hotplug lock.
- cpufreq_update_policy(CPU0) does a bunch of stuff
- Then sends GOV_LIMITS to governor.
- governor is currently STOPed, so it returns an error and 
cpufreq_update_policy() fails.

Thread A
- In POST_DEAD notifier, STARTs the governor again.

So, a perfectly valid call (doing get_online_cpus() and checking for 
cpu_online() on a CPU before calling) fails.

-Saravana

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation

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

* [PATCH v4 1/5] cpufreq: Don't wait for CPU to going offline to restart governor
       [not found] <CAKohpon=xWZJzfN0PceVntumAUFfCsbG1ibUwSxewB7bE=U7bQ@mail.gmail.com>
@ 2014-08-11 22:11 ` Saravana Kannan
  0 siblings, 0 replies; 3+ messages in thread
From: Saravana Kannan @ 2014-08-11 22:11 UTC (permalink / raw)
  To: linux-arm-kernel

On 08/07/2014 01:54 AM, Viresh Kumar wrote:
> Sorry for the really long delay this time around. I am used to replying within a
> day normally, and this time it just took so much time.
>
> For next time please rebase on latest updates in pm/linux-next as there are
> few updates there.

Will do.

>
> On 25 July 2014 06:37, Saravana Kannan <skannan@codeaurora.org> wrote:
>> There's no need to wait for the CPU going down to fully go offline to
>> restart the governor. We can stop the governor, change policy->cpus and
>> immediately restart the governor. This should reduce the time without any
>> CPUfreq monitoring and also help future patches with simplifying the code.
>
> I agree with the idea here, though the $subject can be improved a bit
> here..

Suggestions welcome. I think the current one explains the main point of 
this change.

>> Signed-off-by: Saravana Kannan <skannan@codeaurora.org>
>> ---
>>   drivers/cpufreq/cpufreq.c | 33 ++++++++++++++++++---------------
>>   1 file changed, 18 insertions(+), 15 deletions(-)
>>
>> diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
>> index 62259d2..ee0eb7b 100644
>> --- a/drivers/cpufreq/cpufreq.c
>> +++ b/drivers/cpufreq/cpufreq.c
>> @@ -1390,6 +1390,21 @@ static int __cpufreq_remove_dev_prepare(struct device *dev,
>>                  cpufreq_driver->stop_cpu(policy);
>>          }
>>
>> +       down_write(&policy->rwsem);
>> +       cpumask_clear_cpu(cpu, policy->cpus);
>> +       up_write(&policy->rwsem);
>
> There is a down_read() present early in this routine and we better update this
> at that place only.

I would rather not. My v1 patch series was super refactored to allow a 
lot of reuse, etc. But you guys complained about the diffs being 
confusing (which was a valid point).

Also, if we are talking about refactoring this, there's room for much 
better refactor at the end of the series. I will add a patch to the 
series to do the refactoring.

>
>> +       if (cpus > 1 && has_target()) {
>
> We already have a if (cpus > 1) block, move this there.

That only runs if cpu != policy->cpu. This needs to run irrespective of 
that.

>
>> +               ret = __cpufreq_governor(policy, CPUFREQ_GOV_START);
>> +               if (!ret)
>> +                       ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
>> +
>> +               if (ret) {
>> +                       pr_err("%s: Failed to start governor\n", __func__);
>> +                       return ret;
>> +               }
>> +       }
>> +
>>          return 0;
>>   }
>>
>> @@ -1410,15 +1425,12 @@ static int __cpufreq_remove_dev_finish(struct device *dev,
>>                  return -EINVAL;
>>          }
>>
>> -       down_write(&policy->rwsem);
>> +       down_read(&policy->rwsem);
>>          cpus = cpumask_weight(policy->cpus);
>> -
>> -       if (cpus > 1)
>> -               cpumask_clear_cpu(cpu, policy->cpus);
>> -       up_write(&policy->rwsem);
>> +       up_read(&policy->rwsem);
>>
>>          /* If cpu is last user of policy, free policy */
>> -       if (cpus == 1) {
>> +       if (cpus == 0) {
>>                  if (has_target()) {
>>                          ret = __cpufreq_governor(policy,
>>                                          CPUFREQ_GOV_POLICY_EXIT);
>> @@ -1447,15 +1459,6 @@ static int __cpufreq_remove_dev_finish(struct device *dev,
>>
>>                  if (!cpufreq_suspended)
>>                          cpufreq_policy_free(policy);
>> -       } else if (has_target()) {
>> -               ret = __cpufreq_governor(policy, CPUFREQ_GOV_START);
>> -               if (!ret)
>> -                       ret = __cpufreq_governor(policy, CPUFREQ_GOV_LIMITS);
>> -
>> -               if (ret) {
>> -                       pr_err("%s: Failed to start governor\n", __func__);
>> -                       return ret;
>> -               }
>>          }
>
> Also, you must mention in the log about an important change you are making.
> Don't know if there are any side effects...
>
> You are emptying policy->cpus on removal of last CPU of a policy, which wasn't
> the case earlier.

You mean the log in the cover letter? Will do.

-Saravana

-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
hosted by The Linux Foundation

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

end of thread, other threads:[~2014-08-11 22:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CAKohpon=xWZJzfN0PceVntumAUFfCsbG1ibUwSxewB7bE=U7bQ@mail.gmail.com>
2014-08-11 22:11 ` [PATCH v4 1/5] cpufreq: Don't wait for CPU to going offline to restart governor Saravana Kannan
2014-07-25  1:07 [PATCH v4 0/5] Simplify hotplug/suspend handling Saravana Kannan
2014-07-25  1:07 ` [PATCH v4 1/5] cpufreq: Don't wait for CPU to going offline to restart governor Saravana Kannan
2014-07-31 20:47   ` Saravana Kannan

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).