Patchwork [Precise,SRU,2/3] hwmon: (fam15h_power) Increase output resolution

login
register
mail settings
Submitter Tim Gardner
Date June 13, 2012, 8:52 p.m.
Message ID <1339620776-8097-2-git-send-email-tim.gardner@canonical.com>
Download mbox | patch
Permalink /patch/164757/
State New
Headers show

Comments

Tim Gardner - June 13, 2012, 8:52 p.m.
From: Andre Przywara <andre.przywara@amd.com>

BugLink: http://bugs.launchpad.net/bugs/1009086

On high CPU load the accumulating values in the running_avg_cap
register are very low (below 10), so averaging them too early leads
to unnecessary poor output resolution. Since we pretend to output
micro-Watt we better keep all the bits we have as long as possible.

Signed-off-by: Andre Przywara <andre.przywara@amd.com>
Signed-off-by: Andreas Herrmann <andreas.herrmann3@amd.com>
Acked-by: Guenter Roeck <guenter.roeck@ericsson.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
(cherry picked from commit 941a956b0e387b21f385f486c34ef67576775cfc)

Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
---
 drivers/hwmon/fam15h_power.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Leann Ogasawara - June 13, 2012, 9:13 p.m.
On 06/13/2012 01:52 PM, Tim Gardner wrote:
> From: Andre Przywara <andre.przywara@amd.com>
>
> BugLink: http://bugs.launchpad.net/bugs/1009086
>
> On high CPU load the accumulating values in the running_avg_cap
> register are very low (below 10), so averaging them too early leads
> to unnecessary poor output resolution. Since we pretend to output
> micro-Watt we better keep all the bits we have as long as possible.
>
> Signed-off-by: Andre Przywara <andre.przywara@amd.com>
> Signed-off-by: Andreas Herrmann <andreas.herrmann3@amd.com>
> Acked-by: Guenter Roeck <guenter.roeck@ericsson.com>
> Signed-off-by: Jean Delvare <khali@linux-fr.org>
> (cherry picked from commit 941a956b0e387b21f385f486c34ef67576775cfc)
>
> Signed-off-by: Tim Gardner <tim.gardner@canonical.com>

Appears to do as described.  I assume this will go to upstream stable
just like patch 1/3 and 3/3?

Acked-by: Leann Ogasawara <leann.ogasawara@canonical.com>

> ---
>  drivers/hwmon/fam15h_power.c |    8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c
> index 930370d..b7494af 100644
> --- a/drivers/hwmon/fam15h_power.c
> +++ b/drivers/hwmon/fam15h_power.c
> @@ -61,14 +61,14 @@ static ssize_t show_power(struct device *dev,
>  				  REG_TDP_RUNNING_AVERAGE, &val);
>  	running_avg_capture = (val >> 4) & 0x3fffff;
>  	running_avg_capture = sign_extend32(running_avg_capture, 21);
> -	running_avg_range = val & 0xf;
> +	running_avg_range = (val & 0xf) + 1;
>  
>  	pci_bus_read_config_dword(f4->bus, PCI_DEVFN(PCI_SLOT(f4->devfn), 5),
>  				  REG_TDP_LIMIT3, &val);
>  
>  	tdp_limit = val >> 16;
> -	curr_pwr_watts = tdp_limit + data->base_tdp -
> -		(s32)(running_avg_capture >> (running_avg_range + 1));
> +	curr_pwr_watts = (tdp_limit + data->base_tdp) << running_avg_range;
> +	curr_pwr_watts -= running_avg_capture;
>  	curr_pwr_watts *= data->tdp_to_watts;
>  
>  	/*
> @@ -78,7 +78,7 @@ static ssize_t show_power(struct device *dev,
>  	 * scaling factor 1/(2^16).  For conversion we use
>  	 * (10^6)/(2^16) = 15625/(2^10)
>  	 */
> -	curr_pwr_watts = (curr_pwr_watts * 15625) >> 10;
> +	curr_pwr_watts = (curr_pwr_watts * 15625) >> (10 + running_avg_range);
>  	return sprintf(buf, "%u\n", (unsigned int) curr_pwr_watts);
>  }
>  static DEVICE_ATTR(power1_input, S_IRUGO, show_power, NULL);
Brad Figg - June 13, 2012, 10:47 p.m.
On 06/13/2012 01:52 PM, Tim Gardner wrote:
> From: Andre Przywara <andre.przywara@amd.com>
> 
> BugLink: http://bugs.launchpad.net/bugs/1009086
> 
> On high CPU load the accumulating values in the running_avg_cap
> register are very low (below 10), so averaging them too early leads
> to unnecessary poor output resolution. Since we pretend to output
> micro-Watt we better keep all the bits we have as long as possible.
> 
> Signed-off-by: Andre Przywara <andre.przywara@amd.com>
> Signed-off-by: Andreas Herrmann <andreas.herrmann3@amd.com>
> Acked-by: Guenter Roeck <guenter.roeck@ericsson.com>
> Signed-off-by: Jean Delvare <khali@linux-fr.org>
> (cherry picked from commit 941a956b0e387b21f385f486c34ef67576775cfc)
> 
> Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
> ---
>  drivers/hwmon/fam15h_power.c |    8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c
> index 930370d..b7494af 100644
> --- a/drivers/hwmon/fam15h_power.c
> +++ b/drivers/hwmon/fam15h_power.c
> @@ -61,14 +61,14 @@ static ssize_t show_power(struct device *dev,
>  				  REG_TDP_RUNNING_AVERAGE, &val);
>  	running_avg_capture = (val >> 4) & 0x3fffff;
>  	running_avg_capture = sign_extend32(running_avg_capture, 21);
> -	running_avg_range = val & 0xf;
> +	running_avg_range = (val & 0xf) + 1;
>  
>  	pci_bus_read_config_dword(f4->bus, PCI_DEVFN(PCI_SLOT(f4->devfn), 5),
>  				  REG_TDP_LIMIT3, &val);
>  
>  	tdp_limit = val >> 16;
> -	curr_pwr_watts = tdp_limit + data->base_tdp -
> -		(s32)(running_avg_capture >> (running_avg_range + 1));
> +	curr_pwr_watts = (tdp_limit + data->base_tdp) << running_avg_range;
> +	curr_pwr_watts -= running_avg_capture;
>  	curr_pwr_watts *= data->tdp_to_watts;
>  
>  	/*
> @@ -78,7 +78,7 @@ static ssize_t show_power(struct device *dev,
>  	 * scaling factor 1/(2^16).  For conversion we use
>  	 * (10^6)/(2^16) = 15625/(2^10)
>  	 */
> -	curr_pwr_watts = (curr_pwr_watts * 15625) >> 10;
> +	curr_pwr_watts = (curr_pwr_watts * 15625) >> (10 + running_avg_range);
>  	return sprintf(buf, "%u\n", (unsigned int) curr_pwr_watts);
>  }
>  static DEVICE_ATTR(power1_input, S_IRUGO, show_power, NULL);
Tim Gardner - June 14, 2012, 12:56 p.m.
On 06/13/2012 03:13 PM, Leann Ogasawara wrote:
> On 06/13/2012 01:52 PM, Tim Gardner wrote:
>> From: Andre Przywara <andre.przywara@amd.com>
>>
>> BugLink: http://bugs.launchpad.net/bugs/1009086
>>
>> On high CPU load the accumulating values in the running_avg_cap
>> register are very low (below 10), so averaging them too early leads
>> to unnecessary poor output resolution. Since we pretend to output
>> micro-Watt we better keep all the bits we have as long as possible.
>>
>> Signed-off-by: Andre Przywara <andre.przywara@amd.com>
>> Signed-off-by: Andreas Herrmann <andreas.herrmann3@amd.com>
>> Acked-by: Guenter Roeck <guenter.roeck@ericsson.com>
>> Signed-off-by: Jean Delvare <khali@linux-fr.org>
>> (cherry picked from commit 941a956b0e387b21f385f486c34ef67576775cfc)
>>
>> Signed-off-by: Tim Gardner <tim.gardner@canonical.com>
> 
> Appears to do as described.  I assume this will go to upstream stable
> just like patch 1/3 and 3/3?
> 
> Acked-by: Leann Ogasawara <leann.ogasawara@canonical.com>
> 

Sent to stable.

Patch

diff --git a/drivers/hwmon/fam15h_power.c b/drivers/hwmon/fam15h_power.c
index 930370d..b7494af 100644
--- a/drivers/hwmon/fam15h_power.c
+++ b/drivers/hwmon/fam15h_power.c
@@ -61,14 +61,14 @@  static ssize_t show_power(struct device *dev,
 				  REG_TDP_RUNNING_AVERAGE, &val);
 	running_avg_capture = (val >> 4) & 0x3fffff;
 	running_avg_capture = sign_extend32(running_avg_capture, 21);
-	running_avg_range = val & 0xf;
+	running_avg_range = (val & 0xf) + 1;
 
 	pci_bus_read_config_dword(f4->bus, PCI_DEVFN(PCI_SLOT(f4->devfn), 5),
 				  REG_TDP_LIMIT3, &val);
 
 	tdp_limit = val >> 16;
-	curr_pwr_watts = tdp_limit + data->base_tdp -
-		(s32)(running_avg_capture >> (running_avg_range + 1));
+	curr_pwr_watts = (tdp_limit + data->base_tdp) << running_avg_range;
+	curr_pwr_watts -= running_avg_capture;
 	curr_pwr_watts *= data->tdp_to_watts;
 
 	/*
@@ -78,7 +78,7 @@  static ssize_t show_power(struct device *dev,
 	 * scaling factor 1/(2^16).  For conversion we use
 	 * (10^6)/(2^16) = 15625/(2^10)
 	 */
-	curr_pwr_watts = (curr_pwr_watts * 15625) >> 10;
+	curr_pwr_watts = (curr_pwr_watts * 15625) >> (10 + running_avg_range);
 	return sprintf(buf, "%u\n", (unsigned int) curr_pwr_watts);
 }
 static DEVICE_ATTR(power1_input, S_IRUGO, show_power, NULL);