Re: [PATCH V2 4/6] Thermal: Remove the cooling_cpufreq_list.

2012-10-30 Thread Hongbo Zhang
On 30 October 2012 09:03, Amit Kachhap  wrote:
> On 26 October 2012 12:39, hongbo.zhang  wrote:
>> From: "hongbo.zhang" 
>>
>> Problem of using this list is that the cpufreq_get_max_state callback will be
>> called when register cooling device by thermal_cooling_device_register, but
>> this list isn't ready at this moment. What's more, there is no need to 
>> maintain
>> such a list, we can get cpufreq_cooling_device instance by the private
>> thermal_cooling_device.devdata.
>
> Hi,
>
> Removing this list seems fine as most of frequency checks are moved
> inside generic thermal layer.
> Some minor review comments below,
>
> Reviewed-by: Amit Daniel Kachhap 
Thanks.
>>
>> Signed-off-by: hongbo.zhang 
>> ---
>>  drivers/thermal/cpu_cooling.c | 91 
>> +--
>>  1 file changed, 19 insertions(+), 72 deletions(-)
>>
>> diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
>> index 415b041..2ffd12c 100644
>> --- a/drivers/thermal/cpu_cooling.c
>> +++ b/drivers/thermal/cpu_cooling.c
>> @@ -58,8 +58,9 @@ struct cpufreq_cooling_device {
>>  };
>>  static LIST_HEAD(cooling_cpufreq_list);
>>  static DEFINE_IDR(cpufreq_idr);
>> +static DEFINE_MUTEX(cooling_cpufreq_lock);
>>
>> -static struct mutex cooling_cpufreq_lock;
>> +static unsigned int cpufreq_dev_count;
>>
>>  /* notify_table passes value to the CPUFREQ_ADJUST callback function. */
>>  #define NOTIFY_INVALID NULL
>> @@ -240,28 +241,18 @@ static int cpufreq_thermal_notifier(struct 
>> notifier_block *nb,
>>  static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
>>  unsigned long *state)
>>  {
>> -   int ret = -EINVAL, i = 0;
>> -   struct cpufreq_cooling_device *cpufreq_device;
>> -   struct cpumask *maskPtr;
>> +   struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
> check cdev is not null.
>> +   struct cpumask *maskPtr = _device->allowed_cpus;
>> unsigned int cpu;
>> struct cpufreq_frequency_table *table;
>> unsigned long count = 0;
>> +   int i = 0;
>>
>> -   mutex_lock(_cpufreq_lock);
>> -   list_for_each_entry(cpufreq_device, _cpufreq_list, node) {
>> -   if (cpufreq_device && cpufreq_device->cool_dev == cdev)
>> -   break;
>> -   }
>> -   if (cpufreq_device == NULL)
>> -   goto return_get_max_state;
>> -
>> -   maskPtr = _device->allowed_cpus;
>> cpu = cpumask_any(maskPtr);
>> table = cpufreq_frequency_get_table(cpu);
>> if (!table) {
>> *state = 0;
>> -   ret = 0;
>> -   goto return_get_max_state;
>> +   return 0;
>> }
>>
>> for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {
>> @@ -272,12 +263,10 @@ static int cpufreq_get_max_state(struct 
>> thermal_cooling_device *cdev,
>>
>> if (count > 0) {
>> *state = --count;
>> -   ret = 0;
>> +   return 0;
>> }
>>
>> -return_get_max_state:
>> -   mutex_unlock(_cpufreq_lock);
>> -   return ret;
>> +   return -EINVAL;
>>  }
>>
>>  /**
>> @@ -288,20 +277,10 @@ return_get_max_state:
>>  static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
>>  unsigned long *state)
>>  {
>> -   int ret = -EINVAL;
>> -   struct cpufreq_cooling_device *cpufreq_device;
>> +   struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
>>
>> -   mutex_lock(_cpufreq_lock);
>> -   list_for_each_entry(cpufreq_device, _cpufreq_list, node) {
>> -   if (cpufreq_device && cpufreq_device->cool_dev == cdev) {
>> -   *state = cpufreq_device->cpufreq_state;
>> -   ret = 0;
>> -   break;
>> -   }
>> -   }
>> -   mutex_unlock(_cpufreq_lock);
>> -
>> -   return ret;
>> +   *state = cpufreq_device->cpufreq_state;
>> +   return 0;
>>  }
>>
>>  /**
>> @@ -312,22 +291,9 @@ static int cpufreq_get_cur_state(struct 
>> thermal_cooling_device *cdev,
>>  static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
>>  unsigned long state)
>>  {
>> -   int ret = -EINVAL;
>> -   struct cpufreq_cooling_device *cpufreq_device;
>> +   struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
> check cdev is not null
Such values are used in all the three static cpufreq_***_state
callback functions, when these functions are called, cdev->devdata
should have been set in the registration function, and cannot be null,
no body can call these function before registration, so I think there
is no need to add such a check here.

>>
>> -   mutex_lock(_cpufreq_lock);
>> -   list_for_each_entry(cpufreq_device, _cpufreq_list, node) {
>> -   if (cpufreq_device && cpufreq_device->cool_dev == cdev) {
>> -   ret = 0;
>> 

Re: [PATCH V2 4/6] Thermal: Remove the cooling_cpufreq_list.

2012-10-30 Thread Amit Kachhap
On 26 October 2012 12:39, hongbo.zhang  wrote:
> From: "hongbo.zhang" 
>
> Problem of using this list is that the cpufreq_get_max_state callback will be
> called when register cooling device by thermal_cooling_device_register, but
> this list isn't ready at this moment. What's more, there is no need to 
> maintain
> such a list, we can get cpufreq_cooling_device instance by the private
> thermal_cooling_device.devdata.

Hi,

Removing this list seems fine as most of frequency checks are moved
inside generic thermal layer.
Some minor review comments below,

Reviewed-by: Amit Daniel Kachhap 
>
> Signed-off-by: hongbo.zhang 
> ---
>  drivers/thermal/cpu_cooling.c | 91 
> +--
>  1 file changed, 19 insertions(+), 72 deletions(-)
>
> diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
> index 415b041..2ffd12c 100644
> --- a/drivers/thermal/cpu_cooling.c
> +++ b/drivers/thermal/cpu_cooling.c
> @@ -58,8 +58,9 @@ struct cpufreq_cooling_device {
>  };
>  static LIST_HEAD(cooling_cpufreq_list);
>  static DEFINE_IDR(cpufreq_idr);
> +static DEFINE_MUTEX(cooling_cpufreq_lock);
>
> -static struct mutex cooling_cpufreq_lock;
> +static unsigned int cpufreq_dev_count;
>
>  /* notify_table passes value to the CPUFREQ_ADJUST callback function. */
>  #define NOTIFY_INVALID NULL
> @@ -240,28 +241,18 @@ static int cpufreq_thermal_notifier(struct 
> notifier_block *nb,
>  static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
>  unsigned long *state)
>  {
> -   int ret = -EINVAL, i = 0;
> -   struct cpufreq_cooling_device *cpufreq_device;
> -   struct cpumask *maskPtr;
> +   struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
check cdev is not null.
> +   struct cpumask *maskPtr = _device->allowed_cpus;
> unsigned int cpu;
> struct cpufreq_frequency_table *table;
> unsigned long count = 0;
> +   int i = 0;
>
> -   mutex_lock(_cpufreq_lock);
> -   list_for_each_entry(cpufreq_device, _cpufreq_list, node) {
> -   if (cpufreq_device && cpufreq_device->cool_dev == cdev)
> -   break;
> -   }
> -   if (cpufreq_device == NULL)
> -   goto return_get_max_state;
> -
> -   maskPtr = _device->allowed_cpus;
> cpu = cpumask_any(maskPtr);
> table = cpufreq_frequency_get_table(cpu);
> if (!table) {
> *state = 0;
> -   ret = 0;
> -   goto return_get_max_state;
> +   return 0;
> }
>
> for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {
> @@ -272,12 +263,10 @@ static int cpufreq_get_max_state(struct 
> thermal_cooling_device *cdev,
>
> if (count > 0) {
> *state = --count;
> -   ret = 0;
> +   return 0;
> }
>
> -return_get_max_state:
> -   mutex_unlock(_cpufreq_lock);
> -   return ret;
> +   return -EINVAL;
>  }
>
>  /**
> @@ -288,20 +277,10 @@ return_get_max_state:
>  static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
>  unsigned long *state)
>  {
> -   int ret = -EINVAL;
> -   struct cpufreq_cooling_device *cpufreq_device;
> +   struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
>
> -   mutex_lock(_cpufreq_lock);
> -   list_for_each_entry(cpufreq_device, _cpufreq_list, node) {
> -   if (cpufreq_device && cpufreq_device->cool_dev == cdev) {
> -   *state = cpufreq_device->cpufreq_state;
> -   ret = 0;
> -   break;
> -   }
> -   }
> -   mutex_unlock(_cpufreq_lock);
> -
> -   return ret;
> +   *state = cpufreq_device->cpufreq_state;
> +   return 0;
>  }
>
>  /**
> @@ -312,22 +291,9 @@ static int cpufreq_get_cur_state(struct 
> thermal_cooling_device *cdev,
>  static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
>  unsigned long state)
>  {
> -   int ret = -EINVAL;
> -   struct cpufreq_cooling_device *cpufreq_device;
> +   struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
check cdev is not null
>
> -   mutex_lock(_cpufreq_lock);
> -   list_for_each_entry(cpufreq_device, _cpufreq_list, node) {
> -   if (cpufreq_device && cpufreq_device->cool_dev == cdev) {
> -   ret = 0;
> -   break;
> -   }
> -   }
> -   if (!ret)
> -   ret = cpufreq_apply_cooling(cpufreq_device, state);
> -
> -   mutex_unlock(_cpufreq_lock);
> -
> -   return ret;
> +   return cpufreq_apply_cooling(cpufreq_device, state);
>  }
>
>  /* Bind cpufreq callbacks to thermal cooling device ops */
> @@ -351,7 +317,7 @@ struct thermal_cooling_device *cpufreq_cooling_register(
>  {
> struct thermal_cooling_device *cool_dev;
> 

Re: [PATCH V2 4/6] Thermal: Remove the cooling_cpufreq_list.

2012-10-30 Thread Amit Kachhap
On 26 October 2012 12:39, hongbo.zhang hongbo.zh...@linaro.org wrote:
 From: hongbo.zhang hongbo.zh...@linaro.com

 Problem of using this list is that the cpufreq_get_max_state callback will be
 called when register cooling device by thermal_cooling_device_register, but
 this list isn't ready at this moment. What's more, there is no need to 
 maintain
 such a list, we can get cpufreq_cooling_device instance by the private
 thermal_cooling_device.devdata.

Hi,

Removing this list seems fine as most of frequency checks are moved
inside generic thermal layer.
Some minor review comments below,

Reviewed-by: Amit Daniel Kachhap amit.kach...@linaro.org

 Signed-off-by: hongbo.zhang hongbo.zh...@linaro.com
 ---
  drivers/thermal/cpu_cooling.c | 91 
 +--
  1 file changed, 19 insertions(+), 72 deletions(-)

 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
 index 415b041..2ffd12c 100644
 --- a/drivers/thermal/cpu_cooling.c
 +++ b/drivers/thermal/cpu_cooling.c
 @@ -58,8 +58,9 @@ struct cpufreq_cooling_device {
  };
  static LIST_HEAD(cooling_cpufreq_list);
  static DEFINE_IDR(cpufreq_idr);
 +static DEFINE_MUTEX(cooling_cpufreq_lock);

 -static struct mutex cooling_cpufreq_lock;
 +static unsigned int cpufreq_dev_count;

  /* notify_table passes value to the CPUFREQ_ADJUST callback function. */
  #define NOTIFY_INVALID NULL
 @@ -240,28 +241,18 @@ static int cpufreq_thermal_notifier(struct 
 notifier_block *nb,
  static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
  unsigned long *state)
  {
 -   int ret = -EINVAL, i = 0;
 -   struct cpufreq_cooling_device *cpufreq_device;
 -   struct cpumask *maskPtr;
 +   struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
check cdev is not null.
 +   struct cpumask *maskPtr = cpufreq_device-allowed_cpus;
 unsigned int cpu;
 struct cpufreq_frequency_table *table;
 unsigned long count = 0;
 +   int i = 0;

 -   mutex_lock(cooling_cpufreq_lock);
 -   list_for_each_entry(cpufreq_device, cooling_cpufreq_list, node) {
 -   if (cpufreq_device  cpufreq_device-cool_dev == cdev)
 -   break;
 -   }
 -   if (cpufreq_device == NULL)
 -   goto return_get_max_state;
 -
 -   maskPtr = cpufreq_device-allowed_cpus;
 cpu = cpumask_any(maskPtr);
 table = cpufreq_frequency_get_table(cpu);
 if (!table) {
 *state = 0;
 -   ret = 0;
 -   goto return_get_max_state;
 +   return 0;
 }

 for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {
 @@ -272,12 +263,10 @@ static int cpufreq_get_max_state(struct 
 thermal_cooling_device *cdev,

 if (count  0) {
 *state = --count;
 -   ret = 0;
 +   return 0;
 }

 -return_get_max_state:
 -   mutex_unlock(cooling_cpufreq_lock);
 -   return ret;
 +   return -EINVAL;
  }

  /**
 @@ -288,20 +277,10 @@ return_get_max_state:
  static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
  unsigned long *state)
  {
 -   int ret = -EINVAL;
 -   struct cpufreq_cooling_device *cpufreq_device;
 +   struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;

 -   mutex_lock(cooling_cpufreq_lock);
 -   list_for_each_entry(cpufreq_device, cooling_cpufreq_list, node) {
 -   if (cpufreq_device  cpufreq_device-cool_dev == cdev) {
 -   *state = cpufreq_device-cpufreq_state;
 -   ret = 0;
 -   break;
 -   }
 -   }
 -   mutex_unlock(cooling_cpufreq_lock);
 -
 -   return ret;
 +   *state = cpufreq_device-cpufreq_state;
 +   return 0;
  }

  /**
 @@ -312,22 +291,9 @@ static int cpufreq_get_cur_state(struct 
 thermal_cooling_device *cdev,
  static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
  unsigned long state)
  {
 -   int ret = -EINVAL;
 -   struct cpufreq_cooling_device *cpufreq_device;
 +   struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
check cdev is not null

 -   mutex_lock(cooling_cpufreq_lock);
 -   list_for_each_entry(cpufreq_device, cooling_cpufreq_list, node) {
 -   if (cpufreq_device  cpufreq_device-cool_dev == cdev) {
 -   ret = 0;
 -   break;
 -   }
 -   }
 -   if (!ret)
 -   ret = cpufreq_apply_cooling(cpufreq_device, state);
 -
 -   mutex_unlock(cooling_cpufreq_lock);
 -
 -   return ret;
 +   return cpufreq_apply_cooling(cpufreq_device, state);
  }

  /* Bind cpufreq callbacks to thermal cooling device ops */
 @@ -351,7 +317,7 @@ struct thermal_cooling_device *cpufreq_cooling_register(
  {
 struct thermal_cooling_device 

Re: [PATCH V2 4/6] Thermal: Remove the cooling_cpufreq_list.

2012-10-30 Thread Hongbo Zhang
On 30 October 2012 09:03, Amit Kachhap amit.kach...@linaro.org wrote:
 On 26 October 2012 12:39, hongbo.zhang hongbo.zh...@linaro.org wrote:
 From: hongbo.zhang hongbo.zh...@linaro.com

 Problem of using this list is that the cpufreq_get_max_state callback will be
 called when register cooling device by thermal_cooling_device_register, but
 this list isn't ready at this moment. What's more, there is no need to 
 maintain
 such a list, we can get cpufreq_cooling_device instance by the private
 thermal_cooling_device.devdata.

 Hi,

 Removing this list seems fine as most of frequency checks are moved
 inside generic thermal layer.
 Some minor review comments below,

 Reviewed-by: Amit Daniel Kachhap amit.kach...@linaro.org
Thanks.

 Signed-off-by: hongbo.zhang hongbo.zh...@linaro.com
 ---
  drivers/thermal/cpu_cooling.c | 91 
 +--
  1 file changed, 19 insertions(+), 72 deletions(-)

 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
 index 415b041..2ffd12c 100644
 --- a/drivers/thermal/cpu_cooling.c
 +++ b/drivers/thermal/cpu_cooling.c
 @@ -58,8 +58,9 @@ struct cpufreq_cooling_device {
  };
  static LIST_HEAD(cooling_cpufreq_list);
  static DEFINE_IDR(cpufreq_idr);
 +static DEFINE_MUTEX(cooling_cpufreq_lock);

 -static struct mutex cooling_cpufreq_lock;
 +static unsigned int cpufreq_dev_count;

  /* notify_table passes value to the CPUFREQ_ADJUST callback function. */
  #define NOTIFY_INVALID NULL
 @@ -240,28 +241,18 @@ static int cpufreq_thermal_notifier(struct 
 notifier_block *nb,
  static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
  unsigned long *state)
  {
 -   int ret = -EINVAL, i = 0;
 -   struct cpufreq_cooling_device *cpufreq_device;
 -   struct cpumask *maskPtr;
 +   struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
 check cdev is not null.
 +   struct cpumask *maskPtr = cpufreq_device-allowed_cpus;
 unsigned int cpu;
 struct cpufreq_frequency_table *table;
 unsigned long count = 0;
 +   int i = 0;

 -   mutex_lock(cooling_cpufreq_lock);
 -   list_for_each_entry(cpufreq_device, cooling_cpufreq_list, node) {
 -   if (cpufreq_device  cpufreq_device-cool_dev == cdev)
 -   break;
 -   }
 -   if (cpufreq_device == NULL)
 -   goto return_get_max_state;
 -
 -   maskPtr = cpufreq_device-allowed_cpus;
 cpu = cpumask_any(maskPtr);
 table = cpufreq_frequency_get_table(cpu);
 if (!table) {
 *state = 0;
 -   ret = 0;
 -   goto return_get_max_state;
 +   return 0;
 }

 for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {
 @@ -272,12 +263,10 @@ static int cpufreq_get_max_state(struct 
 thermal_cooling_device *cdev,

 if (count  0) {
 *state = --count;
 -   ret = 0;
 +   return 0;
 }

 -return_get_max_state:
 -   mutex_unlock(cooling_cpufreq_lock);
 -   return ret;
 +   return -EINVAL;
  }

  /**
 @@ -288,20 +277,10 @@ return_get_max_state:
  static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
  unsigned long *state)
  {
 -   int ret = -EINVAL;
 -   struct cpufreq_cooling_device *cpufreq_device;
 +   struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;

 -   mutex_lock(cooling_cpufreq_lock);
 -   list_for_each_entry(cpufreq_device, cooling_cpufreq_list, node) {
 -   if (cpufreq_device  cpufreq_device-cool_dev == cdev) {
 -   *state = cpufreq_device-cpufreq_state;
 -   ret = 0;
 -   break;
 -   }
 -   }
 -   mutex_unlock(cooling_cpufreq_lock);
 -
 -   return ret;
 +   *state = cpufreq_device-cpufreq_state;
 +   return 0;
  }

  /**
 @@ -312,22 +291,9 @@ static int cpufreq_get_cur_state(struct 
 thermal_cooling_device *cdev,
  static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
  unsigned long state)
  {
 -   int ret = -EINVAL;
 -   struct cpufreq_cooling_device *cpufreq_device;
 +   struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
 check cdev is not null
Such values are used in all the three static cpufreq_***_state
callback functions, when these functions are called, cdev-devdata
should have been set in the registration function, and cannot be null,
no body can call these function before registration, so I think there
is no need to add such a check here.


 -   mutex_lock(cooling_cpufreq_lock);
 -   list_for_each_entry(cpufreq_device, cooling_cpufreq_list, node) {
 -   if (cpufreq_device  cpufreq_device-cool_dev == cdev) {
 -   ret = 0;
 -   break;
 -   }
 -   }
 -   if (!ret)
 

Re: [PATCH V2 4/6] Thermal: Remove the cooling_cpufreq_list.

2012-10-27 Thread Francesco Lavra
On Fri, 26 Oct 2012 15:09:05 +0800, Hongbo Zhang wrote:
> From: "hongbo.zhang" 
> 
> Problem of using this list is that the cpufreq_get_max_state callback will be
> called when register cooling device by thermal_cooling_device_register, but
> this list isn't ready at this moment. What's more, there is no need to 
> maintain
> such a list, we can get cpufreq_cooling_device instance by the private
> thermal_cooling_device.devdata.
> 
> Signed-off-by: hongbo.zhang 

FWIW,
Reviewed-by: Francesco Lavra 
--
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 V2 4/6] Thermal: Remove the cooling_cpufreq_list.

2012-10-27 Thread Francesco Lavra
On Fri, 26 Oct 2012 15:09:05 +0800, Hongbo Zhang wrote:
 From: hongbo.zhang hongbo.zhang at linaro.com
 
 Problem of using this list is that the cpufreq_get_max_state callback will be
 called when register cooling device by thermal_cooling_device_register, but
 this list isn't ready at this moment. What's more, there is no need to 
 maintain
 such a list, we can get cpufreq_cooling_device instance by the private
 thermal_cooling_device.devdata.
 
 Signed-off-by: hongbo.zhang hongbo.zhang at linaro.com

FWIW,
Reviewed-by: Francesco Lavra francescolavra...@gmail.com
--
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/


[PATCH V2 4/6] Thermal: Remove the cooling_cpufreq_list.

2012-10-26 Thread hongbo.zhang
From: "hongbo.zhang" 

Problem of using this list is that the cpufreq_get_max_state callback will be
called when register cooling device by thermal_cooling_device_register, but
this list isn't ready at this moment. What's more, there is no need to maintain
such a list, we can get cpufreq_cooling_device instance by the private
thermal_cooling_device.devdata.

Signed-off-by: hongbo.zhang 
---
 drivers/thermal/cpu_cooling.c | 91 +--
 1 file changed, 19 insertions(+), 72 deletions(-)

diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 415b041..2ffd12c 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -58,8 +58,9 @@ struct cpufreq_cooling_device {
 };
 static LIST_HEAD(cooling_cpufreq_list);
 static DEFINE_IDR(cpufreq_idr);
+static DEFINE_MUTEX(cooling_cpufreq_lock);
 
-static struct mutex cooling_cpufreq_lock;
+static unsigned int cpufreq_dev_count;
 
 /* notify_table passes value to the CPUFREQ_ADJUST callback function. */
 #define NOTIFY_INVALID NULL
@@ -240,28 +241,18 @@ static int cpufreq_thermal_notifier(struct notifier_block 
*nb,
 static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
 unsigned long *state)
 {
-   int ret = -EINVAL, i = 0;
-   struct cpufreq_cooling_device *cpufreq_device;
-   struct cpumask *maskPtr;
+   struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
+   struct cpumask *maskPtr = _device->allowed_cpus;
unsigned int cpu;
struct cpufreq_frequency_table *table;
unsigned long count = 0;
+   int i = 0;
 
-   mutex_lock(_cpufreq_lock);
-   list_for_each_entry(cpufreq_device, _cpufreq_list, node) {
-   if (cpufreq_device && cpufreq_device->cool_dev == cdev)
-   break;
-   }
-   if (cpufreq_device == NULL)
-   goto return_get_max_state;
-
-   maskPtr = _device->allowed_cpus;
cpu = cpumask_any(maskPtr);
table = cpufreq_frequency_get_table(cpu);
if (!table) {
*state = 0;
-   ret = 0;
-   goto return_get_max_state;
+   return 0;
}
 
for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {
@@ -272,12 +263,10 @@ static int cpufreq_get_max_state(struct 
thermal_cooling_device *cdev,
 
if (count > 0) {
*state = --count;
-   ret = 0;
+   return 0;
}
 
-return_get_max_state:
-   mutex_unlock(_cpufreq_lock);
-   return ret;
+   return -EINVAL;
 }
 
 /**
@@ -288,20 +277,10 @@ return_get_max_state:
 static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
 unsigned long *state)
 {
-   int ret = -EINVAL;
-   struct cpufreq_cooling_device *cpufreq_device;
+   struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
 
-   mutex_lock(_cpufreq_lock);
-   list_for_each_entry(cpufreq_device, _cpufreq_list, node) {
-   if (cpufreq_device && cpufreq_device->cool_dev == cdev) {
-   *state = cpufreq_device->cpufreq_state;
-   ret = 0;
-   break;
-   }
-   }
-   mutex_unlock(_cpufreq_lock);
-
-   return ret;
+   *state = cpufreq_device->cpufreq_state;
+   return 0;
 }
 
 /**
@@ -312,22 +291,9 @@ static int cpufreq_get_cur_state(struct 
thermal_cooling_device *cdev,
 static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
 unsigned long state)
 {
-   int ret = -EINVAL;
-   struct cpufreq_cooling_device *cpufreq_device;
+   struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
 
-   mutex_lock(_cpufreq_lock);
-   list_for_each_entry(cpufreq_device, _cpufreq_list, node) {
-   if (cpufreq_device && cpufreq_device->cool_dev == cdev) {
-   ret = 0;
-   break;
-   }
-   }
-   if (!ret)
-   ret = cpufreq_apply_cooling(cpufreq_device, state);
-
-   mutex_unlock(_cpufreq_lock);
-
-   return ret;
+   return cpufreq_apply_cooling(cpufreq_device, state);
 }
 
 /* Bind cpufreq callbacks to thermal cooling device ops */
@@ -351,7 +317,7 @@ struct thermal_cooling_device *cpufreq_cooling_register(
 {
struct thermal_cooling_device *cool_dev;
struct cpufreq_cooling_device *cpufreq_dev = NULL;
-   unsigned int cpufreq_dev_count = 0, min = 0, max = 0;
+   unsigned int min = 0, max = 0;
char dev_name[THERMAL_NAME_LENGTH];
int ret = 0, i;
struct cpufreq_policy policy;
@@ -360,9 +326,6 @@ struct thermal_cooling_device *cpufreq_cooling_register(
if (!cpufreq_frequency_get_table(cpumask_any(clip_cpus)))
return ERR_PTR(-EPROBE_DEFER);
 
-   list_for_each_entry(cpufreq_dev, _cpufreq_list, node)
- 

[PATCH V2 4/6] Thermal: Remove the cooling_cpufreq_list.

2012-10-26 Thread hongbo.zhang
From: hongbo.zhang hongbo.zh...@linaro.com

Problem of using this list is that the cpufreq_get_max_state callback will be
called when register cooling device by thermal_cooling_device_register, but
this list isn't ready at this moment. What's more, there is no need to maintain
such a list, we can get cpufreq_cooling_device instance by the private
thermal_cooling_device.devdata.

Signed-off-by: hongbo.zhang hongbo.zh...@linaro.com
---
 drivers/thermal/cpu_cooling.c | 91 +--
 1 file changed, 19 insertions(+), 72 deletions(-)

diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 415b041..2ffd12c 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -58,8 +58,9 @@ struct cpufreq_cooling_device {
 };
 static LIST_HEAD(cooling_cpufreq_list);
 static DEFINE_IDR(cpufreq_idr);
+static DEFINE_MUTEX(cooling_cpufreq_lock);
 
-static struct mutex cooling_cpufreq_lock;
+static unsigned int cpufreq_dev_count;
 
 /* notify_table passes value to the CPUFREQ_ADJUST callback function. */
 #define NOTIFY_INVALID NULL
@@ -240,28 +241,18 @@ static int cpufreq_thermal_notifier(struct notifier_block 
*nb,
 static int cpufreq_get_max_state(struct thermal_cooling_device *cdev,
 unsigned long *state)
 {
-   int ret = -EINVAL, i = 0;
-   struct cpufreq_cooling_device *cpufreq_device;
-   struct cpumask *maskPtr;
+   struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
+   struct cpumask *maskPtr = cpufreq_device-allowed_cpus;
unsigned int cpu;
struct cpufreq_frequency_table *table;
unsigned long count = 0;
+   int i = 0;
 
-   mutex_lock(cooling_cpufreq_lock);
-   list_for_each_entry(cpufreq_device, cooling_cpufreq_list, node) {
-   if (cpufreq_device  cpufreq_device-cool_dev == cdev)
-   break;
-   }
-   if (cpufreq_device == NULL)
-   goto return_get_max_state;
-
-   maskPtr = cpufreq_device-allowed_cpus;
cpu = cpumask_any(maskPtr);
table = cpufreq_frequency_get_table(cpu);
if (!table) {
*state = 0;
-   ret = 0;
-   goto return_get_max_state;
+   return 0;
}
 
for (i = 0; (table[i].frequency != CPUFREQ_TABLE_END); i++) {
@@ -272,12 +263,10 @@ static int cpufreq_get_max_state(struct 
thermal_cooling_device *cdev,
 
if (count  0) {
*state = --count;
-   ret = 0;
+   return 0;
}
 
-return_get_max_state:
-   mutex_unlock(cooling_cpufreq_lock);
-   return ret;
+   return -EINVAL;
 }
 
 /**
@@ -288,20 +277,10 @@ return_get_max_state:
 static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
 unsigned long *state)
 {
-   int ret = -EINVAL;
-   struct cpufreq_cooling_device *cpufreq_device;
+   struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
 
-   mutex_lock(cooling_cpufreq_lock);
-   list_for_each_entry(cpufreq_device, cooling_cpufreq_list, node) {
-   if (cpufreq_device  cpufreq_device-cool_dev == cdev) {
-   *state = cpufreq_device-cpufreq_state;
-   ret = 0;
-   break;
-   }
-   }
-   mutex_unlock(cooling_cpufreq_lock);
-
-   return ret;
+   *state = cpufreq_device-cpufreq_state;
+   return 0;
 }
 
 /**
@@ -312,22 +291,9 @@ static int cpufreq_get_cur_state(struct 
thermal_cooling_device *cdev,
 static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
 unsigned long state)
 {
-   int ret = -EINVAL;
-   struct cpufreq_cooling_device *cpufreq_device;
+   struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
 
-   mutex_lock(cooling_cpufreq_lock);
-   list_for_each_entry(cpufreq_device, cooling_cpufreq_list, node) {
-   if (cpufreq_device  cpufreq_device-cool_dev == cdev) {
-   ret = 0;
-   break;
-   }
-   }
-   if (!ret)
-   ret = cpufreq_apply_cooling(cpufreq_device, state);
-
-   mutex_unlock(cooling_cpufreq_lock);
-
-   return ret;
+   return cpufreq_apply_cooling(cpufreq_device, state);
 }
 
 /* Bind cpufreq callbacks to thermal cooling device ops */
@@ -351,7 +317,7 @@ struct thermal_cooling_device *cpufreq_cooling_register(
 {
struct thermal_cooling_device *cool_dev;
struct cpufreq_cooling_device *cpufreq_dev = NULL;
-   unsigned int cpufreq_dev_count = 0, min = 0, max = 0;
+   unsigned int min = 0, max = 0;
char dev_name[THERMAL_NAME_LENGTH];
int ret = 0, i;
struct cpufreq_policy policy;
@@ -360,9 +326,6 @@ struct thermal_cooling_device *cpufreq_cooling_register(
if (!cpufreq_frequency_get_table(cpumask_any(clip_cpus)))
 

Re: [PATCH V2 4/6] Thermal: Remove the cooling_cpufreq_list

2012-10-25 Thread Hongbo Zhang
On 26 October 2012 03:14, Francesco Lavra  wrote:
> Hi,
> Hongbo Zhang wrote:
>> Problem of using this list is that the cpufreq_get_max_state callback will be
>> called when register cooling device by thermal_cooling_device_register, but
>> this list isn't ready at this moment. What's more, there is no need to 
>> maintain
>> such a list, we can get cpufreq_cooling_device instance by the private
>> thermal_cooling_device.devdata.
>>
>> Signed-off-by: hongbo.zhang 
>> ---
>>  drivers/thermal/cpu_cooling.c | 81 
>> +--
>>  1 file changed, 16 insertions(+), 65 deletions(-)
>>
>> diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
>> index 415b041..cc80d29 100644
>> --- a/drivers/thermal/cpu_cooling.c
>> +++ b/drivers/thermal/cpu_cooling.c
>> @@ -58,8 +58,9 @@ struct cpufreq_cooling_device {
>>  };
>>  static LIST_HEAD(cooling_cpufreq_list);
>>  static DEFINE_IDR(cpufreq_idr);
>> +static DEFINE_MUTEX(cooling_cpufreq_lock);
>>
>> -static struct mutex cooling_cpufreq_lock;
>> +static unsigned int cpufreq_dev_count;
>>
>>  /* notify_table passes value to the CPUFREQ_ADJUST callback function. */
>>  #define NOTIFY_INVALID NULL
>> @@ -241,20 +242,12 @@ static int cpufreq_get_max_state(struct 
>> thermal_cooling_device *cdev,
>>unsigned long *state)
>>  {
>>   int ret = -EINVAL, i = 0;
>> - struct cpufreq_cooling_device *cpufreq_device;
>> + struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
>>   struct cpumask *maskPtr;
>>   unsigned int cpu;
>>   struct cpufreq_frequency_table *table;
>>   unsigned long count = 0;
>>
>> - mutex_lock(_cpufreq_lock);
>> - list_for_each_entry(cpufreq_device, _cpufreq_list, node) {
>> - if (cpufreq_device && cpufreq_device->cool_dev == cdev)
>> - break;
>> - }
>> - if (cpufreq_device == NULL)
>> - goto return_get_max_state;
>> -
>>   maskPtr = _device->allowed_cpus;
>>   cpu = cpumask_any(maskPtr);
>>   table = cpufreq_frequency_get_table(cpu);
>> @@ -276,7 +269,6 @@ static int cpufreq_get_max_state(struct 
>> thermal_cooling_device *cdev,
>>   }
>>
>>  return_get_max_state:
>> - mutex_unlock(_cpufreq_lock);
>>   return ret;
>
> Since there is no mutex locking/unlocking anymore, I'd say the goto
> label should be removed.
Good.
>
> [...]
>>  void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
>>  {
>> - struct cpufreq_cooling_device *cpufreq_dev = NULL;
>> - unsigned int cpufreq_dev_count = 0;
>> + struct cpufreq_cooling_device *cpufreq_dev = cdev->devdata;
>>
>> - mutex_lock(_cpufreq_lock);
>> - list_for_each_entry(cpufreq_dev, _cpufreq_list, node) {
>> - if (cpufreq_dev && cpufreq_dev->cool_dev == cdev)
>> - break;
>> - cpufreq_dev_count++;
>> - }
>> -
>> - if (!cpufreq_dev || cpufreq_dev->cool_dev != cdev) {
>> - mutex_unlock(_cpufreq_lock);
>> - return;
>> - }
>> + thermal_cooling_device_unregister(cpufreq_dev->cool_dev);
>>
>> - list_del(_dev->node);
>> + mutex_lock(_cpufreq_lock);
>> + cpufreq_dev_count--;
>>
>>   /* Unregister the notifier for the last cpufreq cooling device */
>> - if (cpufreq_dev_count == 1) {
>> + if (cpufreq_dev_count == 0) {
>>   cpufreq_unregister_notifier(_cpufreq_notifier_block,
>>   CPUFREQ_POLICY_NOTIFIER);
>>   }
>>   mutex_unlock(_cpufreq_lock);
>> - thermal_cooling_device_unregister(cpufreq_dev->cool_dev);
>
> Why did you move the call to thermal_cooling_device_unregister() from
> here? I don't see any reason for moving it.
In common sense, usually unregister first and then count--;
But here it should be opposite sequence of cpufreq_cooling_register,
will update it.

>
>> +
>>   release_idr(_idr, cpufreq_dev->id);
>> - if (cpufreq_dev_count == 1)
>> - mutex_destroy(_cpufreq_lock);
>>   kfree(cpufreq_dev);
>>  }
>>  EXPORT_SYMBOL(cpufreq_cooling_unregister);
>> --
>> 1.7.11.3
>
> --
> Francesco
--
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 V2 4/6] Thermal: Remove the cooling_cpufreq_list

2012-10-25 Thread Francesco Lavra
Hi,
Hongbo Zhang wrote:
> Problem of using this list is that the cpufreq_get_max_state callback will be
> called when register cooling device by thermal_cooling_device_register, but
> this list isn't ready at this moment. What's more, there is no need to 
> maintain
> such a list, we can get cpufreq_cooling_device instance by the private
> thermal_cooling_device.devdata.
> 
> Signed-off-by: hongbo.zhang 
> ---
>  drivers/thermal/cpu_cooling.c | 81 
> +--
>  1 file changed, 16 insertions(+), 65 deletions(-)
> 
> diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
> index 415b041..cc80d29 100644
> --- a/drivers/thermal/cpu_cooling.c
> +++ b/drivers/thermal/cpu_cooling.c
> @@ -58,8 +58,9 @@ struct cpufreq_cooling_device {
>  };
>  static LIST_HEAD(cooling_cpufreq_list);
>  static DEFINE_IDR(cpufreq_idr);
> +static DEFINE_MUTEX(cooling_cpufreq_lock);
>  
> -static struct mutex cooling_cpufreq_lock;
> +static unsigned int cpufreq_dev_count;
>  
>  /* notify_table passes value to the CPUFREQ_ADJUST callback function. */
>  #define NOTIFY_INVALID NULL
> @@ -241,20 +242,12 @@ static int cpufreq_get_max_state(struct 
> thermal_cooling_device *cdev,
>unsigned long *state)
>  {
>   int ret = -EINVAL, i = 0;
> - struct cpufreq_cooling_device *cpufreq_device;
> + struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
>   struct cpumask *maskPtr;
>   unsigned int cpu;
>   struct cpufreq_frequency_table *table;
>   unsigned long count = 0;
>  
> - mutex_lock(_cpufreq_lock);
> - list_for_each_entry(cpufreq_device, _cpufreq_list, node) {
> - if (cpufreq_device && cpufreq_device->cool_dev == cdev)
> - break;
> - }
> - if (cpufreq_device == NULL)
> - goto return_get_max_state;
> -
>   maskPtr = _device->allowed_cpus;
>   cpu = cpumask_any(maskPtr);
>   table = cpufreq_frequency_get_table(cpu);
> @@ -276,7 +269,6 @@ static int cpufreq_get_max_state(struct 
> thermal_cooling_device *cdev,
>   }
>  
>  return_get_max_state:
> - mutex_unlock(_cpufreq_lock);
>   return ret;

Since there is no mutex locking/unlocking anymore, I'd say the goto
label should be removed.

[...]
>  void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
>  {
> - struct cpufreq_cooling_device *cpufreq_dev = NULL;
> - unsigned int cpufreq_dev_count = 0;
> + struct cpufreq_cooling_device *cpufreq_dev = cdev->devdata;
>  
> - mutex_lock(_cpufreq_lock);
> - list_for_each_entry(cpufreq_dev, _cpufreq_list, node) {
> - if (cpufreq_dev && cpufreq_dev->cool_dev == cdev)
> - break;
> - cpufreq_dev_count++;
> - }
> -
> - if (!cpufreq_dev || cpufreq_dev->cool_dev != cdev) {
> - mutex_unlock(_cpufreq_lock);
> - return;
> - }
> + thermal_cooling_device_unregister(cpufreq_dev->cool_dev);
>  
> - list_del(_dev->node);
> + mutex_lock(_cpufreq_lock);
> + cpufreq_dev_count--;
>  
>   /* Unregister the notifier for the last cpufreq cooling device */
> - if (cpufreq_dev_count == 1) {
> + if (cpufreq_dev_count == 0) {
>   cpufreq_unregister_notifier(_cpufreq_notifier_block,
>   CPUFREQ_POLICY_NOTIFIER);
>   }
>   mutex_unlock(_cpufreq_lock);
> - thermal_cooling_device_unregister(cpufreq_dev->cool_dev);

Why did you move the call to thermal_cooling_device_unregister() from
here? I don't see any reason for moving it.

> +
>   release_idr(_idr, cpufreq_dev->id);
> - if (cpufreq_dev_count == 1)
> - mutex_destroy(_cpufreq_lock);
>   kfree(cpufreq_dev);
>  }
>  EXPORT_SYMBOL(cpufreq_cooling_unregister);
> -- 
> 1.7.11.3

--
Francesco
--
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 V2 4/6] Thermal: Remove the cooling_cpufreq_list

2012-10-25 Thread Francesco Lavra
Hi,
Hongbo Zhang wrote:
 Problem of using this list is that the cpufreq_get_max_state callback will be
 called when register cooling device by thermal_cooling_device_register, but
 this list isn't ready at this moment. What's more, there is no need to 
 maintain
 such a list, we can get cpufreq_cooling_device instance by the private
 thermal_cooling_device.devdata.
 
 Signed-off-by: hongbo.zhang hongbo.zhang at linaro.com
 ---
  drivers/thermal/cpu_cooling.c | 81 
 +--
  1 file changed, 16 insertions(+), 65 deletions(-)
 
 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
 index 415b041..cc80d29 100644
 --- a/drivers/thermal/cpu_cooling.c
 +++ b/drivers/thermal/cpu_cooling.c
 @@ -58,8 +58,9 @@ struct cpufreq_cooling_device {
  };
  static LIST_HEAD(cooling_cpufreq_list);
  static DEFINE_IDR(cpufreq_idr);
 +static DEFINE_MUTEX(cooling_cpufreq_lock);
  
 -static struct mutex cooling_cpufreq_lock;
 +static unsigned int cpufreq_dev_count;
  
  /* notify_table passes value to the CPUFREQ_ADJUST callback function. */
  #define NOTIFY_INVALID NULL
 @@ -241,20 +242,12 @@ static int cpufreq_get_max_state(struct 
 thermal_cooling_device *cdev,
unsigned long *state)
  {
   int ret = -EINVAL, i = 0;
 - struct cpufreq_cooling_device *cpufreq_device;
 + struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
   struct cpumask *maskPtr;
   unsigned int cpu;
   struct cpufreq_frequency_table *table;
   unsigned long count = 0;
  
 - mutex_lock(cooling_cpufreq_lock);
 - list_for_each_entry(cpufreq_device, cooling_cpufreq_list, node) {
 - if (cpufreq_device  cpufreq_device-cool_dev == cdev)
 - break;
 - }
 - if (cpufreq_device == NULL)
 - goto return_get_max_state;
 -
   maskPtr = cpufreq_device-allowed_cpus;
   cpu = cpumask_any(maskPtr);
   table = cpufreq_frequency_get_table(cpu);
 @@ -276,7 +269,6 @@ static int cpufreq_get_max_state(struct 
 thermal_cooling_device *cdev,
   }
  
  return_get_max_state:
 - mutex_unlock(cooling_cpufreq_lock);
   return ret;

Since there is no mutex locking/unlocking anymore, I'd say the goto
label should be removed.

[...]
  void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
  {
 - struct cpufreq_cooling_device *cpufreq_dev = NULL;
 - unsigned int cpufreq_dev_count = 0;
 + struct cpufreq_cooling_device *cpufreq_dev = cdev-devdata;
  
 - mutex_lock(cooling_cpufreq_lock);
 - list_for_each_entry(cpufreq_dev, cooling_cpufreq_list, node) {
 - if (cpufreq_dev  cpufreq_dev-cool_dev == cdev)
 - break;
 - cpufreq_dev_count++;
 - }
 -
 - if (!cpufreq_dev || cpufreq_dev-cool_dev != cdev) {
 - mutex_unlock(cooling_cpufreq_lock);
 - return;
 - }
 + thermal_cooling_device_unregister(cpufreq_dev-cool_dev);
  
 - list_del(cpufreq_dev-node);
 + mutex_lock(cooling_cpufreq_lock);
 + cpufreq_dev_count--;
  
   /* Unregister the notifier for the last cpufreq cooling device */
 - if (cpufreq_dev_count == 1) {
 + if (cpufreq_dev_count == 0) {
   cpufreq_unregister_notifier(thermal_cpufreq_notifier_block,
   CPUFREQ_POLICY_NOTIFIER);
   }
   mutex_unlock(cooling_cpufreq_lock);
 - thermal_cooling_device_unregister(cpufreq_dev-cool_dev);

Why did you move the call to thermal_cooling_device_unregister() from
here? I don't see any reason for moving it.

 +
   release_idr(cpufreq_idr, cpufreq_dev-id);
 - if (cpufreq_dev_count == 1)
 - mutex_destroy(cooling_cpufreq_lock);
   kfree(cpufreq_dev);
  }
  EXPORT_SYMBOL(cpufreq_cooling_unregister);
 -- 
 1.7.11.3

--
Francesco
--
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 V2 4/6] Thermal: Remove the cooling_cpufreq_list

2012-10-25 Thread Hongbo Zhang
On 26 October 2012 03:14, Francesco Lavra francescolavra...@gmail.com wrote:
 Hi,
 Hongbo Zhang wrote:
 Problem of using this list is that the cpufreq_get_max_state callback will be
 called when register cooling device by thermal_cooling_device_register, but
 this list isn't ready at this moment. What's more, there is no need to 
 maintain
 such a list, we can get cpufreq_cooling_device instance by the private
 thermal_cooling_device.devdata.

 Signed-off-by: hongbo.zhang hongbo.zhang at linaro.com
 ---
  drivers/thermal/cpu_cooling.c | 81 
 +--
  1 file changed, 16 insertions(+), 65 deletions(-)

 diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
 index 415b041..cc80d29 100644
 --- a/drivers/thermal/cpu_cooling.c
 +++ b/drivers/thermal/cpu_cooling.c
 @@ -58,8 +58,9 @@ struct cpufreq_cooling_device {
  };
  static LIST_HEAD(cooling_cpufreq_list);
  static DEFINE_IDR(cpufreq_idr);
 +static DEFINE_MUTEX(cooling_cpufreq_lock);

 -static struct mutex cooling_cpufreq_lock;
 +static unsigned int cpufreq_dev_count;

  /* notify_table passes value to the CPUFREQ_ADJUST callback function. */
  #define NOTIFY_INVALID NULL
 @@ -241,20 +242,12 @@ static int cpufreq_get_max_state(struct 
 thermal_cooling_device *cdev,
unsigned long *state)
  {
   int ret = -EINVAL, i = 0;
 - struct cpufreq_cooling_device *cpufreq_device;
 + struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
   struct cpumask *maskPtr;
   unsigned int cpu;
   struct cpufreq_frequency_table *table;
   unsigned long count = 0;

 - mutex_lock(cooling_cpufreq_lock);
 - list_for_each_entry(cpufreq_device, cooling_cpufreq_list, node) {
 - if (cpufreq_device  cpufreq_device-cool_dev == cdev)
 - break;
 - }
 - if (cpufreq_device == NULL)
 - goto return_get_max_state;
 -
   maskPtr = cpufreq_device-allowed_cpus;
   cpu = cpumask_any(maskPtr);
   table = cpufreq_frequency_get_table(cpu);
 @@ -276,7 +269,6 @@ static int cpufreq_get_max_state(struct 
 thermal_cooling_device *cdev,
   }

  return_get_max_state:
 - mutex_unlock(cooling_cpufreq_lock);
   return ret;

 Since there is no mutex locking/unlocking anymore, I'd say the goto
 label should be removed.
Good.

 [...]
  void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
  {
 - struct cpufreq_cooling_device *cpufreq_dev = NULL;
 - unsigned int cpufreq_dev_count = 0;
 + struct cpufreq_cooling_device *cpufreq_dev = cdev-devdata;

 - mutex_lock(cooling_cpufreq_lock);
 - list_for_each_entry(cpufreq_dev, cooling_cpufreq_list, node) {
 - if (cpufreq_dev  cpufreq_dev-cool_dev == cdev)
 - break;
 - cpufreq_dev_count++;
 - }
 -
 - if (!cpufreq_dev || cpufreq_dev-cool_dev != cdev) {
 - mutex_unlock(cooling_cpufreq_lock);
 - return;
 - }
 + thermal_cooling_device_unregister(cpufreq_dev-cool_dev);

 - list_del(cpufreq_dev-node);
 + mutex_lock(cooling_cpufreq_lock);
 + cpufreq_dev_count--;

   /* Unregister the notifier for the last cpufreq cooling device */
 - if (cpufreq_dev_count == 1) {
 + if (cpufreq_dev_count == 0) {
   cpufreq_unregister_notifier(thermal_cpufreq_notifier_block,
   CPUFREQ_POLICY_NOTIFIER);
   }
   mutex_unlock(cooling_cpufreq_lock);
 - thermal_cooling_device_unregister(cpufreq_dev-cool_dev);

 Why did you move the call to thermal_cooling_device_unregister() from
 here? I don't see any reason for moving it.
In common sense, usually unregister first and then count--;
But here it should be opposite sequence of cpufreq_cooling_register,
will update it.


 +
   release_idr(cpufreq_idr, cpufreq_dev-id);
 - if (cpufreq_dev_count == 1)
 - mutex_destroy(cooling_cpufreq_lock);
   kfree(cpufreq_dev);
  }
  EXPORT_SYMBOL(cpufreq_cooling_unregister);
 --
 1.7.11.3

 --
 Francesco
--
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/


[PATCH V2 4/6] Thermal: Remove the cooling_cpufreq_list.

2012-10-24 Thread hongbo.zhang
From: "hongbo.zhang" 

Problem of using this list is that the cpufreq_get_max_state callback will be
called when register cooling device by thermal_cooling_device_register, but
this list isn't ready at this moment. What's more, there is no need to maintain
such a list, we can get cpufreq_cooling_device instance by the private
thermal_cooling_device.devdata.

Signed-off-by: hongbo.zhang 
---
 drivers/thermal/cpu_cooling.c | 81 +--
 1 file changed, 16 insertions(+), 65 deletions(-)

diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 415b041..cc80d29 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -58,8 +58,9 @@ struct cpufreq_cooling_device {
 };
 static LIST_HEAD(cooling_cpufreq_list);
 static DEFINE_IDR(cpufreq_idr);
+static DEFINE_MUTEX(cooling_cpufreq_lock);
 
-static struct mutex cooling_cpufreq_lock;
+static unsigned int cpufreq_dev_count;
 
 /* notify_table passes value to the CPUFREQ_ADJUST callback function. */
 #define NOTIFY_INVALID NULL
@@ -241,20 +242,12 @@ static int cpufreq_get_max_state(struct 
thermal_cooling_device *cdev,
 unsigned long *state)
 {
int ret = -EINVAL, i = 0;
-   struct cpufreq_cooling_device *cpufreq_device;
+   struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
struct cpumask *maskPtr;
unsigned int cpu;
struct cpufreq_frequency_table *table;
unsigned long count = 0;
 
-   mutex_lock(_cpufreq_lock);
-   list_for_each_entry(cpufreq_device, _cpufreq_list, node) {
-   if (cpufreq_device && cpufreq_device->cool_dev == cdev)
-   break;
-   }
-   if (cpufreq_device == NULL)
-   goto return_get_max_state;
-
maskPtr = _device->allowed_cpus;
cpu = cpumask_any(maskPtr);
table = cpufreq_frequency_get_table(cpu);
@@ -276,7 +269,6 @@ static int cpufreq_get_max_state(struct 
thermal_cooling_device *cdev,
}
 
 return_get_max_state:
-   mutex_unlock(_cpufreq_lock);
return ret;
 }
 
@@ -288,20 +280,10 @@ return_get_max_state:
 static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
 unsigned long *state)
 {
-   int ret = -EINVAL;
-   struct cpufreq_cooling_device *cpufreq_device;
-
-   mutex_lock(_cpufreq_lock);
-   list_for_each_entry(cpufreq_device, _cpufreq_list, node) {
-   if (cpufreq_device && cpufreq_device->cool_dev == cdev) {
-   *state = cpufreq_device->cpufreq_state;
-   ret = 0;
-   break;
-   }
-   }
-   mutex_unlock(_cpufreq_lock);
+   struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
 
-   return ret;
+   *state = cpufreq_device->cpufreq_state;
+   return 0;
 }
 
 /**
@@ -312,22 +294,9 @@ static int cpufreq_get_cur_state(struct 
thermal_cooling_device *cdev,
 static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
 unsigned long state)
 {
-   int ret = -EINVAL;
-   struct cpufreq_cooling_device *cpufreq_device;
-
-   mutex_lock(_cpufreq_lock);
-   list_for_each_entry(cpufreq_device, _cpufreq_list, node) {
-   if (cpufreq_device && cpufreq_device->cool_dev == cdev) {
-   ret = 0;
-   break;
-   }
-   }
-   if (!ret)
-   ret = cpufreq_apply_cooling(cpufreq_device, state);
+   struct cpufreq_cooling_device *cpufreq_device = cdev->devdata;
 
-   mutex_unlock(_cpufreq_lock);
-
-   return ret;
+   return cpufreq_apply_cooling(cpufreq_device, state);
 }
 
 /* Bind cpufreq callbacks to thermal cooling device ops */
@@ -351,7 +320,7 @@ struct thermal_cooling_device *cpufreq_cooling_register(
 {
struct thermal_cooling_device *cool_dev;
struct cpufreq_cooling_device *cpufreq_dev = NULL;
-   unsigned int cpufreq_dev_count = 0, min = 0, max = 0;
+   unsigned int min = 0, max = 0;
char dev_name[THERMAL_NAME_LENGTH];
int ret = 0, i;
struct cpufreq_policy policy;
@@ -360,9 +329,6 @@ struct thermal_cooling_device *cpufreq_cooling_register(
if (!cpufreq_frequency_get_table(cpumask_any(clip_cpus)))
return ERR_PTR(-EPROBE_DEFER);
 
-   list_for_each_entry(cpufreq_dev, _cpufreq_list, node)
-   cpufreq_dev_count++;
-
/*Verify that all the clip cpus have same freq_min, freq_max limit*/
for_each_cpu(i, clip_cpus) {
/*continue if cpufreq policy not found and not return error*/
@@ -384,9 +350,6 @@ struct thermal_cooling_device *cpufreq_cooling_register(
 
cpumask_copy(_dev->allowed_cpus, clip_cpus);
 
-   if (cpufreq_dev_count == 0)
-   mutex_init(_cpufreq_lock);
-
ret = get_idr(_idr, _dev->id);
if (ret) {
   

[PATCH V2 4/6] Thermal: Remove the cooling_cpufreq_list.

2012-10-24 Thread hongbo.zhang
From: hongbo.zhang hongbo.zh...@linaro.com

Problem of using this list is that the cpufreq_get_max_state callback will be
called when register cooling device by thermal_cooling_device_register, but
this list isn't ready at this moment. What's more, there is no need to maintain
such a list, we can get cpufreq_cooling_device instance by the private
thermal_cooling_device.devdata.

Signed-off-by: hongbo.zhang hongbo.zh...@linaro.com
---
 drivers/thermal/cpu_cooling.c | 81 +--
 1 file changed, 16 insertions(+), 65 deletions(-)

diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 415b041..cc80d29 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -58,8 +58,9 @@ struct cpufreq_cooling_device {
 };
 static LIST_HEAD(cooling_cpufreq_list);
 static DEFINE_IDR(cpufreq_idr);
+static DEFINE_MUTEX(cooling_cpufreq_lock);
 
-static struct mutex cooling_cpufreq_lock;
+static unsigned int cpufreq_dev_count;
 
 /* notify_table passes value to the CPUFREQ_ADJUST callback function. */
 #define NOTIFY_INVALID NULL
@@ -241,20 +242,12 @@ static int cpufreq_get_max_state(struct 
thermal_cooling_device *cdev,
 unsigned long *state)
 {
int ret = -EINVAL, i = 0;
-   struct cpufreq_cooling_device *cpufreq_device;
+   struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
struct cpumask *maskPtr;
unsigned int cpu;
struct cpufreq_frequency_table *table;
unsigned long count = 0;
 
-   mutex_lock(cooling_cpufreq_lock);
-   list_for_each_entry(cpufreq_device, cooling_cpufreq_list, node) {
-   if (cpufreq_device  cpufreq_device-cool_dev == cdev)
-   break;
-   }
-   if (cpufreq_device == NULL)
-   goto return_get_max_state;
-
maskPtr = cpufreq_device-allowed_cpus;
cpu = cpumask_any(maskPtr);
table = cpufreq_frequency_get_table(cpu);
@@ -276,7 +269,6 @@ static int cpufreq_get_max_state(struct 
thermal_cooling_device *cdev,
}
 
 return_get_max_state:
-   mutex_unlock(cooling_cpufreq_lock);
return ret;
 }
 
@@ -288,20 +280,10 @@ return_get_max_state:
 static int cpufreq_get_cur_state(struct thermal_cooling_device *cdev,
 unsigned long *state)
 {
-   int ret = -EINVAL;
-   struct cpufreq_cooling_device *cpufreq_device;
-
-   mutex_lock(cooling_cpufreq_lock);
-   list_for_each_entry(cpufreq_device, cooling_cpufreq_list, node) {
-   if (cpufreq_device  cpufreq_device-cool_dev == cdev) {
-   *state = cpufreq_device-cpufreq_state;
-   ret = 0;
-   break;
-   }
-   }
-   mutex_unlock(cooling_cpufreq_lock);
+   struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
 
-   return ret;
+   *state = cpufreq_device-cpufreq_state;
+   return 0;
 }
 
 /**
@@ -312,22 +294,9 @@ static int cpufreq_get_cur_state(struct 
thermal_cooling_device *cdev,
 static int cpufreq_set_cur_state(struct thermal_cooling_device *cdev,
 unsigned long state)
 {
-   int ret = -EINVAL;
-   struct cpufreq_cooling_device *cpufreq_device;
-
-   mutex_lock(cooling_cpufreq_lock);
-   list_for_each_entry(cpufreq_device, cooling_cpufreq_list, node) {
-   if (cpufreq_device  cpufreq_device-cool_dev == cdev) {
-   ret = 0;
-   break;
-   }
-   }
-   if (!ret)
-   ret = cpufreq_apply_cooling(cpufreq_device, state);
+   struct cpufreq_cooling_device *cpufreq_device = cdev-devdata;
 
-   mutex_unlock(cooling_cpufreq_lock);
-
-   return ret;
+   return cpufreq_apply_cooling(cpufreq_device, state);
 }
 
 /* Bind cpufreq callbacks to thermal cooling device ops */
@@ -351,7 +320,7 @@ struct thermal_cooling_device *cpufreq_cooling_register(
 {
struct thermal_cooling_device *cool_dev;
struct cpufreq_cooling_device *cpufreq_dev = NULL;
-   unsigned int cpufreq_dev_count = 0, min = 0, max = 0;
+   unsigned int min = 0, max = 0;
char dev_name[THERMAL_NAME_LENGTH];
int ret = 0, i;
struct cpufreq_policy policy;
@@ -360,9 +329,6 @@ struct thermal_cooling_device *cpufreq_cooling_register(
if (!cpufreq_frequency_get_table(cpumask_any(clip_cpus)))
return ERR_PTR(-EPROBE_DEFER);
 
-   list_for_each_entry(cpufreq_dev, cooling_cpufreq_list, node)
-   cpufreq_dev_count++;
-
/*Verify that all the clip cpus have same freq_min, freq_max limit*/
for_each_cpu(i, clip_cpus) {
/*continue if cpufreq policy not found and not return error*/
@@ -384,9 +350,6 @@ struct thermal_cooling_device *cpufreq_cooling_register(
 
cpumask_copy(cpufreq_dev-allowed_cpus, clip_cpus);
 
-   if (cpufreq_dev_count ==