Re: [PATCH] cpufreq, powernow-k8: Fix usage of smp_processor_id() in preemptible code

2012-10-10 Thread Tejun Heo
Hello,

On Wed, Oct 10, 2012 at 9:48 PM, Andreas Herrmann
 wrote:
> Please ignore my patch. It was insufficiently tested -- sorry for this.
> (powernowk8_target_fn might sleep).
>
> Have to take a closer look how to avoid below issue.

Probably the only thing which can be done is always bouncing to the
percpu work item.

Thanks.

-- 
tejun
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] cpufreq, powernow-k8: Fix usage of smp_processor_id() in preemptible code

2012-10-10 Thread Andreas Herrmann
Rafael,

Please ignore my patch. It was insufficiently tested -- sorry for this.
(powernowk8_target_fn might sleep).

Have to take a closer look how to avoid below issue.


Regards,
Andreas


On Tue, Oct 09, 2012 at 09:38:44PM +0200, Andreas Herrmann wrote:
> 
> Commit 6889125b8b4e09c5e53e6ecab3433bed1ce198c9
> (cpufreq/powernow-k8: workqueue user shouldn't migrate the kworker to another 
> CPU)
> causes powernow-k8 to trigger a preempt warning, e.g.:
> 
>   BUG: using smp_processor_id() in preemptible [] code: cpufreq/3776
>   caller is powernowk8_target+0x20/0x49
>   Pid: 3776, comm: cpufreq Not tainted 3.6.0 #9
>   Call Trace:
>[] debug_smp_processor_id+0xc7/0xe0
>[] powernowk8_target+0x20/0x49
>[] __cpufreq_driver_target+0x82/0x8a
>[] cpufreq_governor_performance+0x4e/0x54
>[] __cpufreq_governor+0x8c/0xc9
>[] __cpufreq_set_policy+0x1a9/0x21e
>[] store_scaling_governor+0x16f/0x19b
>[] ? cpufreq_update_policy+0x124/0x124
>[] ? _raw_spin_unlock_irqrestore+0x2c/0x49
>[] store+0x60/0x88
>[] sysfs_write_file+0xf4/0x130
>[] vfs_write+0xb5/0x151
>[] sys_write+0x4a/0x71
>[] system_call_fastpath+0x16/0x1b
> 
> Fix this by using get_cpu/put_cpu in powernowk8_target().
> 
> Cc: Tejun Heo 
> Cc: sta...@vger.kernel.org
> Signed-off-by: Andreas Herrmann 
> ---
>  drivers/cpufreq/powernow-k8.c | 19 +++
>  1 file changed, 11 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/cpufreq/powernow-k8.c b/drivers/cpufreq/powernow-k8.c
> index 1a40935..3d1df2a 100644
> --- a/drivers/cpufreq/powernow-k8.c
> +++ b/drivers/cpufreq/powernow-k8.c
> @@ -1220,17 +1220,20 @@ static long powernowk8_target_fn(void *arg)
>  static int powernowk8_target(struct cpufreq_policy *pol,
>   unsigned targfreq, unsigned relation)
>  {
> + int this_cpu, ret;
>   struct powernowk8_target_arg pta = { .pol = pol, .targfreq = targfreq,
>.relation = relation };
>  
> - /*
> -  * Must run on @pol->cpu.  cpufreq core is responsible for ensuring
> -  * that we're bound to the current CPU and pol->cpu stays online.
> -  */
> - if (smp_processor_id() == pol->cpu)
> - return powernowk8_target_fn();
> - else
> - return work_on_cpu(pol->cpu, powernowk8_target_fn, );
> + this_cpu = get_cpu();
> + if (this_cpu == pol->cpu) {
> + ret = powernowk8_target_fn();
> + put_cpu();
> + } else {
> + put_cpu();
> + ret = work_on_cpu(pol->cpu, powernowk8_target_fn, );
> + }
> +
> + return ret;
>  }
>  
>  /* Driver entry point to verify the policy and range of frequencies */
> -- 
> 1.7.12
> 

-- 
Operating | Advanced Micro Devices GmbH
  System  | Einsteinring 24, 85609 Dornach/Aschheim, Germany
 Research | Geschäftsführer: Alberto Bozzo
  Center  | Sitz: Dornach, Gemeinde Aschheim, Landkreis München
  (OSRC)  | Registergericht München, HRB Nr. 43632, WEEE-Reg-Nr: DE 12919551

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] cpufreq, powernow-k8: Fix usage of smp_processor_id() in preemptible code

2012-10-10 Thread Andreas Herrmann
Rafael,

Please ignore my patch. It was insufficiently tested -- sorry for this.
(powernowk8_target_fn might sleep).

Have to take a closer look how to avoid below issue.


Regards,
Andreas


On Tue, Oct 09, 2012 at 09:38:44PM +0200, Andreas Herrmann wrote:
 
 Commit 6889125b8b4e09c5e53e6ecab3433bed1ce198c9
 (cpufreq/powernow-k8: workqueue user shouldn't migrate the kworker to another 
 CPU)
 causes powernow-k8 to trigger a preempt warning, e.g.:
 
   BUG: using smp_processor_id() in preemptible [] code: cpufreq/3776
   caller is powernowk8_target+0x20/0x49
   Pid: 3776, comm: cpufreq Not tainted 3.6.0 #9
   Call Trace:
[8125b447] debug_smp_processor_id+0xc7/0xe0
[814877e7] powernowk8_target+0x20/0x49
[81482b02] __cpufreq_driver_target+0x82/0x8a
[81484fc6] cpufreq_governor_performance+0x4e/0x54
[81482c50] __cpufreq_governor+0x8c/0xc9
[81482e6f] __cpufreq_set_policy+0x1a9/0x21e
[814839af] store_scaling_governor+0x16f/0x19b
[81484f16] ? cpufreq_update_policy+0x124/0x124
[8162b4a5] ? _raw_spin_unlock_irqrestore+0x2c/0x49
[81483640] store+0x60/0x88
[811708c0] sysfs_write_file+0xf4/0x130
[8111243b] vfs_write+0xb5/0x151
[811126e0] sys_write+0x4a/0x71
[816319a9] system_call_fastpath+0x16/0x1b
 
 Fix this by using get_cpu/put_cpu in powernowk8_target().
 
 Cc: Tejun Heo t...@kernel.org
 Cc: sta...@vger.kernel.org
 Signed-off-by: Andreas Herrmann andreas.herrma...@amd.com
 ---
  drivers/cpufreq/powernow-k8.c | 19 +++
  1 file changed, 11 insertions(+), 8 deletions(-)
 
 diff --git a/drivers/cpufreq/powernow-k8.c b/drivers/cpufreq/powernow-k8.c
 index 1a40935..3d1df2a 100644
 --- a/drivers/cpufreq/powernow-k8.c
 +++ b/drivers/cpufreq/powernow-k8.c
 @@ -1220,17 +1220,20 @@ static long powernowk8_target_fn(void *arg)
  static int powernowk8_target(struct cpufreq_policy *pol,
   unsigned targfreq, unsigned relation)
  {
 + int this_cpu, ret;
   struct powernowk8_target_arg pta = { .pol = pol, .targfreq = targfreq,
.relation = relation };
  
 - /*
 -  * Must run on @pol-cpu.  cpufreq core is responsible for ensuring
 -  * that we're bound to the current CPU and pol-cpu stays online.
 -  */
 - if (smp_processor_id() == pol-cpu)
 - return powernowk8_target_fn(pta);
 - else
 - return work_on_cpu(pol-cpu, powernowk8_target_fn, pta);
 + this_cpu = get_cpu();
 + if (this_cpu == pol-cpu) {
 + ret = powernowk8_target_fn(pta);
 + put_cpu();
 + } else {
 + put_cpu();
 + ret = work_on_cpu(pol-cpu, powernowk8_target_fn, pta);
 + }
 +
 + return ret;
  }
  
  /* Driver entry point to verify the policy and range of frequencies */
 -- 
 1.7.12
 

-- 
Operating | Advanced Micro Devices GmbH
  System  | Einsteinring 24, 85609 Dornach/Aschheim, Germany
 Research | Geschäftsführer: Alberto Bozzo
  Center  | Sitz: Dornach, Gemeinde Aschheim, Landkreis München
  (OSRC)  | Registergericht München, HRB Nr. 43632, WEEE-Reg-Nr: DE 12919551

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] cpufreq, powernow-k8: Fix usage of smp_processor_id() in preemptible code

2012-10-10 Thread Tejun Heo
Hello,

On Wed, Oct 10, 2012 at 9:48 PM, Andreas Herrmann
andreas.herrma...@amd.com wrote:
 Please ignore my patch. It was insufficiently tested -- sorry for this.
 (powernowk8_target_fn might sleep).

 Have to take a closer look how to avoid below issue.

Probably the only thing which can be done is always bouncing to the
percpu work item.

Thanks.

-- 
tejun
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] cpufreq, powernow-k8: Fix usage of smp_processor_id() in preemptible code

2012-10-09 Thread Tejun Heo
Hello,

On Tue, Oct 09, 2012 at 09:38:44PM +0200, Andreas Herrmann wrote:
> 
> Commit 6889125b8b4e09c5e53e6ecab3433bed1ce198c9
> (cpufreq/powernow-k8: workqueue user shouldn't migrate the kworker to another 
> CPU)
> causes powernow-k8 to trigger a preempt warning, e.g.:
> 
>   BUG: using smp_processor_id() in preemptible [] code: cpufreq/3776
>   caller is powernowk8_target+0x20/0x49
>   Pid: 3776, comm: cpufreq Not tainted 3.6.0 #9
>   Call Trace:
>[] debug_smp_processor_id+0xc7/0xe0
>[] powernowk8_target+0x20/0x49
>[] __cpufreq_driver_target+0x82/0x8a
>[] cpufreq_governor_performance+0x4e/0x54
>[] __cpufreq_governor+0x8c/0xc9
>[] __cpufreq_set_policy+0x1a9/0x21e
>[] store_scaling_governor+0x16f/0x19b
>[] ? cpufreq_update_policy+0x124/0x124
>[] ? _raw_spin_unlock_irqrestore+0x2c/0x49
>[] store+0x60/0x88
>[] sysfs_write_file+0xf4/0x130
>[] vfs_write+0xb5/0x151
>[] sys_write+0x4a/0x71
>[] system_call_fastpath+0x16/0x1b
...
> - /*
> -  * Must run on @pol->cpu.  cpufreq core is responsible for ensuring
> -  * that we're bound to the current CPU and pol->cpu stays online.
> -  */

Urgh... so this wasn't true?  Well, the perils of the last minute
changes.

> - if (smp_processor_id() == pol->cpu)
> - return powernowk8_target_fn();
> - else
> - return work_on_cpu(pol->cpu, powernowk8_target_fn, );
> + this_cpu = get_cpu();
> + if (this_cpu == pol->cpu) {
> + ret = powernowk8_target_fn();
> + put_cpu();
> + } else {
> + put_cpu();
> + ret = work_on_cpu(pol->cpu, powernowk8_target_fn, );
> + }
> +
> + return ret;

Looking at the code, yes, I think the above is correct.  Rafael, can
you please confirm?

Thanks.

-- 
tejun
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] cpufreq, powernow-k8: Fix usage of smp_processor_id() in preemptible code

2012-10-09 Thread Tejun Heo
Hello,

On Tue, Oct 09, 2012 at 09:38:44PM +0200, Andreas Herrmann wrote:
 
 Commit 6889125b8b4e09c5e53e6ecab3433bed1ce198c9
 (cpufreq/powernow-k8: workqueue user shouldn't migrate the kworker to another 
 CPU)
 causes powernow-k8 to trigger a preempt warning, e.g.:
 
   BUG: using smp_processor_id() in preemptible [] code: cpufreq/3776
   caller is powernowk8_target+0x20/0x49
   Pid: 3776, comm: cpufreq Not tainted 3.6.0 #9
   Call Trace:
[8125b447] debug_smp_processor_id+0xc7/0xe0
[814877e7] powernowk8_target+0x20/0x49
[81482b02] __cpufreq_driver_target+0x82/0x8a
[81484fc6] cpufreq_governor_performance+0x4e/0x54
[81482c50] __cpufreq_governor+0x8c/0xc9
[81482e6f] __cpufreq_set_policy+0x1a9/0x21e
[814839af] store_scaling_governor+0x16f/0x19b
[81484f16] ? cpufreq_update_policy+0x124/0x124
[8162b4a5] ? _raw_spin_unlock_irqrestore+0x2c/0x49
[81483640] store+0x60/0x88
[811708c0] sysfs_write_file+0xf4/0x130
[8111243b] vfs_write+0xb5/0x151
[811126e0] sys_write+0x4a/0x71
[816319a9] system_call_fastpath+0x16/0x1b
...
 - /*
 -  * Must run on @pol-cpu.  cpufreq core is responsible for ensuring
 -  * that we're bound to the current CPU and pol-cpu stays online.
 -  */

Urgh... so this wasn't true?  Well, the perils of the last minute
changes.

 - if (smp_processor_id() == pol-cpu)
 - return powernowk8_target_fn(pta);
 - else
 - return work_on_cpu(pol-cpu, powernowk8_target_fn, pta);
 + this_cpu = get_cpu();
 + if (this_cpu == pol-cpu) {
 + ret = powernowk8_target_fn(pta);
 + put_cpu();
 + } else {
 + put_cpu();
 + ret = work_on_cpu(pol-cpu, powernowk8_target_fn, pta);
 + }
 +
 + return ret;

Looking at the code, yes, I think the above is correct.  Rafael, can
you please confirm?

Thanks.

-- 
tejun
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/